Skip to content

Commit

Permalink
Add icon for toggling pen pressure support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Dec 24, 2024
1 parent 9015f1f commit 4b50ce4
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ original file.
* [Help Icon](https://www.iconfinder.com/icons/211675/help_icon) - Made by Ionicons
* [Fullscreen Icon](https://www.iconfinder.com/icons/298714/screen_full_icon) - Made by Github
* [Pencil Icon](https://github.com/twitter/twemoji/blob/8e58ae4/svg/270f.svg)
* [Drawing Tablet Pen Icon](https://www.iconfinder.com/icons/8665767/pen_icon)
* [Checkmark Icon](https://commons.wikimedia.org/wiki/File:Green_check_icon_with_gradient.svg)
* [Fill Icon](https://commons.wikimedia.org/wiki/File:Circle-icons-paintcan.svg)
* [Trash Icon](https://www.iconfinder.com/icons/315225/trash_can_icon) - Made by [Yannick Lung](https://yannicklung.com)
Expand Down
21 changes: 20 additions & 1 deletion internal/frontend/lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ const soundToggleLabel = document.getElementById("sound-toggle-label");
let sound = localStorage.getItem("sound") !== "false";
updateSoundIcon();

const penToggleLabel = document.getElementById("pen-pressure-toggle-label");
let penPressure = localStorage.getItem("penPressure") !== "false";
updateTogglePenIcon();

const set_dummy_word_hints = () => {
// Dummy wordhint to prevent layout changes.
applyWordHints([{
Expand Down Expand Up @@ -388,6 +392,21 @@ function updateSoundIcon() {
}
}

function togglePenPressure() {
penPressure = !penPressure;
localStorage.setItem("penPressure", penPressure.toString());
updateTogglePenIcon();
}
document.getElementById("toggle-pen-pressure-button").addEventListener("click", togglePenPressure);

function updateTogglePenIcon() {
if (penPressure) {
penToggleLabel.src = "{{.RootPath}}/resources/pen.svg?cache_bust={{.CacheBust}}";
} else {
penToggleLabel.src = "{{.RootPath}}/resources/no-pen.svg?cache_bust={{.CacheBust}}";
}
}

//The drawing board has a base size. This base size results in a certain ratio
//that the actual canvas has to be resized accordingly too. This is needed
//since not every client has the same screensize.
Expand Down Expand Up @@ -1452,7 +1471,7 @@ function pressureToLineWidth(event) {
if (event.buttons !== 1 || event.pressure === 0 || event.pointerType === "touch") {
return 0;
}
if (event.pressure === 0.5 || !event.pressure) {
if (!penPressure || event.pressure === 0.5 || !event.pressure) {
return localLineWidth;
}
return Math.ceil(event.pressure * 32);
Expand Down
47 changes: 47 additions & 0 deletions internal/frontend/resources/no-pen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions internal/frontend/resources/pen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions internal/frontend/templates/lobby.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
<img id="sound-toggle-label" class="header-button-image" />
{{.Translation.Get "toggle-soundeffects"}}
</button>
<button id="toggle-pen-pressure-button"
class="dialog-button menu-item header-button"
alt="{{.Translation.Get "toggle-pen-pressure"}}"
title="{{.Translation.Get "toggle-pen-pressure"}}">
<img id="pen-pressure-toggle-label" class="header-button-image" />
{{.Translation.Get "toggle-pen-pressure"}}
</button>
<button id="name-change-button" class="dialog-button menu-item header-button"
alt="{{.Translation.Get "change-your-name"}}"
title="{{.Translation.Get "change-your-name"}}">
Expand Down
1 change: 1 addition & 0 deletions internal/translations/de_DE.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func initGermanTranslation() {

translation.put("round", "Runde")
translation.put("toggle-soundeffects", "Sound ein- / ausschalten")
translation.put("toggle-pen-pressure", "Tablet-Stiftdruck ein- / ausschalten")
translation.put("change-your-name", "Anzeigename")
translation.put("randomize", "Zufälliger Name")
translation.put("apply", "Anwenden")
Expand Down
1 change: 1 addition & 0 deletions internal/translations/en_us.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func initEnglishTranslation() Translation {

translation.put("round", "Round")
translation.put("toggle-soundeffects", "Toggle soundeffects")
translation.put("toggle-pen-pressure", "Toggle pen pressure")
translation.put("change-your-name", "Nickname")
translation.put("randomize", "Randomize")
translation.put("apply", "Apply")
Expand Down

0 comments on commit 4b50ce4

Please sign in to comment.