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; 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() this.start = function()
{ {
} }
@ -19,7 +14,7 @@ function Controller()
if(!this.menu[mode]){ this.menu[mode] = {}; } if(!this.menu[mode]){ this.menu[mode] = {}; }
if(!this.menu[mode][cat]){ this.menu[mode][cat] = {}; } if(!this.menu[mode][cat]){ this.menu[mode][cat] = {}; }
this.menu[mode][cat][label] = {fn:fn,accelerator:accelerator}; 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() 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.interface.start();
this.controller.start(); this.controller.start();
this.controller.add("default","File","New",dotgrid.new,"CmdOrCtrl+N"); 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","Open",() => { dotgrid.open(); },"CmdOrCtrl+O");
this.controller.add("default","File","Save",dotgrid.save,"CmdOrCtrl+S"); 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","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.add("default","Develop","Inspect",app.inspect,"CmdOrCtrl+.");
this.controller.commit(); this.controller.commit();
window.addEventListener('drop', dotgrid.drag); 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(); this.draw();
} }
// FILE
this.new = function() this.new = function()
{ {
dotgrid.segments = []; 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 // Cursor
this.translation = null; this.translation = null;
@ -486,63 +585,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
} }
// Draw // 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() this.reset = function()
{ {
from = null; from = null;
@ -566,17 +609,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.draw(); this.draw();
} }
this.erase = function()
{
if(from || to || end){
this.reset();
}
else{
this.segments.pop();
}
this.draw();
}
this.drag = function(e) this.drag = function(e)
{ {
e.preventDefault(); e.preventDefault();

View File

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

View File

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