Skip to content

Commit

Permalink
Merge pull request #1806 from googlefonts/bg-image-lock-refinements
Browse files Browse the repository at this point in the history
[background image] Some image lock refinements
  • Loading branch information
justvanrossum authored Nov 18, 2024
2 parents 7d97238 + 1a0535d commit 547ad23
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/fontra/views/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,10 @@ export class EditorController {
for (const componentIndex of range(positionedGlyph.glyph.components.length)) {
newSelection.add(`component/${componentIndex}`);
}
if (!this.sceneSettings.backgroundImagesAreLocked) {
if (
!this.sceneSettings.backgroundImagesAreLocked &&
this.visualizationLayersSettings.model["fontra.background-image"]
) {
for (const backgroundImageIndex of positionedGlyph.glyph.backgroundImage
? [0]
: []) {
Expand Down
45 changes: 29 additions & 16 deletions src/fontra/views/editor/scene-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class SceneController {

this.setupSceneSettings();
this.sceneSettings = this.sceneSettingsController.model;
this.visualizationLayersSettings = visualizationLayersSettings;

// We need to do isPointInPath without having a context, we'll pass a bound method
const isPointInPath = canvasController.context.isPointInPath.bind(
Expand Down Expand Up @@ -302,6 +303,7 @@ export class SceneController {
this.sceneSettings.selection,
this.sceneSettings.hoverSelection
);
this.canvasController.requestUpdate();
},
true
);
Expand Down Expand Up @@ -341,9 +343,15 @@ export class SceneController {

_checkSelectionForLockedItems() {
if (
this.sceneSettings.backgroundImagesAreLocked &&
this.sceneSettings.selection.has("backgroundImage/0")
this.sceneSettings.backgroundImagesAreLocked ||
!this.visualizationLayersSettings.model["fontra.background-image"]
) {
this._deselectBackroundImage();
}
}

_deselectBackroundImage() {
if (this.sceneSettings.selection.has("backgroundImage/0")) {
this.sceneSettings.selection = difference(this.sceneSettings.selection, [
"backgroundImage/0",
]);
Expand Down Expand Up @@ -396,12 +404,21 @@ export class SceneController {
this.sceneSettingsController.addKeyListener(
"backgroundImagesAreLocked",
(event) => {
if (!event.value && this.selection.has("backgroundImage/0")) {
this.selection = difference(this.selection, ["backgroundImage/0"]);
if (event.newValue) {
this._deselectBackroundImage();
}
},
true
);

this.visualizationLayersSettings.addKeyListener(
"fontra.background-image",
(event) => {
if (!event.newValue) {
this._deselectBackroundImage();
}
}
);
}

setupEventHandling() {
Expand Down Expand Up @@ -474,13 +491,14 @@ export class SceneController {
() => !!this.contextMenuState?.componentSelection?.length
);

registerAction(
"action.lock-background-images",
{ topic },
() =>
(this.sceneSettings.backgroundImagesAreLocked =
!this.sceneSettings.backgroundImagesAreLocked)
);
registerAction("action.lock-background-images", { topic }, () => {
this.sceneSettings.backgroundImagesAreLocked =
!this.sceneSettings.backgroundImagesAreLocked;
if (!this.sceneSettings.backgroundImagesAreLocked) {
// If background images are hidden, show them
this.visualizationLayersSettings.model["fontra.background-image"] = true;
}
});
}

setAutoViewBox() {
Expand Down Expand Up @@ -840,11 +858,6 @@ export class SceneController {
if (!lenientIsEqualSet(selection, this.selection)) {
this.sceneModel.selection = selection || new Set();
this.sceneModel.hoverSelection = new Set();
this.canvasController.requestUpdate();
// Delay the notification by a tiny amount, to work around
// an ordering problem: sometimes the selection is set to
// something that will be valid soon but isn't right now.
setTimeout(() => this._dispatchEvent("selectionChanged"), 20);
}
}

Expand Down

0 comments on commit 547ad23

Please sign in to comment.