/
main.lua
212 lines (179 loc) · 4.65 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
-- Filename: main.lua
-- Author: Luke Perkin
-- Date: 2010-02-25
-- Initialization
goo = require 'goo/goo'
anim = require 'anim/anim'
panels = {}
panels.name = { 'Open panel with button', 'Slide in panel with checkbox', 'Zoom in panel with textinput and colorpick', 'using the null object', 'Change skin', 'Multiline Text Input.'}
function love.load()
goo:load()
love.graphics.setBackgroundColor(255,255,255)
createButtons()
end
-- Logic
function love.update(dt)
goo:update(dt)
anim:update(dt)
end
-- Scene Drawing
function love.draw()
goo:draw()
end
-- Input
function love.keypressed( key, unicode )
goo:keypressed( key, unicode )
end
function love.keyreleased( key, unicode )
goo:keyreleased( key, unicode )
end
function love.mousepressed( x, y, button )
goo:mousepressed( x, y, button )
end
function love.mousereleased( x, y, button )
goo:mousereleased( x, y, button )
end
function createButtons()
for i,v in ipairs( panels ) do
local button = goo.button:new()
button:setPos( -350, i*25 )
button:setText( panels.name[i] )
button:sizeToText()
button.onClick = function(self,button)
if button == 'l' then
panels[i]()
end
end
anim:new{ table = button, key = 'x', finish = 10, style = 'quartOut', delay = (i-1)/2 }:play()
end
end
-- Open panel with button.
panels[1] = function()
local panel = goo.panel:new()
panel:setPos( 10, 10 )
panel:setSize( 200, 200 )
panel:setTitle( 'I am a panel' )
local button = goo.button:new( panel )
button:setPos( 10, 20 )
print( button:getAbsolutePos() ) -- 20, 30
button:setText( 'Click me' )
button:sizeToText()
button.onClick = function( self, button )
print( 'I have been clicked' )
end
local redButton = goo.button:new( panel )
redButton:setPos( 10, 100 )
redButton:setText( 'My style has been overridden' )
redButton:sizeToText( 10 )
local redStyle = {
backgroundColor = {255,0,0},
backgroundColorHover = {125,0,0},
borderColor = {0,0,0,0},
borderColorHover = {0,0,0,0},
}
redButton:setStyle( redStyle )
end
-- Slide in panel with checkbox.
panels[2] = function()
local panel = goo.panel:new()
panel:setPos( 10, 50 )
panel:setSize( 200, 200 )
panel:setTitle( 'I am a panel' )
local checkbox = goo.checkbox:new( panel )
checkbox:setPos( 10, 20 )
function checkbox:onClick( button )
print( self.class.name .. ' has been clicked' )
end
function checkbox:enterHover()
print( self.class.name .. ' enter hover')
end
local slideIn = anim:new{
table = panel,
key = 'x',
start = -250,
finish = 350,
time = 2,
style = 'expoOut'
}
slideIn:play()
function slideIn:onFinish()
checkbox:setChecked( true )
end
end
-- Zoom in panel with textinput and colorpick
panels[3] = function()
local testPanel = goo.panel:new()
testPanel:setPos( 100, 50 )
testPanel:setSize( 370, 500 )
testPanel:setTitle( "This is a Color Panel." )
testPanel:setOpacity( 10 )
local colorPicker = goo.colorpick:new( testPanel )
colorPicker:setPos(0,20)
local input = goo.textinput:new( testPanel )
input:setPos(3,486)
input:setSize(360,20)
input:setText('hello!')
function colorPicker:onClick()
local r,g,b = self:getColor()
local str = string.format( 'Red = %i, Green = %i, Blue = %i', r,g,b)
input:setText( str )
end
anim:easy( testPanel, 'xscale', 0, 1, 3, 'elastic')
anim:easy( testPanel, 'yscale', 0.9, 1, 3, 'elastic')
anim:easy( testPanel, 'opacity', 0, 255, 0.5, 'quadInOut')
end
-- Using the null object.
panels[4] = function()
local group = goo.null()
group:setPos( 300, 300 )
local n = 1
function group:update(dt)
self:setPos( 300 + n, 300 )
n=n+1
self:recurse('children','updateBounds')
end
local panel_style = {
titleColor = {0,0,0,0},
seperatorColor = {0,0,0,0}
}
local p1 = goo.panel:new( group )
p1:setPos( 0, 0 )
p1:setSize( 50, 50 )
p1:showCloseButton( false )
p1:setStyle( panel_style )
p1:setDraggable( false )
local p2 = goo.panel:new( group )
p2:setPos( 75, 0 )
p2:setSize( 50, 50 )
p2:setStyle( panel_style )
p2:setDraggable( false )
end
-- Changing the style
panels[5] = function()
local panel = goo.panel:new()
panel:setPos( 100, 100 )
panel:setSize( 200, 100 )
local button = goo.button:new( panel )
button:setPos( 15, 15 )
button:setText( 'toggle theme' )
button:sizeToText( 15 )
themeSwitch = true
function button:onClick()
if themeSwitch then
goo:setSkinAllObjects( 'dark' )
themeSwitch = not themeSwitch
else
goo:setSkinAllObjects( 'default' )
themeSwitch = not themeSwitch
end
end
end
panels[6] = function()
local panel = goo.panel:new()
panel:setPos( 100, 100 )
panel:setSize( 200, 300 )
local input = goo.textinput:new( panel )
input:setMultiline( true )
input:setPos( 10, 15 )
input:setSize( 180, 280 )
end