added orientation attribute to text element, closes #159

This commit is contained in:
hneemann 2018-06-08 08:39:23 +02:00
parent 0f338cdecb
commit 19193e96ec
6 changed files with 47 additions and 3 deletions

View File

@ -13,6 +13,7 @@ import de.neemann.digital.core.extern.Application;
import de.neemann.digital.core.io.InValue; import de.neemann.digital.core.io.InValue;
import de.neemann.digital.core.memory.DataField; import de.neemann.digital.core.memory.DataField;
import de.neemann.digital.core.memory.rom.ROMManger; 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.graphics.Style;
import de.neemann.digital.draw.library.ElementLibrary; import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.model.InverterConfig; import de.neemann.digital.draw.model.InverterConfig;
@ -140,6 +141,13 @@ public final class Keys {
.setMin(10) .setMin(10)
.setMax(70); .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 * The size of a LED
*/ */
@ -515,7 +523,7 @@ public final class Keys {
new Key.KeyInteger("pinCount", 0) new Key.KeyInteger("pinCount", 0)
.setMin(0) .setMin(0)
.setDependsOn(IS_DIL) .setDependsOn(IS_DIL)
.setSecondary(); .setSecondary();
/** /**

View File

@ -23,6 +23,7 @@ import de.neemann.digital.lang.Lang;
public class TextShape implements Shape { public class TextShape implements Shape {
private final String text; private final String text;
private final int fontSize; private final int fontSize;
private Orientation orientation;
/** /**
* Create a new instance * Create a new instance
@ -47,6 +48,7 @@ public class TextShape implements Shape {
this.text = Lang.evalMultilingualContent(text); this.text = Lang.evalMultilingualContent(text);
fontSize = attr.get(Keys.FONT_SIZE); fontSize = attr.get(Keys.FONT_SIZE);
orientation = attr.get(Keys.TEXT_ORIENTATION);
} }
@Override @Override
@ -61,6 +63,7 @@ public class TextShape implements Shape {
@Override @Override
public void drawTo(Graphic graphic, Style highLight) { public void drawTo(Graphic graphic, Style highLight) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Style style = Style.NORMAL.deriveFontStyle(fontSize, true); Style style = Style.NORMAL.deriveFontStyle(fontSize, true);
Vector pos = new Vector(0, 0); Vector pos = new Vector(0, 0);
@ -69,7 +72,7 @@ public class TextShape implements Shape {
char c = text.charAt(i); char c = text.charAt(i);
if (c == '\n') { if (c == '\n') {
if (sb.length() > 0) { 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); sb.setLength(0);
} }
pos = pos.add(0, dy); pos = pos.add(0, dy);
@ -77,6 +80,6 @@ public class TextShape implements Shape {
sb.append(c); sb.append(c);
} }
if (sb.length() > 0) 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);
} }
} }

View File

@ -18,6 +18,7 @@ import de.neemann.digital.core.memory.ROM;
import de.neemann.digital.core.memory.rom.ROMManger; import de.neemann.digital.core.memory.rom.ROMManger;
import de.neemann.digital.draw.elements.PinException; import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.elements.VisualElement; 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.library.ElementNotFoundException;
import de.neemann.digital.draw.model.InverterConfig; import de.neemann.digital.draw.model.InverterConfig;
import de.neemann.digital.draw.model.ModelCreator; import de.neemann.digital.draw.model.ModelCreator;
@ -65,6 +66,7 @@ public final class EditorFactory {
add(BarrelShifterMode.class, BarrelShifterModeEditor.class); add(BarrelShifterMode.class, BarrelShifterModeEditor.class);
add(LeftRightFormat.class, LeftRightFormatsEditor.class); add(LeftRightFormat.class, LeftRightFormatsEditor.class);
add(IntFormat.class, IntFormatsEditor.class); add(IntFormat.class, IntFormatsEditor.class);
add(Orientation.class, OrientationEditor.class);
add(Language.class, LanguageEditor.class); add(Language.class, LanguageEditor.class);
add(TestCaseDescription.class, TestCaseDescriptionEditor.class); add(TestCaseDescription.class, TestCaseDescriptionEditor.class);
add(FormatToExpression.class, FormatEditor.class); add(FormatToExpression.class, FormatEditor.class);
@ -589,6 +591,12 @@ public final class EditorFactory {
} }
} }
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> { private static final class BarrelShifterModeEditor extends EnumEditor<BarrelShifterMode> {
public BarrelShifterModeEditor(BarrelShifterMode value, Key<BarrelShifterMode> key) { public BarrelShifterModeEditor(BarrelShifterMode value, Key<BarrelShifterMode> key) {
super(value, key); super(value, key);

View File

@ -32,6 +32,7 @@ public class DummyElement implements Element {
public static final ElementTypeDescription TEXTDESCRIPTION = new ElementTypeDescription("Text", DummyElement.class) public static final ElementTypeDescription TEXTDESCRIPTION = new ElementTypeDescription("Text", DummyElement.class)
.addAttribute(Keys.DESCRIPTION) .addAttribute(Keys.DESCRIPTION)
.addAttribute(Keys.ROTATE) .addAttribute(Keys.ROTATE)
.addAttribute(Keys.TEXT_ORIENTATION)
.addAttribute(Keys.FONT_SIZE); .addAttribute(Keys.FONT_SIZE);
/** /**

View File

@ -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 <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> 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_insertWire">Leitung eingefügt.</string>
<string name="mod_insertCopied">Aus Zwischenablage 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> <string name="mod_setKey_N0_in_element_N1">Wert ''{0}'' in Element ''{1}'' verändert.</string>

View File

@ -1137,6 +1137,18 @@
<string name="key_useDefShape">Use Default Shape</string> <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_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_insertWire">Inserted wire.</string>
<string name="mod_insertCopied">Insert from clipboard.</string> <string name="mod_insertCopied">Insert from clipboard.</string>
<string name="mod_setKey_N0_in_element_N1">Value ''{0}'' in component ''{1}'' modified.</string> <string name="mod_setKey_N0_in_element_N1">Value ''{0}'' in component ''{1}'' modified.</string>