fixed X11_softare_info changing
[ego.git] / test / test.lua
blob295b88911d218df0e642e4307d39e1d589da59df
1 -- compile time definitions
3 WIDTH = 400
4 HEIGHT = 400
6 images = {
7 ['frywintux.jpeg'] = 0
10 --require 'move'
12 -- edje
13 edj = {}
14 n = 16
15 for i = 1, n do
16 edj[i] = {}
17 for j = 1, n do
18 edj[i][j] = ego:edje {
19 name = 'icon_' .. i .. '_' .. j,
20 group = 'icon',
21 pos = {(i-1)/n, (j-1)/n},
22 size = {1/n, 1/n},
23 visible = true
26 edj[i][j].rect = ego:rectangle {
27 name = 'rect_' .. i .. '_' .. j,
28 color = {i*255/n, j*255/n, 0, 255}
31 edj[i][j].container.swallow = edj[i][j].rect
32 end
33 end
35 -- image
36 img = ego:image {
37 repeat_events = true,
38 file = images['frywintux.jpeg'],
39 color = {255, 255, 255, 128},
40 moveto = function (self, x, y, v)
41 self.animator = coroutine.wrap (function (anim)
42 geo = anim.ptr.geometry
43 if x > geo[1] then
44 e = v
45 else
46 e = -v
47 end
48 for X = geo[1], x, e do
49 anim.ptr:move (X, geo[2])
50 coroutine.yield (true)
51 end
52 anim.ptr.anim = nil
53 return false
54 end)
55 if (self.anim) then
56 self.anim:del ()
57 end
58 self.anim = ego:animator (self.animator)
59 self.anim.ptr = self
60 end,
61 callback_resize = function (self) self:fit () end,
62 pos = {0.3, 0.4},
63 size = {0.3, 0.4},
64 visible = true
67 -- rectangle
68 overlay = ego:rectangle {
69 focus = true,
70 color = {0, 0, 0, 0},
71 repeat_events = true,
73 callback_key_down = function (self, key)
74 if key == 'Escape'
75 then ego:quit ()
76 elseif key == 't'
77 then ego:hide ()
78 end
79 end,
81 callback_mouse_down = function (self, button, x, y, X, Y)
82 img:moveto (x, y, 5)
83 end,
84 pos = {0, 0},
85 size = {1, 1},
86 visible = true
89 -- smart
90 --[[
91 self.mv = ego:smart (move)
92 mv:set {
93 color = {255, 0, 0, 128},
94 visible = true
96 mv:move (100, 100)
97 mv:resize (100, 100)
98 --]]
100 -- gradient
101 gra = ego:gradient {
102 angle = 45,
103 fill = {0, 0, HEIGHT, WIDTH},
104 repeat_events = true,
106 colors = {
107 {0,0,0,0,0},
108 {0,0,0,255,100},
111 animator = coroutine.wrap( function (self)
112 while true do
113 for i = 0, 360, 2 do
114 gra.angle = i
115 coroutine.yield (true)
118 end),
119 visible = true,
120 size = {1, 1}
122 gra:clear()
123 for _,v in ipairs (gra.colors) do
124 gra:color_stop_add (v)
126 --gra.anim = ego:animator (gra.animator)
128 -- line
129 line = ego:line {
130 repeat_events = true,
131 xy = {
132 math.random (WIDTH),
133 math.random (HEIGHT),
134 math.random (WIDTH),
135 math.random (HEIGHT)
137 visible = true
140 -- polygon
141 poly = ego:polygon {
142 pass_events = true,
143 color = {255,255,0,32},
145 points = {
146 {50,100},
147 {10,200},
148 {30,50}
150 visible = true
152 for _,v in ipairs (poly.points) do
153 poly:point_add (v[1], v[2])
156 -- text
157 tex = ego:text {
158 repeat_events = true,
159 style = 4,
160 font_source = 'test.ego',
161 font = {'default', 20},
162 text = 'hello world',
163 color = {255, 255, 255, 255},
164 outline_color = {0, 0, 0, 255},
165 glow_color = {0, 0, 255, 255},
166 glow2_color = {0, 255, 0, 255},
167 shadow_color = {255, 0, 0, 128} ,
168 visible = true
171 -- textblock style
172 sty = ego:textblock_style ()
173 sty.style = [[
174 DEFAULT='font=notepad.ttf font_size=20 align=center color=#000 style=outline_shadow outline_color=#000 shadow_color=#fff wrap=word'
175 r='+color=#f00'
176 g='+color=#0f0'
177 b='+color=#00f'
178 y='+color=#ff0'
181 -- textblock
182 tb = ego:textblock {
183 repeat_events = true,
184 style = sty,
185 text_markup = '<r>hello</r> world, <g>whats</g> up? <b>are</b> you <y>alright</y>?',
187 pos = {0, 0.25},
188 size = {1, 0.25},
189 visible = true
192 -- button
193 b = ego:button {
194 label = 'hello',
195 clicked = coroutine.wrap (function (self)
196 for i = 1, 10 do
197 print (i)
198 coroutine.yield ()
200 self:hide ()
201 end),
202 visible = true
205 -- scroller
206 scr = ego:scroller {
207 content = b,
208 content_min_limit = {true, false},
209 visible = true,
210 pos = {0.2, 0.2},
211 size = {0.5, 0.1}
214 -- label
215 lab = ego:label {
216 label = 'I am a label',
217 visible= true,
218 pos = {0.6, 0.6}
221 -- toggle
222 tog = ego:toggle {
223 states_labels = {'off', 'on'},
224 state = true,
225 changed = function (self)
226 print (self.state)
227 end,
228 visible = true
231 -- frame
232 frm = ego:frame {
233 label = 'test frame',
234 content = tog,
235 visible = true,
236 pos = {0.7, 0.7}
239 -- table
240 tbl = ego:table {
241 homogenous = true,
242 visible = true,
243 pos = {0.1, 0.1},
244 size = {0.3, 0.3}
246 for i = 0, 3 do
247 for j = 0, 3 do
248 r = ego:rectangle {
249 color = {64*i, 64*j, 0, 255},
250 visible = true,
251 size = {0.1, 0.1}
253 tbl:pack (r, i, j, 1, 1)
257 -- entry
258 ent = ego:entry {
259 single_line = true,
260 password = false,
261 entry = 'edit me',
262 line_wrap = false,
263 editable = true,
264 visible = true,
266 ['changed'] = function (self) print 'changed' end,
267 ['selection,start'] = function (self) print 'selection,start' end,
268 ['selection,changed'] = function (self) print 'selection,changed' end,
269 ['selection,cleard'] = function (self) print 'selection,cleared' end,
270 ['selection,paste'] = function (self) print 'selection,paste' end,
271 ['selection,copy'] = function (self) print 'selection,copy' end,
272 ['selection,cut'] = function (self) print 'selection,cut' end,
273 ['cursor,changed'] = function (self) print 'cursor,changed' end,
274 ['anchor,clicked'] = function (self) print 'anchor,clicked' end,
275 ['activated'] = function (self) print 'activated' end,
278 -- transform
279 trans = ego:transform {
280 matrix = {
281 {1, 0, 0},
282 {0, 1, 0},
283 {0, 0, 1}
286 trans:rotate (33)
288 -- gradient2
289 gra2 = ego:gradient2_linear {
290 fill_spread = 0,
291 fill_transform = trans,
292 fill = {0, 0, 50, 50},
294 visible = true,
295 pos = {0, 0.8},
296 size = {0.2, 0.2},
297 transient = {
298 {255, 0, 0, 255, 0.0},
299 {0, 255, 0, 255, 0.2},
300 {0, 0, 255, 255, 0.7},
301 {0, 255, 255, 255, 1.0}
304 for _, v in ipairs (gra2.transient) do
305 gra2:color_np_stop_insert (v)
308 -- bubble
309 bub = ego:bubble {
310 label = 'I am a bubble',
311 info = 'I really am a bubble',
312 icon = ego:rectangle {
313 color = {255, 0, 0, 255},
314 visible = true
316 content = ent,
317 visible = true,
318 pos = {0.3, 0.8},
319 size = {0.7, 0.2}