better handling of text orientations but still no vertical text

This commit is contained in:
hneemann 2016-03-28 14:52:02 +02:00
parent 61d5922a76
commit fa588d007e
7 changed files with 37 additions and 14 deletions

View File

@ -24,6 +24,7 @@ public class LookUpTable extends Node implements Element {
return names; return names;
} }
} }
.addAttribute(AttributeKey.Rotate)
.addAttribute(AttributeKey.Bits) .addAttribute(AttributeKey.Bits)
.addAttribute(AttributeKey.InputCount) .addAttribute(AttributeKey.InputCount)
.addAttribute(AttributeKey.Data) .addAttribute(AttributeKey.Data)

View File

@ -133,11 +133,11 @@ public class Circuit implements Drawable {
return m; return m;
} }
public ArrayList<Moveable> getElementsToCopy(Vector min, Vector max) { public ArrayList<Moveable> getElementsToCopy(Vector min, Vector max, ShapeFactory shapeFactory) {
ArrayList<Moveable> m = new ArrayList<>(); ArrayList<Moveable> m = new ArrayList<>();
for (VisualElement vp : visualElements) for (VisualElement vp : visualElements)
if (vp.matches(min, max)) if (vp.matches(min, max))
m.add(new VisualElement(vp)); m.add(new VisualElement(vp).setShapeFactory(shapeFactory));
for (Wire w : wires) for (Wire w : wires)
if (w.p1.inside(min, max) && w.p2.inside(min, max)) if (w.p1.inside(min, max) && w.p2.inside(min, max))

View File

@ -12,7 +12,6 @@ public class GraphicSwing implements Graphic {
public GraphicSwing(Graphics2D gr) { public GraphicSwing(Graphics2D gr) {
this.gr = gr; this.gr = gr;
// gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gr.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); gr.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
} }
@ -56,6 +55,16 @@ public class GraphicSwing implements Graphic {
@Override @Override
public void drawText(Vector p1, Vector p2, String text, Orientation orientation, Style style) { public void drawText(Vector p1, Vector p2, String text, Orientation orientation, Style style) {
if (p1.y == p2.y) { // 0 and 180 deg
if (p1.x > p2.x) // 180
orientation = orientation.rot(2);
} else {
if (p1.y < p2.y) // 90
orientation = orientation.rot(3);
else
orientation = orientation.rot(1);
}
applyStyle(style); applyStyle(style);
int xoff = 0; int xoff = 0;
if (orientation.getX() != 0) { if (orientation.getX() != 0) {

View File

@ -4,17 +4,17 @@ package de.neemann.digital.draw.graphics;
* @author hneemann * @author hneemann
*/ */
public enum Orientation { public enum Orientation {
LEFTCENTER(0, 1), LEFTBOTTOM(0, 0),
CENTERBOTTOM(1, 0),
RIGHTBOTTOM(2, 0),
RIGHTCENTER(2, 1), RIGHTCENTER(2, 1),
CENTERCENTER(1, 1),
LEFTTOP(0, 2),
RIGHTTOP(2, 2), RIGHTTOP(2, 2),
CENTERTOP(1, 2), CENTERTOP(1, 2),
LEFTTOP(0, 2),
LEFTCENTER(0, 1),
CENTERCENTER(1, 1);
LEFTBOTTOM(0, 0),
RIGHTBOTTOM(2, 0),
CENTERBOTTOM(1, 0);
private final int x; private final int x;
private final int y; private final int y;
@ -31,4 +31,14 @@ public enum Orientation {
public int getY() { public int getY() {
return y; return y;
} }
public Orientation rot(int n) {
if (this == CENTERCENTER) return CENTERCENTER;
int p = this.ordinal() + n * 2;
if (p > 7) p = p - 8;
if (p < 0) p = p + 8;
return Orientation.values()[p];
}
} }

View File

@ -39,7 +39,7 @@ public class GenericShape implements Shape {
label = null; label = null;
this.label = label; this.label = label;
this.showPinLabels = showPinLabels; this.showPinLabels = showPinLabels;
width = inputs.length == 1 && outputs.length == 1 ? 1 : 3; width = inputs.length == 1 && outputs.length == 1 && !showPinLabels ? 1 : 3;
symmetric = outputs.length == 1; symmetric = outputs.length == 1;
} }

View File

@ -70,7 +70,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
boolean normalMode = savedListener == null; boolean normalMode = savedListener == null;
Circuit cr = new Circuit(); Circuit cr = new Circuit();
circuitComponent = new CircuitComponent(cr, library); circuitComponent = new CircuitComponent(cr, library, shapeFactory);
if (fileToOpen != null) { if (fileToOpen != null) {
SwingUtilities.invokeLater(() -> loadFile(fileToOpen, false)); SwingUtilities.invokeLater(() -> loadFile(fileToOpen, false));

View File

@ -12,6 +12,7 @@ import de.neemann.digital.draw.graphics.Polygon;
import de.neemann.digital.draw.library.ElementLibrary; import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.shapes.Drawable; import de.neemann.digital.draw.shapes.Drawable;
import de.neemann.digital.draw.shapes.GenericShape; import de.neemann.digital.draw.shapes.GenericShape;
import de.neemann.digital.draw.shapes.ShapeFactory;
import de.neemann.digital.gui.LibrarySelector; import de.neemann.digital.gui.LibrarySelector;
import de.neemann.digital.gui.Main; import de.neemann.digital.gui.Main;
import de.neemann.digital.gui.SavedListener; import de.neemann.digital.gui.SavedListener;
@ -32,13 +33,15 @@ public class CircuitComponent extends JComponent implements Observer {
private static final String delAction = "myDelAction"; private static final String delAction = "myDelAction";
private final ElementLibrary library; private final ElementLibrary library;
private final ShapeFactory shapeFactory;
private Circuit circuit; private Circuit circuit;
private Mouse listener; private Mouse listener;
private AffineTransform transform = new AffineTransform(); private AffineTransform transform = new AffineTransform();
private Observer manualChangeObserver; private Observer manualChangeObserver;
public CircuitComponent(Circuit aCircuit, ElementLibrary library) { public CircuitComponent(Circuit aCircuit, ElementLibrary library, ShapeFactory shapeFactory) {
this.library = library; this.library = library;
this.shapeFactory = shapeFactory;
setCircuit(aCircuit); setCircuit(aCircuit);
KeyStroke delKey = KeyStroke.getKeyStroke("DELETE"); KeyStroke delKey = KeyStroke.getKeyStroke("DELETE");
@ -378,7 +381,7 @@ public class CircuitComponent extends JComponent implements Observer {
elements = circuit.getElementsToMove(Vector.min(corner1, corner2), Vector.max(corner1, corner2)); elements = circuit.getElementsToMove(Vector.min(corner1, corner2), Vector.max(corner1, corner2));
state = State.MOVE; state = State.MOVE;
} else { } else {
elements = circuit.getElementsToCopy(Vector.min(corner1, corner2), Vector.max(corner1, corner2)); elements = circuit.getElementsToCopy(Vector.min(corner1, corner2), Vector.max(corner1, corner2), shapeFactory);
copyStartPosition = raster(getPosVector(e)); copyStartPosition = raster(getPosVector(e));
state = State.COPY; state = State.COPY;
} }