Migrating to full canvas rendering
This commit is contained in:
parent
7fd21cf2a1
commit
1923c4b04c
4
main.js
4
main.js
@ -6,7 +6,7 @@ let win
|
|||||||
|
|
||||||
app.on('ready', () =>
|
app.on('ready', () =>
|
||||||
{
|
{
|
||||||
win = new BrowserWindow({width: 390, height: 420, minWidth: 390, minHeight: 420, backgroundColor:"#000", frame:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
|
win = new BrowserWindow({width: 900, height: 420, minWidth: 390, minHeight: 420, backgroundColor:"#000", frame:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
|
||||||
|
|
||||||
win.loadURL(`file://${__dirname}/sources/index.html`)
|
win.loadURL(`file://${__dirname}/sources/index.html`)
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ app.on('ready', () =>
|
|||||||
is_shown = true;
|
is_shown = true;
|
||||||
})
|
})
|
||||||
// Open the DevTools.
|
// Open the DevTools.
|
||||||
// win.webContents.openDevTools()
|
win.webContents.openDevTools()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('window-all-closed', () =>
|
app.on('window-all-closed', () =>
|
||||||
|
@ -1,33 +1,44 @@
|
|||||||
function Guide()
|
function Guide()
|
||||||
{
|
{
|
||||||
this.el = document.createElement("div");
|
this.el = document.createElement("canvas");
|
||||||
|
|
||||||
// Guide
|
|
||||||
this.el.id = "guide";
|
this.el.id = "guide";
|
||||||
|
this.el.width = 600;
|
||||||
|
this.el.height = 600;
|
||||||
|
this.el.style.width = "300px";
|
||||||
|
this.el.style.height = "300px";
|
||||||
this.markers;
|
this.markers;
|
||||||
|
|
||||||
this.start = function()
|
this.start = function()
|
||||||
{
|
{
|
||||||
// Markers
|
this.update();
|
||||||
this.markers = JSON.parse("["+"[],".repeat(dotgrid.grid_x)+"[]"+"]")
|
}
|
||||||
|
|
||||||
|
this.clear = function()
|
||||||
|
{
|
||||||
|
this.el.getContext('2d').clearRect(0, 0, 600, 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.update = function()
|
||||||
|
{
|
||||||
|
this.clear();
|
||||||
|
|
||||||
for (var x = dotgrid.grid_x; x >= 0; x--) {
|
for (var x = dotgrid.grid_x; x >= 0; x--) {
|
||||||
for (var y = dotgrid.grid_y; y >= 0; y--) {
|
for (var y = dotgrid.grid_y; y >= 0; y--) {
|
||||||
let marker = document.createElement("div");
|
var pos_x = parseInt(x * dotgrid.grid_width) ;
|
||||||
marker.setAttribute("class",(x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0 ? "marker bm" : "marker bl"));
|
var pos_y = parseInt(y * dotgrid.grid_height) ;
|
||||||
marker.style.left = parseInt(x * dotgrid.grid_width + (dotgrid.grid_width/2)) ;
|
var is_step = x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0;
|
||||||
marker.style.top = parseInt(y * dotgrid.grid_height + (dotgrid.grid_height/2)) ;
|
var radius = is_step ? 1.5 : 0.5;
|
||||||
this.el.appendChild(marker);
|
dotgrid.guide.draw_marker({x:pos_x * 2,y:pos_y * 2},radius,is_step);
|
||||||
this.markers[x][y] = marker
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.update = function() // it's less than ideal to reuse this much code, but I couldn't find a way to reuse the function that wouldn't mess with the architecture
|
|
||||||
|
this.draw_marker = function(pos,radius = 1,step)
|
||||||
{
|
{
|
||||||
for (var x = dotgrid.grid_x; x >= 0; x--) {
|
var ctx = this.el.getContext('2d');
|
||||||
for (var y = dotgrid.grid_y; y >= 0; y--) {
|
ctx.beginPath();
|
||||||
let marker = this.markers[x][y]
|
ctx.arc(pos.x, pos.y, radius, 0, 2 * Math.PI, false);
|
||||||
marker.style.left = parseInt(x * dotgrid.grid_width + (dotgrid.grid_width/2) +(5*dotgrid.scale));
|
ctx.fillStyle = step ? 'green' : 'red';
|
||||||
marker.style.top = parseInt(y * dotgrid.grid_height + (dotgrid.grid_height/2) +(5*dotgrid.scale));
|
ctx.fill();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user