From f33554b64dabcf6d0d9d9c7731cf400943000c61 Mon Sep 17 00:00:00 2001 From: hneemann Date: Tue, 26 Apr 2016 20:30:38 +0200 Subject: [PATCH] text is ignored if the visual elements bounding box is calculated --- src/main/dig/combinatorial/Adder8bit.dig | 248 +++++++++++++----- .../digital/draw/elements/VisualElement.java | 9 +- .../digital/draw/graphics/GraphicMinMax.java | 24 +- 3 files changed, 202 insertions(+), 79 deletions(-) diff --git a/src/main/dig/combinatorial/Adder8bit.dig b/src/main/dig/combinatorial/Adder8bit.dig index 6870017e9..b83147b3c 100644 --- a/src/main/dig/combinatorial/Adder8bit.dig +++ b/src/main/dig/combinatorial/Adder8bit.dig @@ -14,7 +14,7 @@ 1,1,1,1,1,1,1,1 - + 0 @@ -60,7 +60,7 @@ 1,1,1,1,1,1,1,1 - + 0 @@ -112,17 +112,6 @@ 0 - - Clock - - - Label - Takt - - - - 0 - Out @@ -134,132 +123,247 @@ 0 + + In + + + Label + C_i-1 + + + + 0 + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + - + - + - + + + + + - - + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + - + + + + + + + + + + + + + + + + + - - + + - + + + + + + + + + - - + + + + + + + + + + + + + + + + + + - + + + + + - + + + + + - - + + + + + + + + + + - + + + + + @@ -269,40 +373,40 @@ - + + + + + - + - - + + + + + + - - + + - - - - - - - - \ No newline at end of file diff --git a/src/main/java/de/neemann/digital/draw/elements/VisualElement.java b/src/main/java/de/neemann/digital/draw/elements/VisualElement.java index 6b15a25d1..069a1225e 100644 --- a/src/main/java/de/neemann/digital/draw/elements/VisualElement.java +++ b/src/main/java/de/neemann/digital/draw/elements/VisualElement.java @@ -183,11 +183,11 @@ public class VisualElement implements Drawable, Moveable, AttributeListener { } /** - * @return the bounding box of the shape of this element + * @return the bounding box of the shape of this element, text is ignored */ public GraphicMinMax getMinMax() { if (minMax == null) { - GraphicMinMax mm = new GraphicMinMax(); + GraphicMinMax mm = new GraphicMinMax(false); drawShape(mm, false); minMax = mm; } @@ -205,10 +205,11 @@ public class VisualElement implements Drawable, Moveable, AttributeListener { * Is used to create the icons in the element menu * * @param maxHeight the maximum height - * @return the icon or null if the maximum height is exceeded. + * @return the created icon */ public ImageIcon createIcon(int maxHeight) { - GraphicMinMax mm = getMinMax(); + GraphicMinMax mm = new GraphicMinMax(); + drawShape(mm, false); double scale = 0.5; if (mm.getMax().y - mm.getMin().y > maxHeight / scale) diff --git a/src/main/java/de/neemann/digital/draw/graphics/GraphicMinMax.java b/src/main/java/de/neemann/digital/draw/graphics/GraphicMinMax.java index 8c9f5e02d..bbe3ef5ce 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/GraphicMinMax.java +++ b/src/main/java/de/neemann/digital/draw/graphics/GraphicMinMax.java @@ -4,16 +4,33 @@ import static de.neemann.digital.core.element.ElementAttributes.cleanLabel; /** * This class is used to determine the size of shapes or the whole circuit. - * You can draw the items to a instance of this class an then obtain the size + * You can draw the items to an instance of this class and then obtain the size * by the getters getMin() and getMax(). * * @author hneemann */ public class GraphicMinMax implements Graphic { + private final boolean includeText; private Vector min; private Vector max; + /** + * Creates a new instance + */ + public GraphicMinMax() { + this(true); + } + + /** + * Creates a new instance + * + * @param includeText true if text is included in measurement + */ + public GraphicMinMax(boolean includeText) { + this.includeText = includeText; + } + @Override public void drawLine(Vector p1, Vector p2, Style style) { check(p1); @@ -44,7 +61,8 @@ public class GraphicMinMax implements Graphic { @Override public void drawText(Vector p1, Vector p2, String text, Orientation orientation, Style style) { - approxTextSize(this, p1, p2, text, orientation, style); + if (includeText) + approxTextSize(this, p1, p2, text, orientation, style); } /** @@ -64,7 +82,7 @@ public class GraphicMinMax implements Graphic { Vector height = new Vector(delta.y, -delta.x).mul(style.getFontSize()).div(128); int div = 190; - if (text.length() > 15) div = 240; + if (text.length() > 2) div = 220; Vector width = delta.mul(text.length() * style.getFontSize()).div(div);