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.Point
center(java.awt.Graphics2D g)
Get the object's centerpointPath
cursorTo(int x, int y)
Move the cursor to a new positionPath
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.protected void
drawFill(java.awt.Graphics2D gc)
protected void
drawOutline(java.awt.Graphics2D gc)
Path
getThis()
Path
lineTo(int x, int y)
Make a line from the current cursor position to a new positionPath
quadTo(int x1, int y1, int x2, int y2)
Make a quadratic curve from the current cursor position to a new position.Path
setLineColor(java.awt.Color color)
Set the color of the line, equivalent to setOutline(thickness, color);Path
setStroke(java.awt.Stroke stroke)
Set the stroke of the line.Path
setThickness(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.Color
getOutlineColor()
Gets the outline colorjava.awt.Stroke
getOutlineStroke()
Gets the outline strokevoid
internalSetFilled(boolean filled)
void
internalSetOutlineColor(java.awt.Color color)
void
internalSetOutlineStroke(java.awt.Stroke stroke)
-
Methods inherited from class paintingcanvas.drawable.DrawableBase
Modifier and Type Method Description java.awt.Color
getColor()
Get the current color of an element as aColor
int
getLayer()
Gets the current layer of the object.java.awt.Point
getPos()
Get the position of the elementdouble
getRotation()
Get an elements rotationT
hide()
Hide the Object.double
internalGetRotation()
void
internalSetColor(java.awt.Color color)
void
internalSetLayer(int layer)
void
internalSetPos(int x, int y)
void
internalSetRotation(double rotation)
void
render(java.awt.Graphics2D g)
Actually render the object itselfT
show()
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 AnimationBuilder
colorTo(int hex, double duration)
Change the color ofthis
to the specifiedcolor
overduration
seconds.default AnimationBuilder
colorTo(int r, int g, int b, double duration)
Change the color ofthis
to the specifiedcolor
overduration
seconds.default AnimationBuilder
colorTo(int r, int g, int b, int a, double duration)
Change the color ofthis
to the specifiedcolor
overduration
seconds.default AnimationBuilder
colorTo(java.awt.Color color, double duration)
Change the color ofthis
to the specifiedcolor
overduration
seconds.default AnimationBuilder
colorTo(java.lang.String name, double duration)
Change the color ofthis
to the specifiedcolor
overduration
seconds.default AnimationBuilder
colorTo(Hue hue, double duration)
Change the color ofthis
to the specifiedcolor
overduration
seconds.Drawable<?>
drawable()
Get theDrawable
element from thisAnimatable
.default AnimationBuilder
fadeIn(double duration)
Fadethis
in overduration
seconds.default AnimationBuilder
fadeOut(double duration)
Fadethis
out overduration
seconds.default AnimationBuilder
moveBy(int x, int y, double duration)
Movethis
by the specifiedx
andy
overduration
seconds.default AnimationBuilder
moveHorizontalBy(int x, double duration)
Movethis
by the specifiedx
horizontally overduration
seconds.default AnimationBuilder
moveTo(int x, int y, double duration)
Movethis
to the specifiedx
andy
overduration
secondsdefault AnimationBuilder
moveVerticalBy(int y, double duration)
Movethis
by the specifiedy
vertically overduration
seconds.default AnimationBuilder
rotateBy(int angle, double duration)
Rotatethis
byangle
degrees overduration
seconds.default AnimationBuilder
rotateTo(int angle, double duration)
Rotatethis
to the specifiedangle
degrees overduration
seconds.
-
Methods inherited from interface paintingcanvas.drawable.Colorable
Modifier and Type Method Description java.awt.Color
getColor()
Get the current color of an element as aColor
void
internalSetColor(java.awt.Color color)
default T
setColor(int hex)
Set the color ofthis
to the specifiedcolor
.default T
setColor(int r, int g, int b)
Set the color ofthis
to the specifiedcolor
.default T
setColor(int r, int g, int b, int a)
default T
setColor(java.awt.Color color)
Set the color of the object with aColor
object.default T
setColor(java.lang.String name)
Set the color of the object with a hue name or hex code.default T
setColor(Hue hue)
Set the color of the object with aHue
object.
-
Methods inherited from interface paintingcanvas.drawable.Drawable
Modifier and Type Method Description default AnimationBuilder
animate()
Start animating this object.default T
bringToFront()
Brings the object in front of all other objects.java.awt.Point
center(java.awt.Graphics2D g)
Get the object's centerpointdefault Drawable<?>
drawable()
Get theDrawable
element from thisAnimatable
.default void
erase()
Erase this object from the canvas.int
getLayer()
Gets the current layer of the object.T
getThis()
T
hide()
Hide the Object.void
internalSetLayer(int layer)
void
render(java.awt.Graphics2D g)
Actually render the object itselfdefault T
sendToBack()
Puts the object behind all other objects.default T
setLayer(int layer)
Puts the object on a specific layer.T
show()
Show the Object
-
Methods inherited from interface paintingcanvas.drawable.Outlineable
Modifier and Type Method Description java.awt.Color
getOutlineColor()
Gets the outline colorjava.awt.Stroke
getOutlineStroke()
Gets the outline strokevoid
internalSetFilled(boolean filled)
void
internalSetOutlineColor(java.awt.Color color)
void
internalSetOutlineStroke(java.awt.Stroke stroke)
default T
removeOutline()
Removes the outline from the shapedefault T
setFilled(boolean filled)
Set whether this object is filled or notdefault T
setOutline(int thickness)
Sets the parameters for the outline of the shape, with the color defaulting to blackdefault T
setOutline(int thickness, java.awt.Color color)
Sets the parameters for the outline of the shapedefault T
setOutline(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.Point
getPos()
Get the position of the elementdouble
getRotation()
Get an elements rotationdefault int
getX()
Get the X-position of the elementdefault int
getY()
Get the Y-position of the element.double
internalGetRotation()
void
internalSetPos(int x, int y)
void
internalSetRotation(double rotation)
default T
move(int x, int y)
Moves this drawable by the specified x and y.default T
moveHorizontal(int x)
Moves this drawable by the specified x and y.default T
moveVertical(int y)
Moves this drawable by the specified x and y.default T
rotate(double rotation)
Rotate this element byrotation
degrees.default T
setPos(int x, int y)
Set the position of the element.default T
setRotation(double rotation)
Set an elements rotation torotation
degrees.default T
setX(int x)
Set the X-position of the objectdefault T
setY(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
- aStroke
object 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:Drawable
Get 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()
-
-