Started to implement menus
This commit is contained in:
parent
4e957f0f28
commit
abb83374b7
19
main.js
19
main.js
@ -5,12 +5,20 @@ const shell = require('electron').shell
|
|||||||
|
|
||||||
let win
|
let win
|
||||||
|
|
||||||
|
app.inspect = function()
|
||||||
|
{
|
||||||
|
win.webContents.openDevTools();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.inject_menu = function(m)
|
||||||
|
{
|
||||||
|
Menu.setApplicationMenu(Menu.buildFromTemplate(m));
|
||||||
|
}
|
||||||
|
|
||||||
app.on('ready', () =>
|
app.on('ready', () =>
|
||||||
{
|
{
|
||||||
win = new BrowserWindow({width: 400, height: 420, minWidth: 400, minHeight: 400, backgroundColor:"#000", frame:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
|
win = new BrowserWindow({width: 400, height: 420, minWidth: 400, minHeight: 400, backgroundColor:"#000", frame:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
|
||||||
|
|
||||||
win.loadURL(`file://${__dirname}/sources/index.html`)
|
|
||||||
|
|
||||||
let is_shown = true;
|
let is_shown = true;
|
||||||
|
|
||||||
Menu.setApplicationMenu(Menu.buildFromTemplate([
|
Menu.setApplicationMenu(Menu.buildFromTemplate([
|
||||||
@ -28,6 +36,12 @@ app.on('ready', () =>
|
|||||||
}
|
}
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
win.loadURL(`file://${__dirname}/sources/index.html`)
|
||||||
|
|
||||||
|
win.webContents.on('did-finish-load', () => {
|
||||||
|
win.webContents.send('controller-access', "hello");
|
||||||
|
})
|
||||||
|
|
||||||
win.on('closed', () => {
|
win.on('closed', () => {
|
||||||
win = null
|
win = null
|
||||||
app.quit()
|
app.quit()
|
||||||
@ -38,6 +52,7 @@ app.on('ready', () =>
|
|||||||
})
|
})
|
||||||
|
|
||||||
win.on('show',function() {
|
win.on('show',function() {
|
||||||
|
var something = {name:"fuck"}
|
||||||
is_shown = true;
|
is_shown = true;
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<script type="text/javascript" src="scripts/render.js"></script>
|
<script type="text/javascript" src="scripts/render.js"></script>
|
||||||
<script type="text/javascript" src="scripts/serializer.js"></script>
|
<script type="text/javascript" src="scripts/serializer.js"></script>
|
||||||
<script type="text/javascript" src="scripts/theme.js"></script>
|
<script type="text/javascript" src="scripts/theme.js"></script>
|
||||||
|
<script type="text/javascript" src="scripts/controller.js"></script>
|
||||||
<script type="text/javascript" src="scripts/interface.js"></script>
|
<script type="text/javascript" src="scripts/interface.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="links/reset.css"/>
|
<link rel="stylesheet" type="text/css" href="links/reset.css"/>
|
||||||
<link rel="stylesheet" type="text/css" href="links/fonts.css"/>
|
<link rel="stylesheet" type="text/css" href="links/fonts.css"/>
|
||||||
@ -22,7 +23,7 @@
|
|||||||
<script>
|
<script>
|
||||||
const {dialog,app} = require('electron').remote;
|
const {dialog,app} = require('electron').remote;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
dotgrid = new Dotgrid(300,300,20,20,4,4, 10,"square","#000000");
|
dotgrid = new Dotgrid(300,300,20,20,4,4, 10,"square","#000000");
|
||||||
dotgrid.install();
|
dotgrid.install();
|
||||||
|
|
||||||
|
41
sources/scripts/controller.js
Normal file
41
sources/scripts/controller.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
function Controller()
|
||||||
|
{
|
||||||
|
this.menu = {default:{}};
|
||||||
|
this.mode = "default";
|
||||||
|
|
||||||
|
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.add = function(mode,cat,label,fn,accelerator)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.commit = function()
|
||||||
|
{
|
||||||
|
var f = [];
|
||||||
|
var m = this.menu[this.mode];
|
||||||
|
for(cat in m){
|
||||||
|
var submenu = [];
|
||||||
|
for(name in m[cat]){
|
||||||
|
var option = m[cat][name];
|
||||||
|
submenu.push({label:name,accelerator:option.accelerator,click:option.fn})
|
||||||
|
}
|
||||||
|
f.push({label:cat,submenu:submenu});
|
||||||
|
}
|
||||||
|
this.app.inject_menu(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new Controller();
|
@ -1,5 +1,6 @@
|
|||||||
function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,linecap = "round", color = "#000000")
|
function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,linecap = "round", color = "#000000")
|
||||||
{
|
{
|
||||||
|
this.controller = new Controller();
|
||||||
this.theme = new Theme();
|
this.theme = new Theme();
|
||||||
this.interface = new Interface();
|
this.interface = new Interface();
|
||||||
|
|
||||||
@ -124,6 +125,14 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
|
|||||||
this.theme.start();
|
this.theme.start();
|
||||||
this.guide.start();
|
this.guide.start();
|
||||||
this.interface.start();
|
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","Develop","Inspect",app.inspect,"CmdOrCtrl+.");
|
||||||
|
this.controller.commit();
|
||||||
|
|
||||||
window.addEventListener('drop', dotgrid.drag);
|
window.addEventListener('drop', dotgrid.drag);
|
||||||
|
|
||||||
@ -131,6 +140,44 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
|
|||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.new = function()
|
||||||
|
{
|
||||||
|
dotgrid.segments = [];
|
||||||
|
dotgrid.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.save = function()
|
||||||
|
{
|
||||||
|
if(this.segments.length == 0){ return; }
|
||||||
|
this.scale = 1
|
||||||
|
this.draw();
|
||||||
|
|
||||||
|
if(dotgrid.fill){ dotgrid.svg_el.style.fill = "black"; dotgrid.render.draw(); }
|
||||||
|
|
||||||
|
var svg = dotgrid.svg_el.outerHTML;
|
||||||
|
|
||||||
|
dialog.showSaveDialog((fileName) => {
|
||||||
|
if (fileName === undefined){ return; }
|
||||||
|
fs.writeFile(fileName+".svg", svg);
|
||||||
|
fs.writeFile(fileName+'.png', dotgrid.render.buffer());
|
||||||
|
fs.writeFile(fileName+'.dot', JSON.stringify(dotgrid.serializer.serialize()));
|
||||||
|
dotgrid.draw()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.open = function()
|
||||||
|
{
|
||||||
|
var paths = dialog.showOpenDialog({properties: ['openFile'],filters:[{name:"Dotgrid Image",extensions:["dot"]}]});
|
||||||
|
|
||||||
|
if(!paths){ console.log("Nothing to load"); return; }
|
||||||
|
|
||||||
|
fs.readFile(paths[0], 'utf-8', (err, data) => {
|
||||||
|
if(err){ alert("An error ocurred reading the file :" + err.message); return; }
|
||||||
|
dotgrid.serializer.deserialize(JSON.parse(data.toString().trim()));
|
||||||
|
dotgrid.draw();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Cursor
|
// Cursor
|
||||||
|
|
||||||
this.translation = null;
|
this.translation = null;
|
||||||
@ -157,7 +204,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
|
|||||||
if(o == "linecap"){ this.mod_linecap(); }
|
if(o == "linecap"){ this.mod_linecap(); }
|
||||||
if(o == "mirror"){ this.mod_mirror(); }
|
if(o == "mirror"){ this.mod_mirror(); }
|
||||||
if(o == "fill"){ this.toggle_fill(); }
|
if(o == "fill"){ this.toggle_fill(); }
|
||||||
if(o == "export"){ this.export(); }
|
if(o == "export"){ this.save(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mouse_move = function(e)
|
this.mouse_move = function(e)
|
||||||
@ -530,38 +577,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
|
|||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.export = function()
|
|
||||||
{
|
|
||||||
if(this.segments.length == 0){ return; }
|
|
||||||
this.scale = 1
|
|
||||||
this.draw();
|
|
||||||
|
|
||||||
if(dotgrid.fill){ dotgrid.svg_el.style.fill = "black"; dotgrid.render.draw(); }
|
|
||||||
|
|
||||||
var svg = dotgrid.svg_el.outerHTML;
|
|
||||||
|
|
||||||
dialog.showSaveDialog((fileName) => {
|
|
||||||
if (fileName === undefined){ return; }
|
|
||||||
fs.writeFile(fileName+".svg", svg);
|
|
||||||
fs.writeFile(fileName+'.png', dotgrid.render.buffer());
|
|
||||||
fs.writeFile(fileName+'.dot', JSON.stringify(dotgrid.serializer.serialize()));
|
|
||||||
dotgrid.draw()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.open = function()
|
|
||||||
{
|
|
||||||
var paths = dialog.showOpenDialog({properties: ['openFile'],filters:[{name:"Dotgrid Image",extensions:["dot"]}]});
|
|
||||||
|
|
||||||
if(!paths){ console.log("Nothing to load"); return; }
|
|
||||||
|
|
||||||
fs.readFile(paths[0], 'utf-8', (err, data) => {
|
|
||||||
if(err){ alert("An error ocurred reading the file :" + err.message); return; }
|
|
||||||
dotgrid.serializer.deserialize(JSON.parse(data.toString().trim()));
|
|
||||||
dotgrid.draw();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.drag = function(e)
|
this.drag = function(e)
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user