--- /dev/null
+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
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());
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++)
@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;
}
/**