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

Side by Side Diff: sky/sdk/lib/framework/rendering/box.dart

Issue 1152273004: Add support for transforms to container (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/sdk/lib/framework/fn2.dart ('k') | sky/sdk/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:sky' as sky;
6 import 'dart:typed_data';
5 import 'node.dart'; 7 import 'node.dart';
6 import 'dart:sky' as sky; 8 import 'package:vector_math/vector_math.dart';
7 9
8 // GENERIC BOX RENDERING 10 // GENERIC BOX RENDERING
9 // Anything that has a concept of x, y, width, height is going to derive from th is 11 // Anything that has a concept of x, y, width, height is going to derive from th is
10 12
11 class EdgeDims { 13 class EdgeDims {
12 // used for e.g. padding 14 // used for e.g. padding
13 const EdgeDims(this.top, this.right, this.bottom, this.left); 15 const EdgeDims(this.top, this.right, this.bottom, this.left);
14 const EdgeDims.all(double value) 16 const EdgeDims.all(double value)
15 : top = value, right = value, bottom = value, left = value; 17 : top = value, right = value, bottom = value, left = value;
16 18
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 278
277 if (_decoration == null) 279 if (_decoration == null)
278 return; 280 return;
279 281
280 if (_decoration.backgroundColor != null) { 282 if (_decoration.backgroundColor != null) {
281 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; 283 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor;
282 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint); 284 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint);
283 } 285 }
284 super.paint(canvas); 286 super.paint(canvas);
285 } 287 }
288 }
286 289
290 class RenderTransform extends RenderProxyBox {
291 RenderTransform({
292 Matrix4 transform,
293 RenderBox child
294 }) : super(child) {
295 assert(transform != null);
296 this.transform = transform;
297 }
298
299 Matrix4 _transform;
300
301 void set transform (Matrix4 value) {
302 assert(value != null);
303 if (_transform == value)
304 return;
305 _transform = new Matrix4.copy(value);
306 markNeedsPaint();
307 }
308
309 void rotateX(double radians) {
310 _transform.rotateX(radians);
311 markNeedsPaint();
312 }
313
314 void rotateY(double radians) {
315 _transform.rotateY(radians);
316 markNeedsPaint();
317 }
318
319 void rotateZ(double radians) {
320 _transform.rotateZ(radians);
321 markNeedsPaint();
322 }
323
324 void translate(x, [double y=0.0, double z=0.0]) {
eseidel 2015/06/03 17:16:18 Does the style put a space around these or not?
325 _transform.translate(x, y, z);
326 markNeedsPaint();
327 }
328
329 void scale(x, [double y=null, double z=null]) {
330 _transform.scale(x, y, z);
331 markNeedsPaint();
332 }
333
334 void hitTestChildren(HitTestResult result, { sky.Point position }) {
335 Matrix4 inverse = new Matrix4.zero();
336 double det = inverse.copyInverse(_transform);
337 // TODO(abarth): Check the determinant for degeneracy.
338
339 Vector3 position3 = new Vector3(position.x, position.y, 0.0);
340 Vector3 transformed3 = inverse.transform3(position3);
341 sky.Point transformed = new sky.Point(transformed3.x, transformed3.y);
342 super.hitTestChildren(result, position: transformed);
343 }
344
345 void paint(RenderNodeDisplayList canvas) {
346 Float32List storage = _transform.storage;
347
348 canvas.save();
349 canvas.concat([
350 storage[ 0], storage[ 1], storage[ 3],
351 storage[ 4], storage[ 5], storage[ 7],
352 storage[12], storage[13], storage[15],
353 ]);
354 super.paint(canvas);
355 canvas.restore();
356 }
287 } 357 }
288 358
289 359
290 // RENDER VIEW LAYOUT MANAGER 360 // RENDER VIEW LAYOUT MANAGER
291 361
292 class ViewConstraints { 362 class ViewConstraints {
293 363
294 const ViewConstraints({ 364 const ViewConstraints({
295 this.width: 0.0, this.height: 0.0, this.orientation: null 365 this.width: 0.0, this.height: 0.0, this.orientation: null
296 }); 366 });
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 457
388 void defaultPaint(RenderNodeDisplayList canvas) { 458 void defaultPaint(RenderNodeDisplayList canvas) {
389 RenderBox child = firstChild; 459 RenderBox child = firstChild;
390 while (child != null) { 460 while (child != null) {
391 assert(child.parentData is ParentDataType); 461 assert(child.parentData is ParentDataType);
392 canvas.paintChild(child, child.parentData.position); 462 canvas.paintChild(child, child.parentData.position);
393 child = child.parentData.nextSibling; 463 child = child.parentData.nextSibling;
394 } 464 }
395 } 465 }
396 } 466 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/fn2.dart ('k') | sky/sdk/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698