pointvec/desktop/sources/scripts/guide.js

139 lines
3.6 KiB
JavaScript
Raw Normal View History

2017-11-09 14:47:06 -05:00
function Guide()
{
2017-11-12 21:25:29 -05:00
this.el = document.createElement("canvas");
2017-11-09 14:47:06 -05:00
this.el.id = "guide";
2017-11-12 22:54:56 -05:00
this.el.width = 640;
this.el.height = 640;
this.el.style.width = "320px";
this.el.style.height = "320px";
2017-11-09 14:47:06 -05:00
this.start = function()
2017-11-21 17:58:07 -05:00
{
this.clear();
2018-05-07 18:59:38 -04:00
this.refresh();
2017-11-21 17:58:07 -05:00
}
2018-01-12 15:00:53 -05:00
this.toggle = function()
{
this.el.style.opacity = !this.el.style.opacity || this.el.style.opacity == 1 ? 0 : 1;
}
2017-11-21 17:58:07 -05:00
this.resize = function(size)
{
this.el.width = (size.width+40)*2;
this.el.height = (size.height+40)*2;
this.el.style.width = (size.width+40)+"px";
this.el.style.height = (size.height+40)+"px";
2018-05-07 18:59:38 -04:00
this.refresh();
2017-11-21 17:58:07 -05:00
}
2017-11-12 21:25:29 -05:00
this.clear = function()
{
2018-05-07 00:51:58 -04:00
this.el.getContext('2d').clearRect(0, 0, this.el.width*2, this.el.height*2);
2017-11-12 16:47:34 -05:00
}
2017-11-12 21:25:29 -05:00
2018-05-07 18:59:38 -04:00
this.refresh = function()
2017-11-12 16:47:34 -05:00
{
2018-05-07 18:59:38 -04:00
console.log("refresh")
2017-11-12 21:25:29 -05:00
this.clear();
2018-05-07 18:59:38 -04:00
// Markers
for (var x = dotgrid.grid_x; x >= 0; x--) {
for (var y = dotgrid.grid_y; y >= 0; y--) {
var pos_x = parseInt(x * dotgrid.grid_width) + dotgrid.grid_width ;
var pos_y = parseInt(y * dotgrid.grid_height) + dotgrid.grid_height ;
var is_step = x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0;
var radius = is_step ? 2.5 : 1.5;
this.draw_marker({x:pos_x,y:pos_y},radius,is_step);
}
}
// Verteces
for(id in dotgrid.tool.verteces){
this.draw_vertex(dotgrid.tool.verteces[id]);
2017-11-12 22:54:56 -05:00
}
2018-05-07 18:59:38 -04:00
// Handles
2018-02-05 20:23:25 -05:00
for(segment_id in dotgrid.tool.layer()){
var segment = dotgrid.tool.layer()[segment_id];
for(vertex_id in segment.verteces){
var vertex = segment.verteces[vertex_id];
this.draw_handle(vertex);
}
}
2017-11-12 22:54:56 -05:00
// Translations
2018-05-07 19:32:00 -04:00
if(dotgrid.cursor.translation){
2017-11-12 22:54:56 -05:00
this.draw_translation();
2017-11-09 14:47:06 -05:00
}
2018-05-07 19:32:00 -04:00
// Cursor
this.draw_cursor(dotgrid.cursor.pos);
2017-11-09 14:47:06 -05:00
}
2017-11-12 21:25:29 -05:00
this.draw_vertex = function(pos, radius = 5)
{
var ctx = this.el.getContext('2d');
ctx.beginPath();
2018-05-07 18:47:09 -04:00
ctx.lineWidth = 2;
ctx.arc((pos.x * 2)+30, (pos.y * 2)+30, radius, 0, 2 * Math.PI, false);
2018-02-05 22:27:48 -05:00
ctx.fillStyle = dotgrid.theme.active.f_med;
ctx.fill();
ctx.closePath();
}
2017-11-12 21:25:29 -05:00
this.draw_marker = function(pos,radius = 1,step)
{
var ctx = this.el.getContext('2d');
ctx.beginPath();
2018-05-07 18:47:09 -04:00
ctx.lineWidth = 2;
2017-11-12 22:54:56 -05:00
ctx.arc(pos.x * 2, pos.y * 2, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = step ? dotgrid.theme.active.f_med : dotgrid.theme.active.f_low;
2017-11-12 21:25:29 -05:00
ctx.fill();
2017-11-12 22:54:56 -05:00
ctx.closePath();
}
2018-05-07 18:47:09 -04:00
this.draw_handle = function(pos,radius = 15)
2017-11-12 22:54:56 -05:00
{
2018-05-07 18:47:09 -04:00
var ctx = this.el.getContext('2d');
2017-11-12 22:54:56 -05:00
ctx.beginPath();
2018-05-07 18:47:09 -04:00
ctx.lineWidth = 3;
ctx.lineCap="round";
ctx.arc((pos.x * 2)+30, (pos.y * 2)+30, radius, 0, 2 * Math.PI, false);
ctx.strokeStyle = dotgrid.theme.active.f_low;
ctx.stroke();
2017-11-12 22:54:56 -05:00
ctx.closePath();
}
this.draw_translation = function()
{
// From
2018-05-07 18:47:09 -04:00
var ctx = this.el.getContext('2d');
2018-05-07 19:32:00 -04:00
var from = dotgrid.cursor.translation.from;
var to = dotgrid.cursor.translation.to;
2017-11-12 22:54:56 -05:00
2017-11-13 20:28:06 -05:00
if(to.x<=0) {
ctx.beginPath();
2018-05-07 18:47:09 -04:00
ctx.moveTo((from.x * -2)+30,(from.y * 2)+30);
ctx.lineTo((to.x * -2)+30,(to.y * 2)+30);
2017-11-13 20:28:06 -05:00
ctx.lineCap="round";
ctx.lineWidth = 5;
2018-01-31 15:32:47 -05:00
ctx.strokeStyle = dotgrid.theme.active.b_inv;
2017-11-13 20:28:06 -05:00
ctx.stroke();
ctx.closePath();
}
2017-11-12 21:25:29 -05:00
}
2018-05-07 19:32:00 -04:00
2018-05-07 19:35:27 -04:00
this.draw_cursor = function(pos = dotgrid.cursor.pos,radius = 10)
2018-05-07 19:32:00 -04:00
{
var ctx = this.el.getContext('2d');
ctx.beginPath();
ctx.lineWidth = 3;
ctx.lineCap="round";
2018-05-07 19:35:27 -04:00
ctx.arc(Math.abs(pos.x * -2)+30, Math.abs(pos.y * 2)+30, radius, 0, 2 * Math.PI, false);
2018-05-07 19:32:00 -04:00
ctx.strokeStyle = dotgrid.theme.active.f_med;
ctx.stroke();
ctx.closePath();
}
2017-11-09 14:47:06 -05:00
}