From 78f2ad7ddf90a2debb1b637aa4195351e0eba69e Mon Sep 17 00:00:00 2001 From: Alistair Date: Thu, 9 Feb 2017 17:11:10 -0800 Subject: [PATCH] Update view after changes The view wasn't being redrawn for all the operations which require it --- src/com/modsim/gui/GUI.java | 4 +-- src/com/modsim/gui/view/ContextMenu.java | 2 ++ src/com/modsim/gui/view/View.java | 2 ++ src/com/modsim/operations/Ops.java | 37 ++++++++++++++++++++---- src/com/modsim/util/Selection.java | 2 ++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/com/modsim/gui/GUI.java b/src/com/modsim/gui/GUI.java index c8e276a..92ee244 100644 --- a/src/com/modsim/gui/GUI.java +++ b/src/com/modsim/gui/GUI.java @@ -254,7 +254,7 @@ private void createViewport() { */ public void zoomInToView() { - view.zoom(view.getWidth()/2, view.getHeight()/2, 1.0); + view.zoom(view.getWidth()/2, view.getHeight()/2, -2.0); } /* @@ -262,7 +262,7 @@ public void zoomInToView() */ public void zoomOutToView() { - view.zoom(view.getWidth()/2, view.getHeight()/2, -1.0); + view.zoom(view.getWidth()/2, view.getHeight()/2, 2.0); } public void resetView() diff --git a/src/com/modsim/gui/view/ContextMenu.java b/src/com/modsim/gui/view/ContextMenu.java index 1ccceb1..0160bee 100644 --- a/src/com/modsim/gui/view/ContextMenu.java +++ b/src/com/modsim/gui/view/ContextMenu.java @@ -40,6 +40,8 @@ public ContextMenu() { public void actionPerformed(ActionEvent arg0) { if (port != null && port.link != null) { port.link.delete(); + //redraw + Main.ui.view.flagStaticRedraw(); } } }); diff --git a/src/com/modsim/gui/view/View.java b/src/com/modsim/gui/view/View.java index 76205f7..a4e9cc8 100644 --- a/src/com/modsim/gui/view/View.java +++ b/src/com/modsim/gui/view/View.java @@ -314,6 +314,8 @@ else if (zoom > maxZoom) { camX -= newScreenPt.x - x; camY -= newScreenPt.y - y; calcXForm(); + //redraw + flagStaticRedraw(); } /*** diff --git a/src/com/modsim/operations/Ops.java b/src/com/modsim/operations/Ops.java index 7c7345c..a190fcc 100644 --- a/src/com/modsim/operations/Ops.java +++ b/src/com/modsim/operations/Ops.java @@ -161,10 +161,19 @@ public static void fileNew() { /// Action implementations // Undo stack - undo = new DesignAction(event -> {Main.ui.view.cancelTool(); Main.opStack.undo();}, - "Undo", "Undo the previous operation", ctrlZ); - redo = new DesignAction(event -> {if (!Main.ui.view.hasTool()) Main.opStack.redo();}, - "Redo", "Repeat an undone operation", ctrlY); + undo = new DesignAction(event -> { + Main.ui.view.cancelTool(); + Main.opStack.undo(); + //redraw + Main.ui.view.flagStaticRedraw(); + }, "Undo", "Undo the previous operation", ctrlZ); + redo = new DesignAction(event -> { + if (!Main.ui.view.hasTool()) { + Main.opStack.redo(); + } + //redraw + Main.ui.view.flagStaticRedraw(); + }, "Redo", "Repeat an undone operation", ctrlY); // Copy/paste copy = new DesignAction(event -> Main.clipboard.copy(Main.selection), "Copy", @@ -181,7 +190,11 @@ public static void fileNew() { }, "Paste", "Paste into the design from the application clipboard", ctrlV); // Deletion - delete = new DesignAction(event -> Main.selection.deleteAll(), "Delete", "Deletes the selection", del); + delete = new DesignAction(event -> { + Main.selection.deleteAll(); + //redraw + Main.ui.view.flagStaticRedraw(); + }, "Delete", "Deletes the selection", del); // Rotation rotateCW = new DesignAction(event -> doRotate(BaseModule.rotationDir.ROT_CW), @@ -205,6 +218,8 @@ public static void fileNew() { } } Main.opStack.endCompoundOp(); + //redraw + Main.ui.view.flagStaticRedraw(); }, "Add/Edit label", null, ctrlL); // Label sizing @@ -219,6 +234,8 @@ public static void fileNew() { } } Main.opStack.endCompoundOp(); + //redraw + Main.ui.view.flagStaticRedraw(); }, "Big"); labelSmall = new DesignAction(event -> { Main.opStack.beginCompoundOp(); @@ -231,6 +248,8 @@ public static void fileNew() { } } Main.opStack.endCompoundOp(); + //redraw + Main.ui.view.flagStaticRedraw(); }, "Small (default)"); // Simulator controls @@ -251,7 +270,11 @@ public static void fileNew() { resetView = new DesignAction(event -> Main.ui.resetView(), "Reset View"); // View controls - toggleAA = new DesignAction(event -> Main.ui.view.useAA = !Main.ui.view.useAA, + toggleAA = new DesignAction(event -> { + Main.ui.view.useAA = !Main.ui.view.useAA; + //redraw + Main.ui.view.flagStaticRedraw(); + }, "Toggle anti-aliasing", "Toggles anti-aliased rendering in the viewport: " + "disabling AA may improve performance on older machines."); @@ -279,6 +302,8 @@ private static void doRotate(BaseModule.rotationDir dir){ } } Main.opStack.endCompoundOp(); + //redraw + Main.ui.view.flagStaticRedraw(); } /** diff --git a/src/com/modsim/util/Selection.java b/src/com/modsim/util/Selection.java index b51b5c4..8f81551 100644 --- a/src/com/modsim/util/Selection.java +++ b/src/com/modsim/util/Selection.java @@ -95,6 +95,8 @@ public void deleteAll() { } clear(); Main.opStack.endCompoundOp(); + //redraw + Main.ui.view.flagStaticRedraw(); } public boolean isEmpty() {