From 2042b541a899c48f53639b0bca37abf568fc20b7 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 14 Nov 2017 08:45:31 +1300 Subject: [PATCH] Improved shortcuts further --- BUILD.md | 2 -- main.js | 2 +- sources/index.html | 4 ++-- sources/links/main.css | 12 +++++++----- sources/scripts/dotgrid.js | 19 +++++++++---------- sources/scripts/keyboard.js | 8 ++++---- sources/scripts/pos.js | 12 ++++++++++++ 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/BUILD.md b/BUILD.md index 9957f98..f21452a 100644 --- a/BUILD.md +++ b/BUILD.md @@ -32,8 +32,6 @@ cd /xxiivv/Nataniev/public/public.projects/builds/ rm -r /xxiivv/Nataniev/public/public.projects/builds/Dotgrid-darwin-x64/ rm -r /xxiivv/Nataniev/public/public.projects/builds/Dotgrid-linux-x64/ rm -r /xxiivv/Nataniev/public/public.projects/builds/Dotgrid-win32-x64/ - - ``` diff --git a/main.js b/main.js index 9483787..69d88a8 100644 --- a/main.js +++ b/main.js @@ -6,7 +6,7 @@ let win app.on('ready', () => { - win = new BrowserWindow({width: 390, height: 420, minWidth: 390, minHeight: 420, maxWidth: 390, maxHeight: 420, backgroundColor:"#000", frame:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'}) + win = new BrowserWindow({width: 400, height: 420, minWidth: 400, minHeight: 420, maxWidth: 400, maxHeight: 420, backgroundColor:"#000", frame:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'}) win.loadURL(`file://${__dirname}/sources/index.html`) diff --git a/sources/index.html b/sources/index.html index 136a8ed..58ac096 100644 --- a/sources/index.html +++ b/sources/index.html @@ -20,12 +20,12 @@ const {dialog,app} = require('electron').remote; const fs = require('fs'); - dotgrid = new Dotgrid(300,300,30,30,5,5, 10,"square","#000000"); + dotgrid = new Dotgrid(300,300,20,20,4,4, 10,"square","#000000"); dotgrid.install(); var keyboard = new Keyboard(); - document.onkeydown = function myFunction(event){ keyboard.listen(event); }; + document.onkeyup = function myFunction(event){ keyboard.listen(event); }; document.addEventListener('mousedown', function(e){ dotgrid.mouse_down(e); }, false); document.addEventListener('mousemove', function(e){ dotgrid.mouse_move(e); }, false); document.addEventListener('mouseup', function(e){ dotgrid.mouse_up(e);}, false); diff --git a/sources/links/main.css b/sources/links/main.css index 6e72396..3798c84 100644 --- a/sources/links/main.css +++ b/sources/links/main.css @@ -1,14 +1,14 @@ body { background:#fff; padding: 5px; font-family: 'input_mono_regular'; -webkit-user-select: none; overflow: hidden;} #wrapper { width: calc(100% - 50px); height: calc(100% - 50px); padding: 25px; background: inherit; -webkit-app-region: drag;} -#dotgrid { margin:0px auto; position:relative; overflow: hidden; padding:10px;-webkit-app-region: no-drag;} -#cursor { width:8px; height:8px; margin-top:-5px; margin-left:-5px; position:absolute; z-index:25; border-radius:5px; border:1px solid black;} +#dotgrid { margin:0px auto; position:relative; overflow: hidden; padding:10px;-webkit-app-region: no-drag; width:310px !important; height:310px !important;} +#cursor { opacity: 1; transition: all 50ms; width:8px; height:8px; margin-top:-5px; margin-left:-5px; position:absolute; z-index:25; border-radius:5px; border:1px solid black;} #cursor_coord { font-size:10px; z-index: 10000; margin-left:15px; margin-top:-2px;} #cursor_coord.left { margin-left:-110px; text-align: right; width:100px; } #cursor_from { width:4px; height:4px; background:white; margin-top:-3px; margin-left:-3px; position:absolute; z-index:2500; border-radius:10px; left:-100px;border:1px solid black;} #cursor_to { width:4px; height:4px; background:white; margin-top:-3px; margin-left:-3px; position:absolute; z-index:2500; border-radius:10px; left:-100px; border:1px solid black;} #cursor_end { width:4px; height:4px; background:white; margin-top:-3px; margin-left:-3px; position:absolute; z-index:2500; border-radius:10px; left:-100px; border:1px solid black;} -#interface { max-width: 295px;margin:0px auto;font-size: 11px;line-height: 30px; text-transform: uppercase; margin-top:20px;-webkit-app-region: no-drag;} + #guide,#widgets { position: absolute;top: 0px;left: 0px; width: 300px;height: 300px;} #widgets { z-index: 9000 } #render { display: none } @@ -18,9 +18,11 @@ body { background:#fff; padding: 5px; font-family: 'input_mono_regular'; -webkit .icon.inactive { opacity: 0.1 !important } .icon:hover { cursor: pointer; opacity: 1 } -svg.vector { z-index: 1000;position: relative } +svg.vector { z-index: 1000;position: relative; left:5px; top:5px; } #dotgrid #guide { opacity: 0; transition: all 500ms; } -#dotgrid #widgets { opacity: 0; transition: all 150ms; } +#dotgrid #widgets { opacity: 0; transition: all 150ms; left: 5px;top: 5px; } #dotgrid:hover #guide { opacity: 1 } #dotgrid:hover #widgets { opacity: 1 } + +#interface { max-width: 295px;margin:0px auto;font-size: 11px;line-height: 30px; text-transform: uppercase; margin-top:15px;-webkit-app-region: no-drag;} \ No newline at end of file diff --git a/sources/scripts/dotgrid.js b/sources/scripts/dotgrid.js index 8eae569..711cde2 100644 --- a/sources/scripts/dotgrid.js +++ b/sources/scripts/dotgrid.js @@ -201,26 +201,26 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca this.set_from = function(pos) { - from = pos; + from = pos.mirror().clamp(0,300).mirror(); - cursor_from.style.left = Math.floor(-pos.x*this.scale + this.grid_width); - cursor_from.style.top = Math.floor(pos.y*this.scale + this.grid_height); + cursor_from.style.left = Math.floor(-from.x*this.scale + this.grid_width); + cursor_from.style.top = Math.floor(from.y*this.scale + this.grid_height); } this.set_to = function(pos) { - cursor_to.style.left = Math.floor(-pos.x*this.scale + this.grid_width); - cursor_to.style.top = Math.floor(pos.y*this.scale + this.grid_height); + to = pos.mirror().clamp(0,300).mirror(); - to = pos; + cursor_to.style.left = Math.floor(-to.x*this.scale + this.grid_width); + cursor_to.style.top = Math.floor(to.y*this.scale + this.grid_height); } this.set_end = function(pos) { - cursor_end.style.left = Math.floor(-pos.x*this.scale + this.grid_width); - cursor_end.style.top = Math.floor(pos.y*this.scale + this.grid_height); + end = pos.mirror().clamp(0,300).mirror(); - end = pos; + cursor_end.style.left = Math.floor(-end.x*this.scale + this.grid_width); + cursor_end.style.top = Math.floor(end.y*this.scale + this.grid_height); } this.delete_at = function(pos) @@ -436,7 +436,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca this.draw() var svg = this.svg_el.outerHTML - dotgrid.resize() dialog.showSaveDialog((fileName) => { dotgrid.resize() diff --git a/sources/scripts/keyboard.js b/sources/scripts/keyboard.js index 2f871bc..2946263 100644 --- a/sources/scripts/keyboard.js +++ b/sources/scripts/keyboard.js @@ -45,10 +45,10 @@ function Keyboard() case 9 : dotgrid.toggle_fill(); e.preventDefault(); break; // 'tab' - case 38 : dotgrid.mod_move(new Pos(0,-10)); break; // 'up' - case 40 : dotgrid.mod_move(new Pos(0,10)); break; // 'down' - case 37 : dotgrid.mod_move(new Pos(-10,0)); break; // 'left' - case 39 : dotgrid.mod_move(new Pos(10,0)); break; // 'right' + case 38 : dotgrid.mod_move(new Pos(0,-15)); break; // 'up' + case 40 : dotgrid.mod_move(new Pos(0,15)); break; // 'down' + case 37 : dotgrid.mod_move(new Pos(-15,0)); break; // 'left' + case 39 : dotgrid.mod_move(new Pos(15,0)); break; // 'right' } dotgrid.draw(); } diff --git a/sources/scripts/pos.js b/sources/scripts/pos.js index 9d82fbf..e8b20e0 100644 --- a/sources/scripts/pos.js +++ b/sources/scripts/pos.js @@ -27,4 +27,16 @@ function Pos(x,y) { return new Pos(this.x*a,this.y*a) } + + this.mirror = function(x = -1,y = 1) + { + return new Pos(this.x * x,this.y * y); + } + + this.clamp = function(min,max) + { + return new Pos(clamp(this.x,min,max),clamp(this.y,min,max)); + } + + function clamp(v, min, max) { return v < min ? min : v > max ? max : v; } } \ No newline at end of file