Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: sky/examples/game/lib/sprite_box.dart

Issue 1190393004: Sprites correctly handles zPosition (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/examples/game/lib/node_with_size.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 part of sprites; 1 part of sprites;
2 2
3 enum SpriteBoxTransformMode { 3 enum SpriteBoxTransformMode {
4 nativePoints, 4 nativePoints,
5 letterbox, 5 letterbox,
6 stretch, 6 stretch,
7 scaleToFit, 7 scaleToFit,
8 fixedWidth, 8 fixedWidth,
9 fixedHeight, 9 fixedHeight,
10 } 10 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 void performLayout() { 68 void performLayout() {
69 size = constraints.constrain(Size.infinite); 69 size = constraints.constrain(Size.infinite);
70 _invalidateTransformMatrix(); 70 _invalidateTransformMatrix();
71 _callSpriteBoxPerformedLayout(_rootNode); 71 _callSpriteBoxPerformedLayout(_rootNode);
72 } 72 }
73 73
74 // Event handling 74 // Event handling
75 75
76 void _addEventTargets(Node node, List<Node> eventTargets) { 76 void _addEventTargets(Node node, List<Node> eventTargets) {
77 List children = node.children;
78 int i = 0;
79
80 // Add childrens that are behind this node
81 while (i < children.length) {
82 Node child = children[i];
83 if (child.zPosition >= 0.0) break;
84 _addEventTargets(child, eventTargets);
85 i++;
86 }
87
88 // Add this node
77 if (node.userInteractionEnabled) { 89 if (node.userInteractionEnabled) {
78 eventTargets.add(node); 90 eventTargets.add(node);
79 } 91 }
80 for (Node child in node.children) { 92
93 // Add children in front of this node
94 while (i < children.length) {
95 Node child = children[i];
81 _addEventTargets(child, eventTargets); 96 _addEventTargets(child, eventTargets);
97 i++;
82 } 98 }
83 } 99 }
84 100
85 void handleEvent(Event event, SpriteBoxHitTestEntry entry) { 101 void handleEvent(Event event, SpriteBoxHitTestEntry entry) {
86 if (event is PointerEvent) { 102 if (event is PointerEvent) {
87 103
88 if (event.type == 'pointerdown') { 104 if (event.type == 'pointerdown') {
89 // Build list of event targets 105 // Build list of event targets
90 if (_eventTargets == null) { 106 if (_eventTargets == null) {
91 _eventTargets = []; 107 _eventTargets = [];
92 _addEventTargets(_rootNode, _eventTargets); 108 _addEventTargets(_rootNode, _eventTargets);
93 } 109 }
94 110
95 // Find the once that are hit by the pointer 111 // Find the once that are hit by the pointer
96 List<Node> nodeTargets = []; 112 List<Node> nodeTargets = [];
97 for (int i = _eventTargets.length - 1; i >= 0; i--) { 113 for (int i = _eventTargets.length - 1; i >= 0; i--) {
98 Node node = _eventTargets[i]; 114 Node node = _eventTargets[i];
99 115
100 // Check if the node is ready to handle a pointer 116 // Check if the node is ready to handle a pointer
101 if (node.handleMultiplePointers || node._handlingPointer == null) { 117 if (node.handleMultiplePointers || node._handlingPointer == null) {
102 // Do the hit test 118 // Do the hit test
103 Point posInNodeSpace = node.convertPointToNodeSpace(entry.localPosit ion); 119 Point posInNodeSpace = node.convertPointToNodeSpace(entry.localPosit ion);
104 if (node.hitTest(posInNodeSpace)) { 120 if (node.isPointInside(posInNodeSpace)) {
105 nodeTargets.add(node); 121 nodeTargets.add(node);
106 node._handlingPointer = event.pointer; 122 node._handlingPointer = event.pointer;
107 } 123 }
108 } 124 }
109 } 125 }
110 126
111 entry.nodeTargets = nodeTargets; 127 entry.nodeTargets = nodeTargets;
112 } 128 }
113 129
114 // Pass the event down to nodes that were hit by the pointerdown 130 // Pass the event down to nodes that were hit by the pointerdown
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 _rootNode._invalidateToBoxTransformMatrix(); 230 _rootNode._invalidateToBoxTransformMatrix();
215 } 231 }
216 232
217 void paint(RenderObjectDisplayList canvas) { 233 void paint(RenderObjectDisplayList canvas) {
218 canvas.save(); 234 canvas.save();
219 235
220 // Move to correct coordinate space before drawing 236 // Move to correct coordinate space before drawing
221 canvas.concat(transformMatrix.storage); 237 canvas.concat(transformMatrix.storage);
222 238
223 // Draw the sprite tree 239 // Draw the sprite tree
224 _rootNode.visit(canvas); 240 _rootNode._visit(canvas);
225 241
226 canvas.restore(); 242 canvas.restore();
227 } 243 }
228 244
229 // Updates 245 // Updates
230 246
231 int _animationId = 0; 247 int _animationId = 0;
232 248
233 void _scheduleTick() { 249 void _scheduleTick() {
234 _animationId = scheduler.requestAnimationFrame(_tick); 250 _animationId = scheduler.requestAnimationFrame(_tick);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 return nodes; 298 return nodes;
283 } 299 }
284 300
285 _addNodesAtPosition(Node node, Point position, List<Node> list) { 301 _addNodesAtPosition(Node node, Point position, List<Node> list) {
286 // Visit children first 302 // Visit children first
287 for (Node child in node.children) { 303 for (Node child in node.children) {
288 _addNodesAtPosition(child, position, list); 304 _addNodesAtPosition(child, position, list);
289 } 305 }
290 // Do the hit test 306 // Do the hit test
291 Point posInNodeSpace = node.convertPointToNodeSpace(position); 307 Point posInNodeSpace = node.convertPointToNodeSpace(position);
292 if (node.hitTest(posInNodeSpace)) { 308 if (node.isPointInside(posInNodeSpace)) {
293 list.add(node); 309 list.add(node);
294 } 310 }
295 } 311 }
296 } 312 }
297 313
298 class SpriteBoxHitTestEntry extends BoxHitTestEntry { 314 class SpriteBoxHitTestEntry extends BoxHitTestEntry {
299 List<Node> nodeTargets; 315 List<Node> nodeTargets;
300 SpriteBoxHitTestEntry(RenderBox target, Point localPosition) : super(target, l ocalPosition); 316 SpriteBoxHitTestEntry(RenderBox target, Point localPosition) : super(target, l ocalPosition);
301 } 317 }
302 318
303 class SpriteBoxEvent { 319 class SpriteBoxEvent {
304 Point boxPosition; 320 Point boxPosition;
305 String type; 321 String type;
306 int pointer; 322 int pointer;
307 323
308 SpriteBoxEvent(this.boxPosition, this.type, this.pointer); 324 SpriteBoxEvent(this.boxPosition, this.type, this.pointer);
309 } 325 }
OLDNEW
« no previous file with comments | « sky/examples/game/lib/node_with_size.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698