mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Issue #258 : Move resize method to utils + add unit test
This commit is contained in:
@@ -4,10 +4,15 @@
|
||||
var MIN_PENSIZE = 1;
|
||||
var MAX_PENSIZE = 4;
|
||||
|
||||
ns.PenSizeService = function () {};
|
||||
/**
|
||||
* Service to retrieve and modify the current pen size.
|
||||
*/
|
||||
ns.PenSizeService = function () {
|
||||
this.size = MIN_PENSIZE;
|
||||
};
|
||||
|
||||
ns.PenSizeService.prototype.init = function () {
|
||||
this.size = pskl.UserSettings.get('PEN_SIZE');
|
||||
this.size = pskl.UserSettings.get(pskl.UserSettings.PEN_SIZE);
|
||||
|
||||
var shortcuts = pskl.service.keyboard.Shortcuts;
|
||||
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.INCREASE_PENSIZE, this.increasePenSize_.bind(this));
|
||||
@@ -22,10 +27,14 @@
|
||||
this.setPenSize(this.size - 1);
|
||||
};
|
||||
|
||||
ns.PenSizeService.prototype.getPenSize = function () {
|
||||
return this.size;
|
||||
};
|
||||
|
||||
ns.PenSizeService.prototype.setPenSize = function (size) {
|
||||
if (this.isPenSizeValid_(size) && size != this.size) {
|
||||
this.size = size;
|
||||
pskl.UserSettings.set('PEN_SIZE', size);
|
||||
pskl.UserSettings.set(pskl.UserSettings.PEN_SIZE, size);
|
||||
$.publish(Events.PEN_SIZE_CHANGED);
|
||||
}
|
||||
};
|
||||
@@ -38,32 +47,4 @@
|
||||
return size >= MIN_PENSIZE && size <= MAX_PENSIZE;
|
||||
};
|
||||
|
||||
ns.PenSizeService.prototype.getPenSize = function () {
|
||||
return this.size;
|
||||
};
|
||||
|
||||
ns.PenSizeService.prototype.getPixelsForPenSize = function (col, row, penSize) {
|
||||
var size = penSize || this.size;
|
||||
if (size == 1) {
|
||||
return [[col, row]];
|
||||
} else if (size == 2) {
|
||||
return [
|
||||
[col, row], [col + 1, row],
|
||||
[col, row + 1], [col + 1, row + 1]
|
||||
];
|
||||
} else if (size == 3) {
|
||||
return [
|
||||
[col - 1, row - 1], [col, row - 1], [col + 1, row - 1],
|
||||
[col - 1, row + 0], [col, row + 0], [col + 1, row + 0],
|
||||
[col - 1, row + 1], [col, row + 1], [col + 1, row + 1],
|
||||
];
|
||||
} else if (size == 4) {
|
||||
return [
|
||||
[col - 1, row - 1], [col, row - 1], [col + 1, row - 1], [col + 2, row - 1],
|
||||
[col - 1, row + 0], [col, row + 0], [col + 1, row + 0], [col + 2, row + 0],
|
||||
[col - 1, row + 1], [col, row + 1], [col + 1, row + 1], [col + 2, row + 1],
|
||||
[col - 1, row + 2], [col, row + 2], [col + 1, row + 2], [col + 2, row + 2],
|
||||
];
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user