Progress on documentation tools.

This commit is contained in:
Devine Lu Linvega 2018-01-13 16:03:21 +13:00
parent bb43273b6f
commit fe23311063
9 changed files with 233 additions and 126 deletions

110
docs.js Normal file
View File

@ -0,0 +1,110 @@
function Docs()
{
this.layout = [
{x:0, y:0, width:60, height:60, name:"esc"},
{x:60, y:0, width:60, height:60, name:"1"},
{x:120, y:0, width:60, height:60, name:"2"},
{x:180, y:0, width:60, height:60, name:"3"},
{x:240, y:0, width:60, height:60, name:"4"},
{x:300, y:0, width:60, height:60, name:"5"},
{x:360, y:0, width:60, height:60, name:"6"},
{x:420, y:0, width:60, height:60, name:"7"},
{x:480, y:0, width:60, height:60, name:"8"},
{x:540, y:0, width:60, height:60, name:"9"},
{x:600, y:0, width:60, height:60, name:"0"},
{x:660, y:0, width:60, height:60, name:"-"},
{x:720, y:0, width:60, height:60, name:"+"},
{x:780, y:0, width:120, height:60, name:"del"},
{x:0, y:60, width:90, height:60, name:"tab"},
{x:90, y:60, width:60, height:60, name:"q"},
{x:150, y:60, width:60, height:60, name:"w"},
{x:210, y:60, width:60, height:60, name:"e"},
{x:270, y:60, width:60, height:60, name:"r"},
{x:330, y:60, width:60, height:60, name:"t"},
{x:390, y:60, width:60, height:60, name:"y"},
{x:450, y:60, width:60, height:60, name:"u"},
{x:510, y:60, width:60, height:60, name:"i"},
{x:570, y:60, width:60, height:60, name:"o"},
{x:630, y:60, width:60, height:60, name:"p"},
{x:690, y:60, width:60, height:60, name:"["},
{x:750, y:60, width:60, height:60, name:"]"},
{x:810, y:60, width:90, height:60, name:"|"},
{x:0, y:120, width:105, height:60, name:"caps"},
{x:105, y:120, width:60, height:60, name:"a"},
{x:165, y:120, width:60, height:60, name:"s"},
{x:225, y:120, width:60, height:60, name:"d"},
{x:285, y:120, width:60, height:60, name:"f"},
{x:345, y:120, width:60, height:60, name:"g"},
{x:405, y:120, width:60, height:60, name:"h"},
{x:465, y:120, width:60, height:60, name:"j"},
{x:525, y:120, width:60, height:60, name:"k"},
{x:585, y:120, width:60, height:60, name:"l"},
{x:645, y:120, width:60, height:60, name:";"},
{x:705, y:120, width:60, height:60, name:"'"},
{x:765, y:120, width:135, height:60, name:"enter"},
{x:0, y:180, width:135, height:60, name:"shift"},
{x:135, y:180, width:60, height:60, name:"z"},
{x:195, y:180, width:60, height:60, name:"x"},
{x:255, y:180, width:60, height:60, name:"c"},
{x:315, y:180, width:60, height:60, name:"v"},
{x:375, y:180, width:60, height:60, name:"b"},
{x:435, y:180, width:60, height:60, name:"n"},
{x:495, y:180, width:60, height:60, name:"m"},
{x:555, y:180, width:60, height:60, name:","},
{x:615, y:180, width:60, height:60, name:"."},
{x:675, y:180, width:60, height:60, name:"/"},
{x:735, y:180, width:165, height:60, name:"capslock"},
{x:0, y:240, width:90, height:60, name:"ctrl"},
{x:90, y:240, width:90, height:60, name:"cmd"},
{x:180, y:240, width:90, height:60, name:"alt"},
{x:270, y:240, width:270, height:60, name:"space"},
{x:810, y:240, width:90, height:60, name:"ctrl"},
{x:720, y:240, width:90, height:60, name:"pn"},
{x:630, y:240, width:90, height:60, name:"fn"},
{x:540, y:240, width:90, height:60, name:"alt"}]
this.generate = function(m)
{
var svg_html = "";
for(id in this.layout){
var key = this.layout[id];
var acc = this.accelerator_for_key(key.name,m);
console.log(acc)
svg_html += `<rect x="${key.x + 1}" y="${key.y + 1}" width="${key.width - 2}" height="${key.height - 2}" rx="4" ry="4" title="${key.name}" stroke="#ccc" fill="none" stroke-width="1"/>`;
svg_html += `<rect x="${key.x + 3}" y="${key.y + 3}" width="${key.width - 6}" height="${key.height - 12}" rx="3" ry="3" title="${key.name}" stroke="${acc.basic || acc.ctrl ? '#000' : '#ccc'}" fill="${acc.basic || acc.ctrl ? '#000' : '#fff'}" stroke-width="1"/>`;
svg_html += `<text x="${key.x + 10}" y="${key.y + 20}" font-size='11' font-family='Input Mono' stroke-width='0' fill='${acc.basic || acc.ctrl ? '#fff' : '#000'}'>${key.name.toUpperCase()}</text>`;
svg_html += acc && acc.basic ? `<text x="${key.x + 10}" y="${key.y + 35}" font-size='7' font-family='Input Mono' stroke-width='0' fill='#fff'>${acc.basic}</text>` : '';
svg_html += acc && acc.ctrl ? `<text x="${key.x + 10}" y="${key.y + 45}" font-size='7' font-family='Input Mono' stroke-width='0' fill='#aaa'>${acc.ctrl}</text>` : '';
}
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="900"
height="300"
version="1.0"
style="fill:none; stroke:black; stroke-width:2px; padding:50px">${svg_html}</svg>`;
}
this.accelerator_for_key = function(key,menu)
{
var acc = {basic:null,ctrl:null}
for(cat in menu){
var options = menu[cat];
for(id in options.submenu){
var option = options.submenu[id];
acc.basic = (option.accelerator.toLowerCase() == key.toLowerCase()) ? option.label.toUpperCase().replace("TOGGLE ","").substr(0,8).trim() : acc.basic;
acc.ctrl = (option.accelerator.toLowerCase() == ("CmdOrCtrl+"+key).toLowerCase()) ? option.label.toUpperCase().replace("TOGGLE ","").substr(0,8).trim() : acc.ctrl;
}
}
return acc;
}
}
module.exports = new Docs();

29
main.js
View File

@ -3,22 +3,21 @@ const path = require('path')
const url = require('url')
const shell = require('electron').shell
let win
let is_shown = true;
app.inspect = function()
{
this.win.webContents.openDevTools();
app.win.toggleDevTools();
}
app.toggle_fullscreen = function()
{
win.setFullScreen(win.isFullScreen() ? false : true);
app.win.setFullScreen(app.win.isFullScreen() ? false : true);
}
app.toggle_visible = function()
{
if(is_shown){ win.hide(); } else{ win.show(); }
if(is_shown){ app.win.hide(); } else{ app.win.show(); }
}
app.inject_menu = function(m)
@ -26,24 +25,32 @@ app.inject_menu = function(m)
Menu.setApplicationMenu(Menu.buildFromTemplate(m));
}
app.win = win;
app.generate_docs = function(m)
{
console.log("Generating docs..");
var docs = require('./docs.js');
var fs = require('fs');
fs.writeFile("/Users/VillaMoirai/Desktop/keyboard.svg", docs.generate(m));
}
app.win = null;
app.on('ready', () =>
{
win = new BrowserWindow({width: 400, height: 420, minWidth: 400, minHeight: 400, backgroundColor:"#000", frame:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
app.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`);
app.win.loadURL(`file://${__dirname}/sources/index.html`);
win.on('closed', () => {
app.win.on('closed', () => {
win = null
app.quit()
})
win.on('hide',function() {
app.win.on('hide',function() {
is_shown = false;
})
win.on('show',function() {
app.win.on('show',function() {
is_shown = true;
})
})
@ -54,7 +61,7 @@ app.on('window-all-closed', () =>
})
app.on('activate', () => {
if (win === null) {
if (app.win === null) {
createWindow()
}
else{

View File

@ -17,6 +17,7 @@
"theme_osx" : "cp -R ~/Github/HundredRabbits/Themes/themes ~/Desktop/Dotgrid-darwin-x64/",
"theme_linux" : "cp -R ~/Github/HundredRabbits/Themes/themes ~/Desktop/Dotgrid-linux-x64/",
"theme_win" : "cp -R ~/Github/HundredRabbits/Themes/themes ~/Desktop/Dotgrid-win32-x64/",
"docs" : "electron . docs",
"push" : "npm run build ; npm run theme ; npm run push_osx ; npm run push_linux ; npm run push_win ; npm run clean ; npm run push_status"
},
"devDependencies": {

View File

@ -6,7 +6,6 @@
<script type="text/javascript" src="scripts/path_bezier.js"></script>
<script type="text/javascript" src="scripts/path_close.js"></script>
<script type="text/javascript" src="scripts/dotgrid.js"></script>
<script type="text/javascript" src="scripts/keyboard.js"></script>
<script type="text/javascript" src="scripts/guide.js"></script>
<script type="text/javascript" src="scripts/render.js"></script>
<script type="text/javascript" src="scripts/serializer.js"></script>
@ -27,9 +26,6 @@
dotgrid = new Dotgrid(300,300,20,20,4,4, 10,"square","#000000");
dotgrid.install();
var keyboard = new Keyboard();
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);

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="900"
height="300"
version="1.0"
style="fill:none; stroke:black; stroke-width:2px; padding:30px">
<!-- ROW 1 -->
<rect x="0" y="0" width="60" height="60" rx="4" ry="4" title="escape"/>
<rect x="60" y="0" width="60" height="60" rx="4" ry="4" title="1" class='red'/>
<rect x="120" y="0" width="60" height="60" rx="4" ry="4" title="2"/>
<rect x="180" y="0" width="60" height="60" rx="4" ry="4" title="3"/>
<rect x="240" y="0" width="60" height="60" rx="4" ry="4" title="4"/>
<rect x="300" y="0" width="60" height="60" rx="4" ry="4" title="5"/>
<rect x="360" y="0" width="60" height="60" rx="4" ry="4" title="6"/>
<rect x="420" y="0" width="60" height="60" rx="4" ry="4" title="7"/>
<rect x="480" y="0" width="60" height="60" rx="4" ry="4" title="8"/>
<rect x="540" y="0" width="60" height="60" rx="4" ry="4" title="9"/>
<rect x="600" y="0" width="60" height="60" rx="4" ry="4" title="0"/>
<rect x="660" y="0" width="60" height="60" rx="4" ry="4" title="+"/>
<rect x="720" y="0" width="60" height="60" rx="4" ry="4" title="-"/>
<rect x="780" y="0" width="120" height="60" rx="4" ry="4" title="-"/>
<!-- ROW 2 -->
<rect x="0" y="60" width="90" height="60" rx="4" ry="4" title="tab"/>
<rect x="90" y="60" width="60" height="60" rx="4" ry="4" title="q"/>
<rect x="150" y="60" width="60" height="60" rx="4" ry="4" title="w"/>
<rect x="210" y="60" width="60" height="60" rx="4" ry="4" title="e"/>
<rect x="270" y="60" width="60" height="60" rx="4" ry="4" title="r"/>
<rect x="330" y="60" width="60" height="60" rx="4" ry="4" title="t"/>
<rect x="390" y="60" width="60" height="60" rx="4" ry="4" title="y"/>
<rect x="450" y="60" width="60" height="60" rx="4" ry="4" title="u"/>
<rect x="510" y="60" width="60" height="60" rx="4" ry="4" title="i"/>
<rect x="570" y="60" width="60" height="60" rx="4" ry="4" title="o"/>
<rect x="630" y="60" width="60" height="60" rx="4" ry="4" title="p"/>
<rect x="690" y="60" width="60" height="60" rx="4" ry="4" title="["/>
<rect x="750" y="60" width="60" height="60" rx="4" ry="4" title="]"/>
<rect x="810" y="60" width="90" height="60" rx="4" ry="4" title="¥"/>
<!-- ROW 3 -->
<rect x="0" y="120" width="105" height="60" rx="4" ry="4" title="capslock"/>
<rect x="105" y="120" width="60" height="60" rx="4" ry="4" title="s"/>
<rect x="165" y="120" width="60" height="60" rx="4" ry="4" title="d"/>
<rect x="225" y="120" width="60" height="60" rx="4" ry="4" title="f"/>
<rect x="285" y="120" width="60" height="60" rx="4" ry="4" title="g"/>
<rect x="345" y="120" width="60" height="60" rx="4" ry="4" title="h"/>
<rect x="405" y="120" width="60" height="60" rx="4" ry="4" title="j"/>
<rect x="465" y="120" width="60" height="60" rx="4" ry="4" title="k"/>
<rect x="525" y="120" width="60" height="60" rx="4" ry="4" title="l"/>
<rect x="585" y="120" width="60" height="60" rx="4" ry="4" title=";"/>
<rect x="645" y="120" width="60" height="60" rx="4" ry="4" title="'"/>
<rect x="705" y="120" width="60" height="60" rx="4" ry="4" title="a"/>
<rect x="765" y="120" width="135" height="60" rx="4" ry="4" title="enter"/>
<!-- ROW 4 -->
<rect x="0" y="180" width="135" height="60" rx="4" ry="4" title="shift"/>
<rect x="135" y="180" width="60" height="60" rx="4" ry="4" title="z"/>
<rect x="195" y="180" width="60" height="60" rx="4" ry="4" title="x"/>
<rect x="255" y="180" width="60" height="60" rx="4" ry="4" title="c"/>
<rect x="315" y="180" width="60" height="60" rx="4" ry="4" title="v"/>
<rect x="375" y="180" width="60" height="60" rx="4" ry="4" title="b"/>
<rect x="435" y="180" width="60" height="60" rx="4" ry="4" title="n"/>
<rect x="495" y="180" width="60" height="60" rx="4" ry="4" title="m"/>
<rect x="555" y="180" width="60" height="60" rx="4" ry="4" title=","/>
<rect x="615" y="180" width="60" height="60" rx="4" ry="4" title="."/>
<rect x="675" y="180" width="60" height="60" rx="4" ry="4" title="/"/>
<rect x="735" y="180" width="165" height="60" rx="4" ry="4" title="capslock"/>
<!-- ROW 5 -->
<rect x="0" y="240" width="90" height="60" rx="4" ry="4" title="ctrl"/>
<rect x="90" y="240" width="90" height="60" rx="4" ry="4" title="cmd"/>
<rect x="180" y="240" width="90" height="60" rx="4" ry="4" title="alt"/>
<rect x="270" y="240" width="270" height="60" rx="4" ry="4" title="space"/>
<rect x="810" y="240" width="90" height="60" rx="4" ry="4" title="ctrl"/>
<rect x="720" y="240" width="90" height="60" rx="4" ry="4" title="pn"/>
<rect x="630" y="240" width="90" height="60" rx="4" ry="4" title="fn"/>
<rect x="540" y="240" width="90" height="60" rx="4" ry="4" title="alt"/>
</svg>

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -14,10 +14,10 @@ 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,accelerator)
console.log(`${mode}/${cat}/${label} <${accelerator}>`);
}
this.commit = function()
this.format = function()
{
var f = [];
var m = this.menu[this.mode];
@ -29,7 +29,18 @@ function Controller()
}
f.push({label:cat,submenu:submenu});
}
this.app.inject_menu(f);
return f;
}
this.commit = function()
{
this.app.inject_menu(this.format());
}
this.docs = function()
{
console.log("Generating docs..");
this.app.generate_docs(this.format());
}
}

View File

@ -125,11 +125,11 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.theme.start();
this.guide.start();
this.interface.start();
this.controller.start();
this.controller.add("default","*","Reset",() => { dotgrid.reset(); dotgrid.theme.reset(); },"CmdOrCtrl+Backspace");
this.controller.add("default","*","About Dotgrid",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Dotgrid'); },"CmdOrCtrl+,");
this.controller.add("default","*","Developer Tools",() => { app.inspect },"CmdOrCtrl+.");
this.controller.add("default","*","Developer Tools",() => { app.inspect(); },"CmdOrCtrl+.");
this.controller.add("default","*","Generate Docs",() => { dotgrid.controller.docs(); },"CmdOrCtrl+Esc");
this.controller.add("default","*","Toggle Fullscreen",() => { app.toggle_fullscreen(); },"CmdOrCtrl+Enter");
this.controller.add("default","*","Toggle Visible",() => { app.toggle_visible(); },"CmdOrCtrl+H");
this.controller.add("default","*","Quit",() => { app.exit(); },"CmdOrCtrl+Q");
@ -149,7 +149,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
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","Arc Reverse",() => { 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");

View File

@ -10,16 +10,16 @@ function Interface()
// Interface
var html = ""
var path_arr = [
["line","line (d)","M60,60 L240,240",""],
["arc_c","arc clockwise (s)","M60,60 A180,180 0 0,1 240,240",""],
["arc_r","arc reverse (a)","M60,60 A180,180 0 0,0 240,240",""],
["bezier","bezier (f)","M60,60 Q60,150 150,150 Q240,150 240,240 ",""],
["close","close (g)","M60,60 A180,180 0 0,1 240,240 M60,60 A180,180 0 0,0 240,240",""],
["line","line","M60,60 L240,240",""],
["arc_c","arc clockwise","M60,60 A180,180 0 0,1 240,240",""],
["arc_r","arc reverse","M60,60 A180,180 0 0,0 240,240",""],
["bezier","bezier","M60,60 Q60,150 150,150 Q240,150 240,240 ",""],
["close","close","M60,60 A180,180 0 0,1 240,240 M60,60 A180,180 0 0,0 240,240",""],
["thickness","thickness ([ & ])","M60,60 L240,240","stroke-dasharray: 30,15"],
["linecap","linecap (/)","M60,60 L240,240 M240,180 L240,240 M180,240 L240,240"],
["mirror","mirror (space)","M60,60 L240,240 M180,120 L210,90 M120,180 L90,210 "],
["fill","fill (h)","M60,60 L60,150 L150,150 L240,150 L240,240 Z "],
["thickness","thickness","M60,60 L240,240","stroke-dasharray: 30,15"],
["linecap","linecap","M60,60 L240,240 M240,180 L240,240 M180,240 L240,240"],
["mirror","mirror","M60,60 L240,240 M180,120 L210,90 M120,180 L90,210 "],
["fill","fill","M60,60 L60,150 L150,150 L240,150 L240,240 Z "],
["export","export (ctrl s)","M150,50 L50,150 L150,250 L250,150 L150,50 Z"]
]

View File

@ -1,96 +0,0 @@
function Keyboard()
{
this.listen = function(e)
{
// // zoom
// if(e.key == "~" || e.keyCode == 192){
// dotgrid.interface.toggle_zoom();
// e.preventDefault();
// return;
// }
// // undo
// if(e.key == "z" && (e.ctrlKey || e.metaKey)){
// e.preventDefault();
// dotgrid.erase();
// return;
// }
// // Reset
// if((e.key == "Backspace" || e.key == "Delete") && e.ctrlKey && e.shiftKey){
// e.preventDefault();
// dotgrid.theme.reset();
// 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 = "";
// }
// 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 "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 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();
}
this.code_history = "";
this.cheatcode = function(key)
{
if(key.length != 1){ return; }
this.code_history += key;
if(this.code_history.length == 2){
var x = this.code_history.substr(0,2);
var y = 15;
dotgrid.move_cursor(new Pos(x * -15,y * 15))
}
if(this.code_history.length > 3){
var x = this.code_history.substr(0,2);
var y = this.code_history.substr(2,2);
dotgrid.add_point(new Pos(x * -15,y * 15))
dotgrid.move_cursor(new Pos(x * -15,y * 15))
this.code_history = "";
}
}
}