Engine 0.0.6
Game engine in lua
Loading...
Searching...
No Matches
draw.lua
Go to the documentation of this file.
1local modes = {
2 [true] = {
3 [0] = true,
4 [1] = false
5 },
6 [false] = {
7 [0] = 'fill',
8 [1] = 'line'
9 }
10}
11
12local function color(c)
13 local DIV = love.wiimote and 1 or 255
14 local R = bit.band(bit.rshift(c, 24), 0xFF)/DIV
15 local G = bit.band(bit.rshift(c, 16), 0xFF)/DIV
16 local B = bit.band(bit.rshift(c, 8), 0xFF)/DIV
17 local A = bit.band(bit.rshift(c, 0), 0xFF)/DIV
18 love.graphics.setColor(R, G, B, A)
19end
20
21local function rect(a,b,c,d,e,f)
22 love.graphics.rectangle(modes[love.wiimote ~= nil][a], b, c, d, e)
23end
24
25--! @todo support WII
26local function text(x, y, text)
27 if love.wiimote then return 32 end
28 local font = love.graphics.getFont()
29 local t = text and tostring(text) or tostring(x)
30 local n = select(2, t:gsub('\n', '')) + 1
31 local w = font:getWidth(t)
32 local h = (font:getHeight('A') * n) + (font:getLineHeight() * n)
33 if x and y then
34 love.graphics.print(t, x, y)
35 end
36 return w, h
37end
38
39local function line(x1, y1, x2, y2)
40 love.graphics.line(x1, y1, x2, y2)
41end
42
43local function triangle(mode, x1, y1, x2, y2, x3, y3)
44 love.graphics.line(x1, y1, x2, y2)
45 love.graphics.line(x2, y2, x3, y3)
46 if mode <= 1 then
47 love.graphics.line(x1, y1, x3, y3)
48 end
49end
50
51local function font(name, size)
52 if type(name) == 'number' and not size then
53 size = name
54 name = 'Tiresias'
55 end
56 local index = 'font_'..tostring(name)..tostring(size)
57 if not _G[index] then
58 _G[index] = love.graphics.newFont(size)
59 end
60 love.graphics.setFont(_G[index])
61end
62
63local function install(std, game, application)
64 application.callbacks.draw = application.callbacks.draw or function() end
65
71
72 std.draw.clear = function(c)
73 color(c)
74 love.graphics.rectangle(modes[love.wiimote ~= nil][0], 0, 0, game.width, game.height)
75 end
76
77 local event_draw = function()
78 application.callbacks.draw(std, game)
79 end
80
81 return {
82 event={draw=event_draw},
83 std={draw=std.draw}
84 }
85end
86
87local P = {
89 triangle=triangle
90}
91
92return P
local function draw(std, game)
local application
Definition main.lua:16
local game
Definition main.lua:17
local std
Definition main.lua:18
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 function text(x, y, text)