- Inside Canvas.onPaint() event, you should use this method before any drawing operation and call Canvas.flip() once it's done.
- When drawing operations are executed inside an event or in a Task, Canvas.begin() and Canvas.flip() must be called to preserve the Direct2D drawing state across Tasks.
Canvas:begin() method
Starts drawing operations on the Canvas.
Return value
This function returns no value.Example
local ui = require "ui"
require "canvas"
-- create a simple window
local win = ui.Window("canvas.onPaint() sample", "fixed", 500, 400)
local canvas = ui.Canvas(win)
canvas.align = "all"
function canvas:onPaint()
-- Aternates canvas fill using a random color...
self:begin()
self:clear(math.random(0xFFFFFFFF))
self:flip()
sleep(250)
-- ...and a red color
self:begin()
self:clear(0xFF0000FF)
self:flip()
sleep(250)
end
ui.run(win):wait()