-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
88 lines (70 loc) · 1.7 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local Swipe = require "swipe"
local font = love.graphics.newFont("assets/wakuwaku.otf", 36)
local keyboard = Swipe.new(
love.graphics.getWidth() / 2,
(love.graphics.getHeight() / 2) + 40,
{ "a", "n", "g", "l", "u", "r", "a" },
{
textFont = font
}
)
local lastWord = love.graphics.newText(font, "")
function love.draw()
keyboard:draw()
love.graphics.draw(
lastWord,
love.graphics.getWidth() / 2,
40,
0,
1,
1,
lastWord:getWidth() / 2,
lastWord:getHeight() / 2
)
end
-- =============================================================================
-- Mouse
-- =============================================================================
function love.mousepressed(x, y, button)
keyboard:start(button, x, y)
local text = keyboard:get()
if text then
lastWord:set(keyboard:get())
end
end
function love.mousemoved(x, y)
keyboard:moved(x, y)
local text = keyboard:get()
if text then
lastWord:set(keyboard:get())
end
end
function love.mousereleased(x, y, button)
local result = keyboard:stop(button)
if result then
lastWord:set(result)
end
end
-- =============================================================================
-- Touch
-- =============================================================================
function love.touchpressed(id, x, y)
keyboard:start(id, x, y)
local text = keyboard:get()
if text then
lastWord:set(keyboard:get())
end
end
function love.touchmoved(id, x, y)
keyboard:touchMoved(id, x, y)
local text = keyboard:get()
if text then
lastWord:set(keyboard:get())
end
end
function love.touchreleased(id, x, y)
local result = keyboard:stop(id)
if result then
lastWord:set(result)
end
end