OLD | NEW |
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:math' as math; | 5 import 'dart:math' as math; |
6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 | 7 |
8 import 'package:sky/base/debug.dart'; | 8 import 'package:sky/base/debug.dart'; |
9 import 'package:sky/painting/box_painter.dart'; | 9 import 'package:sky/painting/box_painter.dart'; |
10 import 'package:sky/rendering/object.dart'; | 10 import 'package:sky/rendering/object.dart'; |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 Rect childBounds = child.parentData.position & child.size; | 1242 Rect childBounds = child.parentData.position & child.size; |
1243 if (childBounds.contains(position + -scrollOffset)) | 1243 if (childBounds.contains(position + -scrollOffset)) |
1244 child.hitTest(result, position: position + scrollOffset); | 1244 child.hitTest(result, position: position + scrollOffset); |
1245 } | 1245 } |
1246 } | 1246 } |
1247 | 1247 |
1248 } | 1248 } |
1249 | 1249 |
1250 class RenderImage extends RenderBox { | 1250 class RenderImage extends RenderBox { |
1251 | 1251 |
1252 RenderImage(sky.Image image, Size requestedSize) | 1252 RenderImage(sky.Image image, Size requestedSize, { sky.ColorFilter colorFilter
}) |
1253 : _image = image, _requestedSize = requestedSize; | 1253 : _image = image, |
| 1254 _requestedSize = requestedSize, |
| 1255 _colorFilter = colorFilter; |
1254 | 1256 |
1255 sky.Image _image; | 1257 sky.Image _image; |
1256 sky.Image get image => _image; | 1258 sky.Image get image => _image; |
1257 void set image (sky.Image value) { | 1259 void set image (sky.Image value) { |
1258 if (value == _image) | 1260 if (value == _image) |
1259 return; | 1261 return; |
1260 _image = value; | 1262 _image = value; |
1261 markNeedsPaint(); | 1263 markNeedsPaint(); |
1262 if (_requestedSize.width == null || _requestedSize.height == null) | 1264 if (_requestedSize.width == null || _requestedSize.height == null) |
1263 markNeedsLayout(); | 1265 markNeedsLayout(); |
1264 } | 1266 } |
1265 | 1267 |
1266 Size _requestedSize; | 1268 Size _requestedSize; |
1267 Size get requestedSize => _requestedSize; | 1269 Size get requestedSize => _requestedSize; |
1268 void set requestedSize (Size value) { | 1270 void set requestedSize (Size value) { |
1269 if (value == null) | 1271 if (value == null) |
1270 value = const Size(null, null); | 1272 value = const Size(null, null); |
1271 if (value == _requestedSize) | 1273 if (value == _requestedSize) |
1272 return; | 1274 return; |
1273 _requestedSize = value; | 1275 _requestedSize = value; |
1274 markNeedsLayout(); | 1276 markNeedsLayout(); |
1275 } | 1277 } |
1276 | 1278 |
| 1279 sky.ColorFilter _colorFilter; |
| 1280 sky.ColorFilter get colorFilter => _colorFilter; |
| 1281 void set colorFilter (sky.ColorFilter value) { |
| 1282 if (value == _colorFilter) |
| 1283 return; |
| 1284 _colorFilter = value; |
| 1285 _cachedPaint = null; |
| 1286 markNeedsPaint(); |
| 1287 } |
| 1288 |
| 1289 Paint _cachedPaint; |
| 1290 Paint get _paint { |
| 1291 if (_cachedPaint == null) { |
| 1292 _cachedPaint = new Paint(); |
| 1293 if (colorFilter != null) |
| 1294 _cachedPaint.setColorFilter(colorFilter); |
| 1295 } |
| 1296 return _cachedPaint; |
| 1297 } |
| 1298 |
1277 Size _sizeForConstraints(BoxConstraints innerConstraints) { | 1299 Size _sizeForConstraints(BoxConstraints innerConstraints) { |
1278 // If there's no image, we can't size ourselves automatically | 1300 // If there's no image, we can't size ourselves automatically |
1279 if (_image == null) { | 1301 if (_image == null) { |
1280 double width = requestedSize.width == null ? 0.0 : requestedSize.width; | 1302 double width = requestedSize.width == null ? 0.0 : requestedSize.width; |
1281 double height = requestedSize.height == null ? 0.0 : requestedSize.height; | 1303 double height = requestedSize.height == null ? 0.0 : requestedSize.height; |
1282 return constraints.constrain(new Size(width, height)); | 1304 return constraints.constrain(new Size(width, height)); |
1283 } | 1305 } |
1284 | 1306 |
1285 if (!innerConstraints.isTight) { | 1307 if (!innerConstraints.isTight) { |
1286 // If neither height nor width are specified, use inherent image | 1308 // If neither height nor width are specified, use inherent image |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 return; | 1365 return; |
1344 bool needsScale = size.width != _image.width || size.height != _image.height
; | 1366 bool needsScale = size.width != _image.width || size.height != _image.height
; |
1345 if (needsScale) { | 1367 if (needsScale) { |
1346 double widthScale = size.width / _image.width; | 1368 double widthScale = size.width / _image.width; |
1347 double heightScale = size.height / _image.height; | 1369 double heightScale = size.height / _image.height; |
1348 canvas.save(); | 1370 canvas.save(); |
1349 canvas.translate(offset.dx, offset.dy); | 1371 canvas.translate(offset.dx, offset.dy); |
1350 canvas.scale(widthScale, heightScale); | 1372 canvas.scale(widthScale, heightScale); |
1351 offset = Offset.zero; | 1373 offset = Offset.zero; |
1352 } | 1374 } |
1353 canvas.drawImage(_image, offset.toPoint(), new Paint()); | 1375 canvas.drawImage(_image, offset.toPoint(), _paint); |
1354 if (needsScale) | 1376 if (needsScale) |
1355 canvas.restore(); | 1377 canvas.restore(); |
1356 } | 1378 } |
1357 | 1379 |
1358 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}dimensions: ${requestedSize}\n'; | 1380 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}dimensions: ${requestedSize}\n'; |
1359 } | 1381 } |
1360 | 1382 |
1361 class RenderDecoratedBox extends RenderProxyBox { | 1383 class RenderDecoratedBox extends RenderProxyBox { |
1362 | 1384 |
1363 RenderDecoratedBox({ | 1385 RenderDecoratedBox({ |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 | 1690 |
1669 void defaultPaint(PaintingCanvas canvas, Offset offset) { | 1691 void defaultPaint(PaintingCanvas canvas, Offset offset) { |
1670 RenderBox child = firstChild; | 1692 RenderBox child = firstChild; |
1671 while (child != null) { | 1693 while (child != null) { |
1672 assert(child.parentData is ParentDataType); | 1694 assert(child.parentData is ParentDataType); |
1673 canvas.paintChild(child, child.parentData.position + offset); | 1695 canvas.paintChild(child, child.parentData.position + offset); |
1674 child = child.parentData.nextSibling; | 1696 child = child.parentData.nextSibling; |
1675 } | 1697 } |
1676 } | 1698 } |
1677 } | 1699 } |
OLD | NEW |