LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
draw

Drawing shapes and text on the screen (uses vita2d) More...

Detailed Description

Everything drawn with this library (and with images, ImGui, etc.) is drawn to a hidden buffer first. Nothing appears on the screen until you call draw.swapbuffers(), which shows the finished frame and clears the buffer for the next one. Because of this, a LifeLua app is usually one big loop:

local white = color.new(255, 255, 255)
while true do
draw.text(10, 10, "Hello World!", white)
draw.rect(10, 40, 100, 50, color.new(255, 0, 0))
draw.swapbuffers()
end

The screen is 960 × 544 pixels. (0, 0) is the top-left corner, x grows to the right and y grows downwards.

Every parameter written as color accepts either a color value made with color.new() or a plain number in 0xAABBGGRR order (see tocolor()).

Functions

nil draw.swapbuffers (color color)
 
nil draw.text (number x, number y, string text, color color, number size, font font)
 
number draw.textwidth (string text, number size, font font)
 
number draw.textheight (string text, number size, font font)
 
nil draw.rect (number x, number y, number width, number height, color color, color outline)
 
nil draw.circle (number x, number y, number radius, color color)
 
nil draw.radialcircle (number x, number y, number radius, color center, color edge, number smoothness)
 
nil draw.triangle (number x1, number y1, number x2, number y2, number x3, number y3, color c1, color c2, color c3)
 
nil draw.line (number start_x, number start_y, number end_x, number end_y, color color)
 
nil draw.gradientline (number start_x, number start_y, number end_x, number end_y, color start_color, color end_color)
 
nil draw.polyline (number x1, number y1, color color1, number x2, number y2, color color2,...)
 
nil draw.pixel (number x, number y, color color)
 
nil draw.gradientrect (number x, number y, number width, number height, color top_left, color top_right, color bottom_left, color bottom_right)
 
nil draw.vdoublegradientrect (number x, number y, number width, number height, color top_left, color top_right, color center_left, color center_right, color bottom_left, color bottom_right)
 
nil draw.hdoublegradientrect (number x, number y, number width, number height, color left_top, color center_top, color right_top, color left_bottom, color center_bottom, color right_bottom)
 
nil draw.enableclip (boolean enable)
 
nil draw.cliprect (number x1, number y1, number x2, number y2)
 
nil draw.clipcircle (number x, number y, number radius)
 

Function Documentation

◆ draw.circle()

nil draw.circle ( number x,
number y,
number radius,
color color )

Draws a filled circle

Parameters
xX position of the center
yY position of the center
radiusRadius in pixels
colorFill color

◆ draw.clipcircle()

nil draw.clipcircle ( number x,
number y,
number radius )

Sets a circular clipping area. Works like draw.cliprect(), but the visible area is a circle.

Parameters
xX of the circle's center
yY of the circle's center
radiusRadius of the circle

◆ draw.cliprect()

nil draw.cliprect ( number x1,
number y1,
number x2,
number y2 )

Sets a rectangular clipping area, useful for cutting off long text or making scrollable areas. Only has an effect while clipping is turned on with draw.enableclip().

Parameters
x1Left edge of the area
y1Top edge of the area
x2Right edge of the area (this is a position, not a width)
y2Bottom edge of the area (this is a position, not a height)
Example:
draw.enableclip(true)
draw.cliprect(10, 10, 110, 30) -- a 100 × 20 area at (10, 10)
draw.text(10, 10, "This long text gets cut off at x = 110", white)
draw.enableclip(false)

◆ draw.enableclip()

nil draw.enableclip ( boolean enable)

Turns clipping on or off. While clipping is on, only the area set with draw.cliprect() or draw.clipcircle() can be drawn on; everything outside of it is cut off.

Parameters
enabletrue to turn clipping on, false to turn it off

◆ draw.gradientline()

nil draw.gradientline ( number start_x,
number start_y,
number end_x,
number end_y,
color start_color,
color end_color )

Draws a 1 pixel wide line that fades from one color to another

Parameters
start_xX of the start point
start_yY of the start point
end_xX of the end point
end_yY of the end point
start_colorColor at the start point
end_colorColor at the end point

◆ draw.gradientrect()

nil draw.gradientrect ( number x,
number y,
number width,
number height,
color top_left,
color top_right,
color bottom_left,
color bottom_right )

Draws a rectangle with a different color in each corner, shaded between them

Parameters
xLeft position
yTop position
widthWidth in pixels
heightHeight in pixels
top_leftTop-left color
top_rightTop-right color
bottom_leftBottom-left color
bottom_rightBottom-right color
Example:
-- Horizontal gradient from red to blue
draw.gradientrect(0, 0, 960, 60, red, blue, red, blue)

◆ draw.hdoublegradientrect()

nil draw.hdoublegradientrect ( number x,
number y,
number width,
number height,
color left_top,
color center_top,
color right_top,
color left_bottom,
color center_bottom,
color right_bottom )

Draws a rectangle shaded in two halves side by side: the left half goes from the left colors to the center colors, the right half from the center colors to the right colors

Parameters
xLeft position
yTop position
widthWidth in pixels
heightHeight in pixels
left_topTop-left color
center_topTop-middle color
right_topTop-right color
left_bottomBottom-left color
center_bottomBottom-middle color
right_bottomBottom-right color

◆ draw.line()

nil draw.line ( number start_x,
number start_y,
number end_x,
number end_y,
color color )

Draws a 1 pixel wide line

Parameters
start_xX of the start point
start_yY of the start point
end_xX of the end point
end_yY of the end point
colorLine color

◆ draw.pixel()

nil draw.pixel ( number x,
number y,
color color )

Draws a single pixel

Parameters
xX position
yY position
colorPixel color

◆ draw.polyline()

nil draw.polyline ( number x1,
number y1,
color color1,
number x2,
number y2,
color color2,
... )

Draws lines connecting several points, one after another. Each point is given as 3 values: x, y, color. At least 2 points are required. Each line fades between the colors of the 2 points it connects.

Parameters
x1X of the 1st point
y1Y of the 1st point
color1Color of the 1st point
x2X of the 2nd point
y2Y of the 2nd point
color2Color of the 2nd point
...More points, 3 values each
Example:
-- A white-blue-green zigzag
draw.polyline(10, 10, white, 50, 10, blue, 30, 70, green)

◆ draw.radialcircle()

nil draw.radialcircle ( number x,
number y,
number radius,
color center,
color edge,
number smoothness )

Draws a filled circle with a gradient from its center to its edge

Parameters
xX position of the center
yY position of the center
radiusRadius in pixels
centerColor in the center
edgeColor at the edge
smoothnessNumber of segments used for the edge, higher is smoother (optional, default: 64, minimum: 3)

◆ draw.rect()

nil draw.rect ( number x,
number y,
number width,
number height,
color color,
color outline )

Draws a filled rectangle

Parameters
xLeft position
yTop position
widthWidth in pixels
heightHeight in pixels
colorFill color
outlineColor of a 1 pixel border around the rectangle (optional, no border if omitted)

◆ draw.swapbuffers()

nil draw.swapbuffers ( color color)

Shows everything that was drawn since the last call on the screen, then clears the drawing buffer. Call this once at the end of every frame of your main loop.

Parameters
colorThe color the next frame starts with (optional, default: black)

◆ draw.text()

nil draw.text ( number x,
number y,
string text,
color color,
number size,
font font )

Draws text on the screen

After the 4 required parameters, you can choose the font and the size in any of these ways:

  • draw.text(x, y, text, color): system font (PGF), size 1
  • draw.text(x, y, text, color, size): system font (PGF) at size
  • draw.text(x, y, text, color, font) or draw.text(x, y, text, color, font, size): a font loaded with font.load()
  • draw.text(x, y, text, color, size, font): same as above, with the size first
  • draw.text(x, y, text, color, true) / draw.text(x, y, text, color, true, size): system PVF font (false = system PGF font)
  • draw.text(x, y, text, color, size, true): same as above, with the size first
Parameters
xLeft position of the text
yTop position of the text
textThe text to draw
colorColor of the text
sizeText scale, 1 is the normal size (optional, default: 1)
fontA font from font.load(), or a boolean to pick the system PVF (true) or PGF (false) font (optional)
Example:
local white = color.new(255, 255, 255)
local myfont = font.load("app0:font.ttf")
draw.text(10, 10, "System font", white)
draw.text(10, 40, "Twice as big", white, 2)
draw.text(10, 100, "Custom font", white, myfont)

◆ draw.textheight()

number draw.textheight ( string text,
number size,
font font )

Gets how tall a text will be when drawn with draw.text()

Accepts the same size/font combinations as draw.textwidth().

Parameters
textThe text to measure
sizeText scale (optional, default: 1)
fontA font from font.load(), or true/false for the system PVF/PGF font (optional)
Returns
The height in pixels

◆ draw.textwidth()

number draw.textwidth ( string text,
number size,
font font )

Gets how wide a text will be when drawn with draw.text()

Accepts the same size/font combinations as draw.text(), e.g. draw.textwidth(text), draw.textwidth(text, size), draw.textwidth(text, font), draw.textwidth(text, font, size), draw.textwidth(text, true), etc.

Parameters
textThe text to measure
sizeText scale (optional, default: 1)
fontA font from font.load(), or true/false for the system PVF/PGF font (optional)
Returns
The width in pixels
Example:
-- Center a text horizontally
local text = "Centered!"
draw.text(480 - draw.textwidth(text) / 2, 10, text, color.new(255, 255, 255))

◆ draw.triangle()

nil draw.triangle ( number x1,
number y1,
number x2,
number y2,
number x3,
number y3,
color c1,
color c2,
color c3 )

Draws a filled triangle. If you give 3 colors, each corner gets its own color and the triangle is shaded between them.

Parameters
x1X of the 1st corner
y1Y of the 1st corner
x2X of the 2nd corner
y2Y of the 2nd corner
x3X of the 3rd corner
y3Y of the 3rd corner
c1Color of the 1st corner (or of the whole triangle)
c2Color of the 2nd corner (optional, default: c1)
c3Color of the 3rd corner (optional, default: c1)

◆ draw.vdoublegradientrect()

nil draw.vdoublegradientrect ( number x,
number y,
number width,
number height,
color top_left,
color top_right,
color center_left,
color center_right,
color bottom_left,
color bottom_right )

Draws a rectangle shaded in two halves stacked vertically: the top half goes from the top colors to the center colors, the bottom half from the center colors to the bottom colors

Parameters
xLeft position
yTop position
widthWidth in pixels
heightHeight in pixels
top_leftTop-left color
top_rightTop-right color
center_leftMiddle-left color
center_rightMiddle-right color
bottom_leftBottom-left color
bottom_rightBottom-right color