mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Basic cut implementation
SelectionManager implmentaiton Rectangular seleciton impl Utils refacoring Event manager refactoring basic cut implmentation
This commit is contained in:
39
js/utils/core.js
Normal file
39
js/utils/core.js
Normal file
@ -0,0 +1,39 @@
|
||||
jQuery.namespace = function() {
|
||||
var a=arguments, o=null, i, j, d;
|
||||
for (i=0; i<a.length; i=i+1) {
|
||||
d=a[i].split(".");
|
||||
o=window;
|
||||
for (j=0; j<d.length; j=j+1) {
|
||||
o[d[j]]=o[d[j]] || {};
|
||||
o=o[d[j]];
|
||||
}
|
||||
}
|
||||
return o;
|
||||
};
|
||||
|
||||
/*
|
||||
* @provide pskl.utils
|
||||
*
|
||||
* @require Constants
|
||||
*/
|
||||
(function() { // namespace: pskl.utils
|
||||
|
||||
var ns = $.namespace("pskl.utils");
|
||||
|
||||
ns.rgbToHex = function(r, g, b) {
|
||||
if (r > 255 || g > 255 || b > 255)
|
||||
throw "Invalid color component";
|
||||
return ((r << 16) | (g << 8) | b).toString(16);
|
||||
};
|
||||
|
||||
ns.inherit = function(extendedObject, inheritFrom) {
|
||||
extendedObject.prototype = Object.create(inheritFrom.prototype);
|
||||
extendedObject.prototype.constructor = extendedObject;
|
||||
extendedObject.prototype.superclass = inheritFrom.prototype;
|
||||
|
||||
//pskl.ToolBehavior.Eraser.prototype = Object.create(pskl.ToolBehavior.BaseTool.prototype);
|
||||
//prototypeskl.ToolBehavior.Eraser.prototype.constructor = pskl.ToolBehavior.Eraser;
|
||||
};
|
||||
|
||||
})();
|
||||
|
60
js/utils/pixelUtils.js
Normal file
60
js/utils/pixelUtils.js
Normal file
@ -0,0 +1,60 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl");
|
||||
|
||||
ns.PixelUtils = {
|
||||
|
||||
getRectanglePixels : function (x0, y0, x1, y1) {
|
||||
var pixels = [];
|
||||
var swap;
|
||||
|
||||
if(x0 > x1) {
|
||||
swap = x0;
|
||||
x0 = x1;
|
||||
x1 = swap;
|
||||
}
|
||||
if(y0 > y1) {
|
||||
swap = y0;
|
||||
y0 = y1;
|
||||
y1 = swap;
|
||||
}
|
||||
|
||||
for(var x = x0; x <= x1; x++) {
|
||||
for(var y = y0; y <= y1; y++) {
|
||||
pixels.push({"col": x, "row": y});
|
||||
}
|
||||
}
|
||||
|
||||
return pixels;
|
||||
},
|
||||
|
||||
getBoundRectanglePixels : function (x0, y0, x1, y1) {
|
||||
var pixels = [];
|
||||
var swap;
|
||||
|
||||
if(x0 > x1) {
|
||||
swap = x0;
|
||||
x0 = x1;
|
||||
x1 = swap;
|
||||
}
|
||||
if(y0 > y1) {
|
||||
swap = y0;
|
||||
y0 = y1;
|
||||
y1 = swap;
|
||||
}
|
||||
|
||||
// Creating horizontal sides of the rectangle:
|
||||
for(var x = x0; x <= x1; x++) {
|
||||
pixels.push({"col": x, "row": y0});
|
||||
pixels.push({"col": x, "row": y1});
|
||||
}
|
||||
|
||||
// Creating vertical sides of the rectangle:
|
||||
for(var y = y0; y <= y1; y++) {
|
||||
pixels.push({"col": x0, "row": y});
|
||||
pixels.push({"col": x1, "row": y});
|
||||
}
|
||||
|
||||
return pixels;
|
||||
}
|
||||
};
|
||||
})();
|
Reference in New Issue
Block a user