Implemented SubmodelComponent.clicked(); removed obsolete TODOs
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 22 Jun 2019 07:33:50 +0000 (09:33 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 22 Jun 2019 07:33:50 +0000 (09:33 +0200)
net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/ClickableSubmodelComponentsTest.java [new file with mode: 0644]
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIBitDisplay.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUICustomComponentCreator.java
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/SubmodelComponent.java

diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/ClickableSubmodelComponentsTest.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/examples/ClickableSubmodelComponentsTest.java
new file mode 100644 (file)
index 0000000..cd45ee6
--- /dev/null
@@ -0,0 +1,34 @@
+package net.mograsim.logic.ui.examples;
+
+import net.mograsim.logic.ui.SimpleLogicUIStandalone;
+import net.mograsim.logic.ui.model.ViewModelModifiable;
+import net.mograsim.logic.ui.model.components.GUIBitDisplay;
+import net.mograsim.logic.ui.model.components.GUIManualSwitch;
+import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent;
+
+public class ClickableSubmodelComponentsTest
+{
+       public static void main(String[] args)
+       {
+               SimpleLogicUIStandalone.executeVisualisation(ClickableSubmodelComponentsTest::createExample);
+       }
+
+       public static void createExample(ViewModelModifiable model)
+       {
+               SimpleRectangularSubmodelComponent comp = new SimpleRectangularSubmodelComponent(model, 1, "")
+               {
+                       {
+                               setSubmodelScale(.4);
+                               setOutputPins("O0");
+
+                               GUIManualSwitch sw = new GUIManualSwitch(submodelModifiable);
+                               GUIBitDisplay bd = new GUIBitDisplay(submodelModifiable);
+
+                               sw.moveTo(10, 5);
+                               bd.moveTo(50, 5);
+
+                       }
+               };
+               comp.moveTo(10, 10);
+       }
+}
\ No newline at end of file
index 82399c1..0ca249e 100644 (file)
@@ -37,7 +37,6 @@ public class GUIBitDisplay extends GUIComponent
                double posX = getBounds().x;
                double posY = getBounds().y;
 
-               // TODO maybe draw switch state too?
                gc.drawRectangle(getBounds());
                String label = bitDisplay == null ? BitVectorFormatter.formatAsString(null)
                                : BitVectorFormatter.formatAsString(bitDisplay.getDisplayedValue());
index ee034c8..6055f1a 100644 (file)
@@ -82,7 +82,6 @@ public final class GUICustomComponentCreator
                        rect.setSubmodelScale(params.composition.innerScale);
                        // rect.setSize(params.width, params.height);
 
-                       // TODO save & restore names
                        int inputCount = ((Number) m.get(SimpleRectangularSubmodelComponent.kInCount)).intValue();
                        String[] inputNames = new String[inputCount];
                        for (int i = 0; i < inputCount; i++)
index c2a900c..be9b854 100644 (file)
@@ -205,13 +205,12 @@ public abstract class SubmodelComponent extends GUIComponent
        @Override
        public boolean clicked(double x, double y)
        {
-               // TODO
                double scaledX = (x - getBounds().x) / submodelScale;
                double scaledY = (y - getBounds().y) / submodelScale;
-               double roundedScaledX = Math.round(scaledX / 5 * 2) * 5 / 2.;
-               double roundedScaledY = Math.round(scaledY / 5 * 2) * 5 / 2.;
-               System.out.println(scaledX + "|" + scaledY + ", rounded " + roundedScaledX + "|" + roundedScaledY);
-               return true;
+               for (GUIComponent component : submodel.getComponents())
+                       if (component.getBounds().contains(scaledX, scaledY) && component.clicked(scaledX, scaledY))
+                               return true;
+               return false;
        }
 
        /**