From 68f2064da63d2e381c8d8ddaf6b7158f73872e23 Mon Sep 17 00:00:00 2001 From: Max <m.giller.dev@gmail.com> Date: Thu, 14 Oct 2021 10:55:32 +0200 Subject: [PATCH] Save commit --- editor/js/editor.js | 2 +- editor/js/graph.js | 5 ++++ editor/js/state.js | 35 ++++++++++++++++----------- editor/js/tools/menus/settingsmenu.js | 6 ++--- editor/js/tools/settingstool.js | 18 +++++++++++++- 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/editor/js/editor.js b/editor/js/editor.js index 8473bf1..cdd8d53 100644 --- a/editor/js/editor.js +++ b/editor/js/editor.js @@ -30,7 +30,7 @@ window.onload = function () { setTimeout(() => { graph.stopPhysics(); graph.storeCurrentData("Physics stopped"); - }, Graph.STOP_PHYSICS_DELAY); + }, graph.physicsDelay); }); }; diff --git a/editor/js/graph.js b/editor/js/graph.js index 22ba703..d3a6c27 100644 --- a/editor/js/graph.js +++ b/editor/js/graph.js @@ -45,6 +45,11 @@ export class Graph extends ManagedData { this.calculateLinkTypes(); this.onChangeCallbacks = []; + this.physicsDelay = STOP_PHYSICS_DELAY; + } + + restartSimulation() { + } triggerOnChange() { diff --git a/editor/js/state.js b/editor/js/state.js index 5135b65..a8fae50 100644 --- a/editor/js/state.js +++ b/editor/js/state.js @@ -42,6 +42,7 @@ export class State extends Tool { this.selectedItem = undefined; this.selectedItems = new Set(); this.itemsContext = CONTEXT.nothing; + this.labelVisible = true; this.keyStates = {}; } @@ -156,20 +157,22 @@ export class State extends Tool { } // Draw label - const label = node[Graph.NODE_LABEL]; - const fontSize = 11/globalScale; - ctx.font = `${fontSize}px Sans-Serif`; - const textWidth = ctx.measureText(label).width; - const bckgDimensions = [textWidth, fontSize].map(n => n + fontSize * 0.2); // some padding - - const nodeHeightOffset = Graph.IMAGE_SIZE / 3 + bckgDimensions[1]; - ctx.fillStyle = 'rgba(0, 0, 0, 0.5)'; - ctx.fillRect(node.x - bckgDimensions[0] / 2, node.y - bckgDimensions[1] / 2 + nodeHeightOffset, ...bckgDimensions); - - ctx.textAlign = 'center'; - ctx.textBaseline = 'middle'; - ctx.fillStyle = 'white'; - ctx.fillText(label, node.x, node.y + nodeHeightOffset); + if (this.labelVisible) { + const label = node[Graph.NODE_LABEL]; + const fontSize = 11/globalScale; + ctx.font = `${fontSize}px Sans-Serif`; + const textWidth = ctx.measureText(label).width; + const bckgDimensions = [textWidth, fontSize].map(n => n + fontSize * 0.2); // some padding + + const nodeHeightOffset = Graph.IMAGE_SIZE / 3 + bckgDimensions[1]; + ctx.fillStyle = 'rgba(0, 0, 0, 0.5)'; + ctx.fillRect(node.x - bckgDimensions[0] / 2, node.y - bckgDimensions[1] / 2 + nodeHeightOffset, ...bckgDimensions); + + ctx.textAlign = 'center'; + ctx.textBaseline = 'middle'; + ctx.fillStyle = 'white'; + ctx.fillText(label, node.x, node.y + nodeHeightOffset); + } // TODO: Render label as always visible } @@ -244,4 +247,8 @@ export class State extends Tool { graph.isLinkOnNode(link, this.selectedItem) ); } + + setLabelVisibility(visibility) { + this.labelVisible = visibility; + } } diff --git a/editor/js/tools/menus/settingsmenu.js b/editor/js/tools/menus/settingsmenu.js index 008efb0..bb78507 100644 --- a/editor/js/tools/menus/settingsmenu.js +++ b/editor/js/tools/menus/settingsmenu.js @@ -1,8 +1,8 @@ import ToolMenu from "./toolmenu"; -export const LABEL_TOGGLE_ID = "#label-toggle"; -export const RESIMULATE_BUTTON_ID = "#reanimate-button"; -export const PHYSICS_DELAY_ID = "#stop-physics-delay"; +const LABEL_TOGGLE_ID = "#label-toggle"; +const RESIMULATE_BUTTON_ID = "#reanimate-button"; +const PHYSICS_DELAY_ID = "#stop-physics-delay"; export const PHYSICS_DELAY_KEY = "delay"; export const RESIMULATE_KEY = "resimulate"; diff --git a/editor/js/tools/settingstool.js b/editor/js/tools/settingstool.js index a717a5b..cd0cf59 100644 --- a/editor/js/tools/settingstool.js +++ b/editor/js/tools/settingstool.js @@ -1,8 +1,24 @@ -import { SettingsMenu } from "./menus/settingsmenu"; +import { graph, state } from "../editor"; +import { + SettingsMenu, + LABELS_KEY, + RESIMULATE_KEY, + PHYSICS_DELAY_KEY, +} from "./menus/settingsmenu"; import Tool from "./tool"; export default class SettingsTool extends Tool { constructor(key) { super("Settings", "settings", key, new SettingsMenu()); } + + onMenuChange(key, value) { + if (key === LABELS_KEY) { + state.setLabelVisibility(value); + } else if (key === RESIMULATE_KEY) { + graph.restartSimulation(); + } else if (key === PHYSICS_DELAY_KEY) { + graph.physicsDelay = value; + } + } } -- GitLab