Clean up
parent
adc524e241
commit
50730f5e64
|
@ -71,7 +71,7 @@ class OnCanvasSelection extends OnCanvasObject {
|
|||
});
|
||||
let mox, moy;
|
||||
const pointermove = e => {
|
||||
const m = e2c(e);
|
||||
const m = to_canvas_coords(e);
|
||||
this.x = Math.max(Math.min(m.x - mox, canvas.width), -this.width);
|
||||
this.y = Math.max(Math.min(m.y - moy, canvas.height), -this.height);
|
||||
this.position();
|
||||
|
|
|
@ -48,7 +48,7 @@ class OnCanvasTextBox extends OnCanvasObject {
|
|||
});
|
||||
let mox, moy;
|
||||
const pointermove = e => {
|
||||
const m = e2c(e);
|
||||
const m = to_canvas_coords(e);
|
||||
this.x = Math.max(Math.min(m.x - mox, canvas.width), -this.width);
|
||||
this.y = Math.max(Math.min(m.y - moy, canvas.height), -this.height);
|
||||
this.position();
|
||||
|
|
28
src/app.js
28
src/app.js
|
@ -1,4 +1,9 @@
|
|||
|
||||
const default_canvas_width = 683;
|
||||
const default_canvas_height = 384;
|
||||
let my_canvas_width = default_canvas_width;
|
||||
let my_canvas_height = default_canvas_height;
|
||||
|
||||
let aliasing = true;
|
||||
let transparency = false;
|
||||
let monochrome = false;
|
||||
|
@ -6,11 +11,6 @@ let monochrome = false;
|
|||
let magnification = 1;
|
||||
let return_to_magnification = 4;
|
||||
|
||||
const default_canvas_width = 683;
|
||||
const default_canvas_height = 384;
|
||||
let my_canvas_width = default_canvas_width;
|
||||
let my_canvas_height = default_canvas_height;
|
||||
|
||||
const canvas = make_canvas();
|
||||
canvas.classList.add("main-canvas");
|
||||
const ctx = canvas.ctx;
|
||||
|
@ -61,6 +61,10 @@ let file_name;
|
|||
let document_file_path;
|
||||
let saved = true;
|
||||
|
||||
let pointer, pointer_start, pointer_previous, pointer_type, pointer_buttons;
|
||||
let reverse;
|
||||
let ctrl;
|
||||
let button;
|
||||
|
||||
|
||||
const $app = $(E("div")).addClass("jspaint").appendTo("body");
|
||||
|
@ -452,11 +456,7 @@ if(window.document_file_path_to_open){
|
|||
});
|
||||
}
|
||||
|
||||
let pointer, pointer_start, pointer_previous, pointer_type, pointer_buttons;
|
||||
let reverse;
|
||||
let ctrl;
|
||||
var button;
|
||||
function e2c({clientX, clientY}) {
|
||||
function to_canvas_coords({clientX, clientY}) {
|
||||
const rect = canvas_bounding_client_rect;
|
||||
const cx = clientX - rect.left;
|
||||
const cy = clientY - rect.top;
|
||||
|
@ -529,7 +529,7 @@ function tool_go(selected_tool, event_name){
|
|||
function canvas_pointer_move(e){
|
||||
ctrl = e.ctrlKey;
|
||||
shift = e.shiftKey;
|
||||
pointer = e2c(e);
|
||||
pointer = to_canvas_coords(e);
|
||||
|
||||
// Quick Undo
|
||||
// (Note: pointermove also occurs when the set of buttons pressed changes,
|
||||
|
@ -581,7 +581,7 @@ function canvas_pointer_move(e){
|
|||
pointer_previous = pointer;
|
||||
}
|
||||
$canvas.on("pointermove", e => {
|
||||
pointer = e2c(e);
|
||||
pointer = to_canvas_coords(e);
|
||||
$status_position.text(`${pointer.x},${pointer.y}`);
|
||||
});
|
||||
$canvas.on("pointerenter", e => {
|
||||
|
@ -645,7 +645,7 @@ $canvas.on("pointerdown", e => {
|
|||
button = e.button;
|
||||
ctrl = e.ctrlKey;
|
||||
shift = e.shiftKey;
|
||||
pointer_start = pointer_previous = pointer = e2c(e);
|
||||
pointer_start = pointer_previous = pointer = to_canvas_coords(e);
|
||||
|
||||
const pointerdown_action = () => {
|
||||
// TODO for multitools: don't register event listeners for each tool
|
||||
|
@ -665,7 +665,7 @@ $canvas.on("pointerdown", e => {
|
|||
if(canceling){
|
||||
selected_tool.cancel && selected_tool.cancel();
|
||||
}else{
|
||||
pointer = e2c(e);
|
||||
pointer = to_canvas_coords(e);
|
||||
selected_tool.pointerup && selected_tool.pointerup(ctx, pointer.x, pointer.y);
|
||||
}
|
||||
if (selected_tools.length === 1) {
|
||||
|
|
|
@ -37,7 +37,7 @@ function update_helper_layer_immediately(e) {
|
|||
info_for_updating_pointer.clientX *= rescale;
|
||||
info_for_updating_pointer.clientY *= rescale;
|
||||
info_for_updating_pointer.devicePixelRatio = devicePixelRatio;
|
||||
pointer = e2c(info_for_updating_pointer);
|
||||
pointer = to_canvas_coords(info_for_updating_pointer);
|
||||
}
|
||||
|
||||
update_fill_and_stroke_colors_and_lineWidth(selected_tool);
|
||||
|
|
|
@ -331,7 +331,7 @@
|
|||
});
|
||||
});
|
||||
let previous_uri;
|
||||
let pointer_operations = [];
|
||||
let pointer_operations = []; // this was supposed to be shared as a global, but the multiplayer syncing stuff is a can of worms
|
||||
const sync = () => {
|
||||
const save_paused = handle_data_loss();
|
||||
if (save_paused) {
|
||||
|
@ -394,7 +394,7 @@
|
|||
});
|
||||
// Update the cursor status
|
||||
$G.on("pointermove.session-hook", e => {
|
||||
const m = e2c(e);
|
||||
const m = to_canvas_coords(e);
|
||||
this.fb_user.child("cursor").update({
|
||||
x: m.x,
|
||||
y: m.y,
|
||||
|
|
|
@ -33,7 +33,7 @@ tools = [{
|
|||
// paint(ctx, x, y) will be called for each pixel the pointer moves
|
||||
// and we only need to record individual pointer events to make the polygon
|
||||
const onpointermove = e => {
|
||||
const pointer = e2c(e);
|
||||
const pointer = to_canvas_coords(e);
|
||||
// Constrain the pointer to the canvas
|
||||
pointer.x = Math.min(canvas.width, pointer.x);
|
||||
pointer.x = Math.max(0, pointer.x);
|
||||
|
|
Loading…
Reference in New Issue