An sdl_layer shows an sdl_texture in an sdl_window. The renderer
scales, rotates and flips the texture while it draws it. Layers are
drawn below the graphicals of the window, the first layer of
sdl_window<-layers
at the bottom.
The texture is first placed in sdl_layer<-area
according to sdl_layer<-scale.
It is then flipped according to sdl_layer<-flip,
rotated by sdl_layer<-angle
and finally mapped through sdl_layer<-transform.
With the default sdl_layer<-area
and sdl_layer<-scale,
the texture fits the window, as is common for video.
A layer is a sprite if its scale is none and it
has a sdl_layer<-transform:
the hot spot of the texture (see sdl_texture<->hot_spot)
is then at the origin of the transform, which moves and rotates it
around this point, as figure->transform
does for a figure. Draw the figure into a texture once, after which
moving the sprite is cheap:
new(T, sdl_texture(ShipFigure)), send(Window, append, new(Ship, sdl_layer(T, @nil, none))), ... new(Tr, transform), send(Tr, set, Cos, -Sin, Sin, Cos, X, Y), send(Ship, transform, Tr).
Setting any of the instance variables shows the window again. An
area object passed to sdl_layer->area
or sdl_layer->source
is used as is: changing it later is not noticed, so send the area again
after changing it.
|sdl_canvas*<-scale
is none, only the position is used.<-area. stretch
makes it exactly as large as the area; fit (default) makes
it as large as possible while keeping its aspect ratio and centres it; fill
covers the area while keeping the aspect ratio, cutting off what falls
outside;
none shows it at its own size with its hot spot at the
top-left corner of the area. The hot spot is
sdl_texture<-hot_spot
or else the top-left of the texture.
tile repeats the texture at its own size to fill the area,
starting at its top-left corner shifted by sdl_layer<-offset;
flipping, rotating and sdl_layer<-transform
apply to the whole tiled area. Tiles that are not rotated or flipped are
drawn in a single call by renderers that can repeat a texture, provided sdl_layer<-source
is @nil.
Otherwise each tile is drawn separately, so tiling a large area with a
small rotated texture is slow..0..1.0 Opacity: 0.0
is invisible, 1.0 (default) is opaque.horizontal shows a camera as in a
mirror.blend (default) is normal alpha blending.
add adds the colours, which makes glows, light, fire and
particles. mod multiplies the colours below with those of
the texture, ignoring its transparency. mul does the same,
but keeps what is below where the texture is transparent, e.g.,
for shadows.
none replaces what is below by the texture, ignoring sdl_layer<-alpha
and transparency; it is only useful for opaque textures.<-alpha.linear (default) interpolates, which is smooth for photos
and video. nearest uses the nearest pixel, keeping sharp
pixel edges. pixelart (SDL 3.4
or later, otherwise nearest) also keeps the pixels sharp,
but avoids the uneven pixel sizes of
nearest at scales that are not whole numbers.<-scale
is tile, in pixels of the window.
@nil is the
same as point(0,0). Changing the offset scrolls the
pattern, e.g., for a scrolling background;
layers that share a texture can scroll at different speeds for a
parallax effect. As with sdl_layer<-area,
send a new point rather than changing it.<-scale
is stretch or tile, the texture is scaled as
nine parts (9-slice scaling), as is common for the frames of
buttons and panels. The area is the centre part, in pixels of the
texture; it is limited to sdl_layer<-source.
The four corners keep their size, the top and bottom edges only stretch
horizontally, the left and right edges only vertically and the centre in
both directions. Using tile, the edges and centre are
repeated instead of stretched. If sdl_layer<-area
is too small for the corners, they are shrunk. Other scales ignore the
slices. With
sdl_layer<-scale_mode linear,
a stretched part blends with the pixels of its neighbours at its border;
use nearest if this is a problem.<-texture
in sdl_layer<-area.
The texture is then mapped onto the triangles as their vertices say;
without a texture, the triangles show the colours of the vertices. See
class sdl_mesh.|sdl_canvas*<-device
is the device showing a graphical. See sdl_window->append
and
sdl_canvas->append.
|sdl_canvas*],
area=[area*], scale=[{stretch,fit,fill,none,tile}]<-scale
(default fit). If area is omitted, the layer uses the whole
window.<-layers,
or just above
above. Fails if the layer is not shown in a window, or if above
is in another window. This is the same as graphical->expose.<-layers,
or just below
below. This is the same as graphical->hide.