diff --git a/index.html b/index.html index 2dd0219..6e101c9 100644 --- a/index.html +++ b/index.html @@ -84,6 +84,19 @@

New version available

+

sdraw

sdraw />
MIT License
-
Version: 0.1.2
+
Version
2023
diff --git a/js/boot.mjs b/js/boot.mjs index 3e3a1c3..ef6951a 100644 --- a/js/boot.mjs +++ b/js/boot.mjs @@ -3,6 +3,7 @@ import { getCursorCanvas, setCanvasSizeByViewport, setCanvasSizeWithoutPanel, + setCanvasFill, setVideoSizeByCanvasSize, } from "./dom.mjs"; import { @@ -29,6 +30,7 @@ function attachResizeListeners() { setCanvasSizeByViewport(cursorCanvas); setCanvasSizeWithoutPanel(canvas); setVideoSizeByCanvasSize(canvas); + setCanvasFill(canvas); attachWindowResizeListeners({ canvas, cursorCanvas }); } diff --git a/js/canvas-utils.mjs b/js/canvas-utils.mjs index 24dc175..01a6803 100644 --- a/js/canvas-utils.mjs +++ b/js/canvas-utils.mjs @@ -1,7 +1,7 @@ import { COLOR } from "./state/constants.mjs"; import { getCursorCanvas, getCanvas } from "./dom.mjs"; import { getPanel } from "./dom.mjs"; -import { isCursorWithinPanelBounds } from "./ui-utils.mjs"; +import { isCursorWithinPanelBounds } from "./ui/utils.mjs"; const ctx = getCursorCanvas().getContext("2d"); const canvasCtx = getCanvas().getContext("2d"); @@ -19,8 +19,8 @@ const LINE_WIDTH = 5; * * @returns {number[]} - Inverted color in r, g,b order. */ -function invertColor(r, g, b, a) { - const rgb = [r, g, b, a]; +function invertColor(r, g, b) { + const rgb = [r, g, b]; for (var i = 0; i < rgb.length; i++) rgb[i] = (i === 3 ? 1 : 255) - rgb[i]; return rgb; } @@ -42,9 +42,9 @@ function getPixelRGBAColor(x, y) { } const pixel = canvasCtx.getImageData(x, y, GAP, GAP); - const [r, g, b, a] = invertColor(...pixel.data); + const [r, g, b] = invertColor(...pixel.data); - return `rgb(${r}, ${g}, ${b}, ${Math.abs(a)})`; + return `rgb(${r}, ${g}, ${b})`; } export function drawCursor(x, y) { diff --git a/js/dom.mjs b/js/dom.mjs index 2665aee..7adb358 100644 --- a/js/dom.mjs +++ b/js/dom.mjs @@ -1,3 +1,5 @@ +import { COLOR } from "./state/constants.mjs"; + export function getCanvas() { return document.getElementById("canvas"); } @@ -53,6 +55,12 @@ export function setVideoSizeByCanvasSize(canvas) { video.style.height = `${canvas.height}px`; } +export function setCanvasFill(canvas) { + const ctx = canvas.getContext("2d"); + ctx.fillStyle = COLOR.WHITE; + ctx.fillRect(0, 0, canvas.width, canvas.height); +} + export function insertCountdown() { const countdown = document.createElement("div"); countdown.id = "countdown"; diff --git a/js/state/actions/canvas.mjs b/js/state/actions/canvas.mjs index e0fa8e3..3d30033 100644 --- a/js/state/actions/canvas.mjs +++ b/js/state/actions/canvas.mjs @@ -1,11 +1,10 @@ -import { getCanvas } from "../../dom.mjs"; +import { getCanvas, setCanvasFill } from "../../dom.mjs"; import { storeCanvas } from "../storage.mjs"; export function resetCanvas() { const canvas = getCanvas(); - const ctx = canvas.getContext("2d"); - ctx.clearRect(0, 0, canvas.width, canvas.height); + setCanvasFill(canvas); storeCanvas(canvas); } diff --git a/js/ui-utils.mjs b/js/ui-utils.mjs deleted file mode 100644 index f4b5b99..0000000 --- a/js/ui-utils.mjs +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Is cursor located on UI panel? - * - * @param {number} x - Cursor x coordinate. - * @param {number} y - Cursor y coordinate. - * @param {DOMRect} rect - Panel bounds. - * - * @returns {boolean} - Is cursor located on UI panel? - */ -export function isCursorWithinPanelBounds(x, y, rect) { - return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom; -} diff --git a/js/ui/panel.mjs b/js/ui/panel.mjs index 2ad51ca..316c0e6 100644 --- a/js/ui/panel.mjs +++ b/js/ui/panel.mjs @@ -3,7 +3,7 @@ import { isPrimaryGamepadButtonPressed, } from "../controls/gamepad.mjs"; import { getPanel } from "../dom.mjs"; -import { isCursorWithinPanelBounds } from "../ui-utils.mjs"; +import { isCursorWithinPanelBounds } from "./utils.mjs"; function getPanelButtonByCoordinates(x, y, panel) { const buttons = panel.querySelectorAll("button"); diff --git a/js/ui/utils.mjs b/js/ui/utils.mjs index 67d32d1..89b5704 100644 --- a/js/ui/utils.mjs +++ b/js/ui/utils.mjs @@ -38,3 +38,16 @@ export function updateActivatedButton(buttonContainer, value) { } }); } + +/** + * Is cursor located on UI panel? + * + * @param {number} x - Cursor x coordinate. + * @param {number} y - Cursor y coordinate. + * @param {DOMRect} rect - Panel bounds. + * + * @returns {boolean} - Is cursor located on UI panel? + */ +export function isCursorWithinPanelBounds(x, y, rect) { + return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom; +} diff --git a/package-lock.json b/package-lock.json index 935b4c5..2d5d4e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sdraw", - "version": "0.1.3", + "version": "0.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sdraw", - "version": "0.1.3", + "version": "0.1.4", "license": "MIT", "devDependencies": { "eslint": "^8.52.0", diff --git a/package.json b/package.json index a2eef95..4630d18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sdraw", - "version": "0.1.3", + "version": "0.1.4", "description": "Simple drawing application for kids, can be controlled via mouse, keyboard or gamepad.", "private": true, "main": "index.mjs", diff --git a/service-worker.js b/service-worker.js index 0897e4b..1e98fda 100644 --- a/service-worker.js +++ b/service-worker.js @@ -1,5 +1,5 @@ const STATIC_CACHE_NAME = "static"; -const STATIC_CACHE_VERSION = "v41"; +const STATIC_CACHE_VERSION = "v42"; const STATIC_CACHE_ID = `${STATIC_CACHE_NAME}-${STATIC_CACHE_VERSION}`; // All the files need to be added here manually. I want to avoid @@ -10,6 +10,7 @@ const STATIC_ASSETS = [ "favicon.ico", "manifest.json", "README.md", + "package.json", /* JS */ "index.mjs",