mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00

* add fill tool * add fill tool logic * open colour picker on fill tool activation * refactor/add fill attr to io clozes * fill masks in editor * fill text and inactive masks in reviewer * fix lint * remove debug option
28 lines
1,006 B
TypeScript
28 lines
1,006 B
TypeScript
// 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();
|
|
});
|
|
};
|