Renderer

smile.infrastructure.Renderer
See theRenderer companion object
trait Renderer

Renders elements into bitmaps through the shared draw plan, which every platform's backend draws the same way. Renderer() gives the platform's renderer.

Renderer, with its JVM extension smile.infrastructure.renderInto, and, on Scala.js, smile.infrastructure.JSRenderer are the stable entry points of smile.infrastructure. Everything else in the package is internal to SMILe.

Attributes

Companion
object
Source
Renderer.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object JSRenderer

Members list

Value members

Concrete methods

def createBitmapFrom(picture: Element, scaleFactor: Double = ..., settings: RenderSettings = ..., timeMillis: Long = ...): Bitmap

Renders picture into a buffer with scaleFactor pixels per logical pixel. A factor above 1 is for display on a high-DPI screen.

Renders picture into a buffer with scaleFactor pixels per logical pixel. A factor above 1 is for display on a high-DPI screen.

The bitmap covers the whole device pixels that the picture's bounds touch, and its bounds are those pixels in logical units, the same at every factor up to the rounding to device pixels, while its buffer is denser by the given factor. Pixel coordinates in getColor/colorAt therefore index the dense buffer and no longer correspond 1:1 to logical coordinates. Use the default factor whenever that 1:1 invariant matters. The bitmap's anchor is where the picture's is, and the empty picture gives an empty bitmap.

Value parameters

scaleFactor

Buffer pixels per logical pixel. Must be positive and finite, and 1 when the settings ask for ResamplingMode.Stepwise.

settings

The settings the rendering is done with, including those of the bitmaps it draws. See smile.RenderSettings.

timeMillis

The instant the picture is drawn at, in milliseconds on the scale of System.currentTimeMillis(). Each animation in it shows its frame at that instant, and so does each animation in a bitmap of a picture that the rendering draws, unless that bitmap has been rendered already. Equal pictures drawn at the same instant draw the same pixels.

Attributes

Source
Renderer.scala
def renderInto(target: Graphics2D, picture: Element, scaleFactor: Double = ..., settings: RenderSettings = ..., timeMillis: Long = ...): Unit
Extension method from smile.infrastructure

Draws picture onto target with scaleFactor device pixels per logical pixel. It draws what drawing the bitmap smile.infrastructure.Renderer.createBitmapFrom gives for the same arguments at the target's translation would draw, and makes no bitmap. On graphics whose transform only translates, it draws as target.drawImage(bitmap.toAWTImage(settings), 0, 0, null) does. JVM only.

Draws picture onto target with scaleFactor device pixels per logical pixel. It draws what drawing the bitmap smile.infrastructure.Renderer.createBitmapFrom gives for the same arguments at the target's translation would draw, and makes no bitmap. On graphics whose transform only translates, it draws as target.drawImage(bitmap.toAWTImage(settings), 0, 0, null) does. JVM only.

The drawing is on the target's device pixels. The upper left corner of the bitmap lands where the translation of the target's transform is, rounded to the nearest whole device pixel, with a half going to the even one. That corner is the corner of the picture's bounds, covered by whole device pixels, which is seldom the picture's origin. A circle is centered on its origin, so its bounds start above and to the left of it. The rest of the transform is not used, so a target whose transform scales, as a Swing component's does on a high-DPI screen, takes that scale as scaleFactor. Only the target's clip is drawn into. Its transform, clip, composite, paint and hints are left as they were. The empty picture draws nothing.

To place the picture's origin on the translation instead, translate the target further by the upper left corner of the picture's smile.pictures.Element.bounds, in device pixels, or in logical pixels on a target whose transform already scales by scaleFactor. The origin then lands exactly there when that corner is on whole device pixels. Otherwise it can land one device pixel off, because the bitmap's corner is the bounds' corner rounded down to a whole device pixel, while the translation is rounded to the nearest one.

In a Swing component's paintComponent:

val g2d   = graphics.asInstanceOf[java.awt.Graphics2D]
val scale = g2d.getDeviceConfiguration.getDefaultTransform.getScaleX
Renderer().renderInto(g2d, picture, scale)

Value parameters

scaleFactor

Device pixels per logical pixel. Must be positive and finite, and 1 when the settings ask for ResamplingMode.Stepwise.

settings

The settings the picture is drawn with. See smile.RenderSettings.

timeMillis

The instant the picture is drawn at, as for smile.infrastructure.Renderer.createBitmapFrom.

Attributes

Source
JVMRendering.scala