|
|
|
@ -24,38 +24,15 @@ function init_listeners(state, context) {
@@ -24,38 +24,15 @@ function init_listeners(state, context) {
|
|
|
|
|
|
|
|
|
|
function debug_panel_init(state, context) { |
|
|
|
|
document.getElementById('debug-red').checked = state.debug.red; |
|
|
|
|
document.getElementById('debug-do-prepass').checked = state.debug.do_prepass; |
|
|
|
|
document.getElementById('debug-limit-from').checked = state.debug.limit_from; |
|
|
|
|
document.getElementById('debug-limit-to').checked = state.debug.limit_to; |
|
|
|
|
document.getElementById('do-snap').checked = state.snap !== null; |
|
|
|
|
|
|
|
|
|
document.getElementById('debug-red').addEventListener('change', (e) => { |
|
|
|
|
state.debug.red = e.target.checked; |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('debug-do-prepass').addEventListener('change', (e) => { |
|
|
|
|
state.debug.do_prepass = e.target.checked; |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('debug-limit-from').addEventListener('change', (e) => { |
|
|
|
|
state.debug.limit_from = e.target.checked; |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('debug-limit-to').addEventListener('change', (e) => { |
|
|
|
|
state.debug.limit_to = e.target.checked; |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('debug-render-from').addEventListener('input', (e) => { |
|
|
|
|
state.debug.render_from = parseInt(e.target.value); |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('debug-render-to').addEventListener('input', (e) => { |
|
|
|
|
state.debug.render_to = parseInt(e.target.value); |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
document.getElementById('do-snap').addEventListener('change', (e) => { |
|
|
|
|
state.snap = e.target.checked ? 'grid' : null; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
document.getElementById('debug-begin-benchmark').addEventListener('click', (e) => { |
|
|
|
@ -173,6 +150,13 @@ function keyup(e, state, context) {
@@ -173,6 +150,13 @@ function keyup(e, state, context) {
|
|
|
|
|
function mousedown(e, state, context) { |
|
|
|
|
const screenp = {'x': window.devicePixelRatio * e.clientX, 'y': window.devicePixelRatio * e.clientY}; |
|
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
const raw_canvasp = {...canvasp}; |
|
|
|
|
|
|
|
|
|
if (state.snap === 'grid') { |
|
|
|
|
const step = grid_snap_step(state); |
|
|
|
|
canvasp.x = Math.round(canvasp.x / step) * step; |
|
|
|
|
canvasp.y = Math.round(canvasp.y / step) * step; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.button !== 0 && e.button !== 1) { |
|
|
|
|
return; |
|
|
|
@ -225,7 +209,7 @@ function mousedown(e, state, context) {
@@ -225,7 +209,7 @@ function mousedown(e, state, context) {
|
|
|
|
|
// Check for resize first, because it supports
|
|
|
|
|
// clicking slightly outside of the image
|
|
|
|
|
const image = get_image(context, state.active_image); |
|
|
|
|
const corner = image_corner(state, image, canvasp); |
|
|
|
|
const corner = image_corner(state, image, raw_canvasp); |
|
|
|
|
if (corner !== null) { |
|
|
|
|
// Resize
|
|
|
|
|
state.imagescaling = true; |
|
|
|
@ -244,11 +228,13 @@ function mousedown(e, state, context) {
@@ -244,11 +228,13 @@ function mousedown(e, state, context) {
|
|
|
|
|
|
|
|
|
|
// Only do picking logic if we haven't started imagescaling already
|
|
|
|
|
if (!state.imagescaling) { |
|
|
|
|
const image = image_at(context, canvasp.x, canvasp.y); |
|
|
|
|
const image = image_at(context, raw_canvasp.x, raw_canvasp.y); |
|
|
|
|
if (image !== null) { |
|
|
|
|
state.active_image = image.key; |
|
|
|
|
// Allow immediately moving
|
|
|
|
|
state.imagemoving = true; |
|
|
|
|
image.raw_at.x = image.at.x; |
|
|
|
|
image.raw_at.y = image.at.y; |
|
|
|
|
} else { |
|
|
|
|
state.active_image = null; |
|
|
|
|
} |
|
|
|
@ -278,11 +264,18 @@ function mousemove(e, state, context) {
@@ -278,11 +264,18 @@ function mousemove(e, state, context) {
|
|
|
|
|
|
|
|
|
|
const screenp = {'x': window.devicePixelRatio * e.clientX, 'y': window.devicePixelRatio * e.clientY}; |
|
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
const raw_canvasp = {...canvasp}; |
|
|
|
|
|
|
|
|
|
if (state.snap === 'grid') { |
|
|
|
|
const step = grid_snap_step(state); |
|
|
|
|
canvasp.x = Math.round(canvasp.x / step) * step; |
|
|
|
|
canvasp.y = Math.round(canvasp.y / step) * step; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.tools.active === 'pointer') { |
|
|
|
|
if (state.active_image !== null) { |
|
|
|
|
const image = get_image(context, state.active_image); |
|
|
|
|
const corner = image_corner(state, image, canvasp); |
|
|
|
|
const corner = image_corner(state, image, raw_canvasp); |
|
|
|
|
|
|
|
|
|
if (state.scaling_corner === null) { |
|
|
|
|
document.querySelector('canvas').classList.remove('resize-topleft'); |
|
|
|
@ -301,8 +294,9 @@ function mousemove(e, state, context) {
@@ -301,8 +294,9 @@ function mousemove(e, state, context) {
|
|
|
|
|
const me = state.players[state.me]; |
|
|
|
|
const width = Math.max(me.width * state.canvas.zoom, 2.0); |
|
|
|
|
const radius = Math.round(width / 2); |
|
|
|
|
const brush_x = screenp.x - radius - 2; |
|
|
|
|
const brush_y = screenp.y - radius - 2; |
|
|
|
|
const brush_screen = canvas_to_screen(state, canvasp); |
|
|
|
|
const brush_x = brush_screen.x - radius - 2; |
|
|
|
|
const brush_y = brush_screen.y - radius - 2; |
|
|
|
|
document.querySelector('.brush-dom').style.transform = `translate(${brush_x}px, ${brush_y}px)`; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -367,8 +361,17 @@ function mousemove(e, state, context) {
@@ -367,8 +361,17 @@ function mousemove(e, state, context) {
|
|
|
|
|
const dx = e.movementX / state.canvas.zoom; |
|
|
|
|
const dy = e.movementY / state.canvas.zoom; |
|
|
|
|
|
|
|
|
|
image.at.x += dx; |
|
|
|
|
image.at.y += dy; |
|
|
|
|
image.raw_at.x += dx; |
|
|
|
|
image.raw_at.y += dy; |
|
|
|
|
|
|
|
|
|
if (state.snap === 'grid') { |
|
|
|
|
const step = grid_snap_step(state); |
|
|
|
|
image.at.x = Math.round(image.raw_at.x / step) * step; |
|
|
|
|
image.at.y = Math.round(image.raw_at.y / step) * step; |
|
|
|
|
} else if (state.snap === null) { |
|
|
|
|
image.at.x = image.raw_at.x; |
|
|
|
|
image.at.y = image.raw_at.y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
do_draw = true; |
|
|
|
|
} |
|
|
|
@ -438,6 +441,13 @@ function mousemove(e, state, context) {
@@ -438,6 +441,13 @@ function mousemove(e, state, context) {
|
|
|
|
|
function mouseup(e, state, context) { |
|
|
|
|
const screenp = {'x': window.devicePixelRatio * e.clientX, 'y': window.devicePixelRatio * e.clientY}; |
|
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
const raw_canvasp = {...canvasp}; |
|
|
|
|
|
|
|
|
|
if (state.snap === 'grid') { |
|
|
|
|
const step = grid_snap_step(state); |
|
|
|
|
canvasp.x = Math.round(canvasp.x / step) * step; |
|
|
|
|
canvasp.y = Math.round(canvasp.y / step) * step; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.button !== 0 && e.button !== 1) { |
|
|
|
|
return; |
|
|
|
@ -451,6 +461,8 @@ function mouseup(e, state, context) {
@@ -451,6 +461,8 @@ function mouseup(e, state, context) {
|
|
|
|
|
if (state.imagemoving) { |
|
|
|
|
state.imagemoving = false; |
|
|
|
|
const image = get_image(context, state.active_image); |
|
|
|
|
image.raw_at.x = image.at.x; |
|
|
|
|
image.raw_at.y = image.at.y; |
|
|
|
|
queue_event(state, image_move_event(state.active_image, image.at.x, image.at.y)); |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
return; |
|
|
|
|