mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Added back eyedropper alt key binding
This commit is contained in:
parent
2ca5aa75b4
commit
73f7c980eb
30
js/Input.js
30
js/Input.js
@ -1,11 +1,18 @@
|
|||||||
const Input = (() => {
|
const Input = (() => {
|
||||||
let dragging = false;
|
let dragging = false;
|
||||||
let currentMouseEvent = undefined;
|
let currentMouseEvent = undefined;
|
||||||
|
let spacePressed = false;
|
||||||
|
let altPressed = false;
|
||||||
|
let ctrlPressed = false;
|
||||||
|
|
||||||
// Hotkeys when pressing a key
|
// Hotkeys when pressing a key
|
||||||
Events.on("keydown", document, KeyPress);
|
Events.on("keydown", document, KeyPress);
|
||||||
// Update held keys when releasing a key
|
// Update held keys when releasing a key
|
||||||
Events.on("keyup", window, function (e) {if (e.keyCode == 32) Events.emit("space-released");;});
|
Events.on("keyup", window, function (e) {
|
||||||
|
if (e.keyCode == 32) spacePressed = false;
|
||||||
|
if (!e.altKey) altPressed = false;
|
||||||
|
if (!e.ctrlKey) ctrlPressed = false;
|
||||||
|
});
|
||||||
|
|
||||||
// Update variables on mouse clicks
|
// Update variables on mouse clicks
|
||||||
Events.on("mousedown", window, onMouseDown);
|
Events.on("mousedown", window, onMouseDown);
|
||||||
@ -54,6 +61,8 @@ const Input = (() => {
|
|||||||
*/
|
*/
|
||||||
function KeyPress(e) {
|
function KeyPress(e) {
|
||||||
var keyboardEvent = window.event? event : e;
|
var keyboardEvent = window.event? event : e;
|
||||||
|
altPressed = e.altKey;
|
||||||
|
ctrlPressed = e.ctrlKey;
|
||||||
|
|
||||||
//if the user is typing in an input field or renaming a layer, ignore these hotkeys, unless it's an enter key
|
//if the user is typing in an input field or renaming a layer, ignore these hotkeys, unless it's an enter key
|
||||||
if (document.activeElement.tagName == 'INPUT' || LayerList.isRenamingLayer()) {
|
if (document.activeElement.tagName == 'INPUT' || LayerList.isRenamingLayer()) {
|
||||||
@ -145,7 +154,7 @@ const Input = (() => {
|
|||||||
History.redo();
|
History.redo();
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
Events.emit("space-pressed");
|
spacePressed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,9 +168,24 @@ const Input = (() => {
|
|||||||
return currentMouseEvent;
|
return currentMouseEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAltPressed() {
|
||||||
|
return altPressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isCtrlPressed() {
|
||||||
|
return ctrlPressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSpacePressed() {
|
||||||
|
return spacePressed;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isDragging,
|
isDragging,
|
||||||
getCurrMouseEvent,
|
getCurrMouseEvent,
|
||||||
getCursorPosition
|
getCursorPosition,
|
||||||
|
isAltPressed,
|
||||||
|
isCtrlPressed,
|
||||||
|
isSpacePressed
|
||||||
}
|
}
|
||||||
})();
|
})();
|
20
js/Tool.js
20
js/Tool.js
@ -39,7 +39,7 @@ class Tool {
|
|||||||
|
|
||||||
switch (this.cursorType.type) {
|
switch (this.cursorType.type) {
|
||||||
case 'html':
|
case 'html':
|
||||||
canvasView.style.cursor = 'default';
|
canvasView.style.cursor = 'none';
|
||||||
break;
|
break;
|
||||||
case 'cursor':
|
case 'cursor':
|
||||||
this.cursor = this.cursorType.style;
|
this.cursor = this.cursorType.style;
|
||||||
@ -50,7 +50,11 @@ class Tool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCursor() {}
|
updateCursor() {
|
||||||
|
brushPreview.style.display = 'block';
|
||||||
|
brushPreview.style.width = this.currSize * zoom + 'px';
|
||||||
|
brushPreview.style.height = this.currSize * zoom + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
onMouseWheel(mousePos, mode) {}
|
onMouseWheel(mousePos, mode) {}
|
||||||
|
|
||||||
@ -58,6 +62,8 @@ class Tool {
|
|||||||
this.prevMousePos = this.currMousePos;
|
this.prevMousePos = this.currMousePos;
|
||||||
this.currMousePos = cursorLocation;
|
this.currMousePos = cursorLocation;
|
||||||
|
|
||||||
|
this.updateCursor();
|
||||||
|
|
||||||
let toSub = 1;
|
let toSub = 1;
|
||||||
// Prevents the brush to be put in the middle of pixels
|
// Prevents the brush to be put in the middle of pixels
|
||||||
if (this.currSize % 2 == 0) {
|
if (this.currSize % 2 == 0) {
|
||||||
@ -68,16 +74,14 @@ class Tool {
|
|||||||
brushPreview.style.top = (Math.floor(cursorLocation[1] / zoom) * zoom + currentLayer.canvas.offsetTop - this.currSize * zoom / 2 - zoom / 2 + toSub * zoom) + 'px';
|
brushPreview.style.top = (Math.floor(cursorLocation[1] / zoom) * zoom + currentLayer.canvas.offsetTop - this.currSize * zoom / 2 - zoom / 2 + toSub * zoom) + 'px';
|
||||||
|
|
||||||
if (this.cursorType.type == 'html') {
|
if (this.cursorType.type == 'html') {
|
||||||
if (cursorTarget == 'drawingCanvas'|| cursorTarget.className == 'drawingCanvas') {
|
if (cursorTarget.className == 'drawingCanvas'|| cursorTarget.className == 'drawingCanvas') {
|
||||||
brushPreview.style.visibility = 'visible';
|
brushPreview.style.visibility = 'visible';
|
||||||
|
canvasView.style.cursor = 'none';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
brushPreview.style.visibility = 'hidden';
|
brushPreview.style.visibility = 'hidden';
|
||||||
|
canvasView.style.cursor = 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
brushPreview.style.display = 'block';
|
|
||||||
brushPreview.style.width = this.currSize * zoom + 'px';
|
|
||||||
brushPreview.style.height = this.currSize * zoom + 'px';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +89,9 @@ class Tool {
|
|||||||
if (this.mainButton != undefined)
|
if (this.mainButton != undefined)
|
||||||
this.mainButton.parentElement.classList.remove("selected");
|
this.mainButton.parentElement.classList.remove("selected");
|
||||||
this.isSelected = false;
|
this.isSelected = false;
|
||||||
|
|
||||||
brushPreview.style.visibility = 'hidden';
|
brushPreview.style.visibility = 'hidden';
|
||||||
|
canvasView.style.cursor = 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
onStart(mousePos) {
|
onStart(mousePos) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const ToolManager = (() => {
|
const ToolManager = (() => {
|
||||||
tools = {};
|
tools = {};
|
||||||
|
isPanning = false;
|
||||||
|
|
||||||
tools["brush"] = new BrushTool("brush", {type: 'html'}, switchTool);
|
tools["brush"] = new BrushTool("brush", {type: 'html'}, switchTool);
|
||||||
tools["eraser"] = new EraserTool("eraser", {type: 'html'}, switchTool);
|
tools["eraser"] = new EraserTool("eraser", {type: 'html'}, switchTool);
|
||||||
@ -25,6 +26,7 @@ const ToolManager = (() => {
|
|||||||
Events.on("mousedown", window, onMouseDown);
|
Events.on("mousedown", window, onMouseDown);
|
||||||
Events.on("mousewheel", window, onMouseWheel);
|
Events.on("mousewheel", window, onMouseWheel);
|
||||||
|
|
||||||
|
// Bind tool shortcuts
|
||||||
Events.onCustom("tool-shortcut", onShortcut);
|
Events.onCustom("tool-shortcut", onShortcut);
|
||||||
|
|
||||||
function onShortcut(tool) {
|
function onShortcut(tool) {
|
||||||
@ -45,7 +47,15 @@ const ToolManager = (() => {
|
|||||||
if (!Input.isDragging()) {
|
if (!Input.isDragging()) {
|
||||||
switch(mouseEvent.which) {
|
switch(mouseEvent.which) {
|
||||||
case 1:
|
case 1:
|
||||||
currTool.onStart(mousePos, mouseEvent.target);
|
if (Input.isSpacePressed()) {
|
||||||
|
tools["pan"].onStart(mousePos, mouseEvent.target);
|
||||||
|
}
|
||||||
|
else if (Input.isAltPressed()) {
|
||||||
|
tools["eyedropper"].onStart(mousePos, mouseEvent.target);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currTool.onStart(mousePos, mouseEvent.target);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
tools["pan"].onStart(mousePos, mouseEvent.target);
|
tools["pan"].onStart(mousePos, mouseEvent.target);
|
||||||
@ -69,7 +79,15 @@ const ToolManager = (() => {
|
|||||||
if (Input.isDragging()) {
|
if (Input.isDragging()) {
|
||||||
switch (mouseEvent.which) {
|
switch (mouseEvent.which) {
|
||||||
case 1:
|
case 1:
|
||||||
currTool.onDrag(mousePos, mouseEvent.target);
|
if (Input.isSpacePressed()) {
|
||||||
|
tools["pan"].onDrag(mousePos, mouseEvent.target);
|
||||||
|
}
|
||||||
|
else if (Input.isAltPressed()) {
|
||||||
|
tools["eyedropper"].onDrag(mousePos, mouseEvent.target);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currTool.onDrag(mousePos, mouseEvent.target);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
tools["pan"].onDrag(mousePos, mouseEvent.target);
|
tools["pan"].onDrag(mousePos, mouseEvent.target);
|
||||||
@ -92,7 +110,15 @@ const ToolManager = (() => {
|
|||||||
if (Input.isDragging()) {
|
if (Input.isDragging()) {
|
||||||
switch(mouseEvent.which) {
|
switch(mouseEvent.which) {
|
||||||
case 1:
|
case 1:
|
||||||
currTool.onEnd(mousePos);
|
if (Input.isSpacePressed()) {
|
||||||
|
tools["pan"].onEnd(mousePos, mouseEvent.target);
|
||||||
|
}
|
||||||
|
else if (Input.isAltPressed()) {
|
||||||
|
tools["eyedropper"].onEnd(mousePos, mouseEvent.target);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currTool.onEnd(mousePos);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
tools["pan"].onEnd(mousePos);
|
tools["pan"].onEnd(mousePos);
|
||||||
|
@ -77,7 +77,7 @@ class EyedropperTool extends Tool {
|
|||||||
// Returned colour
|
// Returned colour
|
||||||
let selectedColor;
|
let selectedColor;
|
||||||
|
|
||||||
for (let i=1; i<layers.length; i++) {
|
for (let i=1; i<layers.length-3; i++) {
|
||||||
// Getting the colour of the pixel in the cursorLocation
|
// Getting the colour of the pixel in the cursorLocation
|
||||||
tmpColour = layers[i].context.getImageData(Math.floor(cursorLocation[0]/zoom),Math.floor(cursorLocation[1]/zoom),1,1).data;
|
tmpColour = layers[i].context.getImageData(Math.floor(cursorLocation[0]/zoom),Math.floor(cursorLocation[1]/zoom),1,1).data;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user