Engine 0.0.6
Game engine in lua
Loading...
Searching...
No Matches
draw.lua
Go to the documentation of this file.
1local math = require('math')
2
3--! @cond
4local canvas = nil
5local game = nil
6--! @endcond
7
8local function color(c)
9 local R = math.floor(c/0x1000000)
10 local G = math.floor(c/0x10000) - (R * 0x100)
11 local B = math.floor(c/0x100) - (R * 0x10000) - (G * 0x100)
12 local A = c - (R * 0x1000000) - (G * 0x10000) - (B * 0x100)
13 canvas:attrColor(R, G, B, A)
14end
15
16local function clear(c)
17 color(c)
18 canvas:drawRect('fill', 0, 0, game.width, game.height)
19end
21local function rect(mode, x, y, width, height)
22 canvas:drawRect(mode == 0 and 'fill' or 'frame', x, y, width, height)
23end
24
25local function text(x, y, text)
26 if x and y then
27 canvas:drawText(x, y, text)
28 end
29 return canvas:measureText(text or x)
30end
31
32local function font(name, size)
33 if type(name) == 'number' and not size then
34 size = name
35 name = 'Tiresias'
36 end
37 canvas:attrFont(name, size)
38end
39
40local function line(x1, y1, x2, y2)
41 canvas:drawLine(x1, y1, x2, y2)
42end
43
44local function install(std, lgame, application, ginga)
45 canvas = ginga.canvas
46 game = lgame
47 std = std or {}
48 std.draw = std.draw or {}
55
56 local event_draw = function()
57 application.callbacks.draw(std, game)
58 end
59
60 return {
61 event={draw=event_draw},
62 std={draw=std.draw}
63 }
64end
65
66local P = {
68}
69
70return P
local function require(std, game, application)
local function draw(std, game)
local application
Definition main.lua:16
local canvas
nclua:canvas
Definition main.lua:22
local game
Definition main.lua:17
local std
Definition main.lua:18
local event
nclua:event
Definition main.lua:26
local function install(std, lgame, application, ginga)
local function line(x1, y1, x2, y2)
local function clear(c)
local function color(c)
local function font(name, size)
local function rect(mode, x, y, width, height)
local math
Definition draw.lua:1
local function text(x, y, text)