Skip to content

Commit

Permalink
Merge pull request viliusle#102 from Bartheyrman22/master
Browse files Browse the repository at this point in the history
Fix: Touch scrolling and image rendering.
  • Loading branch information
viliusle authored May 14, 2018
2 parents ea88fe4 + ab4aecd commit 1b9bd8e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
57 changes: 30 additions & 27 deletions src/js/core/base-layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Base_layers_class {

/**
* renders all layers objects on main canvas
*
*
* @param {bool} force
*/
render(force) {
Expand Down Expand Up @@ -212,7 +212,7 @@ class Base_layers_class {

/**
* export current 1ayers to given canvas
*
*
* @param {canvas.context} ctx
* @param {object} object
*/
Expand Down Expand Up @@ -277,13 +277,13 @@ class Base_layers_class {

/**
* creates new layer
*
*
* @param {array} settings
* @param {boolean} can_automate
*/
async insert(settings, can_automate = true) {
var _this = this;

return new Promise(function(resolve, reject) {
var resolvable = false;
var need_autoresize = false;
Expand Down Expand Up @@ -340,6 +340,9 @@ class Base_layers_class {
if (layer.height == 0)
layer.height = layer.data.height;
layer.link = layer.data.cloneNode(true);
layer.link.onload = function () {
config.need_render = true;
};
layer.data = null;
need_autoresize = true;
}
Expand Down Expand Up @@ -417,7 +420,7 @@ class Base_layers_class {

/**
* autoresize layer, based on dimensions, up - always, if 1 layer - down.
*
*
* @param {int} width
* @param {int} height
* @param {int} layer_id
Expand Down Expand Up @@ -468,7 +471,7 @@ class Base_layers_class {

/**
* returns layer
*
*
* @param {int} id
* @returns {object}
*/
Expand All @@ -487,7 +490,7 @@ class Base_layers_class {

/**
* removes layer
*
*
* @param {int} id
* @param {boolean} force - Force to delete first layer?
*/
Expand Down Expand Up @@ -549,7 +552,7 @@ class Base_layers_class {

/**
* toggle layer visibility
*
*
* @param {int} id
*/
toggle_visibility(id) {
Expand All @@ -574,7 +577,7 @@ class Base_layers_class {

/**
* marks layer as selected, active
*
*
* @param {int} id
*/
select(id) {
Expand All @@ -588,7 +591,7 @@ class Base_layers_class {

/**
* change layer opacity
*
*
* @param {int} id
* @param {int} value 0-100
*/
Expand All @@ -606,7 +609,7 @@ class Base_layers_class {

/**
* clear layer data
*
*
* @param {int} id
*/
layer_clear(id) {
Expand All @@ -622,7 +625,7 @@ class Base_layers_class {

/**
* move layer up or down
*
*
* @param {int} id
* @param {int} direction
*/
Expand Down Expand Up @@ -658,7 +661,7 @@ class Base_layers_class {

/**
* checks if layer empty
*
*
* @param {int} id
* @returns {Boolean}
*/
Expand All @@ -671,10 +674,10 @@ class Base_layers_class {

return false;
}

/**
* find next layer
*
*
* @param {int} id layer id
* @returns {layer|null}
*/
Expand All @@ -695,10 +698,10 @@ class Base_layers_class {

return null;
}

/**
* find previous layer
*
*
* @param {int} id layer id
* @returns {layer|null}
*/
Expand All @@ -722,7 +725,7 @@ class Base_layers_class {

/**
* returns global position, for example if canvas is zoomed, it will convert relative mouse position to absolute at 100% zoom.
*
*
* @param {int} x
* @param {int} y
* @returns {object} keys: x, y
Expand All @@ -733,7 +736,7 @@ class Base_layers_class {

/**
* register new live filter
*
*
* @param {int} layer_id
* @param {string} name
* @param {object} params
Expand All @@ -755,7 +758,7 @@ class Base_layers_class {

/**
* delets live filter
*
*
* @param {int} layer_id
* @param {string} filter_id
*/
Expand All @@ -776,7 +779,7 @@ class Base_layers_class {

/**
* exports all layers to canvas for saving
*
*
* @param {canvas.context} ctx
* @param {int} layer_id Optional
*/
Expand All @@ -800,13 +803,13 @@ class Base_layers_class {
}
/**
* exports (active) layer to canvas for saving
*
*
* @param {int} layer_id or current layer by default
* @param {boolean} actual_area used for resized image. Default is false.
* @param {boolean} can_trim default is true
* @returns {canvas}
*/
convert_layer_to_canvas(layer_id, actual_area = false, can_trim) {
convert_layer_to_canvas(layer_id, actual_area = false, can_trim) {
if(actual_area == null)
actual_area = false;
if (layer_id == null)
Expand Down Expand Up @@ -841,7 +844,7 @@ class Base_layers_class {
if (trim_info.left > 0 || trim_info.top > 0 || trim_info.right > 0 || trim_info.bottom > 0) {
offset_x = trim_info.left;
offset_y = trim_info.top;

var w = canvas.width - trim_info.left - trim_info.right;
var h = canvas.height - trim_info.top - trim_info.bottom;
if(w > 1 && h > 1) {
Expand All @@ -858,7 +861,7 @@ class Base_layers_class {

/**
* updates layer image data
*
*
* @param {canvas} canvas
* @param {int} layer_id (optional)
*/
Expand All @@ -871,7 +874,7 @@ class Base_layers_class {
alertify.error('Error: layer must be image.');
return null;
}

if(this.Helper.is_edge_or_ie() == false){
//update image using blob (faster)
canvas.toBlob(function (blob) {
Expand All @@ -889,7 +892,7 @@ class Base_layers_class {

/**
* returns canvas dimensions.
*
*
* @returns {object}
*/
get_dimensions() {
Expand Down
2 changes: 1 addition & 1 deletion src/js/core/base-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Base_tools_class {
_this.dragMove(event);
if (event.target.id === "canvas_minipaint" && !$('.scroll').has($(event.target)).length)
event.preventDefault();
});
}, {passive: false});
document.addEventListener('touchend', function (event) {
_this.dragEnd(event);
});
Expand Down

0 comments on commit 1b9bd8e

Please sign in to comment.