mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Move intToHex to utils and change for to map
This commit is contained in:
parent
6ea9c248d8
commit
ffca6aa44c
@ -65,27 +65,6 @@
|
||||
return result;
|
||||
};
|
||||
|
||||
// TODO Move to utils
|
||||
var componentToHex = function (c) {
|
||||
var hex = c.toString(16);
|
||||
return hex.length == 1 ? '0' + hex : hex;
|
||||
};
|
||||
|
||||
var rgbToHex = function (r, g, b) {
|
||||
return '#' + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
||||
};
|
||||
|
||||
var intHexCache = {};
|
||||
var intToHex = function(int) {
|
||||
if (intHexCache[int]) {
|
||||
return intHexCache[int];
|
||||
}
|
||||
|
||||
var hex = rgbToHex(int & 0xff, int >> 8 & 0xff, int >> 16 & 0xff);
|
||||
intHexCache[int] = hex;
|
||||
return hex;
|
||||
};
|
||||
|
||||
var frameCache = {};
|
||||
ns.CurrentColorsService.prototype.updateCurrentColors_ = function () {
|
||||
var layers = this.piskelController.getLayers();
|
||||
@ -135,11 +114,9 @@
|
||||
// Remove transparent color from used colors
|
||||
delete colors[pskl.utils.colorToInt(Constants.TRANSPARENT_COLOR)];
|
||||
|
||||
var hexColors = [];
|
||||
for (var i in colors) {
|
||||
hexColors.push(intToHex(i));
|
||||
}
|
||||
|
||||
var hexColors = Object.keys(colors).map(function (color) {
|
||||
return pskl.utils.intToHex(color);
|
||||
});
|
||||
this.setCurrentColors(hexColors);
|
||||
}.bind(this, colors);
|
||||
|
||||
|
@ -90,6 +90,17 @@ if (!Uint32Array.prototype.fill) {
|
||||
return hex.length == 1 ? '0' + hex : hex;
|
||||
};
|
||||
|
||||
var intHexCache = {};
|
||||
ns.intToHex = function(int) {
|
||||
if (intHexCache[int]) {
|
||||
return intHexCache[int];
|
||||
}
|
||||
|
||||
var hex = ns.rgbToHex(int & 0xff, int >> 8 & 0xff, int >> 16 & 0xff);
|
||||
intHexCache[int] = hex;
|
||||
return hex;
|
||||
};
|
||||
|
||||
ns.normalize = function (value, def) {
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
return def;
|
||||
|
Loading…
Reference in New Issue
Block a user