Class NoopCanvas
- All Implemented Interfaces:
Canvas
Not final: a test that needs to see one call overrides that one. It used to exist four times under three names, one copy per module, each saying so.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the whole framebuffer (ignores transform/clip/opacity).voidclipRect(float x, float y, float w, float h) Intersects the clip with an axis-aligned rectangle (in current coordinates).voidclipRoundRect(RoundRect roundRect) Intersects the clip with a rounded rectangle.floatvoiddrawCircle(float cx, float cy, float radius, float strokeWidth, Paint paint) voiddrawEllipse(float cx, float cy, float radiusX, float radiusY, float strokeWidth, Paint paint) voidDrawsimageinto the rectangle(x, y, w, h)in logical points, scaled with linear filtering, modulated by the currentCanvas.opacity().voiddrawImage(Image image, float srcX, float srcY, float srcW, float srcH, float dstX, float dstY, float dstW, float dstH) Draws the source rectangle(srcX, srcY, srcW, srcH), in image pixels, into the destination rectangle(dstX, dstY, dstW, dstH)in logical points.voiddrawImage(Image image, float srcX, float srcY, float srcW, float srcH, float dstX, float dstY, float dstW, float dstH, Color tint) The sprite primitive and the tint, together: one cell of a sheet, modulated bytintexactly asCanvas.drawImage(Image, float, float, float, float, Color)modulates a whole image.voidDrawsimagetinted bytint(its RGB and alpha are multiplied by the tint's), the path for modulating a picture (e.g.voidLine segment with round caps.voidStrokes a path with round caps and joins.voidStrokes the rectangle outline, centered on its boundary.voiddrawRoundRect(RoundRect roundRect, float strokeWidth, Paint paint) Strokes the rounded-rect outline, centered on its boundary.voiddrawSurface(GpuSurface surface, float x, float y, float w, float h) Nothing to composite into: a measuring canvas draws nothing.voidDraws a single line of text with(x, y)at the baseline origin.voidfillCircle(float cx, float cy, float radius, Paint paint) voidfillEllipse(float cx, float cy, float radiusX, float radiusY, Paint paint) voidFills a path.voidvoidfillRoundRect(RoundRect roundRect, Paint paint) floatheight()measureText(String text, Font font) Measures a single line of text in logical points (baseline-relative, unquantized and therefore independent of the monitor scale).floatopacity()voidrestore()Pops back to the previously saved state.voidrestoreToCount(int count) Pops saves untilCanvas.saveCount()equalscount.voidrotate(float angleRadians) Rotates byangleRadians(positive = clockwise, y grows down).voidsave()Pushes a copy of the current state (transform, opacity, clip, blend mode, sampling, pixel snap).intHow manyCanvas.save()s are outstanding, the depth of the state stack.voidscale(float sx, float sy) voidsetOpacity(float opacity) Multiplies the current state's opacity byopacity, clamped to [0..1]; every subsequent paint's alpha is multiplied by the result.voidtranslate(float dx, float dy) floatwidth()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface limn.graphics.Canvas
blendMode, clearRect, clipBounds, clipRect, clipRoundRectInsideBorder, damageScissorHint, drawImage, drawImageMask, drawRoundRect, drawRoundRectBorder, drawShadow, drawText, fillBackdropRoundRect, fillBackdropRoundRect, fillRect, fillRoundRect, fillRoundRectInsideBorder, fillRoundRectWithBorder, pixelSnap, readBack, sampling, saveLayer, saveLayer, setBlendMode, setPixelSnap, setSampling
-
Constructor Details
-
Method Details
-
width
public float width() -
height
public float height() -
contentScale
public float contentScale()- Specified by:
contentScalein interfaceCanvas- Returns:
- physical pixels per logical point for this frame
-
clear
Description copied from interface:CanvasClears the whole framebuffer (ignores transform/clip/opacity). -
save
public void save()Description copied from interface:CanvasPushes a copy of the current state (transform, opacity, clip, blend mode, sampling, pixel snap). -
restore
public void restore()Description copied from interface:CanvasPops back to the previously saved state. -
saveCount
public int saveCount()Description copied from interface:CanvasHow manyCanvas.save()s are outstanding, the depth of the state stack.It exists so that a caller can put the canvas back where it found it without knowing how many saves happened in between, which is the only way to be safe against code it does not control: a widget's paint may push clips, may push more of them down a branch, and may stop halfway by throwing.
Widget.paintWidgetreads this before painting a widget and trims back to it afterwards, so one widget's leak cannot become every ancestor's. -
restoreToCount
public void restoreToCount(int count) Description copied from interface:CanvasPops saves untilCanvas.saveCount()equalscount.Does nothing when the depth is already at or below
count: it is a trim, not an assertion, and a caller using it to recover from someone else's mistake must not be given a second mistake to handle. Never pops past zero.- Specified by:
restoreToCountin interfaceCanvas- Parameters:
count- the depth to return to, normally one taken fromCanvas.saveCount()earlier
-
translate
public void translate(float dx, float dy) -
scale
public void scale(float sx, float sy) -
rotate
public void rotate(float angleRadians) Description copied from interface:CanvasRotates byangleRadians(positive = clockwise, y grows down). -
setOpacity
public void setOpacity(float opacity) Description copied from interface:CanvasMultiplies the current state's opacity byopacity, clamped to [0..1]; every subsequent paint's alpha is multiplied by the result. Restored byCanvas.restore().It multiplies rather than replaces so that an opacity set inside a fading surface, or inside a layer, combines with the one around it instead of undoing it: a widget at one half inside a panel fading at one half draws at a quarter. On a fresh
Canvas.save()the current opacity is whatever the enclosing state carries, which is 1 at the top of a frame and inside a layer, so a caller that saves and sets once gets the number it asked for. A caller that wants an absolute value has to know what it is multiplying.This is a per-draw alpha: each draw is translucent on its own, so where one draw covers another the one beneath shows through it. To fade overlapping draws as one picture, open a
layerinstead.- Specified by:
setOpacityin interfaceCanvas- Parameters:
opacity- the factor, clamped to [0..1]
-
opacity
public float opacity()- Specified by:
opacityin interfaceCanvas- Returns:
- the current state's opacity, the product of every
Canvas.setOpacity(float)still in force
-
clipRect
public void clipRect(float x, float y, float w, float h) Description copied from interface:CanvasIntersects the clip with an axis-aligned rectangle (in current coordinates). V1 limitation: under a rotated transform the clip degrades to the device-space AABB of the transformed corners, a superset of the requested region (content may show in the AABB's corners). Axis-aligned transforms clip exactly. -
clipRoundRect
Description copied from interface:CanvasIntersects the clip with a rounded rectangle. The corners are this rectangle's own: aCanvas.clipRect(float, float, float, float)made before or after it cuts the region straight and never rounds where it cuts, so a repaint confined to part of a rounded surface draws that part exactly as a whole frame does.V1 limitations: the clip state tracks one rounded rect, so nested rounded clips intersect their rectangles exactly and the region they leave is rounded by the most recent corner radius alone, as a single uniform radius (the max of the four corners, clamped to that region's half extents). That is exact when the inner rounded rect lies inside the outer one; where the two only overlap, every corner of the region they leave is rounded by the inner radius, whichever rectangle it came from. A rounded rect whose corners are all square clips like
clipRectand leaves an earlier one's corners as they were. Rotation degrades to the AABB likeclipRect.- Specified by:
clipRoundRectin interfaceCanvas
-
fillRect
-
drawRect
Description copied from interface:CanvasStrokes the rectangle outline, centered on its boundary. -
fillRoundRect
- Specified by:
fillRoundRectin interfaceCanvas
-
drawRoundRect
Description copied from interface:CanvasStrokes the rounded-rect outline, centered on its boundary.- Specified by:
drawRoundRectin interfaceCanvas
-
fillCircle
- Specified by:
fillCirclein interfaceCanvas
-
drawCircle
- Specified by:
drawCirclein interfaceCanvas
-
fillEllipse
- Specified by:
fillEllipsein interfaceCanvas
-
drawEllipse
public void drawEllipse(float cx, float cy, float radiusX, float radiusY, float strokeWidth, Paint paint) - Specified by:
drawEllipsein interfaceCanvas
-
drawLine
Description copied from interface:CanvasLine segment with round caps. Axis-aligned lines are pixel-snapped. -
fillPath
Description copied from interface:CanvasFills a path. Each closed subpath is filled independently (seePath2Dfor the v1 winding limitations). -
drawPath
Description copied from interface:CanvasStrokes a path with round caps and joins. V1 limitation: joins are overlapping round caps, so translucent paints double-blend slightly at each vertex. -
drawText
Description copied from interface:CanvasDraws a single line of text with(x, y)at the baseline origin. Glyphs are rasterized atfont.size() ×the effective device scale (content scale × canvas transform) and cached in a glyph atlas keyed by physical pixel size: bitmaps are never scaled, so text stays sharp at 1.0/1.25/1.5/2.0. Under axis-aligned uniform transforms, glyphs are snapped to the physical pixel grid.Full code-point support, surrogate pairs included. A code point the font lacks is resolved against the registered fallback faces, so mixed-script text draws; a code point no face has renders as
.notdef.This is the shaped path with the shaping done for you. A canvas that has a shaper hands the string to the installed
TextRulerand draws theShapedTextit gets back, so contextual forms, ligatures, mark attachment and bidirectional ordering are what any caption gets, not only the widgets that hold a value of their own. What that costs is one memo lookup per call on the ruler's side; what it buys is that the string measured byCanvas.measureText(java.lang.String, limn.graphics.Font)and the string drawn here are the same arithmetic. A caller that draws the same text every frame should still hold aShapedTextand use the overload below — that is the form that pays nothing at all, and the only one that carries a base direction: this one resolves the paragraph from the string alone, left to right where no character is strong, which is wrong exactly for the all-neutral captions a widget could have decided (Widget.shapeText).Control characters,
\nincluded, are skipped: multi-line layout belongs to the widget layer. Under anisotropic scale glyphs rasterize at the larger axis and filter on the smaller one. -
measureText
Description copied from interface:CanvasMeasures a single line of text in logical points (baseline-relative, unquantized and therefore independent of the monitor scale). Same code-point rules asCanvas.drawText(java.lang.String, float, float, limn.graphics.Font, limn.graphics.Paint), and the same shaping: a canvas that shapes when it draws measures what it will draw, so a caption is never laid out to one width and painted at another.- Specified by:
measureTextin interfaceCanvas
-
drawImage
Description copied from interface:CanvasDrawsimageinto the rectangle(x, y, w, h)in logical points, scaled with linear filtering, modulated by the currentCanvas.opacity(). The GPU texture is created lazily on first use and cached per window, withinImages.textureBudget()asImages.setTextureBudget(long)describes: a texture dropped at a frame boundary is made again when its image is next drawn, and none that the frame just ended drew is dropped. -
drawImage
Description copied from interface:CanvasDrawsimagetinted bytint(its RGB and alpha are multiplied by the tint's), the path for modulating a picture (e.g.ImageView.setTint). A white opaque tint draws it unchanged. A black source stays black: to recolor a mask, useCanvas.drawImageMask(limn.graphics.Image, float, float, float, float, limn.graphics.Color). -
drawSurface
Nothing to composite into: a measuring canvas draws nothing.- Specified by:
drawSurfacein interfaceCanvas
-
drawImage
public void drawImage(Image image, float srcX, float srcY, float srcW, float srcH, float dstX, float dstY, float dstW, float dstH) Description copied from interface:CanvasDraws the source rectangle(srcX, srcY, srcW, srcH), in image pixels, into the destination rectangle(dstX, dstY, dstW, dstH)in logical points. This is the sprite primitive: frames of a sprite sheet, tiles of a tileset and regions of a texture atlas all draw from one shared Image (one GPU texture, so batching stays unbroken across sprites of the same sheet).The source rectangle is not clamped: coordinates outside the image sample the edge texels (
CLAMP_TO_EDGE). WithSampling.SMOOTH, half a texel of bleed from neighboring atlas cells is possible at the edges; pack sheets with 1px gutters or useSampling.PIXELATEDfor exact cells. Gutters only protect mip level 0: SMOOTH minification (drawing a cell well below its pixel size) selects coarser mips where whole cells average together; for atlases that will be minified, usePIXELATEDor pad cells generously. -
drawImage
public void drawImage(Image image, float srcX, float srcY, float srcW, float srcH, float dstX, float dstY, float dstW, float dstH, Color tint) Description copied from interface:CanvasThe sprite primitive and the tint, together: one cell of a sheet, modulated bytintexactly asCanvas.drawImage(Image, float, float, float, float, Color)modulates a whole image.Both halves already existed and could not be used at once, which left an ordinary thing (a tinted sprite from a sheet) reachable only by splitting the sheet into one Image per cell and losing the batching that is the point of a sheet. Everything the source-rectangle overload says about clamping, bleed and mips applies here unchanged.
-