|
|
|
@ -217,13 +217,37 @@ function mousedown(e, state, context) {
@@ -217,13 +217,37 @@ function mousedown(e, state, context) {
|
|
|
|
|
} else if (state.tools.active === 'eraser') { |
|
|
|
|
state.erasing = true; |
|
|
|
|
} else if (state.tools.active === 'pointer') { |
|
|
|
|
const image_event = image_at(context, canvasp.x, canvasp.y); |
|
|
|
|
state.scaling_image = null; |
|
|
|
|
|
|
|
|
|
if (context.active_image !== null) { |
|
|
|
|
// Resize image?
|
|
|
|
|
const image = get_image(context, context.active_image); |
|
|
|
|
corner = image_corner(state, image, canvasp); |
|
|
|
|
if (corner !== null) { |
|
|
|
|
state.scaling_image = image.key; |
|
|
|
|
state.scaling_corner = corner; |
|
|
|
|
|
|
|
|
|
document.querySelector('canvas').classList.remove('resize-topleft'); |
|
|
|
|
document.querySelector('canvas').classList.remove('resize-topright'); |
|
|
|
|
|
|
|
|
|
if (corner === 0 || corner === 2) { |
|
|
|
|
document.querySelector('canvas').classList.add('resize-topleft'); |
|
|
|
|
} else if (corner === 1 || corner === 3) { |
|
|
|
|
document.querySelector('canvas').classList.add('resize-topright'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (image_event) { |
|
|
|
|
context.active_image = image_event.key; |
|
|
|
|
state.moving_image = image_event.key; |
|
|
|
|
} else { |
|
|
|
|
context.active_image = null; |
|
|
|
|
if (state.scaling_image === null) { |
|
|
|
|
// Select/move image?
|
|
|
|
|
const image_event = image_at(context, canvasp.x, canvasp.y); |
|
|
|
|
|
|
|
|
|
if (image_event) { |
|
|
|
|
context.active_image = image_event.key; |
|
|
|
|
state.moving_image = image_event.key; |
|
|
|
|
} else { |
|
|
|
|
context.active_image = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
schedule_draw(state, context); |
|
|
|
@ -250,7 +274,25 @@ function mousemove(e, state, context) {
@@ -250,7 +274,25 @@ function mousemove(e, state, context) {
|
|
|
|
|
|
|
|
|
|
const screenp = {'x': window.devicePixelRatio * e.clientX, 'y': window.devicePixelRatio * e.clientY}; |
|
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.tools.active === 'pointer') { |
|
|
|
|
if (context.active_image !== null) { |
|
|
|
|
const image = get_image(context, context.active_image); |
|
|
|
|
const corner = image_corner(state, image, canvasp); |
|
|
|
|
|
|
|
|
|
if (state.scaling_corner === null) { |
|
|
|
|
document.querySelector('canvas').classList.remove('resize-topleft'); |
|
|
|
|
document.querySelector('canvas').classList.remove('resize-topright'); |
|
|
|
|
|
|
|
|
|
if (corner === 0 || corner === 2) { |
|
|
|
|
document.querySelector('canvas').classList.add('resize-topleft'); |
|
|
|
|
} else if (corner === 1 || corner === 3) { |
|
|
|
|
document.querySelector('canvas').classList.add('resize-topright'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.me in state.players) { |
|
|
|
|
const me = state.players[state.me]; |
|
|
|
|
const width = Math.max(me.width * state.canvas.zoom, 2.0); |
|
|
|
@ -308,6 +350,12 @@ function mousemove(e, state, context) {
@@ -308,6 +350,12 @@ function mousemove(e, state, context) {
|
|
|
|
|
do_draw = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.scaling_image) { |
|
|
|
|
const image = get_image(context, state.scaling_image); |
|
|
|
|
scale_image(context, image, state.scaling_corner, canvasp); |
|
|
|
|
do_draw = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.moving_image) { |
|
|
|
|
const image = get_image(context, state.moving_image); |
|
|
|
|
|
|
|
|
@ -371,6 +419,12 @@ function mouseup(e, state, context) {
@@ -371,6 +419,12 @@ function mouseup(e, state, context) {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.scaling_image) { |
|
|
|
|
state.scaling_image = null; |
|
|
|
|
state.scaling_corner = null; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.moving || e.button === 1) { |
|
|
|
|
state.moving = false; |
|
|
|
|
context.canvas.classList.remove('moving'); |
|
|
|
|