diff --git a/src/main/java/graphical/basics/gobject/Line.java b/src/main/java/graphical/basics/gobject/Line.java index b28c8f8..d73db49 100644 --- a/src/main/java/graphical/basics/gobject/Line.java +++ b/src/main/java/graphical/basics/gobject/Line.java @@ -20,28 +20,34 @@ public class Line extends FillAndStroke implements ShapeLike { Location p2; ColorHolder colorHolder; + Line2D.Double line2D; + public Line(Location p1, Location p2, Color color, NumberHolder thickness) { - super(color,color); + super(color, color); this.p1 = p1; this.p2 = p2; + this.line2D = new Line2D.Double(p1.getX(), p1.getY(), p2.getX(), p2.getY()); this.colorHolder = new ColorHolder(color); setStrokeThickness(thickness); } public Line(Location p1, Location p2, Color color) { - super(color,color); + super(color, color); this.p1 = p1; this.p2 = p2; + this.line2D = new Line2D.Double(p1.getX(), p1.getY(), p2.getX(), p2.getY()); this.colorHolder = new ColorHolder(color); } @Override public void paint(Graphics g) { + + line2D.setLine(p1.getX(), p1.getY(), p2.getX(), p2.getY()); Graphics2D g2 = (Graphics2D) g; - g2.setStroke(new BasicStroke((float)getStrokeThickness().getValue())); + g2.setStroke(new BasicStroke((float) getStrokeThickness().getValue())); g.setColor(colorHolder.getColor()); - g.drawLine((int) p1.getX(), (int) p1.getY(), (int) p2.getX(), (int) p2.getY()); + g2.draw(line2D); g2.setStroke(new BasicStroke(1)); } @@ -87,4 +93,11 @@ public Location getP1() { public Location getP2() { return p2; } + + @Override + public Gobject copy() { + var copy = new Line(p1.copy(), p2.copy(), colorHolder.getColor()); + copyBasicFields(copy, this); + return copy; + } } diff --git a/src/main/java/graphical/basics/gobject/latex/Latex.java b/src/main/java/graphical/basics/gobject/latex/Latex.java index 994dfad..43804f9 100644 --- a/src/main/java/graphical/basics/gobject/latex/Latex.java +++ b/src/main/java/graphical/basics/gobject/latex/Latex.java @@ -21,12 +21,17 @@ public static Group of(String s) { return new Group(generateExp(s, Location.at(0, 0), Color.white)); } + public static Group of(String s, double size) { + return new Group(generateExp(s, Location.at(0, 0), Color.white, size)); + } + private static final double FONT_SIZE = 50; public static List generateExp(String s, Location location, Color color) { return generateExp(s, location, color, FONT_SIZE); } + public static List generateExp(String s, Location location, Color color, double size) { final var formula = new TeXFormula(s); diff --git a/src/main/java/graphical/basics/gobject/latex/Rect.java b/src/main/java/graphical/basics/gobject/latex/Rect.java index a471b84..b3a1c5e 100644 --- a/src/main/java/graphical/basics/gobject/latex/Rect.java +++ b/src/main/java/graphical/basics/gobject/latex/Rect.java @@ -3,6 +3,7 @@ import graphical.basics.ColorHolder; import graphical.basics.gobject.shape.ShapeLike; import graphical.basics.gobject.struct.FillAndStroke; +import graphical.basics.gobject.struct.Gobject; import graphical.basics.location.Location; import graphical.basics.location.LocationPair; @@ -76,9 +77,17 @@ private double getCurrentHeight() { return lowerRightPoint.getY() - upperLeftPoint.getY(); } - public Location getUpperLeftPoint() { return upperLeftPoint; } + public Location getUpperLeftPoint() { + return upperLeftPoint; + } public Location getLowerRightPoint() { return lowerRightPoint; } + + + public static Rect backgroundFor(Gobject g, double margin) { + var borders = g.getBorders(); + return new Rect(borders.getL1().plus(-margin, -margin), borders.getL2().plus(margin, margin), new Color(0,0,0,170)); + } } diff --git a/src/main/java/graphical/basics/gobject/struct/Gobject.java b/src/main/java/graphical/basics/gobject/struct/Gobject.java index 8f17a18..b925dd0 100644 --- a/src/main/java/graphical/basics/gobject/struct/Gobject.java +++ b/src/main/java/graphical/basics/gobject/struct/Gobject.java @@ -1,6 +1,7 @@ package graphical.basics.gobject.struct; +import graphical.basics.gobject.Group; import graphical.basics.presentation.Positioning; import graphical.basics.presentation.Presentation; import graphical.basics.ColorHolder; @@ -18,6 +19,8 @@ import java.awt.*; import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static graphical.basics.presentation.Positioning.Reference.*; @@ -207,12 +210,20 @@ public double getHeight() { return getBorders().getheight(); } - public Gobject copy(){ + public Gobject copy() { throw new RuntimeException("not implemented yet"); } - protected void copyBasicFields(Gobject copy, Gobject source){ + + protected void copyBasicFields(Gobject copy, Gobject source) { copy.getScale().setValue(source.getScale().getValue()); copy.getAngle().setValue(source.getAngle().getValue()); } + public Group and(Gobject... gobjects) { + var result = new ArrayList(); + result.add(this); + result.addAll(Arrays.asList(gobjects)); + return new Group(result); + } + } diff --git a/src/main/java/graphical/basics/gobject/struct/ShapeGobject2.java b/src/main/java/graphical/basics/gobject/struct/ShapeGobject2.java index f4d70a0..0bbc452 100644 --- a/src/main/java/graphical/basics/gobject/struct/ShapeGobject2.java +++ b/src/main/java/graphical/basics/gobject/struct/ShapeGobject2.java @@ -135,6 +135,8 @@ public static ShapeGobject2 fromSVGStyle(Shape shape, String style) { @Override public Gobject copy() { var copy = new ShapeGobject2(ShapeCopyMachine.clone(shape),location.copy(), new ColorHolder(getFillColorHolder().getColor()), null); + copy.shapeOfsetX=this.shapeOfsetX; + copy.shapeOfsetY=this.shapeOfsetY; copyBasicFields(copy, this); return copy; } diff --git a/src/main/java/graphical/basics/presentation/Animation.java b/src/main/java/graphical/basics/presentation/Animation.java index 83c1b8c..3ae9aeb 100644 --- a/src/main/java/graphical/basics/presentation/Animation.java +++ b/src/main/java/graphical/basics/presentation/Animation.java @@ -3,6 +3,7 @@ import graphical.basics.ColorHolder; import graphical.basics.gobject.Group; import graphical.basics.gobject.Line; +import graphical.basics.gobject.latex.Rect; import graphical.basics.gobject.shape.ShapeLike; import graphical.basics.gobject.struct.*; import graphical.basics.presentation.effects.T3b1b; @@ -17,8 +18,6 @@ public class Animation { - - private static final Presentation presentation = Presentation.staticReference; public static Task fadeOut(Gobject gobject, int steps) { @@ -121,6 +120,15 @@ public static Task fadeInGrow(Gobject gobject, int steps) { }); } + public static Task fadeInGrowFromBig(Gobject gobject, int steps) { + return new ContextSetupTask(() -> { + var scale = gobject.scale.getValue(); + gobject.getScale().setValue(15); + return fadeIn(gobject, steps).parallel(gobject.getScale().changeTo(scale, steps)); + }); + } + + public static Task fadeoutGrow(Gobject gobject, int steps) { return fadeOut(gobject, steps).parallel(gobject.getScale().change(gobject.getScale().getValue() * -1, steps)); } @@ -200,11 +208,18 @@ public static Task clipInit(Gobject gobject) { })).parallel(fadeIn(gobject)); } - public static Task replace(Gobject replaced,Gobject newGObject){ - return new ContextSetupTask(()->{ - newGObject.setPositionTo(replaced.getMidPoint()); - return t3b1b(replaced,newGObject,presentation.seconds(1)); - }); + public static Task replace(Gobject replaced, Gobject newGObject) { + return new ContextSetupTask(() -> { + newGObject.setPositionTo(replaced.getMidPoint()); + return t3b1b(replaced, newGObject, presentation.seconds(1)); + }); + } + + public static Task emphasizeBox(Gobject g) { + var rect = Rect.backgroundFor(g, 15); + rect.setStrokeColorHolder(new ColorHolder(Color.orange)); + rect.setFillColorHolder(new ColorHolder(new Color(0, 0, 0, 0))); + return strokeAndFill(rect, presentation.seconds(1)); } } \ No newline at end of file diff --git a/src/main/java/graphical/basics/presentation/Positioning.java b/src/main/java/graphical/basics/presentation/Positioning.java index 7ae28f4..aa95535 100644 --- a/src/main/java/graphical/basics/presentation/Positioning.java +++ b/src/main/java/graphical/basics/presentation/Positioning.java @@ -132,10 +132,10 @@ public static Task alignAll(List l1, List l2) { for (int i = 0; i < l1.size(); i++) { if(l1.get(i) instanceof Char2){ - var char1=(Char2)l1.get(i); - var char2=(Char2)l2.get(i); + var char1=l1.get(i); + var char2=l2.get(i); - double ration=(char2.getSize()+0.0)/(char1.getSize()+0.0); + double ration=(char2.getWidth()+0.0)/(char1.getWidth()+0.0); taskList.add(Positioning.animation.align(l1.get(i), l2.get(i), CENTER).parallel(char1.scale(ration))); }else{ diff --git a/src/main/java/graphical/basics/presentation/Presentation.java b/src/main/java/graphical/basics/presentation/Presentation.java index ab084c2..4ff104f 100644 --- a/src/main/java/graphical/basics/presentation/Presentation.java +++ b/src/main/java/graphical/basics/presentation/Presentation.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static javax.swing.WindowConstants.EXIT_ON_CLOSE; @@ -249,6 +250,9 @@ public void runBehaviors() { public void add(Gobject gobject) { gobjects.add(gobject); } + public void add(Gobject... gs){ + gobjects.addAll(Arrays.asList(gs)); + } public void addBefore(Gobject referential, Gobject gobject) { gobjects.add(gobjects.indexOf(referential), gobject); diff --git a/src/main/java/graphical/basics/task/InterruptableTask.java b/src/main/java/graphical/basics/task/InterruptableTask.java index 4d57f24..26e67c1 100644 --- a/src/main/java/graphical/basics/task/InterruptableTask.java +++ b/src/main/java/graphical/basics/task/InterruptableTask.java @@ -1,5 +1,7 @@ package graphical.basics.task; +import graphical.basics.presentation.Presentation; + public class InterruptableTask implements Task { private final Task slave;