pixel-editor/js/_newPixel.js

79 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-03-27 02:20:54 +03:00
function newPixel (width, height, palette) {
2020-04-04 10:41:56 +03:00
// Setting the current layer
currentLayer = new Layer(width, height, canvas, layerListEntry);
currentLayer.initialize();
2019-03-27 02:20:54 +03:00
// Adding the checkerboard behind it
checkerBoard = new Layer(width, height, checkerBoardCanvas);
checkerBoard.initialize();
// Creating the vfx layer on top of everything
VFXLayer = new Layer(width, height, VFXCanvas);
VFXLayer.initialize();
TMPLayer = new Layer(width, height, TMPCanvas);
TMPLayer.initialize();
canvasSize = currentLayer.canvasSize;
// Adding the first layer and the checkerboard to the list of layers
layers.push(checkerBoard);
layers.push(currentLayer);
layers.push(VFXLayer);
2020-03-05 18:13:23 +03:00
layers.push(TMPLayer);
2019-03-27 02:20:54 +03:00
//remove current palette
colors = document.getElementsByClassName('color-button');
while (colors.length > 0) {
colors[0].parentElement.remove();
}
2019-03-27 02:20:54 +03:00
//add colors from selected palette
var selectedPalette = getText('palette-button');
if (selectedPalette != 'Choose a palette...') {
2019-03-27 02:20:54 +03:00
//if this palette isnt the one specified in the url, then reset the url
if (!palettes[selectedPalette].specified)
history.pushState(null, null, '/pixel-editor/app');
2019-03-27 02:20:54 +03:00
//fill the palette with specified palette
createColorPalette(palettes[selectedPalette].colors,true);
fillCheckerboard();
2019-03-27 02:20:54 +03:00
}
else {
//this wasn't a specified palette, so reset the url
history.pushState(null, null, '/pixel-editor/app');
2019-03-27 02:20:54 +03:00
//generate default colors
var fg = hslToRgb(Math.floor(Math.random()*255), 230,70);
var bg = hslToRgb(Math.floor(Math.random()*255), 230,170);
2019-03-27 02:20:54 +03:00
//convert colors to hex
var defaultForegroundColor = rgbToHex(fg.r,fg.g,fg.b);
var defaultBackgroundColor = rgbToHex(bg.r,bg.g,bg.b);
2019-03-27 02:20:54 +03:00
//add colors to paletee
addColor(defaultForegroundColor).classList.add('selected');
addColor(defaultBackgroundColor);
//fill background of canvas with bg color
fillCheckerboard();
2019-03-27 02:20:54 +03:00
//set current drawing color as foreground color
currentLayer.context.fillStyle = '#'+defaultForegroundColor;
currentGlobalColor = '#' + defaultForegroundColor;
2019-03-27 02:20:54 +03:00
selectedPalette = 'none';
}
2019-03-27 02:20:54 +03:00
//reset undo and redo states
undoStates = [];
redoStates = [];
2019-03-27 02:20:54 +03:00
closeDialogue();
currentTool.updateCursor();
2019-03-27 02:20:54 +03:00
document.getElementById('save-as-button').classList.remove('disabled');
documentCreated = true;
2020-04-04 10:41:56 +03:00
}