During this event, all drawing operations occur on the internal backbuffer. When this function returns, the Canvas object will swap it to display it. So there is no need to call the Canvas.flip() method.
Canvas:onPaint() event
This event is fired when the Canvas is about to be redrawn, at a frequency of 30 times per seconds. This event occurs only when the Canvas.sync property is set to true
.
Return value
This event returns no value.Example
local ui = require "ui"
require "canvas"
-- create a simple Window
local win = ui.Window("Canvas:onPaint() sample", 640, 480)
-- create a canvas and center it
local canvas = ui.Canvas(win, 0, 0, 600, 400)
canvas.align = "all"
-- set the onPaint() event handler to draw on the canvas
function canvas:onPaint()
-- clears the canvas backbuffer with white color
canvas:clear(0xFFFFFFFF)
-- prints text
canvas:print("Hello World !", 10, 10)
end
win:show()
-- update the user interface until the user closes the Window
repeat
ui.update()
until not win.visible