Painter
Graphic context.
| Module | require("yue.gui") |
| Type | Class |
The Painter class can not be created by user, its instance can only be recevied in drawing events or via the Canvas class.
Methods
save()
Save the entire state of the painter.
restore()
Restore the most recently saved state.
beginpath()
Create a new path.
closepath()
Close current path and move current point to the start of current path.
A straight line will be drew from current point to the start.
moveto(point)
Move current point to point.
Parameters
PointFpoint
lineto(point)
Connect the last point in current path to point with a straight line.
Parameters
PointFpoint
beziercurveto(cp1, cp2, ep)
Add a cubic Bézier curve to current path.
The first two points are control points and the third one is the end point. The starting point is the last point in the current path.
Parameters
arc(point, radius, sa, ea)
Add an arc to the path which is centered at point with radius
starting at sa angle and ending at ea angle going in clockwise
direction.
Parameters
PointFpoint - Arc's center.numberradius - Arc's radius.numbersa - The angle at which the arc starts, measured clockwise from the positive x axis and expressed in radians.numberea - The angle at which the arc ends, measured clockwise from the positive x axis and expressed in radians.
rect(rect)
Add rectangle to current path.
Parameters
RectFrect
clip()
Add current path to clip area by intersection.
cliprect(rect)
Add rect to clip area by intersection.
Parameters
RectFrect
translate(offset)
Add translate transformation which moves the origin by offset.
Parameters
Vector2dFoffset
rotate(angle)
Add rotation transformation.
Parameters
numberangle - The angle to rotate clockwise in radians.
scale(scale)
Add scaling transformation to the painter.
Parameters
Vector2dFscale
setcolor(color)
Set stroke color and fill color to color.
Parameters
Colorcolor
setstrokecolor(color)
Set the color used for shapes' outlines.
Parameters
Colorcolor
setfillcolor(color)
Set the color used when filling shapes.
Parameters
Colorcolor
setlinewidth(width)
Set the width of lines.
Parameters
numberwidth
stroke()
Draw current path by stroking its outline.
fill()
Draw a solid shape by filling current path's content area.
clear()
Fill the whole area with transparent color.
strokerect(rect)
Draw a rectangular outline.
Parameters
RectFrect
fillrect(rect)
Draw a filled rectangle.
Parameters
RectFrect
drawimage(image, rect)
Draw scaled image to fit rect.
Parameters
drawimagefromrect(image, src, dest)
Draw the specified portion of image at src to fit rect.
Parameters
drawcanvas(canvas, rect)
Draw scaled canvas to fit rect.
Parameters
drawcanvasfromrect(canvas, src, dest)
Draw the specified portion of canvas at src to fit rect.
Parameters
drawattributedtext(text, rect)
Draw text bounded by rect.
Parameters
AttributedTexttextRectFrect
drawtext(text, rect, attributes)
Draw text with attributes bounded by rect.
Parameters
stringtextRectFrectTextAttributesattributes