Class CanvasPainter
- All Implemented Interfaces:
org.inspirenxe.strata.api.extension.Painter
Painter that components draw with, passing each call to the engine's Canvas. The scoped clip
and translation calls pop what they pushed even if the drawing code throws, so the canvas stacks stay balanced.
Each host reuses one painter for every frame.
Sized nine-slices and tiled sprites go to the canvas as they are when the engine
slices sprites itself. Otherwise the painter
draws them from pieces, each one Canvas.spriteRegion(SpriteId, Rect, float, float, float, float, int) call for the part of the image it shows. A row or
column holds at most 1024 copies, and a tiled sprite or tiled part at most 16384 in
all; past either, the sprite or part is stretched instead.
Drawing a sized nine-slice allocates only the rectangle of each of its nine parts, and drawing tiles only the rectangle of each copy, since the canvas takes rectangles; the slice edges are kept in arrays the painter reuses.
Shapes go to the canvas when the engine draws shapes. Otherwise the
painter draws them from fills one device pixel high, gradients at an angle from columns of vertical gradients,
shadows from rings of falling alpha, and round clips as rectangular clips, and never calls the canvas's shape
methods; smoothed(boolean, Runnable) then only runs its drawing. Either way the painter draws nothing for a color with alpha
0, an empty rectangle, a stroke of width 0, an empty shape or fewer than two points, limits each radius to half the
shorter side of its rectangle (a negative radius counts as 0), fills a rounded rectangle of radius 0 with
Canvas.fill(Rect, int), draws an arc of a full turn or more as a whole ellipse, and a shadow without blur as a
rounded rectangle. pixels(PixelBuffer, Rect, int) always goes to the canvas.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a painter with no canvas and no text metrics.CanvasPainter(org.inspirenxe.strata.api.text.TextMetrics metrics) Creates a painter with no canvas that measures inline sprites that fit the line with the given metrics. -
Method Summary
Modifier and TypeMethodDescriptionvoidbackdrop(org.inspirenxe.strata.api.geometry.Rect rect, float radius, float blur, int tint) begin(org.inspirenxe.strata.spi.Canvas canvas) Points the painter at the canvas for this frame, for an engine that stores no slicing with its images.begin(org.inspirenxe.strata.spi.Canvas canvas, boolean slicesSprites) Points the painter at the canvas for this frame.begin(org.inspirenxe.strata.spi.Canvas canvas, org.inspirenxe.strata.spi.Capabilities capabilities, float pixelsPerUnit) Points the painter at the canvas for this frame, with what the engine does for itself and the host's density.org.inspirenxe.strata.spi.Canvascanvas()Returns the canvas set by the lastbegin(Canvas).voidvoidclippedRound(org.inspirenxe.strata.api.geometry.Rect rect, float radius, Runnable draw) voidfill(org.inspirenxe.strata.api.geometry.Rect rect, int argb) voidfillEllipse(org.inspirenxe.strata.api.geometry.Rect oval, int argb) voidfillGradient(org.inspirenxe.strata.api.geometry.Rect rect, int topArgb, int bottomArgb) voidfillGradient(org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.extension.Gradient gradient) voidfillRoundRect(org.inspirenxe.strata.api.geometry.Rect rect, float radius, int argb) voidfillShape(org.inspirenxe.strata.api.extension.Shape shape, int argb) voidline(float x1, float y1, float x2, float y2, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) voidnineSlice(org.inspirenxe.strata.api.theme.SpriteId sprite, org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.geometry.Insets border, int tint) voidnineSlice(org.inspirenxe.strata.api.theme.SpriteId sprite, org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.geometry.Size size, org.inspirenxe.strata.api.geometry.Insets border, boolean tiled, int tint) voidpixels(org.inspirenxe.strata.api.visual.PixelBuffer buffer, org.inspirenxe.strata.api.geometry.Rect rect, int tint) floatReturns the density given tobegin(Canvas, Capabilities, float), 1 after the other forms ofbegin, times every scale in progress.voidpolyline(float[] points, int count, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) voidrightToLeftText(org.inspirenxe.strata.api.text.TextSpan logical, org.inspirenxe.strata.api.text.TextSpan reversed, float x, float y) Draws a run the bidirectional algorithm put right to left: in logical order with its direction to an engine that shapes right-to-left text, or else the reversed span as plain text.voidvoidvoidshadow(org.inspirenxe.strata.api.geometry.Rect rect, float radius, float blur, int argb) voidvoidsprite(org.inspirenxe.strata.api.theme.SpriteId sprite, org.inspirenxe.strata.api.geometry.Rect rect, int tint) voidstrokeArc(org.inspirenxe.strata.api.geometry.Rect oval, float startRadians, float sweepRadians, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) voidstrokeEllipse(org.inspirenxe.strata.api.geometry.Rect oval, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) voidstrokeRect(org.inspirenxe.strata.api.geometry.Rect rect, float radius, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) voidstrokeShape(org.inspirenxe.strata.api.extension.Shape shape, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) voidtext(org.inspirenxe.strata.api.text.TextSpan span, float x, float y) voidtext(org.inspirenxe.strata.api.text.TextSpan span, org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.layout.HorizontalAlignment horizontal, org.inspirenxe.strata.api.layout.VerticalAlignment vertical) voidtiled(org.inspirenxe.strata.api.theme.SpriteId sprite, org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.geometry.Size size, int tint) voidtranslated(float dx, float dy, Runnable draw) voidvisual(org.inspirenxe.strata.api.visual.Visual visual, org.inspirenxe.strata.api.geometry.Rect rect, int tint)
-
Constructor Details
-
CanvasPainter
public CanvasPainter()Creates a painter with no canvas and no text metrics. Callbegin(Canvas)before drawing. It draws inline sprites that fit the line nowhere, since it cannot measure the line. -
CanvasPainter
public CanvasPainter(org.inspirenxe.strata.api.text.TextMetrics metrics) Creates a painter with no canvas that measures inline sprites that fit the line with the given metrics. Callbegin(Canvas)before drawing.- Parameters:
metrics- the host's text metrics
-
-
Method Details
-
begin
Points the painter at the canvas for this frame, for an engine that stores no slicing with its images.- Parameters:
canvas- the frame's canvas- Returns:
- this painter
-
begin
Points the painter at the canvas for this frame.- Parameters:
canvas- the frame's canvasslicesSprites- true when the engine applies slicing stored with its images, so sized nine-slices and tiled sprites go to the canvas as they are- Returns:
- this painter
-
begin
public CanvasPainter begin(org.inspirenxe.strata.spi.Canvas canvas, org.inspirenxe.strata.spi.Capabilities capabilities, float pixelsPerUnit) Points the painter at the canvas for this frame, with what the engine does for itself and the host's density.- Parameters:
canvas- the frame's canvascapabilities- what the engine does for itself; the painter reads whether it slices sprites and draws shapespixelsPerUnit- device pixels per UI unit, greater than 0- Returns:
- this painter
-
canvas
public org.inspirenxe.strata.spi.Canvas canvas()Returns the canvas set by the lastbegin(Canvas).- Returns:
- the canvas, or
nullbefore the first frame
-
fill
public void fill(org.inspirenxe.strata.api.geometry.Rect rect, int argb) - Specified by:
fillin interfaceorg.inspirenxe.strata.api.extension.Painter
-
fillGradient
public void fillGradient(org.inspirenxe.strata.api.geometry.Rect rect, int topArgb, int bottomArgb) - Specified by:
fillGradientin interfaceorg.inspirenxe.strata.api.extension.Painter
-
fillGradient
public void fillGradient(org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.extension.Gradient gradient) - Specified by:
fillGradientin interfaceorg.inspirenxe.strata.api.extension.Painter
-
line
public void line(float x1, float y1, float x2, float y2, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) - Specified by:
linein interfaceorg.inspirenxe.strata.api.extension.Painter
-
polyline
public void polyline(float[] points, int count, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) - Specified by:
polylinein interfaceorg.inspirenxe.strata.api.extension.Painter
-
backdrop
public void backdrop(org.inspirenxe.strata.api.geometry.Rect rect, float radius, float blur, int tint) - Specified by:
backdropin interfaceorg.inspirenxe.strata.api.extension.Painter
-
fillRoundRect
public void fillRoundRect(org.inspirenxe.strata.api.geometry.Rect rect, float radius, int argb) - Specified by:
fillRoundRectin interfaceorg.inspirenxe.strata.api.extension.Painter
-
strokeRect
public void strokeRect(org.inspirenxe.strata.api.geometry.Rect rect, float radius, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) - Specified by:
strokeRectin interfaceorg.inspirenxe.strata.api.extension.Painter
-
fillEllipse
public void fillEllipse(org.inspirenxe.strata.api.geometry.Rect oval, int argb) - Specified by:
fillEllipsein interfaceorg.inspirenxe.strata.api.extension.Painter
-
strokeEllipse
public void strokeEllipse(org.inspirenxe.strata.api.geometry.Rect oval, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) - Specified by:
strokeEllipsein interfaceorg.inspirenxe.strata.api.extension.Painter
-
strokeArc
public void strokeArc(org.inspirenxe.strata.api.geometry.Rect oval, float startRadians, float sweepRadians, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) - Specified by:
strokeArcin interfaceorg.inspirenxe.strata.api.extension.Painter
-
fillShape
public void fillShape(org.inspirenxe.strata.api.extension.Shape shape, int argb) - Specified by:
fillShapein interfaceorg.inspirenxe.strata.api.extension.Painter
-
strokeShape
public void strokeShape(org.inspirenxe.strata.api.extension.Shape shape, org.inspirenxe.strata.api.extension.Stroke stroke, int argb) - Specified by:
strokeShapein interfaceorg.inspirenxe.strata.api.extension.Painter
-
shadow
public void shadow(org.inspirenxe.strata.api.geometry.Rect rect, float radius, float blur, int argb) - Specified by:
shadowin interfaceorg.inspirenxe.strata.api.extension.Painter
-
sampled
- Specified by:
sampledin interfaceorg.inspirenxe.strata.api.extension.Painter
-
smoothed
- Specified by:
smoothedin interfaceorg.inspirenxe.strata.api.extension.Painter
-
clippedRound
- Specified by:
clippedRoundin interfaceorg.inspirenxe.strata.api.extension.Painter
-
pixels
public void pixels(org.inspirenxe.strata.api.visual.PixelBuffer buffer, org.inspirenxe.strata.api.geometry.Rect rect, int tint) - Specified by:
pixelsin interfaceorg.inspirenxe.strata.api.extension.Painter
-
pixelsPerUnit
public float pixelsPerUnit()Returns the density given tobegin(Canvas, Capabilities, float), 1 after the other forms ofbegin, times every scale in progress.- Specified by:
pixelsPerUnitin interfaceorg.inspirenxe.strata.api.extension.Painter
-
sprite
public void sprite(org.inspirenxe.strata.api.theme.SpriteId sprite, org.inspirenxe.strata.api.geometry.Rect rect, int tint) - Specified by:
spritein interfaceorg.inspirenxe.strata.api.extension.Painter
-
nineSlice
public void nineSlice(org.inspirenxe.strata.api.theme.SpriteId sprite, org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.geometry.Insets border, int tint) - Specified by:
nineSlicein interfaceorg.inspirenxe.strata.api.extension.Painter
-
nineSlice
public void nineSlice(org.inspirenxe.strata.api.theme.SpriteId sprite, org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.geometry.Size size, org.inspirenxe.strata.api.geometry.Insets border, boolean tiled, int tint) - Specified by:
nineSlicein interfaceorg.inspirenxe.strata.api.extension.Painter
-
tiled
public void tiled(org.inspirenxe.strata.api.theme.SpriteId sprite, org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.geometry.Size size, int tint) - Specified by:
tiledin interfaceorg.inspirenxe.strata.api.extension.Painter
-
rightToLeftText
public void rightToLeftText(org.inspirenxe.strata.api.text.TextSpan logical, org.inspirenxe.strata.api.text.TextSpan reversed, float x, float y) Draws a run the bidirectional algorithm put right to left: in logical order with its direction to an engine that shapes right-to-left text, or else the reversed span as plain text.- Parameters:
logical- the run in logical orderreversed- the run with its characters reversed and its brackets mirroredx- the run's left edgey- the top of its line box
-
text
public void text(org.inspirenxe.strata.api.text.TextSpan span, org.inspirenxe.strata.api.geometry.Rect rect, org.inspirenxe.strata.api.layout.HorizontalAlignment horizontal, org.inspirenxe.strata.api.layout.VerticalAlignment vertical) - Specified by:
textin interfaceorg.inspirenxe.strata.api.extension.Painter
-
text
public void text(org.inspirenxe.strata.api.text.TextSpan span, float x, float y) - Specified by:
textin interfaceorg.inspirenxe.strata.api.extension.Painter
-
clipped
- Specified by:
clippedin interfaceorg.inspirenxe.strata.api.extension.Painter
-
translated
- Specified by:
translatedin interfaceorg.inspirenxe.strata.api.extension.Painter
-
scaled
- Specified by:
scaledin interfaceorg.inspirenxe.strata.api.extension.Painter
-
visual
public void visual(org.inspirenxe.strata.api.visual.Visual visual, org.inspirenxe.strata.api.geometry.Rect rect, int tint) - Specified by:
visualin interfaceorg.inspirenxe.strata.api.extension.Painter
-