From 8fc3f35321eaa1c56cc948da55aa106d4cdc8773 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 8 Jul 2018 19:01:14 +0200 Subject: [PATCH] Add Edge Rendering with Toggle Button --- lib/app_component.dart | 4 ++++ lib/app_component.html | 1 + lib/src/Grid.dart | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/lib/app_component.dart b/lib/app_component.dart index c23443e..2b54300 100644 --- a/lib/app_component.dart +++ b/lib/app_component.dart @@ -52,4 +52,8 @@ class AppComponent implements OnInit { engine.running = false; engine.grid.addPattern(); } + + void onEdgesClicked() { + engine.grid.switchEdgeRendering(); + } } diff --git a/lib/app_component.html b/lib/app_component.html index 366ce7b..d9e7dfa 100644 --- a/lib/app_component.html +++ b/lib/app_component.html @@ -17,4 +17,5 @@ Speed: + \ No newline at end of file diff --git a/lib/src/Grid.dart b/lib/src/Grid.dart index 062a78c..468d648 100644 --- a/lib/src/Grid.dart +++ b/lib/src/Grid.dart @@ -12,6 +12,8 @@ class Grid { final List> map; bool _dirty = true; + bool _renderEdges = true; + int _startingSeed; int _x; int _y; @@ -174,8 +176,14 @@ class Grid { int brickW = (canvas.width ~/ map[0].length); int brickH = (canvas.height ~/ map.length); ctx.clearRect(0, 0, canvas.width, canvas.height); + for (int y = 0; y < map.length; y++) { for (int x = 0; x < map[y].length; x++) { + if(_renderEdges) { + ctx.setStrokeColorRgb(100, 100, 100); + ctx.strokeRect(x * brickW, y * brickH, brickW, brickH); + } + Cell c = map[y][x]; if (c.state == true) ctx.setFillColorRgb(155, 155, 255); @@ -187,4 +195,9 @@ class Grid { _dirty = false; } + + void switchEdgeRendering([bool on]) { + _renderEdges = on ?? !_renderEdges; + _dirty = true; + } }