From 67cea2db82f26071a2362892e9c75d84d0a567b5 Mon Sep 17 00:00:00 2001 From: hneemann Date: Sat, 9 Feb 2019 13:20:48 +0100 Subject: [PATCH] added some more options to the rectangle layout --- .../de/neemann/digital/core/element/Keys.java | 12 ++++++++++ .../digital/draw/shapes/RectShape.java | 23 ++++++++++++++++--- .../gui/components/data/DummyElement.java | 5 +++- src/main/resources/lang/lang_de.xml | 4 ++++ src/main/resources/lang/lang_en.xml | 4 ++++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/neemann/digital/core/element/Keys.java b/src/main/java/de/neemann/digital/core/element/Keys.java index c76735ae8..60e38a612 100644 --- a/src/main/java/de/neemann/digital/core/element/Keys.java +++ b/src/main/java/de/neemann/digital/core/element/Keys.java @@ -717,4 +717,16 @@ public final class Keys { = new Key.KeyInteger("RectHeight", 3) .setMin(2); + /** + * the position of the text in the rectangle + */ + public static final Key RECT_INSIDE + = new Key<>("RectInside", false).setSecondary(); + + /** + * the position of the text in the rectangle + */ + public static final Key RECT_BOTTOM + = new Key<>("RectBottom", false).setSecondary(); + } diff --git a/src/main/java/de/neemann/digital/draw/shapes/RectShape.java b/src/main/java/de/neemann/digital/draw/shapes/RectShape.java index 804ba8f18..f9304858e 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/RectShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/RectShape.java @@ -23,6 +23,9 @@ public class RectShape implements Shape, DecoratingShape { private final String label; private final int width; private final int height; + private final boolean inside; + private final boolean bottom; + private final Integer fontSize; /** * Create a new instance @@ -42,6 +45,9 @@ public class RectShape implements Shape, DecoratingShape { width = attr.get(Keys.RECT_WIDTH); height = attr.get(Keys.RECT_HEIGHT); + inside = attr.get(Keys.RECT_INSIDE); + bottom = attr.get(Keys.RECT_BOTTOM); + fontSize = attr.get(Keys.FONT_SIZE); } @Override @@ -56,10 +62,21 @@ public class RectShape implements Shape, DecoratingShape { @Override public void drawTo(Graphic graphic, Style highLight) { - Vector pos = new Vector(0, -2); - Style style = Style.NORMAL; + + int ofs = -3; + Orientation orientation = Orientation.LEFTBOTTOM; + if (inside ^ bottom) { + ofs = -ofs; + orientation = Orientation.LEFTTOP; + } + + Vector pos = new Vector(0, ofs); + if (bottom) + pos = pos.add(0, height * SIZE); + + Style style = Style.NORMAL.deriveFontStyle(fontSize, true); if (!label.isEmpty()) - graphic.drawText(pos, pos.add(1, 0), label, Orientation.LEFTBOTTOM, style); + graphic.drawText(pos, pos.add(1, 0), label, orientation, style); graphic.drawPolygon(new Polygon(true) .add(0, 0) diff --git a/src/main/java/de/neemann/digital/gui/components/data/DummyElement.java b/src/main/java/de/neemann/digital/gui/components/data/DummyElement.java index 4da10e6f8..4a4215e9d 100644 --- a/src/main/java/de/neemann/digital/gui/components/data/DummyElement.java +++ b/src/main/java/de/neemann/digital/gui/components/data/DummyElement.java @@ -41,7 +41,10 @@ public class DummyElement implements Element { public static final ElementTypeDescription RECTDESCRIPTION = new ElementTypeDescription("Rectangle", DummyElement.class) .addAttribute(Keys.LABEL) .addAttribute(Keys.RECT_WIDTH) - .addAttribute(Keys.RECT_HEIGHT); + .addAttribute(Keys.RECT_HEIGHT) + .addAttribute(Keys.RECT_INSIDE) + .addAttribute(Keys.RECT_BOTTOM) + .addAttribute(Keys.FONT_SIZE); /** * Creates a new dummy element diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index 40c2738d2..9ac47bbc0 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -1254,6 +1254,10 @@ Sind evtl. die Namen der Variablen nicht eindeutig? Breite in Rastereinheiten Höhe Höhe in Rastereinheiten + Text innen + Text ins Innere des Rechtecks setzen. + Text unten + Text unten ans Rechteck setzen. Breites Symbol Verwendet ein breiteres Symbol zur Darstellung des Gatters. diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index 99cc359d3..234e3a63b 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -1243,6 +1243,10 @@ Width in grid units Height Height in grid units + Text Inside + Place text inside the rectangle. + Text at Bottom + Place text at the bottom of the rectangle. Wide Shape Uses a wider shape to visualize the gate.