Canvas:print(text, x, y, [ brush ] ) method
Draws text on the Canvas, at the specified position
Parameters
text
A string representing the text to be drawn
x
The horizontal position in the Canvas as a number (zero means the left side of the Canvas)
y
The vertical position in the Canvas as a number (zero means the top side of the Canvas)
[ brush ]
An optional value that can represent any of the following values :
- A RGBA color, as an integer value
- LinearGradient : The text will be filled with a colored linear gradient
- RadialGradient : The text will be filled with a colored radial gradient
- Image : The text will be filled with a picture pattern.
Return value
This function returns no value.Example
local ui = require "ui"
require "canvas"
-- create a simple Window
local win = ui.Window("Canvas.print() sample - Move the mouse over the window", "fixed", 500, 400)
-- create a Canvas
local canvas = ui.Canvas(win)
canvas.align = "all"
canvas.font = "Impact"
canvas.fontsize = 40
-- create a RadialGradient
local radial = canvas:RadialGradient { [0] = 0x00FFFFFF, [1] = 0x00008BFF }
radial.radius = { 400, 400 }
local text = "Hello LuaRT World !!!"
-- center the text
local size = canvas:measure(text)
local xpos = (canvas.width - size.width)/2
local ypos = (canvas.height - size.height)/2
function canvas:onPaint()
canvas:print(text, xpos, ypos, radial)
end
function canvas:onHover(x,y buttons)
radial.center = { x, y }
end
win:show()
-- update user interface
repeat
ui.update()
until not win.visible