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', () =>
|
||||
{
|
||||
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`)
|
||||
|
||||
@ -56,7 +56,7 @@ app.on('ready', () =>
|
||||
is_shown = true;
|
||||
})
|
||||
// Open the DevTools.
|
||||
// win.webContents.openDevTools()
|
||||
win.webContents.openDevTools()
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () =>
|
||||
|
@ -1,33 +1,44 @@
|
||||
function Guide()
|
||||
{
|
||||
this.el = document.createElement("div");
|
||||
|
||||
// Guide
|
||||
this.el = document.createElement("canvas");
|
||||
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.start = function()
|
||||
{
|
||||
// Markers
|
||||
this.markers = JSON.parse("["+"[],".repeat(dotgrid.grid_x)+"[]"+"]")
|
||||
this.update();
|
||||
}
|
||||
|
||||
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 y = dotgrid.grid_y; y >= 0; y--) {
|
||||
let marker = document.createElement("div");
|
||||
marker.setAttribute("class",(x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0 ? "marker bm" : "marker bl"));
|
||||
marker.style.left = parseInt(x * dotgrid.grid_width + (dotgrid.grid_width/2)) ;
|
||||
marker.style.top = parseInt(y * dotgrid.grid_height + (dotgrid.grid_height/2)) ;
|
||||
this.el.appendChild(marker);
|
||||
this.markers[x][y] = marker
|
||||
var pos_x = parseInt(x * dotgrid.grid_width) ;
|
||||
var pos_y = parseInt(y * dotgrid.grid_height) ;
|
||||
var is_step = x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0;
|
||||
var radius = is_step ? 1.5 : 0.5;
|
||||
dotgrid.guide.draw_marker({x:pos_x * 2,y:pos_y * 2},radius,is_step);
|
||||
}
|
||||
}
|
||||
}
|
||||
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--) {
|
||||
for (var y = dotgrid.grid_y; y >= 0; y--) {
|
||||
let marker = this.markers[x][y]
|
||||
marker.style.left = parseInt(x * dotgrid.grid_width + (dotgrid.grid_width/2) +(5*dotgrid.scale));
|
||||
marker.style.top = parseInt(y * dotgrid.grid_height + (dotgrid.grid_height/2) +(5*dotgrid.scale));
|
||||
}
|
||||
}
|
||||
var ctx = this.el.getContext('2d');
|
||||
ctx.beginPath();
|
||||
ctx.arc(pos.x, pos.y, radius, 0, 2 * Math.PI, false);
|
||||
ctx.fillStyle = step ? 'green' : 'red';
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user