Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/Bartheyrman22/miniPaint int…
Browse files Browse the repository at this point in the history
…o Bartheyrman22-master
  • Loading branch information
viliusle committed May 10, 2018
2 parents aee8480 + cc3662a commit 2d817c3
Show file tree
Hide file tree
Showing 20 changed files with 846 additions and 370 deletions.
91 changes: 62 additions & 29 deletions src/js/core/base-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,58 @@ class Base_tools_class {
}
}

dragStart(event) {
var _this = this;
_this.set_mouse_info(event);

_this.is_drag = true;
_this.speed_average = 0;
var mouse = _this.get_mouse_info(event, true);
_this.mouse_click_pos[0] = mouse.x;
_this.mouse_click_pos[1] = mouse.y;
}

dragMove(event) {
var _this = this;
_this.set_mouse_info(event);

_this.speed_average = _this.calc_average_mouse_speed(event);
}

dragEnd(event) {
var _this = this;
_this.is_drag = false;
_this.set_mouse_info(event);
}

events() {
var _this = this;



//collect mouse info
document.addEventListener('mousedown', function (event) {
_this.set_mouse_info(event);

_this.is_drag = true;
_this.speed_average = 0;
var mouse = _this.get_mouse_info(event, true);
_this.mouse_click_pos[0] = mouse.x;
_this.mouse_click_pos[1] = mouse.y;
_this.dragStart(event);
});
document.addEventListener('mousemove', function (event) {
_this.set_mouse_info(event);

_this.speed_average = _this.calc_average_mouse_speed(event);
_this.dragMove(event);
});
document.addEventListener('mouseup', function (event) {
_this.is_drag = false;
_this.set_mouse_info(event);
_this.dragEnd(event);
});

// collect touch info
document.addEventListener('touchstart', function (event) {
_this.dragStart(event);
});
document.addEventListener('touchmove', function (event) {
_this.dragMove(event);
if(event.target.id === "canvas_minipaint" && !$('.scroll').has($(event.target)).length)
event.preventDefault();
});
document.addEventListener('touchend', function (event) {
_this.dragEnd(event);
});
}

/**
Expand All @@ -71,30 +101,33 @@ class Base_tools_class {
//not main
return false;
}
if (event != undefined && event.changedTouches) {
//using touch events
event = event.changedTouches[0];
}

var mouse_x = event.pageX - this.canvas_offset.x;
var mouse_y = event.pageY - this.canvas_offset.y;
var eventType = event.type;

if (event.target.id != "canvas_minipaint") {
//outside canvas
this.mouse_valid = false;
}
else {
this.mouse_valid = true;
}
if (event.target.id != "canvas_minipaint") {
//outside canvas
this.mouse_valid = false;
}
else {
this.mouse_valid = true;
}

if (event.type == 'mousedown') {
if (event.target.id != "canvas_minipaint" || event.which != 1)
if (eventType === 'mousedown' || eventType === 'touchstart') {
if (event.target.id != "canvas_minipaint" || (event.which != 1 && eventType !== 'touchstart'))
this.mouse_click_valid = false;
else
this.mouse_click_valid = true;
this.mouse_valid = true;
}

if (event != undefined && event.changedTouches) {
//using touch events
event = event.changedTouches[0];
}

var mouse_x = event.pageX - this.canvas_offset.x;
var mouse_y = event.pageY - this.canvas_offset.y;

//adapt coords to ZOOM
var global_pos = this.Base_layers.get_world_coords(mouse_x, mouse_y);
mouse_x = global_pos.x;
Expand All @@ -120,7 +153,7 @@ class Base_tools_class {
speed_average: this.speed_average,
};

if (event.type == 'mousemove') {
if (eventType === 'mousemove' || eventType === 'touchmove') {
//save last pos
this.mouse_move_last[0] = mouse_x;
this.mouse_move_last[1] = mouse_y;
Expand Down Expand Up @@ -171,7 +204,7 @@ class Base_tools_class {

/**
* customized mouse cursor
*
*
* @param {int} x
* @param {int} y
* @param {int} size
Expand Down
69 changes: 47 additions & 22 deletions src/js/tools/blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,56 @@ class Blur_class extends Base_tools_class {
this.started = false;
}

dragStart(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;
_this.mousedown(event);
}

dragMove(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;
_this.mousemove(event);

//mouse cursor
var mouse = _this.get_mouse_info(e);
var params = _this.getParams();
_this.show_mouse_cursor(mouse.x, mouse.y, params.size, 'circle');
}

dragEnd(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;
_this.mouseup(event);
}

load() {
var _this = this;

//mouse events
document.addEventListener('mousedown', function (e) {
if (config.TOOL.name != _this.name)
return;
_this.mousedown(e);
});
document.addEventListener('mousemove', function (e) {
if (config.TOOL.name != _this.name)
return;
_this.mousemove(e);

//mouse cursor
var mouse = _this.get_mouse_info(e);
var params = _this.getParams();
_this.show_mouse_cursor(mouse.x, mouse.y, params.size, 'circle');

});
document.addEventListener('mouseup', function (e) {
if (config.TOOL.name != _this.name)
return;
_this.mouseup(e);
});
//mouse events
document.addEventListener('mousedown', function (event) {
_this.dragStart(event);
});
document.addEventListener('mousemove', function (event) {
_this.dragMove(event);
});
document.addEventListener('mouseup', function (event) {
_this.dragEnd(event);
});

// collect touch events
document.addEventListener('touchstart', function (event) {
_this.dragStart(event);
});
document.addEventListener('touchmove', function (event) {
_this.dragMove(event);
});
document.addEventListener('touchend', function (event) {
_this.dragEnd(event);
});
}

mousedown(e) {
Expand Down
68 changes: 47 additions & 21 deletions src/js/tools/brush.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,56 @@ class Brush_class extends Base_tools_class {
this.params_hash = false;
}

dragStart(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;
_this.mousedown(event);
}

dragMove(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;
_this.mousemove(event);

//mouse cursor
var mouse = _this.get_mouse_info(event);
var params = _this.getParams();
_this.show_mouse_cursor(mouse.x, mouse.y, params.size, 'circle');
}

dragEnd(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;
_this.mouseup(event);
}

load() {
var _this = this;

//events
document.addEventListener('mousedown', function (e) {
if (config.TOOL.name != _this.name)
return;
_this.mousedown(e);
});
document.addEventListener('mousemove', function (e) {
if (config.TOOL.name != _this.name)
return;
_this.mousemove(e);

//mouse cursor
var mouse = _this.get_mouse_info(e);
var params = _this.getParams();
_this.show_mouse_cursor(mouse.x, mouse.y, params.size, 'circle');
});
document.addEventListener('mouseup', function (e) {
if (config.TOOL.name != _this.name)
return;
_this.mouseup(e);
});
//mouse events
document.addEventListener('mousedown', function (event) {
_this.dragStart(event);
});
document.addEventListener('mousemove', function (event) {
_this.dragMove(event);
});
document.addEventListener('mouseup', function (event) {
_this.dragEnd(event);
});

// collect touch events
document.addEventListener('touchstart', function (event) {
_this.dragStart(event);
});
document.addEventListener('touchmove', function (event) {
_this.dragMove(event);
});
document.addEventListener('touchend', function (event) {
_this.dragEnd(event);
});
}

mousedown(e) {
Expand Down
67 changes: 46 additions & 21 deletions src/js/tools/bulge_pinch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,55 @@ class BulgePinch_class extends Base_tools_class {
this.started = false;
}

dragStart(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;
_this.mousedown(event);
}

dragMove(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;

//mouse cursor
var mouse = _this.get_mouse_info(event);
var params = _this.getParams();
_this.show_mouse_cursor(mouse.x, mouse.y, params.radius, 'circle');
}

dragEnd(event) {
var _this = this;
if (config.TOOL.name != _this.name)
return;
_this.mouseup(event);
}

load() {
var _this = this;

//mouse events
document.addEventListener('mousedown', function (e) {
if (config.TOOL.name != _this.name)
return;
_this.mousedown(e);
});
document.addEventListener('mousemove', function (e) {
if (config.TOOL.name != _this.name)
return;

//mouse cursor
var mouse = _this.get_mouse_info(e);
var params = _this.getParams();
_this.show_mouse_cursor(mouse.x, mouse.y, params.radius, 'circle');

});
document.addEventListener('mouseup', function (e) {
if (config.TOOL.name != _this.name)
return;
_this.mouseup(e);
});
//mouse events
document.addEventListener('mousedown', function (event) {
_this.dragStart(event);
});
document.addEventListener('mousemove', function (event) {
_this.dragMove(event);
});
document.addEventListener('mouseup', function (event) {
_this.dragEnd(event);
});

// collect touch events
document.addEventListener('touchstart', function (event) {
_this.dragStart(event);
});
document.addEventListener('touchmove', function (event) {
_this.dragMove(event);
});
document.addEventListener('touchend', function (event) {
_this.dragEnd(event);
});
}

mousedown(e) {
Expand Down
Loading

0 comments on commit 2d817c3

Please sign in to comment.