Commit 99112425 authored by Ian Hickson's avatar Ian Hickson

Merge pull request #1143 from Hixie/GridPaper

GridPaper updates
parents 8899fe5a d502d237
...@@ -10,29 +10,38 @@ import 'framework.dart'; ...@@ -10,29 +10,38 @@ import 'framework.dart';
class _GridPaperPainter extends CustomPainter { class _GridPaperPainter extends CustomPainter {
const _GridPaperPainter({ const _GridPaperPainter({
this.color, this.color,
this.interval this.interval,
this.divisions,
this.subDivisions
}); });
final Color color; final Color color;
final double interval; final double interval;
final int divisions;
final int subDivisions;
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
Paint linePaint = new Paint() Paint linePaint = new Paint()
..color = color; ..color = color;
for (double x = 0.0; x <= size.width; x += interval / 10.0) { double allDivisions = (divisions * subDivisions).toDouble();
linePaint.strokeWidth = (x % interval == 0.0) ? 1.0 : (x % (interval / 2.0) == 0.0) ? 0.5: 0.25; for (double x = 0.0; x <= size.width; x += interval / allDivisions) {
linePaint.strokeWidth = (x % interval == 0.0) ? 1.0 : (x % (interval / subDivisions) == 0.0) ? 0.5: 0.25;
canvas.drawLine(new Point(x, 0.0), new Point(x, size.height), linePaint); canvas.drawLine(new Point(x, 0.0), new Point(x, size.height), linePaint);
} }
for (double y = 0.0; y <= size.height; y += interval / 10.0) { for (double y = 0.0; y <= size.height; y += interval / allDivisions) {
linePaint.strokeWidth = (y % interval == 0.0) ? 1.0 : (y % (interval / 2.0) == 0.0) ? 0.5: 0.25; linePaint.strokeWidth = (y % interval == 0.0) ? 1.0 : (y % (interval / subDivisions) == 0.0) ? 0.5: 0.25;
canvas.drawLine(new Point(0.0, y), new Point(size.width, y), linePaint); canvas.drawLine(new Point(0.0, y), new Point(size.width, y), linePaint);
} }
} }
bool shouldRepaint(_GridPaperPainter oldPainter) { bool shouldRepaint(_GridPaperPainter oldPainter) {
return oldPainter.color != color return oldPainter.color != color
|| oldPainter.interval != interval; || oldPainter.interval != interval
|| oldPainter.divisions != divisions
|| oldPainter.subDivisions != subDivisions;
} }
bool hitTest(Point position) => false;
} }
/// Draws a rectalinear grid of 1px width lines at the specified color and interval. /// Draws a rectalinear grid of 1px width lines at the specified color and interval.
...@@ -40,21 +49,28 @@ class _GridPaperPainter extends CustomPainter { ...@@ -40,21 +49,28 @@ class _GridPaperPainter extends CustomPainter {
class GridPaper extends StatelessComponent { class GridPaper extends StatelessComponent {
GridPaper({ GridPaper({
Key key, Key key,
this.color: const Color(0xFF000000), this.color: const Color(0x7FC3E8F3),
this.interval: 100.0 this.interval: 100.0,
this.divisions: 2,
this.subDivisions: 5,
this.child
}) : super(key: key); }) : super(key: key);
final Color color; final Color color;
final double interval; final double interval;
final int divisions;
final int subDivisions;
final Widget child;
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new IgnorePointer( return new CustomPaint(
child: new CustomPaint( foregroundPainter: new _GridPaperPainter(
painter: new _GridPaperPainter( color: color,
color: color, interval: interval,
interval: interval divisions: divisions,
) subDivisions: subDivisions
) ),
child: child
); );
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment