mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 14:56:29 -04:00
better handling of text orientations but still no vertical text
This commit is contained in:
parent
61d5922a76
commit
fa588d007e
@ -24,6 +24,7 @@ public class LookUpTable extends Node implements Element {
|
||||
return names;
|
||||
}
|
||||
}
|
||||
.addAttribute(AttributeKey.Rotate)
|
||||
.addAttribute(AttributeKey.Bits)
|
||||
.addAttribute(AttributeKey.InputCount)
|
||||
.addAttribute(AttributeKey.Data)
|
||||
|
@ -133,11 +133,11 @@ public class Circuit implements Drawable {
|
||||
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<>();
|
||||
for (VisualElement vp : visualElements)
|
||||
if (vp.matches(min, max))
|
||||
m.add(new VisualElement(vp));
|
||||
m.add(new VisualElement(vp).setShapeFactory(shapeFactory));
|
||||
|
||||
for (Wire w : wires)
|
||||
if (w.p1.inside(min, max) && w.p2.inside(min, max))
|
||||
|
@ -12,7 +12,6 @@ public class GraphicSwing implements Graphic {
|
||||
|
||||
public GraphicSwing(Graphics2D gr) {
|
||||
this.gr = gr;
|
||||
// gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
gr.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
}
|
||||
|
||||
@ -56,6 +55,16 @@ public class GraphicSwing implements Graphic {
|
||||
|
||||
@Override
|
||||
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);
|
||||
int xoff = 0;
|
||||
if (orientation.getX() != 0) {
|
||||
|
@ -4,17 +4,17 @@ package de.neemann.digital.draw.graphics;
|
||||
* @author hneemann
|
||||
*/
|
||||
public enum Orientation {
|
||||
LEFTCENTER(0, 1),
|
||||
LEFTBOTTOM(0, 0),
|
||||
CENTERBOTTOM(1, 0),
|
||||
RIGHTBOTTOM(2, 0),
|
||||
RIGHTCENTER(2, 1),
|
||||
CENTERCENTER(1, 1),
|
||||
|
||||
LEFTTOP(0, 2),
|
||||
RIGHTTOP(2, 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 y;
|
||||
@ -31,4 +31,14 @@ public enum Orientation {
|
||||
public int getY() {
|
||||
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];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class GenericShape implements Shape {
|
||||
label = null;
|
||||
this.label = label;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
boolean normalMode = savedListener == null;
|
||||
|
||||
Circuit cr = new Circuit();
|
||||
circuitComponent = new CircuitComponent(cr, library);
|
||||
circuitComponent = new CircuitComponent(cr, library, shapeFactory);
|
||||
|
||||
if (fileToOpen != null) {
|
||||
SwingUtilities.invokeLater(() -> loadFile(fileToOpen, false));
|
||||
|
@ -12,6 +12,7 @@ import de.neemann.digital.draw.graphics.Polygon;
|
||||
import de.neemann.digital.draw.library.ElementLibrary;
|
||||
import de.neemann.digital.draw.shapes.Drawable;
|
||||
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.Main;
|
||||
import de.neemann.digital.gui.SavedListener;
|
||||
@ -32,13 +33,15 @@ public class CircuitComponent extends JComponent implements Observer {
|
||||
|
||||
private static final String delAction = "myDelAction";
|
||||
private final ElementLibrary library;
|
||||
private final ShapeFactory shapeFactory;
|
||||
private Circuit circuit;
|
||||
private Mouse listener;
|
||||
private AffineTransform transform = new AffineTransform();
|
||||
private Observer manualChangeObserver;
|
||||
|
||||
public CircuitComponent(Circuit aCircuit, ElementLibrary library) {
|
||||
public CircuitComponent(Circuit aCircuit, ElementLibrary library, ShapeFactory shapeFactory) {
|
||||
this.library = library;
|
||||
this.shapeFactory = shapeFactory;
|
||||
setCircuit(aCircuit);
|
||||
|
||||
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));
|
||||
state = State.MOVE;
|
||||
} 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));
|
||||
state = State.COPY;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user