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 cfe5b972c..34f10001b 100644 --- a/src/main/java/de/neemann/digital/draw/elements/VisualElement.java +++ b/src/main/java/de/neemann/digital/draw/elements/VisualElement.java @@ -158,9 +158,7 @@ public class VisualElement implements Drawable, Moveable, AttributeListener { // draw circle around element if (highLight) { GraphicMinMax mm = getMinMax(); - Vector delta = mm.getMax().sub(mm.getMin()); - int rad = (int) Math.sqrt(delta.x * delta.x + delta.y * delta.y) / 2; - delta = new Vector(rad, rad); + Vector delta = mm.getMax().sub(mm.getMin()).mul(3).div(5); Vector pos = mm.getMax().add(mm.getMin()).div(2); graphic.drawCircle(pos.sub(delta), pos.add(delta), Style.HIGHLIGHT); } diff --git a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVG.java b/src/main/java/de/neemann/digital/draw/graphics/GraphicSVG.java index b70608e4e..8e5f76b04 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVG.java +++ b/src/main/java/de/neemann/digital/draw/graphics/GraphicSVG.java @@ -15,9 +15,9 @@ public class GraphicSVG implements Graphic, Closeable { /** * Creates a new instance. * - * @param out the stream - * @param min upper left corner - * @param max lower right corner + * @param out the stream + * @param min upper left corner + * @param max lower right corner * @throws IOException IOException */ public GraphicSVG(OutputStream out, Vector min, Vector max) throws IOException { @@ -79,38 +79,36 @@ public class GraphicSVG implements Graphic, Closeable { @Override public void drawLine(Vector p1, Vector p2, Style style) { - if (style != Style.INVISIBLE) - try { - w.write("\n"); - } catch (IOException e) { - throw new RuntimeException(e); - } + w.write(" />\n"); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override public void drawPolygon(Polygon p, Style style) { - if (style != Style.INVISIBLE) - try { - w.write("\n"); - else - w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"none\"/>\n"); - } catch (IOException e) { - throw new RuntimeException(e); - } + if (style.isFilled() && p.isClosed()) + w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"" + getColor(style) + "\"/>\n"); + else + w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"none\"/>\n"); + } catch (IOException e) { + throw new RuntimeException(e); + } } private static double getStrokeWidth(Style style) { @@ -119,21 +117,20 @@ public class GraphicSVG implements Graphic, Closeable { @Override public void drawCircle(Vector p1, Vector p2, Style style) { - if (style != Style.INVISIBLE) - try { - Vector c = p1.add(p2).div(2); - double r = Math.abs(p2.sub(p1).x) / 2.0; - if (style.isFilled()) - w.write("\n"); - else { - w.write("\n"); + else { + w.write("\n"); - } - } catch (IOException e) { - throw new RuntimeException(e); + w.write(" />\n"); } + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override diff --git a/src/main/java/de/neemann/digital/draw/graphics/GraphicSwing.java b/src/main/java/de/neemann/digital/draw/graphics/GraphicSwing.java index d7de316ce..0b8914f1f 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/GraphicSwing.java +++ b/src/main/java/de/neemann/digital/draw/graphics/GraphicSwing.java @@ -27,32 +27,28 @@ public class GraphicSwing implements Graphic { @Override public void drawLine(Vector p1, Vector p2, Style style) { - if (style != Style.INVISIBLE) { - applyStyle(style); - gr.drawLine(p1.x, p1.y, p2.x, p2.y); - } + applyStyle(style); + gr.drawLine(p1.x, p1.y, p2.x, p2.y); } @Override public void drawPolygon(Polygon p, Style style) { - if (style != Style.INVISIBLE) { - applyStyle(style); - Path2D path = new GeneralPath(); - boolean first = true; - for (Vector v : p) - if (first) { - first = false; - path.moveTo(v.x, v.y); - } else - path.lineTo(v.x, v.y); + applyStyle(style); + Path2D path = new GeneralPath(); + boolean first = true; + for (Vector v : p) + if (first) { + first = false; + path.moveTo(v.x, v.y); + } else + path.lineTo(v.x, v.y); - if (p.isClosed()) - path.closePath(); + if (p.isClosed()) + path.closePath(); - if (style.isFilled() && p.isClosed()) - gr.fill(path); - gr.draw(path); - } + if (style.isFilled() && p.isClosed()) + gr.fill(path); + gr.draw(path); } @Override diff --git a/src/main/java/de/neemann/digital/draw/graphics/Orientation.java b/src/main/java/de/neemann/digital/draw/graphics/Orientation.java index 42e679b76..684501c5b 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/Orientation.java +++ b/src/main/java/de/neemann/digital/draw/graphics/Orientation.java @@ -1,17 +1,46 @@ package de.neemann.digital.draw.graphics; /** + * The text orientation + * * @author hneemann */ public enum Orientation { + /** + * the anchor point is at the left side of the text at the bottom line + */ LEFTBOTTOM(0, 0), + /** + * the anchor point is at the center of the text at the bottom line + */ CENTERBOTTOM(1, 0), + /** + * the anchor point is at the right side of the text at the bottom line + */ RIGHTBOTTOM(2, 0), + /** + * the anchor point is at the right side of the text in middle height + */ RIGHTCENTER(2, 1), + /** + * the anchor point is at the right side of the text at the top of the text + */ RIGHTTOP(2, 2), + /** + * the anchor point is at the center of the text at the top of the text + */ CENTERTOP(1, 2), + /** + * the anchor point is at the left side of the text at the top of the text + */ LEFTTOP(0, 2), + /** + * the anchor point is at the left side of the text in middle height + */ LEFTCENTER(0, 1), + /** + * the anchor point is in the center of the text + */ CENTERCENTER(1, 1); diff --git a/src/main/java/de/neemann/digital/draw/graphics/Style.java b/src/main/java/de/neemann/digital/draw/graphics/Style.java index 6aa3e571c..0ad0d751f 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/Style.java +++ b/src/main/java/de/neemann/digital/draw/graphics/Style.java @@ -8,18 +8,50 @@ import java.awt.*; * @author hneemann */ public class Style { + /** + * used for all lines to draw the shapes itself + */ public static final Style NORMAL = new Style(4, false, Color.BLACK); + /** + * thin line used for the graphic in the clock or delay shape + */ public static final Style THIN = new Style(2, false, Color.BLACK); + /** + * Used for wires in editing mode + */ public static final Style WIRE = new Style(4, true, Color.BLUE.darker()); + /** + * Used for low wires in running mode + */ public static final Style WIRE_LOW = new Style(4, true, new Color(0, 112, 0)); + /** + * Used for high wires in running mode + */ public static final Style WIRE_HIGH = new Style(4, true, new Color(102, 255, 102)); + /** + * Used for wires in high Z state + */ public static final Style WIRE_HIGHZ = new Style(4, true, Color.GRAY); + /** + * used to draw the output dots + */ public static final Style WIRE_OUT = new Style(4, true, Color.RED.darker()); + /** + * filld style used to fill the splitter or the dark LEDs + */ public static final Style FILLED = new Style(4, true, Color.BLACK); + /** + * Used to draw the grid in the graph + */ public static final Style DASH = new Style(1, false, Color.BLACK, new float[]{4, 4}); + /** + * Used todraw the pin description text + */ public static final Style SHAPE_PIN = new Style(4, false, Color.GRAY, 18, null); + /** + * highlight color used for the circles to mark an element + */ public static final Style HIGHLIGHT = new Style(4, false, Color.CYAN); - public static final Style INVISIBLE = new Style(0, false, Color.WHITE); private final int thickness; private final boolean filled; diff --git a/src/main/java/de/neemann/digital/draw/shapes/TextShape.java b/src/main/java/de/neemann/digital/draw/shapes/TextShape.java index 1df2a15b4..7f0467e9a 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/TextShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/TextShape.java @@ -5,7 +5,10 @@ import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.PinDescription; import de.neemann.digital.draw.elements.IOState; import de.neemann.digital.draw.elements.Pins; -import de.neemann.digital.draw.graphics.*; +import de.neemann.digital.draw.graphics.Graphic; +import de.neemann.digital.draw.graphics.Orientation; +import de.neemann.digital.draw.graphics.Style; +import de.neemann.digital.draw.graphics.Vector; import de.neemann.digital.lang.Lang; /** @@ -41,13 +44,6 @@ public class TextShape implements Shape { @Override public void drawTo(Graphic graphic, boolean highLight) { - int size = Style.NORMAL.getFontSize(); - graphic.drawPolygon( - new Polygon(true) - .add(0, 0) - .add(size * 2, 0) - .add(size * 2, size) - .add(0, size), Style.INVISIBLE); graphic.drawText(new Vector(0, 0), new Vector(1, 0), label, Orientation.LEFTTOP, Style.NORMAL); } }