Issue #258 : Move resize method to utils + add unit test

This commit is contained in:
jdescottes
2015-11-26 23:35:33 +01:00
parent 67b66e4a10
commit f0ed4927e8
11 changed files with 206 additions and 136 deletions

View File

@@ -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],
];
}
};
})();