Implemented basic menus

This commit is contained in:
Devine Lu Linvega 2018-01-12 21:46:09 +13:00
parent abb83374b7
commit 731fd58da1
4 changed files with 163 additions and 158 deletions

View File

@ -5,11 +5,6 @@ function Controller()
this.app = require('electron').remote.app;
const ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.on('controller-access',function(event,data){
console.log(require('electron').Menu)
});
this.start = function()
{
}
@ -19,7 +14,7 @@ function Controller()
if(!this.menu[mode]){ this.menu[mode] = {}; }
if(!this.menu[mode][cat]){ this.menu[mode][cat] = {}; }
this.menu[mode][cat][label] = {fn:fn,accelerator:accelerator};
console.log("Added control",mode,cat,label,fn,accelerator)
console.log("Added control",mode,cat,label,accelerator)
}
this.commit = function()

View File

@ -127,11 +127,36 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.interface.start();
this.controller.start();
this.controller.add("default","File","New",dotgrid.new,"CmdOrCtrl+N");
this.controller.add("default","File","Open",dotgrid.open,"CmdOrCtrl+O");
this.controller.add("default","File","Save",dotgrid.save,"CmdOrCtrl+S");
this.controller.add("default","File","Quit",app.exit,"CmdOrCtrl+Q");
this.controller.add("default","File","New",() => { dotgrid.new(); },"CmdOrCtrl+N");
this.controller.add("default","File","Open",() => { dotgrid.open(); },"CmdOrCtrl+O");
this.controller.add("default","File","Save",() => { dotgrid.save(); },"CmdOrCtrl+S");
this.controller.add("default","File","Quit",() => { app.exit(); },"CmdOrCtrl+Q");
this.controller.add("default","Edit","Undo",() => { dotgrid.undo(); },"CmdOrCtrl+Z");
this.controller.add("default","Edit","Delete Last",() => { dotgrid.undo(); },"Backspace");
this.controller.add("default","Edit","Move Up",() => { dotgrid.mod_move(new Pos(0,-15)); },"Up");
this.controller.add("default","Edit","Move Down",() => { dotgrid.mod_move(new Pos(0,15)); },"Down");
this.controller.add("default","Edit","Move Left",() => { dotgrid.mod_move(new Pos(-15,0)); },"Left");
this.controller.add("default","Edit","Move Right",() => { dotgrid.mod_move(new Pos(15,0)); },"Right");
this.controller.add("default","Edit","Deselect All",() => { dotgrid.reset(); },"Esc");
this.controller.add("default","Stroke","Line",() => { dotgrid.draw_line(); },"A");
this.controller.add("default","Stroke","Arc",() => { dotgrid.draw_arc("0,1"); },"S");
this.controller.add("default","Stroke","Arc(CC)",() => { dotgrid.draw_arc("0,0"); },"D");
this.controller.add("default","Stroke","Bezier",() => { dotgrid.draw_bezier(); },"F");
this.controller.add("default","Stroke","Close",() => { dotgrid.draw_close(); },"Z");
this.controller.add("default","Effect","Increase Thickness",() => { dotgrid.mod_thickness(1) },"]");
this.controller.add("default","Effect","Decrease Thickness",() => { dotgrid.mod_thickness(-1) },"[");
this.controller.add("default","Effect","Linecap",() => { dotgrid.mod_linecap(); },"/");
this.controller.add("default","Effect","Mirror",() => { dotgrid.mod_mirror(); },"Space");
this.controller.add("default","Effect","Fill",() => { dotgrid.toggle_fill(); },"G");
this.controller.add("default","View","Toggle Tools",() => { dotgrid.interface.toggle(); },"Tab");
this.controller.add("default","View","Toggle Canvas Size",() => { dotgrid.interface.toggle_zoom(); },":");
this.controller.add("default","Develop","Inspect",app.inspect,"CmdOrCtrl+.");
this.controller.commit();
window.addEventListener('drop', dotgrid.drag);
@ -140,6 +165,8 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.draw();
}
// FILE
this.new = function()
{
dotgrid.segments = [];
@ -178,6 +205,78 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
});
}
// EDIT
this.undo = function()
{
if(from || to || end){
dotgrid.reset();
}
else{
dotgrid.segments.pop();
}
dotgrid.draw();
}
// STROKE
this.draw_line = function()
{
if(from === null || to === null){ return; }
to = new Pos(to.x * -1, to.y).sub(dotgrid.offset)
from = new Pos(from.x * -1,from.y).sub(dotgrid.offset)
end = end ? new Pos(end.x * -1,end.y).sub(dotgrid.offset) : null;
dotgrid.segments.push(new Path_Line(from,to,end));
dotgrid.reset();
dotgrid.draw();
dotgrid.reset();
}
this.draw_arc = function(orientation = "0,0")
{
if(from === null || to === null){ return; }
to = new Pos(to.x * -1, to.y).sub(dotgrid.offset)
from = new Pos(from.x * -1,from.y).sub(dotgrid.offset)
end = end ? new Pos(end.x * -1,end.y).sub(dotgrid.offset) : null;
dotgrid.segments.push(new Path_Arc(from,to,orientation,end));
dotgrid.reset();
dotgrid.draw();
dotgrid.reset();
}
this.draw_bezier = function()
{
if(from === null || to === null || end === null){ return; }
to = new Pos(to.x * -1, to.y).sub(dotgrid.offset)
from = new Pos(from.x * -1,from.y).sub(dotgrid.offset)
end = new Pos(end.x * -1,end.y).sub(dotgrid.offset)
dotgrid.segments.push(new Path_Bezier(from,to,end));
dotgrid.reset();
dotgrid.draw();
dotgrid.reset();
}
this.draw_close = function()
{
if(dotgrid.segments.length == 0){ return; }
if(dotgrid.segments[dotgrid.segments.length-1].name == "close"){ return; }
dotgrid.segments.push(new Path_Close());
dotgrid.reset();
dotgrid.draw();
dotgrid.reset();
}
// Cursor
this.translation = null;
@ -486,63 +585,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
}
// Draw
this.draw_line = function()
{
if(from === null || to === null){ return; }
to = new Pos(to.x * -1, to.y).sub(this.offset)
from = new Pos(from.x * -1,from.y).sub(this.offset)
end = end ? new Pos(end.x * -1,end.y).sub(this.offset) : null;
this.segments.push(new Path_Line(from,to,end));
this.reset();
this.draw();
this.reset();
}
this.draw_arc = function(orientation)
{
if(from === null || to === null){ return; }
to = new Pos(to.x * -1, to.y).sub(this.offset)
from = new Pos(from.x * -1,from.y).sub(this.offset)
end = end ? new Pos(end.x * -1,end.y).sub(this.offset) : null;
this.segments.push(new Path_Arc(from,to,orientation,end));
this.reset();
this.draw();
this.reset();
}
this.draw_bezier = function()
{
if(from === null || to === null || end === null){ return; }
to = new Pos(to.x * -1, to.y).sub(this.offset)
from = new Pos(from.x * -1,from.y).sub(this.offset)
end = new Pos(end.x * -1,end.y).sub(this.offset)
this.segments.push(new Path_Bezier(from,to,end));
this.reset();
this.draw();
this.reset();
}
this.draw_close = function()
{
if(this.segments.length == 0){ return; }
if(this.segments[this.segments.length-1].name == "close"){ return; }
this.segments.push(new Path_Close());
this.reset();
this.draw();
this.reset();
}
this.reset = function()
{
from = null;
@ -566,17 +609,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.draw();
}
this.erase = function()
{
if(from || to || end){
this.reset();
}
else{
this.segments.pop();
}
this.draw();
}
this.drag = function(e)
{
e.preventDefault();

View File

@ -67,7 +67,6 @@ function Interface()
this.toggle_zoom = function()
{
this.zoom = this.zoom ? false : true;
this.update_size();
}
}

View File

@ -2,96 +2,75 @@ function Keyboard()
{
this.listen = function(e)
{
// zoom
if(e.key == "~" || e.keyCode == 192){
dotgrid.interface.toggle_zoom();
e.preventDefault();
return;
}
// // zoom
// if(e.key == "~" || e.keyCode == 192){
// dotgrid.interface.toggle_zoom();
// e.preventDefault();
// return;
// }
// save
if(e.key == "s" && (e.ctrlKey || e.metaKey)){
e.preventDefault();
dotgrid.export();
return;
}
// // undo
// if(e.key == "z" && (e.ctrlKey || e.metaKey)){
// e.preventDefault();
// dotgrid.erase();
// return;
// }
// open
if(e.key == "o" && (e.ctrlKey || e.metaKey)){
e.preventDefault();
dotgrid.open();
return;
}
// // Reset
// if((e.key == "Backspace" || e.key == "Delete") && e.ctrlKey && e.shiftKey){
// e.preventDefault();
// dotgrid.theme.reset();
// return;
// }
// undo
if(e.key == "z" && (e.ctrlKey || e.metaKey)){
e.preventDefault();
dotgrid.erase();
return;
}
// var numbers = ["0","1","2","3","4","5","6","7","8","9"]
// if(numbers.indexOf(e.key) > -1 || e.code == "Digit0" || e.keyCode == 48){
// keyboard.cheatcode(e.key);
// return;
// }
// else{
// this.code_history = "";
// }
// new
if(e.key == "n" && (e.ctrlKey || e.metaKey)){
e.preventDefault();
dotgrid.clear();
return;
}
// switch(e.keyCode || e.key) {
// case 65 : dotgrid.draw_arc(e.shiftKey ? "1,0" : "0,0"); break; // 'a/A'
// case 83 : dotgrid.draw_arc(e.shiftKey ? "1,1" : "0,1"); break; // 's/S'
// case 68 : dotgrid.draw_line(); break; // 'd'
// case 70 : dotgrid.draw_bezier(); break; // 'f'
// case "g" : dotgrid.draw_close(); break;
// case 71 : dotgrid.draw_close(); break; // 'g'
// case "h" : dotgrid.toggle_fill(); break;
// case 72 : dotgrid.toggle_fill(); break; // 'g'
// Reset
if((e.key == "Backspace" || e.key == "Delete") && e.ctrlKey && e.shiftKey){
e.preventDefault();
dotgrid.theme.reset();
return;
}
// case "[" : dotgrid.mod_thickness(-1); break;
// case 219 : dotgrid.mod_thickness(-1); break; // '['
// case "]" : dotgrid.mod_thickness(1); break;
// case 221 : dotgrid.mod_thickness(1); break; // ']'
var numbers = ["0","1","2","3","4","5","6","7","8","9"]
if(numbers.indexOf(e.key) > -1 || e.code == "Digit0" || e.keyCode == 48){
keyboard.cheatcode(e.key);
return;
}
else{
this.code_history = "";
}
// case "+" : dotgrid.mod_thickness(1); break;
// case "-" : dotgrid.mod_thickness(-1); break;
// case "<" : dotgrid.mod_thickness(1); break;
// case ">" : dotgrid.mod_thickness(-1); break;
switch(e.keyCode || e.key) {
case 65 : dotgrid.draw_arc(e.shiftKey ? "1,0" : "0,0"); break; // 'a/A'
case 83 : dotgrid.draw_arc(e.shiftKey ? "1,1" : "0,1"); break; // 's/S'
case 68 : dotgrid.draw_line(); break; // 'd'
case 70 : dotgrid.draw_bezier(); break; // 'f'
case "g" : dotgrid.draw_close(); break;
case 71 : dotgrid.draw_close(); break; // 'g'
case "h" : dotgrid.toggle_fill(); break;
case 72 : dotgrid.toggle_fill(); break; // 'g'
case "[" : dotgrid.mod_thickness(-1); break;
case 219 : dotgrid.mod_thickness(-1); break; // '['
case "]" : dotgrid.mod_thickness(1); break;
case 221 : dotgrid.mod_thickness(1); break; // ']'
case "+" : dotgrid.mod_thickness(1); break;
case "-" : dotgrid.mod_thickness(-1); break;
case "<" : dotgrid.mod_thickness(1); break;
case ">" : dotgrid.mod_thickness(-1); break;
case "/" : dotgrid.mod_linecap(1); break; // '/'
case 191 : dotgrid.mod_linecap(1); break; // '/'
// case "/" : dotgrid.mod_linecap(1); break; // '/'
// case 191 : dotgrid.mod_linecap(1); break; // '/'
case "space" : dotgrid.mod_linecap(1); break; // '/'
case 32 : dotgrid.mod_mirror(); break; // 'space'
// case "space" : dotgrid.mod_linecap(1); break; // '/'
// case 32 : dotgrid.mod_mirror(); break; // 'space'
case "Escape" : dotgrid.mod_linecap(1); break; // '/'
case 27 : dotgrid.reset(); break; // 'ESC'
case 8 : dotgrid.erase(); break; // 'Backspace'
case 13 : dotgrid.export(); break; // 'Enter'
// case "Escape" : dotgrid.mod_linecap(1); break; // '/'
// case 27 : dotgrid.reset(); break; // 'ESC'
// case 8 : dotgrid.erase(); break; // 'Backspace'
// case 13 : dotgrid.export(); break; // 'Enter'
case 9 : dotgrid.interface.toggle(); e.preventDefault(); break; // 'tab'
// case 9 : dotgrid.interface.toggle(); e.preventDefault(); break; // 'tab'
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();
// 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();
}
this.code_history = "";