diff --git a/css/pixel-editor.scss b/css/pixel-editor.scss index f2ff702..adb461e 100644 --- a/css/pixel-editor.scss +++ b/css/pixel-editor.scss @@ -1231,6 +1231,7 @@ svg { #colour-picker { background-color:$basecolor; width:250px; + height:350px; position:absolute; display:inline-block; @@ -1297,6 +1298,7 @@ svg { display:flex; font-family: 'Roboto', sans-serif; background-color:$basetextweak; + width:100%; button { font-size:14px; @@ -1459,7 +1461,6 @@ div#palette-block { z-index:1000; position:relative; resize: horizontal; - padding: 0 0 0 0; margin: 0 0 0 0; width:600px; height:400px; @@ -1468,10 +1469,14 @@ div#palette-block { div#palette-container { display:inline-block; background-color:black; - position:relative; + position:absolute; scrollbar-color: #332f35 #232125; scroll-behavior: smooth; -/* + left:300px; + width:300px; + height:280px; + overflow-y: scroll; + &::-webkit-scrollbar { background: #232125; width: 0.5em; @@ -1488,7 +1493,6 @@ div#palette-container { &::-webkit-scrollbar-corner { background: #232125; } -*/ } ul#palette-list { @@ -1509,4 +1513,26 @@ ul#palette-list { max-width:75px; max-height:75px; } +} + + +div#pb-options { + position:relative; + left:300px; + height:100px; + width:300px; + top:280px; + + button { + position:relative; + width:50%; + height:100%; + text-align:center; + cursor: pointer; + } + + button:hover { + color: $basehovertext; + background-color: $basehover; + } } \ No newline at end of file diff --git a/js/_addColor.js b/js/_addColor.js index 51649d1..943bccd 100644 --- a/js/_addColor.js +++ b/js/_addColor.js @@ -45,8 +45,6 @@ function addColor (newColor) { showDialogue("palette-block", false); }); - //console.log(currentPalette); - return listItem; } diff --git a/js/_colorPicker.js b/js/_colorPicker.js index 7814521..6554269 100644 --- a/js/_colorPicker.js +++ b/js/_colorPicker.js @@ -370,8 +370,6 @@ function movePickerIcon(event) { let left = (cursorPos[0] - startPickerIconPos[0][0] - 8); let top = (cursorPos[1] - startPickerIconPos[0][1] - 8); - - console.log(left + "," + top); if (left > -8 && top > -8 && left < canvasRect.width-8 && top < canvasRect.height-8){ activePickerIcon.style["left"] = "" + left + "px"; @@ -506,7 +504,7 @@ function updateMiniPickerColour() { function getMiniPickerColour() { let hex; let pickedColour; - console.log(currPickerIconPos[0]); + pickedColour = miniPickerCanvas.getContext('2d').getImageData(currPickerIconPos[0][0] + 8, currPickerIconPos[0][1] + 8, 1, 1).data; @@ -583,7 +581,6 @@ function changePickingMode(event, newMode) { canvasContainer.removeChild(canvasContainer.children[2]); // Deleting extra hex containers - console.log("Deleting :O"); hexContainers[0].parentElement.removeChild(hexContainers[0].parentElement.children[1]); hexContainers[i] = null; } @@ -760,7 +757,6 @@ function updateOtherIcons() { } // If I'm using analogous mode, I place the current colour in the middle else { - console.log("si si si sonooo sono qui"); hexContainers[1].style.backgroundColor = colourValue.value; hexContainers[1].innerHTML = colourValue.value; diff --git a/js/_dialogue.js b/js/_dialogue.js index 29bdb53..8820fd8 100644 --- a/js/_dialogue.js +++ b/js/_dialogue.js @@ -14,6 +14,10 @@ function showDialogue (dialogueName, trackEvent) { // Showing the window document.getElementById(dialogueName).style.display = 'block'; + // If I'm opening the palette window, I initialize the colour picker + if (dialogueName == 'palette-block') + cpInit(); + //track google event if (trackEvent) ga('send', 'event', 'Palette Editor Dialogue', dialogueName); /*global ga*/ diff --git a/js/_paletteBlock.js b/js/_paletteBlock.js new file mode 100644 index 0000000..be75ba1 --- /dev/null +++ b/js/_paletteBlock.js @@ -0,0 +1,281 @@ +let coloursList = document.getElementById("palette-list"); + +let rampMenu = document.getElementById("pb-ramp-options"); +let pbRampDialogue = document.getElementById("pb-ramp-dialogue"); + +let currentSquareSize = coloursList.children[0].clientWidth; +let blockData = {blockWidth: 500, blockHeight: 200, squareSize: 50}; +let isRampSelecting = false; +let ramps = []; +let currentSelection = {startIndex:0, endIndex:0, startCoords:[], endCoords: [], name: "", colour: "", label: null}; + +// Making the palette list sortable +new Sortable(document.getElementById("palette-list"), { + animation: 100, + onEnd: updateRampSelection +}); + +// Listening for the palette block resize +new ResizeObserver(updateSizeData).observe(coloursList.parentElement); + +/** Listens for the mouse wheel, used to change the size of the squares in the palette list + * + */ +coloursList.parentElement.addEventListener("wheel", function (mouseEvent) { + // Only resize when pressing alt, used to distinguish between scrolling through the palette and + // resizing it + if (mouseEvent.altKey) { + resizeSquares(mouseEvent); + } +}); + +/** Tells whether a colour is in the palette or not + * + * @param {*} colour The colour to add + */ +function hasColour(colour) { + for (let i=0; i endIndex) { + let tmp = startIndex; + startIndex = endIndex; + endIndex = tmp; + } + + for (let i=startIndex; i<=endIndex; i++) { + coloursList.removeChild(coloursList.children[startIndex]); + } + clearBorders(); + + // TODO: make it so that ramps update correctly (change start and end indexes if necessary) +} + +/** Starts selecting a ramp. Saves the data needed to draw the outline. + * + * @param {*} mouseEvent + */ +function startRampSelection(mouseEvent) { + if (mouseEvent.which == 3) { + let index = getElementIndex(mouseEvent.target); + + isRampSelecting = true; + + currentSelection.startIndex = index; + currentSelection.endIndex = index; + + currentSelection.startCoords = getColourCoordinates(index); + currentSelection.endCoords = getColourCoordinates(index); + } +} + +/** Updates the outline for the current selection. + * + * @param {*} mouseEvent + */ +function updateRampSelection(mouseEvent) { + if (mouseEvent != null && mouseEvent.which == 3) { + currentSelection.endIndex = getElementIndex(mouseEvent.target); + } + + if (mouseEvent == null || mouseEvent.which == 3) { + let startCoords = getColourCoordinates(currentSelection.startIndex); + let endCoords = getColourCoordinates(currentSelection.endIndex); + + let startIndex = currentSelection.startIndex; + let endIndex = currentSelection.endIndex; + + if (currentSelection.startIndex > endIndex) { + let tmp = startIndex; + startIndex = endIndex; + endIndex = tmp; + + tmp = startCoords; + startCoords = endCoords; + endCoords = tmp; + } + + clearBorders(); + + for (let i=startIndex; i<=endIndex; i++) { + let currentSquare = coloursList.children[i]; + let currentCoords = getColourCoordinates(i); + let borderStyle = "4px solid white"; + let bordersToSet = []; + + // Deciding which borders to use to make the outline + if (i == 0 || i == startIndex) { + bordersToSet.push("border-left"); + } + if (currentCoords[1] == startCoords[1] || ((currentCoords[1] == startCoords[1] + 1)) && currentCoords[0] < startCoords[0]) { + bordersToSet.push("border-top"); + } + if (currentCoords[1] == endCoords[1] || ((currentCoords[1] == endCoords[1] - 1)) && currentCoords[0] > endCoords[0]) { + bordersToSet.push("border-bottom"); + } + if ((i == coloursList.childElementCount - 1) || (currentCoords[0] == Math.floor(blockData.blockWidth / blockData.squareSize) - 1) + || i == endIndex) { + bordersToSet.push("border-right"); + } + if (bordersToSet != []) { + console.log("qui"); + currentSquare.style["box-sizing"] = "border-box"; + + for (let i=0; i 0 ? -5 : 5; + currentSquareSize += amount; + + for (let i=0; i

Edit palette

- -
@@ -436,6 +422,20 @@
+ +
+
    +
  • +
  • +
+
+ +
+ + +