-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add IO mask colour fill tool #4048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dec261c
add fill tool
iamllama 4134708
add fill tool logic
iamllama e886d87
open colour picker on fill tool activation
iamllama 3b056c9
refactor/add fill attr to io clozes
iamllama 1a907af
fill masks in editor
iamllama 9a94b20
fill text and inactive masks in reviewer
iamllama 95b30aa
fix lint
iamllama cb75c53
remove debug option
iamllama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright: Ankitects Pty Ltd and contributors | ||
| // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html | ||
|
|
||
| import { fabric } from "fabric"; | ||
|
|
||
| import { get, type Readable } from "svelte/store"; | ||
| import { findTargetInGroup, stopDraw } from "./lib"; | ||
| import { undoStack } from "./tool-undo-redo"; | ||
|
|
||
| export const fillMask = (canvas: fabric.Canvas, colourStore: Readable<string>): void => { | ||
| // remove selectable for shapes | ||
| canvas.discardActiveObject(); | ||
| canvas.forEachObject(function(o) { | ||
| o.selectable = false; | ||
| }); | ||
| canvas.selectionColor = "rgba(0, 0, 0, 0)"; | ||
| stopDraw(canvas); | ||
|
|
||
| canvas.on("mouse:down", function(o) { | ||
| const target = o.target instanceof fabric.Group | ||
| ? findTargetInGroup(o.target, canvas.getPointer(o.e) as fabric.Point) | ||
| : o.target; | ||
| const colour = get(colourStore); | ||
| if (!target || target.fill === colour) { return; } | ||
| target.fill = colour; | ||
| undoStack.onObjectModified(); | ||
| }); | ||
| }; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL this is possible in TypeScript! Thank you for the typing improvements too. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if i understood correctly 🤔 The fill attr isn't saved in the cloze if its set to the default mask colour (#ffeba2), like the
angleattr when its 0. If its changed to be cleared when set to #000000 then users' existing io notes using the default mask colour would have their notes bloated with itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, that's a thinko on my part - from https://github.com/ankitects/anki/pull/4048/files#diff-a1adc784721911f5063bdb67703c3f2892d9fb58d5ee1738e0df305f7062f5caR361 I assumed #000 was the default. If our default is a color the user is unlikely to be able to pick easily, no point trying to remove it if it's the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, was mistaken as well. The text "clozes" behave differently, they don't save the fill attr when its the default text colour (#000000) and regular masks don't save it when its the default mask colour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
datalistelement should be able to provide preset options for the colour input, and seems to work in external/mobile browsers but not in anki itself, even though its chromium version should support itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing Qt overlooked something when trying to integrate it into their own color picker implementation.
Anyway, thank you as always for your contributions :-)