| OLD | NEW |
| 1 part of sprites; | 1 part of sprites; |
| 2 | 2 |
| 3 double convertDegrees2Radians(double degrees) => degrees * Math.PI/180.8; | 3 double convertDegrees2Radians(double degrees) => degrees * Math.PI/180.8; |
| 4 | 4 |
| 5 double convertRadians2Degrees(double radians) => radians * 180.0/Math.PI; | 5 double convertRadians2Degrees(double radians) => radians * 180.0/Math.PI; |
| 6 | 6 |
| 7 class Node { | 7 class Node { |
| 8 | 8 |
| 9 // Member variables | 9 // Member variables |
| 10 | 10 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 assert(_scaleX == _scaleY); | 86 assert(_scaleX == _scaleY); |
| 87 return _scaleX; | 87 return _scaleX; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void set scale(double scale) { | 90 void set scale(double scale) { |
| 91 assert(scale != null); | 91 assert(scale != null); |
| 92 _scaleX = _scaleY = scale; | 92 _scaleX = _scaleY = scale; |
| 93 _invalidateTransformMatrix(); | 93 _invalidateTransformMatrix(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 List<Node> get children => _children; | 96 double get scaleX => _scaleX; |
| 97 |
| 98 void set scaleX(double scaleX) { |
| 99 assert(scaleX != null); |
| 100 _scaleX = scaleX; |
| 101 _invalidateTransformMatrix(); |
| 102 } |
| 103 |
| 104 double get scaleY => _scaleY; |
| 105 |
| 106 void set scaleY(double scaleY) { |
| 107 assert(scaleY != null); |
| 108 _scaleY = scaleY; |
| 109 _invalidateTransformMatrix(); |
| 110 } |
| 111 |
| 112 List<Node> get children { |
| 113 _sortChildren(); |
| 114 return _children; |
| 115 } |
| 97 | 116 |
| 98 // Adding and removing children | 117 // Adding and removing children |
| 99 | 118 |
| 100 void addChild(Node child) { | 119 void addChild(Node child) { |
| 101 assert(child != null); | 120 assert(child != null); |
| 102 assert(child._parent == null); | 121 assert(child._parent == null); |
| 103 | 122 |
| 104 _childrenNeedSorting = true; | 123 _childrenNeedSorting = true; |
| 105 _children.add(child); | 124 _children.add(child); |
| 106 child._parent = this; | 125 child._parent = this; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 127 void removeAllChildren() { | 146 void removeAllChildren() { |
| 128 for (Node child in _children) { | 147 for (Node child in _children) { |
| 129 child._parent = null; | 148 child._parent = null; |
| 130 child._spriteBox = null; | 149 child._spriteBox = null; |
| 131 } | 150 } |
| 132 _children = []; | 151 _children = []; |
| 133 _childrenNeedSorting = false; | 152 _childrenNeedSorting = false; |
| 134 if (_spriteBox != null) _spriteBox._eventTargets = null; | 153 if (_spriteBox != null) _spriteBox._eventTargets = null; |
| 135 } | 154 } |
| 136 | 155 |
| 156 void _sortChildren() { |
| 157 // Sort children primarily by zPosition, secondarily by added order |
| 158 if (_childrenNeedSorting) { |
| 159 _children.sort((Node a, Node b) { |
| 160 if (a._zPosition == b._zPosition) { |
| 161 return a._addedOrder - b._addedOrder; |
| 162 } |
| 163 else if (a._zPosition > b._zPosition) { |
| 164 return 1; |
| 165 } |
| 166 else { |
| 167 return -1; |
| 168 } |
| 169 }); |
| 170 _childrenNeedSorting = false; |
| 171 } |
| 172 } |
| 173 |
| 137 // Calculating the transformation matrix | 174 // Calculating the transformation matrix |
| 138 | 175 |
| 139 Matrix4 get transformMatrix { | 176 Matrix4 get transformMatrix { |
| 140 if (_transformMatrix != null) { | 177 if (_transformMatrix != null) { |
| 141 return _transformMatrix; | 178 return _transformMatrix; |
| 142 } | 179 } |
| 143 | 180 |
| 144 double cx, sx, cy, sy; | 181 double cx, sx, cy, sy; |
| 145 | 182 |
| 146 if (_rotation == 0.0) { | 183 if (_rotation == 0.0) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 assert(_spriteBox == node._spriteBox); | 274 assert(_spriteBox == node._spriteBox); |
| 238 | 275 |
| 239 Point boxPoint = node.convertPointToBoxSpace(point); | 276 Point boxPoint = node.convertPointToBoxSpace(point); |
| 240 Point localPoint = convertPointToNodeSpace(boxPoint); | 277 Point localPoint = convertPointToNodeSpace(boxPoint); |
| 241 | 278 |
| 242 return localPoint; | 279 return localPoint; |
| 243 } | 280 } |
| 244 | 281 |
| 245 // Hit test | 282 // Hit test |
| 246 | 283 |
| 247 bool hitTest(Point nodePoint) { | 284 bool isPointInside(Point nodePoint) { |
| 248 assert(nodePoint != null); | 285 assert(nodePoint != null); |
| 249 | 286 |
| 250 return false; | 287 return false; |
| 251 } | 288 } |
| 252 | 289 |
| 253 // Rendering | 290 // Rendering |
| 254 | 291 |
| 255 void visit(PictureRecorder canvas) { | 292 void _visit(PictureRecorder canvas) { |
| 256 assert(canvas != null); | 293 assert(canvas != null); |
| 257 if (!visible) return; | 294 if (!visible) return; |
| 258 | 295 |
| 259 prePaint(canvas); | 296 _prePaint(canvas); |
| 260 paint(canvas); | 297 _visitChildren(canvas); |
| 261 visitChildren(canvas); | 298 _postPaint(canvas); |
| 262 postPaint(canvas); | |
| 263 } | 299 } |
| 264 | 300 |
| 265 void prePaint(PictureRecorder canvas) { | 301 void _prePaint(PictureRecorder canvas) { |
| 266 canvas.save(); | 302 canvas.save(); |
| 267 | 303 |
| 268 // Get the transformation matrix and apply transform | 304 // Get the transformation matrix and apply transform |
| 269 canvas.concat(transformMatrix.storage); | 305 canvas.concat(transformMatrix.storage); |
| 270 } | 306 } |
| 271 | 307 |
| 272 void paint(PictureRecorder canvas) { | 308 void paint(PictureRecorder canvas) { |
| 273 } | 309 } |
| 274 | 310 |
| 275 void visitChildren(PictureRecorder canvas) { | 311 void _visitChildren(PictureRecorder canvas) { |
| 276 // Sort children primarily by zPosition, secondarily by added order | 312 // Sort children if needed |
| 277 if (_childrenNeedSorting) { | 313 _sortChildren(); |
| 278 _children.sort((Node a, Node b) { | 314 |
| 279 if (a._zPosition == b._zPosition) { | 315 int i = 0; |
| 280 return a._addedOrder - b._addedOrder; | 316 |
| 281 } | 317 // Visit children behind this node |
| 282 else if (a._zPosition > b._zPosition) { | 318 while (i < _children.length) { |
| 283 return 1; | 319 Node child = _children[i]; |
| 284 } | 320 if (child.zPosition >= 0.0) break; |
| 285 else { | 321 child._visit(canvas); |
| 286 return -1; | 322 i++; |
| 287 } | |
| 288 }); | |
| 289 _childrenNeedSorting = false; | |
| 290 } | 323 } |
| 291 | 324 |
| 292 // Visit each child | 325 // Paint this node |
| 293 _children.forEach((child) => child.visit(canvas)); | 326 paint(canvas); |
| 327 |
| 328 // Visit children in front of this node |
| 329 while (i < _children.length) { |
| 330 Node child = _children[i]; |
| 331 child._visit(canvas); |
| 332 i++; |
| 333 } |
| 294 } | 334 } |
| 295 | 335 |
| 296 void postPaint(PictureRecorder canvas) { | 336 void _postPaint(PictureRecorder canvas) { |
| 297 canvas.restore(); | 337 canvas.restore(); |
| 298 } | 338 } |
| 299 | 339 |
| 300 // Receiving update calls | 340 // Receiving update calls |
| 301 | 341 |
| 302 void update(double dt) { | 342 void update(double dt) { |
| 303 } | 343 } |
| 304 | 344 |
| 305 void spriteBoxPerformedLayout() { | 345 void spriteBoxPerformedLayout() { |
| 306 } | 346 } |
| 307 | 347 |
| 308 // Handling user interaction | 348 // Handling user interaction |
| 309 | 349 |
| 310 bool get userInteractionEnabled => _userInteractionEnabled; | 350 bool get userInteractionEnabled => _userInteractionEnabled; |
| 311 | 351 |
| 312 void set userInteractionEnabled(bool userInteractionEnabled) { | 352 void set userInteractionEnabled(bool userInteractionEnabled) { |
| 313 _userInteractionEnabled = userInteractionEnabled; | 353 _userInteractionEnabled = userInteractionEnabled; |
| 314 if (_spriteBox != null) _spriteBox._eventTargets = null; | 354 if (_spriteBox != null) _spriteBox._eventTargets = null; |
| 315 } | 355 } |
| 316 | 356 |
| 317 bool handleEvent(SpriteBoxEvent event) { | 357 bool handleEvent(SpriteBoxEvent event) { |
| 318 return false; | 358 return false; |
| 319 } | 359 } |
| 320 } | 360 } |
| OLD | NEW |