mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 00:44:40 -04:00
implemented mirroring in the Graphics classes
This commit is contained in:
parent
45776736db
commit
834ee12957
@ -10,6 +10,8 @@ import de.neemann.digital.draw.graphics.text.formatter.GraphicsFormatter;
|
|||||||
import java.awt.font.FontRenderContext;
|
import java.awt.font.FontRenderContext;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
|
import static de.neemann.digital.draw.graphics.GraphicSwing.isMirror;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to determine the size of shapes or the whole circuit.
|
* This class is used to determine the size of shapes or the whole circuit.
|
||||||
* You can draw the items to an instance of this class and then obtain the size
|
* You can draw the items to an instance of this class and then obtain the size
|
||||||
@ -110,8 +112,10 @@ public class GraphicMinMax extends Graphic {
|
|||||||
p = p.sub(width.mul(orientation.getX()).div(2));
|
p = p.sub(width.mul(orientation.getX()).div(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orientation.getY() != 0) {
|
int oy = orientation.getY();
|
||||||
p = p.sub(height.mul(orientation.getY()).div(2));
|
if (isMirror(p1, p2, p3)) oy = 2 - oy;
|
||||||
|
if (oy != 0) {
|
||||||
|
p = p.sub(height.mul(oy).div(2));
|
||||||
} else
|
} else
|
||||||
p = p.sub(height.div(4));
|
p = p.sub(height.div(4));
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import static de.neemann.digital.draw.graphics.GraphicSwing.isMirror;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to create a SVG representation of the circuit.
|
* Used to create a SVG representation of the circuit.
|
||||||
*/
|
*/
|
||||||
@ -204,7 +206,9 @@ public class GraphicSVG extends Graphic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VectorFloat p = new VectorFloat(p1);
|
VectorFloat p = new VectorFloat(p1);
|
||||||
switch (orientation.getY()) {
|
int oy = orientation.getY();
|
||||||
|
if (isMirror(p1, p2, p3)) oy = 2 - oy;
|
||||||
|
switch (oy) {
|
||||||
case 1:
|
case 1:
|
||||||
p = p.add(new VectorFloat(0, style.getFontSize() / 2f - style.getFontSize() / 8f));
|
p = p.add(new VectorFloat(0, style.getFontSize() / 2f - style.getFontSize() / 8f));
|
||||||
break;
|
break;
|
||||||
|
@ -113,11 +113,6 @@ public class GraphicSwing extends Graphic {
|
|||||||
rotateText = true;
|
rotateText = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
VectorInterface d0 = p2.sub(p1).toFloat().getOrthogonal();
|
|
||||||
VectorInterface d1 = p3.sub(p1);
|
|
||||||
boolean mirror = d1.getX() * d0.getX() + d1.getY() * d0.getY() < 0;
|
|
||||||
if (mirror) text += "|";
|
|
||||||
|
|
||||||
GraphicsFormatter.Fragment fragment = GraphicsFormatter.createFragment(gr, text);
|
GraphicsFormatter.Fragment fragment = GraphicsFormatter.createFragment(gr, text);
|
||||||
|
|
||||||
AffineTransform old = null;
|
AffineTransform old = null;
|
||||||
@ -135,9 +130,11 @@ public class GraphicSwing extends Graphic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int yoff = 0;
|
int yoff = 0;
|
||||||
if (orientation.getY() != 0) {
|
int oy = orientation.getY();
|
||||||
|
if (isMirror(p1, p2, p3)) oy = 2 - oy;
|
||||||
|
if (oy != 0) {
|
||||||
int height = fragment.getHeight();
|
int height = fragment.getHeight();
|
||||||
yoff += height * orientation.getY() / 3;
|
yoff += height * oy / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment.draw(gr, p1.getX() + xoff, p1.getY() + yoff);
|
fragment.draw(gr, p1.getX() + xoff, p1.getY() + yoff);
|
||||||
@ -147,6 +144,12 @@ public class GraphicSwing extends Graphic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isMirror(VectorInterface p1, VectorInterface p2, VectorInterface p3) {
|
||||||
|
VectorInterface d0 = p2.sub(p1).toFloat().getOrthogonal();
|
||||||
|
VectorInterface d1 = p3.sub(p1);
|
||||||
|
return d1.getX() * d0.getX() + d1.getY() * d0.getY() < 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFlagSet(Flag flag) {
|
public boolean isFlagSet(Flag flag) {
|
||||||
if (flag == Flag.tiny)
|
if (flag == Flag.tiny)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user