Sciter supports three types of graphics contexts:
| Type |
GPU |
Definition |
How to get |
| <canvas> |
GPU |
W3C specified graphics thing.
Retained (buffered) rasterization. Hardware accelerated. |
let ctx = canvas.getContext("2d")
|
| Paint Graphics |
GPU |
Sciter specific.
Immediate Mode painting.
paintContent method gets called when the engine paints tree of DOM elements. |
element.paintContent = ctx => {...}
|
| Image Graphics |
CPU |
Sciter specific.
Retained, buffered painting on bitmap image.
You will get prepared graphics context (ctx) in your callback methods of Image constructor and optionally in image.update() method. |
image = new Image(100ppx,100ppx, ctx => {...});
// and
image.update(ctx => {...});
|
Paint Graphics
Paint Graphics is used in cases when you need to add some lightweight drawing to the element without changing DOM.
Consider the task of creating resizable component:
Note those eight handles that are drawn on top the element… In Sciter you don’t need to create additional DOM elements for drawing those, just define paintForeground = function(ctx) {...} method and draw them there. Fast and efficient.
Sciter supports the following drawing methods for DOM elements:
element.paintBackground = func(ctx); – invoked before CSS background drawing and return true; (a.k.a. “done”) from the func discards default CSS background drawing.
element.paintContent = func; – invoked before DOM content drawing and return true; (a.k.a. “done”) discards drawing of the content – as if all children have visibility:hidden; set on them.
element.paintForeground = func; – invoked before CSS foreground layer drawing and return true; (a.k.a. “done”) discards default CSS foreground drawing.
element.paintOutline = func; – invoked before CSS outline drawing and return true; (a.k.a. “done”) discards default CSS outline drawing.
Therefore, if you need to draw something on element on top of its content, attach paintForeground painter to the element.
Painting by these functions is done on exactly the same Graphics that is used for drawing DOM element, so it is GPU accelerated and quite lightweight.
Image Graphics
Image graphics is always associated with some bitmap – instance of class Graphics.Image.
Painting on the bitmap surface can be done either in image constructor:
image = new Image(100ppx,100ppx, ctx => {...});
Or later, after image creation, in its update method:
image.update(ctx => {...});
Almost always drawing (primitives rasterization) is done on CPU side, and so is not that performant as GPU drawing – use with care.
Note that in Sciter you can bind instance of Graphics.Image with CSS images. Therefore, you can implement dynamic CSS backgrounds:
let imageForCSS = new Graphics.Image(w,h, painter); // create image
document.bindImage("local:someid", imageForCSS); // attach the image to the "url".
And to use that url in CSS for an element:
div.cool {
background: #fff no-repeat;
background-image: url(local:someid); // url-bound image
}
That <div.cool> element will use background-image defined on JS side and if you want to update that image at runtime do:
imageForCSS.update( ctx => { ... cool drawing goes here ... } );
document.$("div.cool").requestPaint(); // ask Sciter to repaint that element
Cool, isn’t it?