Package paintingcanvas.drawable
Class Path
- java.lang.Object
-
- paintingcanvas.drawable.DrawableBase<T>
-
- paintingcanvas.drawable.DrawableBase.OutlineableDrawableBase<Path>
-
- paintingcanvas.drawable.Path
-
- All Implemented Interfaces:
Animatable,Colorable<Path>,Drawable<Path>,Outlineable<Path>,Positionable<Path>
public class Path extends DrawableBase.OutlineableDrawableBase<Path>
An SVG-like path used to draw lines and curves.Uses Path2D internally.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class paintingcanvas.drawable.DrawableBase
DrawableBase.InteractableShape<T extends Drawable<T>>, DrawableBase.OutlineableDrawableBase<T extends Drawable<T>>, DrawableBase.Shape<T extends Drawable<T>>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Pointcenter(java.awt.Graphics2D g)Get the object's centerpointPathcursorTo(int x, int y)Move the cursor to a new positionPathcurveTo(int x1, int y1, int x2, int y2, int x3, int y3)Make a cubic curve from the current cursor position to a new position.protected voiddrawFill(java.awt.Graphics2D gc)protected voiddrawOutline(java.awt.Graphics2D gc)PathgetThis()PathlineTo(int x, int y)Make a line from the current cursor position to a new positionPathquadTo(int x1, int y1, int x2, int y2)Make a quadratic curve from the current cursor position to a new position.PathsetLineColor(java.awt.Color color)Set the color of the line, equivalent to setOutline(thickness, color);PathsetStroke(java.awt.Stroke stroke)Set the stroke of the line.PathsetThickness(int thickness)Set the thickness of the line, equivalent to setOutline(thickness);-
Methods inherited from class paintingcanvas.drawable.DrawableBase.OutlineableDrawableBase
Modifier and Type Method Description java.awt.ColorgetOutlineColor()Gets the outline colorjava.awt.StrokegetOutlineStroke()Gets the outline strokevoidinternalSetFilled(boolean filled)voidinternalSetOutlineColor(java.awt.Color color)voidinternalSetOutlineStroke(java.awt.Stroke stroke)
-
Methods inherited from class paintingcanvas.drawable.DrawableBase
Modifier and Type Method Description java.awt.ColorgetColor()Get the current color of an element as aColorintgetLayer()Gets the current layer of the object.java.awt.PointgetPos()Get the position of the elementdoublegetRotation()Get an elements rotationThide()Hide the Object.doubleinternalGetRotation()voidinternalSetColor(java.awt.Color color)voidinternalSetLayer(int layer)voidinternalSetPos(int x, int y)voidinternalSetRotation(double rotation)voidrender(java.awt.Graphics2D g)Actually render the object itselfTshow()Show the Object
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface paintingcanvas.animation.Animatable
Modifier and Type Method Description default AnimationBuildercolorTo(int hex, double duration)Change the color ofthisto the specifiedcoloroverdurationseconds.default AnimationBuildercolorTo(int r, int g, int b, double duration)Change the color ofthisto the specifiedcoloroverdurationseconds.default AnimationBuildercolorTo(int r, int g, int b, int a, double duration)Change the color ofthisto the specifiedcoloroverdurationseconds.default AnimationBuildercolorTo(java.awt.Color color, double duration)Change the color ofthisto the specifiedcoloroverdurationseconds.default AnimationBuildercolorTo(java.lang.String name, double duration)Change the color ofthisto the specifiedcoloroverdurationseconds.default AnimationBuildercolorTo(Hue hue, double duration)Change the color ofthisto the specifiedcoloroverdurationseconds.Drawable<?>drawable()Get theDrawableelement from thisAnimatable.default AnimationBuilderfadeIn(double duration)Fadethisin overdurationseconds.default AnimationBuilderfadeOut(double duration)Fadethisout overdurationseconds.default AnimationBuildermoveBy(int x, int y, double duration)Movethisby the specifiedxandyoverdurationseconds.default AnimationBuildermoveHorizontalBy(int x, double duration)Movethisby the specifiedxhorizontally overdurationseconds.default AnimationBuildermoveTo(int x, int y, double duration)Movethisto the specifiedxandyoverdurationsecondsdefault AnimationBuildermoveVerticalBy(int y, double duration)Movethisby the specifiedyvertically overdurationseconds.default AnimationBuilderrotateBy(int angle, double duration)Rotatethisbyangledegrees overdurationseconds.default AnimationBuilderrotateTo(int angle, double duration)Rotatethisto the specifiedangledegrees overdurationseconds.
-
Methods inherited from interface paintingcanvas.drawable.Colorable
Modifier and Type Method Description java.awt.ColorgetColor()Get the current color of an element as aColorvoidinternalSetColor(java.awt.Color color)default TsetColor(int hex)Set the color ofthisto the specifiedcolor.default TsetColor(int r, int g, int b)Set the color ofthisto the specifiedcolor.default TsetColor(int r, int g, int b, int a)default TsetColor(java.awt.Color color)Set the color of the object with aColorobject.default TsetColor(java.lang.String name)Set the color of the object with a hue name or hex code.default TsetColor(Hue hue)Set the color of the object with aHueobject.
-
Methods inherited from interface paintingcanvas.drawable.Drawable
Modifier and Type Method Description default AnimationBuilderanimate()Start animating this object.default TbringToFront()Brings the object in front of all other objects.java.awt.Pointcenter(java.awt.Graphics2D g)Get the object's centerpointdefault Drawable<?>drawable()Get theDrawableelement from thisAnimatable.default voiderase()Erase this object from the canvas.intgetLayer()Gets the current layer of the object.TgetThis()Thide()Hide the Object.voidinternalSetLayer(int layer)voidrender(java.awt.Graphics2D g)Actually render the object itselfdefault TsendToBack()Puts the object behind all other objects.default TsetLayer(int layer)Puts the object on a specific layer.Tshow()Show the Object
-
Methods inherited from interface paintingcanvas.drawable.Outlineable
Modifier and Type Method Description java.awt.ColorgetOutlineColor()Gets the outline colorjava.awt.StrokegetOutlineStroke()Gets the outline strokevoidinternalSetFilled(boolean filled)voidinternalSetOutlineColor(java.awt.Color color)voidinternalSetOutlineStroke(java.awt.Stroke stroke)default TremoveOutline()Removes the outline from the shapedefault TsetFilled(boolean filled)Set whether this object is filled or notdefault TsetOutline(int thickness)Sets the parameters for the outline of the shape, with the color defaulting to blackdefault TsetOutline(int thickness, java.awt.Color color)Sets the parameters for the outline of the shapedefault TsetOutline(java.awt.Color color)Sets the outline color of the shape
-
Methods inherited from interface paintingcanvas.drawable.Positionable
Modifier and Type Method Description java.awt.PointgetPos()Get the position of the elementdoublegetRotation()Get an elements rotationdefault intgetX()Get the X-position of the elementdefault intgetY()Get the Y-position of the element.doubleinternalGetRotation()voidinternalSetPos(int x, int y)voidinternalSetRotation(double rotation)default Tmove(int x, int y)Moves this drawable by the specified x and y.default TmoveHorizontal(int x)Moves this drawable by the specified x and y.default TmoveVertical(int y)Moves this drawable by the specified x and y.default Trotate(double rotation)Rotate this element byrotationdegrees.default TsetPos(int x, int y)Set the position of the element.default TsetRotation(double rotation)Set an elements rotation torotationdegrees.default TsetX(int x)Set the X-position of the objectdefault TsetY(int y)Set the Y-position of the element
-
-
-
-
Constructor Detail
-
Path
public Path()
Create a new Path element. The path is initially empty.Path path = new Path().lineTo(100, 100) .quadTo(150, 0, 200, 100) .lineTo(200, 200) .lineTo(100, 100) .setColor(new Color(255, 0, 0)) .setThickness(5);
-
Path
public Path(java.awt.Color color)
Create a new Path element. The path is initially empty.Path path = new Path(new Color(255, 0, 0)).lineTo(100, 100) .quadTo(150, 0, 200, 100) .lineTo(200, 200) .lineTo(100, 100) .setThickness(5);- Parameters:
color- The color of the path
-
Path
public Path(java.lang.String color)
Create a new Path element with a hue name or hex code- Parameters:
color- The name of the color (case-insensitive)- See Also:
Misc.stringToColor(String)
-
-
Method Detail
-
setStroke
public Path setStroke(java.awt.Stroke stroke)
Set the stroke of the line.- Parameters:
stroke- aStrokeobject to define this line's stroke- Returns:
- The original object to allow method chaining
-
setThickness
public Path setThickness(int thickness)
Set the thickness of the line, equivalent to setOutline(thickness);- Parameters:
thickness- The thickness of the line in pixels- Returns:
- The original object to allow method chaining
-
setLineColor
public Path setLineColor(java.awt.Color color)
Set the color of the line, equivalent to setOutline(thickness, color);- Parameters:
color- The color of the line- Returns:
- The original object to allow method chaining
-
cursorTo
public Path cursorTo(int x, int y)
Move the cursor to a new position- Parameters:
x- The X-position of the new cursor positiony- The Y-position of the new cursor position- Returns:
- The original object to allow method chaining
-
lineTo
public Path lineTo(int x, int y)
Make a line from the current cursor position to a new position- Parameters:
x- The X-position of the line endpointy- The Y-position of the line endpoint- Returns:
- The original object to allow method chaining
-
quadTo
public Path quadTo(int x1, int y1, int x2, int y2)
Make a quadratic curve from the current cursor position to a new position. See Wikipedia: Bézier curve for more information- Parameters:
x1- The X-position of the control pointy1- The Y-position of the control pointx2- The X-position of the curve endpointy2- The Y-position of the curve endpoint- Returns:
- The original object to allow method chaining
-
curveTo
public Path curveTo(int x1, int y1, int x2, int y2, int x3, int y3)
Make a cubic curve from the current cursor position to a new position. See Wikipedia: Bézier curve for more information- Parameters:
x1- The X-position of the first control pointy1- The Y-position of the first control pointx2- The X-position of the second control pointy2- The Y-position of the second control pointx3- The X-position of the curve endpointy3- The Y-position of the curve endpoint- Returns:
- The original object to allow method chaining
-
drawOutline
protected void drawOutline(java.awt.Graphics2D gc)
-
drawFill
protected void drawFill(java.awt.Graphics2D gc)
-
center
public java.awt.Point center(java.awt.Graphics2D g)
Description copied from interface:DrawableGet the object's centerpointimport java.awt.Point; Point p = drawable.getStartpoint(); int x = p.x; int y = p.y;- Parameters:
g- Graphics context- Returns:
- the object's center-point
-
getThis
public Path getThis()
-
-