Skip to content

Commit

Permalink
added orientation attribute to text element, closes #159
Browse files Browse the repository at this point in the history
  • Loading branch information
hneemann committed Jun 8, 2018
1 parent 0f338cd commit 19193e9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/main/java/de/neemann/digital/core/element/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.neemann.digital.core.io.InValue;
import de.neemann.digital.core.memory.DataField;
import de.neemann.digital.core.memory.rom.ROMManger;
import de.neemann.digital.draw.graphics.Orientation;
import de.neemann.digital.draw.graphics.Style;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.InverterConfig;
Expand Down Expand Up @@ -140,6 +141,13 @@ private Keys() {
.setMin(10)
.setMax(70);

/**
* text orientation
*/
public static final Key<Orientation> TEXT_ORIENTATION
= new Key.KeyEnum<>("textOrientation", Orientation.LEFTTOP, Orientation.values()).setSecondary();


/**
* The size of a LED
*/
Expand Down Expand Up @@ -515,7 +523,7 @@ private Keys() {
new Key.KeyInteger("pinCount", 0)
.setMin(0)
.setDependsOn(IS_DIL)
.setSecondary();
.setSecondary();


/**
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/neemann/digital/draw/shapes/TextShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class TextShape implements Shape {
private final String text;
private final int fontSize;
private Orientation orientation;

/**
* Create a new instance
Expand All @@ -47,6 +48,7 @@ public TextShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions
this.text = Lang.evalMultilingualContent(text);

fontSize = attr.get(Keys.FONT_SIZE);
orientation = attr.get(Keys.TEXT_ORIENTATION);
}

@Override
Expand All @@ -61,6 +63,7 @@ public Interactor applyStateMonitor(IOState ioState, Observer guiObserver) {

@Override
public void drawTo(Graphic graphic, Style highLight) {

StringBuilder sb = new StringBuilder();
Style style = Style.NORMAL.deriveFontStyle(fontSize, true);
Vector pos = new Vector(0, 0);
Expand All @@ -69,14 +72,14 @@ public void drawTo(Graphic graphic, Style highLight) {
char c = text.charAt(i);
if (c == '\n') {
if (sb.length() > 0) {
graphic.drawText(pos, pos.add(1, 0), sb.toString(), Orientation.LEFTTOP, style);
graphic.drawText(pos, pos.add(1, 0), sb.toString(), orientation, style);
sb.setLength(0);
}
pos = pos.add(0, dy);
} else
sb.append(c);
}
if (sb.length() > 0)
graphic.drawText(pos, pos.add(1, 0), sb.toString(), Orientation.LEFTTOP, style);
graphic.drawText(pos, pos.add(1, 0), sb.toString(), orientation, style);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import de.neemann.digital.core.memory.rom.ROMManger;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.draw.graphics.Orientation;
import de.neemann.digital.draw.library.ElementNotFoundException;
import de.neemann.digital.draw.model.InverterConfig;
import de.neemann.digital.draw.model.ModelCreator;
Expand Down Expand Up @@ -65,6 +66,7 @@ private EditorFactory() {
add(BarrelShifterMode.class, BarrelShifterModeEditor.class);
add(LeftRightFormat.class, LeftRightFormatsEditor.class);
add(IntFormat.class, IntFormatsEditor.class);
add(Orientation.class, OrientationEditor.class);
add(Language.class, LanguageEditor.class);
add(TestCaseDescription.class, TestCaseDescriptionEditor.class);
add(FormatToExpression.class, FormatEditor.class);
Expand Down Expand Up @@ -589,6 +591,12 @@ public IntFormatsEditor(IntFormat value, Key<IntFormat> key) {
}
}

private static final class OrientationEditor extends EnumEditor<Orientation> {
public OrientationEditor(Orientation value, Key<Orientation> key) {
super(value, key);
}
}

private static final class BarrelShifterModeEditor extends EnumEditor<BarrelShifterMode> {
public BarrelShifterModeEditor(BarrelShifterMode value, Key<BarrelShifterMode> key) {
super(value, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DummyElement implements Element {
public static final ElementTypeDescription TEXTDESCRIPTION = new ElementTypeDescription("Text", DummyElement.class)
.addAttribute(Keys.DESCRIPTION)
.addAttribute(Keys.ROTATE)
.addAttribute(Keys.TEXT_ORIENTATION)
.addAttribute(Keys.FONT_SIZE);

/**
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/lang/lang_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,18 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_useDefShape_tt">Verwendet die einfache Form zur Darstellung. Hat nur einen Effekt, wenn die
Schaltung eine Benutzerdefinierte Form oder eine DIL Form verwendet.</string>

<string name="key_textOrientation">Ausrichtung</string>
<string name="key_textOrientation_tt">Lage der Koordinate relativ zum Text.</string>
<string name="key_textOrientation_LEFTBOTTOM">links unten</string>
<string name="key_textOrientation_CENTERBOTTOM">mitte unten</string>
<string name="key_textOrientation_RIGHTBOTTOM">rechts unten</string>
<string name="key_textOrientation_RIGHTCENTER">rechts mitte</string>
<string name="key_textOrientation_RIGHTTOP">rechts oben</string>
<string name="key_textOrientation_CENTERTOP">mitte oben</string>
<string name="key_textOrientation_LEFTTOP">links oben</string>
<string name="key_textOrientation_LEFTCENTER">links mitte</string>
<string name="key_textOrientation_CENTERCENTER">mitte mitte</string>

<string name="mod_insertWire">Leitung eingefügt.</string>
<string name="mod_insertCopied">Aus Zwischenablage eingefügt.</string>
<string name="mod_setKey_N0_in_element_N1">Wert ''{0}'' in Element ''{1}'' verändert.</string>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/lang/lang_en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,18 @@
<string name="key_useDefShape">Use Default Shape</string>
<string name="key_useDefShape_tt">Use the default shape instead of using the DIL or custom shape configured in the circuit.</string>

<string name="key_textOrientation">Orientation</string>
<string name="key_textOrientation_tt">Position of the coordinate relative to the text.</string>
<string name="key_textOrientation_LEFTBOTTOM">left bottom</string>
<string name="key_textOrientation_CENTERBOTTOM">center bottom</string>
<string name="key_textOrientation_RIGHTBOTTOM">right bottom</string>
<string name="key_textOrientation_RIGHTCENTER">right center</string>
<string name="key_textOrientation_RIGHTTOP">right top</string>
<string name="key_textOrientation_CENTERTOP">center top</string>
<string name="key_textOrientation_LEFTTOP">left top</string>
<string name="key_textOrientation_LEFTCENTER">left center</string>
<string name="key_textOrientation_CENTERCENTER">center center</string>

<string name="mod_insertWire">Inserted wire.</string>
<string name="mod_insertCopied">Insert from clipboard.</string>
<string name="mod_setKey_N0_in_element_N1">Value ''{0}'' in component ''{1}'' modified.</string>
Expand Down

0 comments on commit 19193e9

Please sign in to comment.