mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 06:49:36 -04:00
added different font sizes
This commit is contained in:
parent
e57c2b2930
commit
1b0d26cbf4
@ -11,5 +11,5 @@ public interface Graphic {
|
|||||||
|
|
||||||
void drawCircle(Vector p1, Vector p2, Style style);
|
void drawCircle(Vector p1, Vector p2, Style style);
|
||||||
|
|
||||||
void drawText(Vector p1, Vector p2, String text, Orientation orientation);
|
void drawText(Vector p1, Vector p2, String text, Orientation orientation, Style style);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class GraphicMinMax implements Graphic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawText(Vector p1, Vector p2, String text, Orientation orientation) {
|
public void drawText(Vector p1, Vector p2, String text, Orientation orientation, Style style) {
|
||||||
// ignore text!
|
// ignore text!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,15 +42,16 @@ public class GraphicSwing implements Graphic {
|
|||||||
|
|
||||||
private void applyStyle(Style style) {
|
private void applyStyle(Style style) {
|
||||||
if (style != lastStyle) {
|
if (style != lastStyle) {
|
||||||
gr.setStroke(new BasicStroke(style.getThickness()));
|
gr.setStroke(style.getStroke());
|
||||||
gr.setColor(style.getColor());
|
gr.setColor(style.getColor());
|
||||||
|
gr.setFont(style.getFont());
|
||||||
lastStyle = style;
|
lastStyle = style;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawText(Vector p1, Vector p2, String text, Orientation orientation) {
|
public void drawText(Vector p1, Vector p2, String text, Orientation orientation, Style style) {
|
||||||
gr.setColor(Color.BLACK);
|
applyStyle(style);
|
||||||
int xoff = 0;
|
int xoff = 0;
|
||||||
if (orientation.getX() != 0) {
|
if (orientation.getX() != 0) {
|
||||||
int width = gr.getFontMetrics().stringWidth(text);
|
int width = gr.getFontMetrics().stringWidth(text);
|
||||||
|
@ -32,8 +32,8 @@ public class GraphicTransform implements Graphic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawText(Vector p1, Vector p2, String text, Orientation orientation) {
|
public void drawText(Vector p1, Vector p2, String text, Orientation orientation, Style style) {
|
||||||
parent.drawText(transform(p1), transform(p2), text, orientation);
|
parent.drawText(transform(p1), transform(p2), text, orientation, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector transform(Vector v) {
|
private Vector transform(Vector v) {
|
||||||
|
@ -12,15 +12,27 @@ public class Style {
|
|||||||
public static final Style FILLED = new Style(2, true, Color.BLACK);
|
public static final Style FILLED = new Style(2, true, Color.BLACK);
|
||||||
public static final Style THIN = new Style(1, false, Color.BLACK);
|
public static final Style THIN = new Style(1, false, Color.BLACK);
|
||||||
public static final Style DASH = new Style(1, false, Color.BLACK);
|
public static final Style DASH = new Style(1, false, Color.BLACK);
|
||||||
|
public static final Style SHAPEPIN = new Style(2, false, Color.GRAY, 9);
|
||||||
|
|
||||||
private final int thickness;
|
private final int thickness;
|
||||||
private final boolean filled;
|
private final boolean filled;
|
||||||
private final Color color;
|
private final Color color;
|
||||||
|
private final int fontsize;
|
||||||
|
private final Stroke stroke;
|
||||||
|
private final Font font;
|
||||||
|
|
||||||
public Style(int thickness, boolean filled, Color color) {
|
public Style(int thickness, boolean filled, Color color) {
|
||||||
|
this(thickness, filled, color, 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Style(int thickness, boolean filled, Color color, int fontsize) {
|
||||||
this.thickness = thickness;
|
this.thickness = thickness;
|
||||||
this.filled = filled;
|
this.filled = filled;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.fontsize = fontsize;
|
||||||
|
stroke = new BasicStroke(thickness);
|
||||||
|
|
||||||
|
font = new Font("Arial", Font.PLAIN, fontsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getThickness() {
|
public int getThickness() {
|
||||||
@ -34,4 +46,17 @@ public class Style {
|
|||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stroke getStroke() {
|
||||||
|
return stroke;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFontSize() {
|
||||||
|
return fontsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Font getFont() {
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import de.neemann.digital.core.Listener;
|
|||||||
import de.neemann.digital.core.Model;
|
import de.neemann.digital.core.Model;
|
||||||
import de.neemann.digital.gui.draw.graphics.Graphic;
|
import de.neemann.digital.gui.draw.graphics.Graphic;
|
||||||
import de.neemann.digital.gui.draw.graphics.Orientation;
|
import de.neemann.digital.gui.draw.graphics.Orientation;
|
||||||
|
import de.neemann.digital.gui.draw.graphics.Style;
|
||||||
import de.neemann.digital.gui.draw.graphics.Vector;
|
import de.neemann.digital.gui.draw.graphics.Vector;
|
||||||
import de.neemann.digital.gui.draw.parts.Pin;
|
import de.neemann.digital.gui.draw.parts.Pin;
|
||||||
import de.neemann.digital.gui.draw.parts.Pins;
|
import de.neemann.digital.gui.draw.parts.Pins;
|
||||||
@ -35,6 +36,6 @@ public class ConstShape implements Shape {
|
|||||||
Vector textPos = new Vector(-3, 0);
|
Vector textPos = new Vector(-3, 0);
|
||||||
if (state != null)
|
if (state != null)
|
||||||
value = state.getOutput(0).getValue();
|
value = state.getOutput(0).getValue();
|
||||||
graphic.drawText(textPos, textPos.add(1, 0), Long.toString(value), Orientation.RIGHTCENTER);
|
graphic.drawText(textPos, textPos.add(1, 0), Long.toString(value), Orientation.RIGHTCENTER, Style.NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,17 @@ public class GenericShape implements Shape {
|
|||||||
private boolean invert = false;
|
private boolean invert = false;
|
||||||
|
|
||||||
private transient Pins pins;
|
private transient Pins pins;
|
||||||
|
private boolean showLabels;
|
||||||
|
|
||||||
public GenericShape(String name, String[] inputs, String[] outputs) {
|
public GenericShape(String name, String[] inputs, String[] outputs) {
|
||||||
|
this(name, inputs, outputs, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenericShape(String name, String[] inputs, String[] outputs, boolean showLabels) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
this.outputs = outputs;
|
this.outputs = outputs;
|
||||||
|
this.showLabels = showLabels;
|
||||||
width = inputs.length == 1 && outputs.length == 1 ? 1 : 3;
|
width = inputs.length == 1 && outputs.length == 1 ? 1 : 3;
|
||||||
symmetric = outputs.length == 1;
|
symmetric = outputs.length == 1;
|
||||||
}
|
}
|
||||||
@ -95,7 +101,16 @@ public class GenericShape implements Shape {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
graphic.drawText(new Vector(SIZE2, SIZE), new Vector(SIZE, SIZE), name, Orientation.LEFTBOTTOM);
|
if (showLabels) {
|
||||||
|
for (Pin p : getPins()) {
|
||||||
|
if (p.getDirection() == Pin.Direction.input)
|
||||||
|
graphic.drawText(p.getPos().add(2, 0), p.getPos().add(5, 0), p.getName(), Orientation.LEFTCENTER, Style.SHAPEPIN);
|
||||||
|
else
|
||||||
|
graphic.drawText(p.getPos().add(-2, 0), p.getPos().add(5, 0), p.getName(), Orientation.RIGHTCENTER, Style.SHAPEPIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Vector pos = new Vector(SIZE * width / 2, -SIZE2 + 2);
|
||||||
|
graphic.drawText(pos, pos.add(1, 0), name, Orientation.CENTERTOP, Style.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,6 @@ public class InputShape implements Shape {
|
|||||||
graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 2, -SIZE).add(-2, -SIZE).add(-2, SIZE).add(-SIZE * 2 - 2, SIZE), Style.NORMAL);
|
graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 2, -SIZE).add(-2, -SIZE).add(-2, SIZE).add(-SIZE * 2 - 2, SIZE), Style.NORMAL);
|
||||||
|
|
||||||
Vector textPos = new Vector(-SIZE * 3, 0);
|
Vector textPos = new Vector(-SIZE * 3, 0);
|
||||||
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.RIGHTCENTER);
|
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.RIGHTCENTER, Style.NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,12 @@ import de.neemann.digital.gui.draw.parts.State;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
import static de.neemann.digital.gui.draw.shapes.OutputShape.SIZE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class LEDShape implements Shape {
|
public class LEDShape implements Shape {
|
||||||
public static final int SIZE = 8;
|
|
||||||
public static final Vector RAD = new Vector(SIZE - 1, SIZE - 1);
|
public static final Vector RAD = new Vector(SIZE - 1, SIZE - 1);
|
||||||
public static final Vector RADL = new Vector(SIZE, SIZE);
|
public static final Vector RADL = new Vector(SIZE, SIZE);
|
||||||
private final String label;
|
private final String label;
|
||||||
@ -60,6 +61,6 @@ public class LEDShape implements Shape {
|
|||||||
if (fill)
|
if (fill)
|
||||||
graphic.drawCircle(center.sub(RAD), center.add(RAD), onStyle);
|
graphic.drawCircle(center.sub(RAD), center.add(RAD), onStyle);
|
||||||
Vector textPos = new Vector(SIZE * 3, 0);
|
Vector textPos = new Vector(SIZE * 3, 0);
|
||||||
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.LEFTCENTER);
|
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.LEFTCENTER, Style.NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,6 @@ public class OutputShape implements Shape {
|
|||||||
graphic.drawCircle(center.sub(RAD), center.add(RAD), style);
|
graphic.drawCircle(center.sub(RAD), center.add(RAD), style);
|
||||||
graphic.drawCircle(center.sub(RADL), center.add(RADL), Style.NORMAL);
|
graphic.drawCircle(center.sub(RADL), center.add(RADL), Style.NORMAL);
|
||||||
Vector textPos = new Vector(SIZE * 3, 0);
|
Vector textPos = new Vector(SIZE * 3, 0);
|
||||||
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.LEFTCENTER);
|
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.LEFTCENTER, Style.NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public final class ShapeFactory {
|
|||||||
throw new RuntimeException("no shape for " + partName);
|
throw new RuntimeException("no shape for " + partName);
|
||||||
else {
|
else {
|
||||||
PartTypeDescription pt = library.getPartType(partName);
|
PartTypeDescription pt = library.getPartType(partName);
|
||||||
return new GenericShape(createName(partName), pt.getInputNames(partAttributes), outputNames(pt, partAttributes));
|
return new GenericShape(createName(partName), pt.getInputNames(partAttributes), outputNames(pt, partAttributes), true);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
return cr.create(partAttributes);
|
return cr.create(partAttributes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user