From d4812be0a821a6b0f393718e80a10cdf8ad34024 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 9 Jan 2019 16:19:50 +1200 Subject: [PATCH] Cleaning up specs --- desktop/sources/scripts/cursor.js | 2 +- desktop/sources/scripts/dotgrid.js | 25 +++++++++++-------------- desktop/sources/scripts/renderer.js | 8 ++++---- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js index 5eb0fd3..8f979c2 100644 --- a/desktop/sources/scripts/cursor.js +++ b/desktop/sources/scripts/cursor.js @@ -89,7 +89,7 @@ function Cursor () { } this.pos_snap = function (pos) { - const grid = DOTGRID.tool.settings.size.width / DOTGRID.grid_x + const grid = DOTGRID.tool.settings.size.width / DOTGRID.grid.x return { x: clamp(step(pos.x, grid), grid, DOTGRID.tool.settings.size.width), y: clamp(step(pos.y, grid), grid, DOTGRID.tool.settings.size.height + grid) diff --git a/desktop/sources/scripts/dotgrid.js b/desktop/sources/scripts/dotgrid.js index 2b3de75..e67ef91 100644 --- a/desktop/sources/scripts/dotgrid.js +++ b/desktop/sources/scripts/dotgrid.js @@ -1,6 +1,6 @@ 'use strict' -function Dotgrid (width, height, grid_x, grid_y, block_x, block_y) { +function Dotgrid (width, height) { this.controller = null const defaultTheme = { background: '#eee', f_high: '#000', f_med: '#999', f_low: '#ccc', f_inv: '#000', b_high: '#000', b_med: '#888', b_low: '#aaa', b_inv: '#ffb545' } @@ -8,10 +8,7 @@ function Dotgrid (width, height, grid_x, grid_y, block_x, block_y) { this.theme = new Theme(defaultTheme) this.history = new History() - this.grid_x = grid_x - this.grid_y = grid_y - this.block_x = block_x - this.block_y = block_y + this.grid = {x:20,y:20} // ISU @@ -121,11 +118,11 @@ function Dotgrid (width, height, grid_x, grid_y, block_x, block_y) { console.log('No window') } - this.grid_x = size.width / 15 - this.grid_y = size.height / 15 + this.grid.x = size.width / 15 + this.grid.y = size.height / 15 - this.grid_width = this.tool.settings.size.width / this.grid_x - this.grid_height = this.tool.settings.size.height / this.grid_y + this.grid_width = this.tool.settings.size.width / this.grid.x + this.grid_height = this.tool.settings.size.height / this.grid.y DOTGRID.renderer.resize(size) @@ -170,11 +167,11 @@ function Dotgrid (width, height, grid_x, grid_y, block_x, block_y) { DOTGRID.tool.settings.size.width = size.width DOTGRID.tool.settings.size.height = size.height - DOTGRID.grid_x = size.width / 15 - DOTGRID.grid_y = size.height / 15 + DOTGRID.grid.x = size.width / 15 + DOTGRID.grid.y = size.height / 15 - DOTGRID.grid_width = DOTGRID.tool.settings.size.width / DOTGRID.grid_x - DOTGRID.grid_height = DOTGRID.tool.settings.size.height / DOTGRID.grid_y + DOTGRID.grid_width = DOTGRID.tool.settings.size.width / DOTGRID.grid.x + DOTGRID.grid_height = DOTGRID.tool.settings.size.height / DOTGRID.grid.y DOTGRID.renderer.resize(size) @@ -263,4 +260,4 @@ function isEqual (a, b) { return a && b && a.x == b.x && a.y == b.y } function clamp (v, min, max) { return v < min ? min : v > max ? max : v } function step (v, s) { return Math.round(v / s) * s } -const DOTGRID = new Dotgrid(300, 300, 20, 20, 4, 4) +const DOTGRID = new Dotgrid(300, 300) diff --git a/desktop/sources/scripts/renderer.js b/desktop/sources/scripts/renderer.js index e6b8b00..03d8ab7 100644 --- a/desktop/sources/scripts/renderer.js +++ b/desktop/sources/scripts/renderer.js @@ -93,12 +93,12 @@ function Renderer (dotgrid) { const cursor = { x: parseInt(dotgrid.cursor.pos.x / dotgrid.grid_width), y: parseInt(dotgrid.cursor.pos.y / dotgrid.grid_width) } - for (let x = dotgrid.grid_x - 1; x >= 0; x--) { - for (let y = dotgrid.grid_y; y >= 0; y--) { - let is_step = x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0 + for (let x = dotgrid.grid.x - 1; x >= 0; x--) { + for (let y = dotgrid.grid.y; y >= 0; y--) { + let is_step = x % 4 == 0 && y % 4 == 0 // Color let color = is_step ? dotgrid.theme.active.b_med : dotgrid.theme.active.b_low - if ((y == 0 || y == dotgrid.grid_y) && cursor.x == x + 1) { color = dotgrid.theme.active.b_high } else if ((x == 0 || x == dotgrid.grid_x - 1) && cursor.y == y + 1) { color = dotgrid.theme.active.b_high } else if (cursor.x == x + 1 && cursor.y == y + 1) { color = dotgrid.theme.active.b_high } + if ((y == 0 || y == dotgrid.grid.y) && cursor.x == x + 1) { color = dotgrid.theme.active.b_high } else if ((x == 0 || x == dotgrid.grid.x - 1) && cursor.y == y + 1) { color = dotgrid.theme.active.b_high } else if (cursor.x == x + 1 && cursor.y == y + 1) { color = dotgrid.theme.active.b_high } this.drawMarker({ x: parseInt(x * dotgrid.grid_width) + dotgrid.grid_width,