mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed #56
This commit is contained in:
@ -346,6 +346,7 @@ const ColorModule = (() => {
|
|||||||
* @param {*} paletteColors The colours of the palette
|
* @param {*} paletteColors The colours of the palette
|
||||||
*/
|
*/
|
||||||
function createColorPalette(paletteColors) {
|
function createColorPalette(paletteColors) {
|
||||||
|
console.log("creating palette");
|
||||||
//remove current palette
|
//remove current palette
|
||||||
while (colorsMenu.childElementCount > 1)
|
while (colorsMenu.childElementCount > 1)
|
||||||
colorsMenu.children[0].remove();
|
colorsMenu.children[0].remove();
|
||||||
@ -389,6 +390,9 @@ const ColorModule = (() => {
|
|||||||
*/
|
*/
|
||||||
function createPaletteFromLayers() {
|
function createPaletteFromLayers() {
|
||||||
let colors = {};
|
let colors = {};
|
||||||
|
let nColors = 0;
|
||||||
|
//create array out of colors object
|
||||||
|
let colorPaletteArray = [];
|
||||||
|
|
||||||
for (let i=0; i<layers.length; i++) {
|
for (let i=0; i<layers.length; i++) {
|
||||||
if (layers[i].menuEntry != null) {
|
if (layers[i].menuEntry != null) {
|
||||||
@ -399,12 +403,13 @@ const ColorModule = (() => {
|
|||||||
if (!isPixelEmpty(imageData[j])) {
|
if (!isPixelEmpty(imageData[j])) {
|
||||||
let color = imageData[j]+','+imageData[j + 1]+','+imageData[j + 2];
|
let color = imageData[j]+','+imageData[j + 1]+','+imageData[j + 2];
|
||||||
|
|
||||||
if (!colors[color] && imageData[j + 3] != 0) {
|
if (!colors[color]) {
|
||||||
|
colorPaletteArray.push('#' + new Color("rgb", imageData[j], imageData[j + 1], imageData[j + 2]).hex);
|
||||||
colors[color] = new Color("rgb", imageData[j], imageData[j + 1], imageData[j + 2]).rgb;
|
colors[color] = new Color("rgb", imageData[j], imageData[j + 1], imageData[j + 2]).rgb;
|
||||||
|
nColors++;
|
||||||
//don't allow more than 256 colors to be added
|
//don't allow more than 256 colors to be added
|
||||||
if (Object.keys(colors).length >= settings.maxColorsOnImportedImage) {
|
if (nColors >= Settings.getCurrSettings().maxColorsOnImportedImage) {
|
||||||
alert('The image loaded seems to have more than '+settings.maxColorsOnImportedImage+' colors.');
|
alert('The image loaded seems to have more than '+Settings.getCurrSettings().maxColorsOnImportedImage+' colors.');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,18 +418,10 @@ const ColorModule = (() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//create array out of colors object
|
|
||||||
let colorPaletteArray = [];
|
|
||||||
for (let color in colors) {
|
|
||||||
if (colors.hasOwnProperty(color)) {
|
|
||||||
colorPaletteArray.push('#'+Color.rgbToHex(colors[color]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("palette");
|
|
||||||
|
|
||||||
//create palette from colors array
|
//create palette from colors array
|
||||||
createColorPalette(colorPaletteArray);
|
createColorPalette(colorPaletteArray);
|
||||||
|
|
||||||
|
console.log("Done 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCurrentColor(color, refLayer) {
|
function updateCurrentColor(color, refLayer) {
|
||||||
|
@ -38,8 +38,8 @@ const History = (() => {
|
|||||||
undoStates.push(state);
|
undoStates.push(state);
|
||||||
|
|
||||||
//limit the number of states to settings.numberOfHistoryStates
|
//limit the number of states to settings.numberOfHistoryStates
|
||||||
if (undoStates.length > settings.numberOfHistoryStates) {
|
if (undoStates.length > Settings.getCurrSettings().numberOfHistoryStates) {
|
||||||
undoStates = undoStates.splice(-settings.numberOfHistoryStates, settings.numberOfHistoryStates);
|
undoStates = undoStates.splice(-Settings.getCurrSettings().numberOfHistoryStates, Settings.getCurrSettings().numberOfHistoryStates);
|
||||||
}
|
}
|
||||||
|
|
||||||
//there is now definitely at least 1 undo state, so the button shouldnt be disabled
|
//there is now definitely at least 1 undo state, so the button shouldnt be disabled
|
||||||
|
@ -57,7 +57,12 @@ const Settings = (() => {
|
|||||||
Dialogue.closeDialogue();
|
Dialogue.closeDialogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
function getCurrSettings() {
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
getCurrSettings
|
||||||
|
}
|
||||||
|
|
||||||
})();
|
})();
|
@ -6,16 +6,8 @@
|
|||||||
* @param {*} pixel
|
* @param {*} pixel
|
||||||
*/
|
*/
|
||||||
function isPixelEmpty(pixel) {
|
function isPixelEmpty(pixel) {
|
||||||
if (pixel == null || pixel === undefined) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the alpha channel is 0, the current pixel is empty
|
// If the alpha channel is 0, the current pixel is empty
|
||||||
if (pixel[3] == 0) {
|
return pixel[3] == 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// REFACTOR: move to eyedropper onMouseUp event?
|
// REFACTOR: move to eyedropper onMouseUp event?
|
||||||
|
@ -66,7 +66,7 @@ function fillPixelGrid() {
|
|||||||
pixelGrid.canvas.width = originalSize[0] * Math.round(lineDistance);
|
pixelGrid.canvas.width = originalSize[0] * Math.round(lineDistance);
|
||||||
pixelGrid.canvas.height = originalSize[1] * Math.round(lineDistance);
|
pixelGrid.canvas.height = originalSize[1] * Math.round(lineDistance);
|
||||||
|
|
||||||
context.strokeStyle = settings.pixelGridColour;
|
context.strokeStyle = Settings.getCurrSettings().pixelGridColour;
|
||||||
|
|
||||||
// OPTIMIZABLE, could probably be a bit more elegant
|
// OPTIMIZABLE, could probably be a bit more elegant
|
||||||
// Draw horizontal lines
|
// Draw horizontal lines
|
||||||
|
Reference in New Issue
Block a user