-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f647fd
commit 80a7ec8
Showing
10 changed files
with
62 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,10 @@ | |
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<!-- pickr --> | ||
<script src="https://cdn.jsdelivr.net/npm/@simonwep/[email protected]/dist/pickr.min.js"></script> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@simonwep/[email protected]/dist/themes/classic.min.css" /> | ||
|
||
<link rel="stylesheet" href="./dist/main.css" /> | ||
<script src="./dist/main.js" defer></script> | ||
<title>Canvas</title> | ||
|
@@ -32,9 +36,8 @@ <h1>Canvas</h1> | |
<button id="undo"><img src="assets/menu icons/undo-btn.png" alt=""></button> | ||
<button id="redo"><img src="assets/menu icons/redo-btn.png" alt=""></button> | ||
<!-- color --> | ||
<input type="color" id="color-picker" value="#FFFFFF"> | ||
<input type="color" id="background-color-picker" value="#FFFFFF"> | ||
<label for="background-color-picker">Bg Color</label> | ||
<div id="color-picker" class="pickr"></div> | ||
<!-- <input type="color" id="color-picker" value="#FFFFFF"> --> | ||
<!-- tools --> | ||
<input type="range" id="size-slider" min="1" max="30" value="5"> | ||
<input type="radio" id="brush" name="tool" checked> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,33 @@ | ||
import Pickr from "@simonwep/pickr"; | ||
|
||
class ColorHandler { | ||
constructor(canvasHandler) { | ||
this.canvasHandler = canvasHandler | ||
this.setupColorHandling() | ||
this.canvasHandler = canvasHandler; | ||
this.setupColorPicker(); | ||
this.setupColorHandling(); | ||
} | ||
|
||
setupColorPicker () { | ||
this.brushColorPicker = Pickr.create({ | ||
el: "#color-picker", | ||
theme: "classic", | ||
default: "#ECD1E2", | ||
components: { | ||
preview: true, | ||
hue: true, | ||
}, | ||
}); | ||
// have the color picker be open immediately | ||
this.brushColorPicker.show(); | ||
} | ||
|
||
setupColorHandling() { | ||
this.currentColor = "black"; | ||
|
||
// if a brush color has been selected.. | ||
this.brushColorPicker = document.getElementById("color-picker"); | ||
this.brushColorPicker.addEventListener("input", () => { | ||
this.currentColor = this.brushColorPicker.value; | ||
// color change event for brush color | ||
this.brushColorPicker.on("change", (color) => { | ||
this.currentColor = color.toHEXA().toString() | ||
}); | ||
|
||
// if a bg color has been selected.. | ||
this.bgColorPicker = document.getElementById("background-color-picker"); | ||
|
||
// for erase action | ||
this.bgColorPicker.addEventListener( | ||
"input", | ||
() => { | ||
const drawnPaths = this.canvasHandler.undoAndRedoHandler.drawnPaths; | ||
const redoStack = this.canvasHandler.undoAndRedoHandler.redoStack; | ||
this.canvasHandler.eraseAndClearHandler.clear(); | ||
this.canvasHandler.undoAndRedoHandler.drawnPaths = drawnPaths; | ||
this.canvasHandler.undoAndRedoHandler.redoStack = redoStack; | ||
this.canvasHandler.undoAndRedoHandler.drawnPaths.forEach((path) => | ||
this.canvasHandler.undoAndRedoHandler.redrawPath(path) | ||
); | ||
this.canvasHandler.canvas.style.backgroundColor = this.bgColorPicker.value; | ||
} | ||
); | ||
} | ||
} | ||
|
||
export default ColorHandler | ||
export default ColorHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters