Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
25 May, 2013, 23:12:37 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: 1 ... 4 5 [6] 7   Go Down
  Print  
Author Topic: [Lua] Image Editor -  (Read 6262 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Chockosta
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 19:34:35
Date Registered: 03 June, 2011, 20:14:17
Location: France
Posts: 440


Topic starter
Total Post Ratings: +159

View Profile
« Reply #75 on: 06 January, 2012, 21:07:03 »
+1

Some progress...
Now buttons work, and there is a draft of custom window layouts.

If you're interested, here is the code of the new sample :

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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
--[[

window : {wtype,name,buttons,layout,size}
   --> wtype : "dialogBox","custom"
   --> size : {sizeX,sizeY} (only for custom)

buttons : {{"name",function1},{"name",function2},...}

layout : {{"type",...}}
   --> type : "label","textBox","colorSlider","list"

label : {text,x,y}

textBox : {text,x,y,sizeX,cursor}

colorSlider : {color,value,x,y}
   --> color : "red","green","blue"

list : {elements,scroll,x,y,sizeX,sizeY}

]]


--GUI GESTION
gui={}
gui.windows={}
gui.dialogBox={}
gui.custom={}
gui.resized=false

function gui.errorMessage(errorText)
 gui.addWindow("dialogBox","Error",{{"OK",function() gui.closeWindow() refresh() end}},errorText)
end

function gui.addWindow(windowType,windowName,windowButtons,windowLayout,windowSize)
 table.insert(gui.windows,{wtype=windowType,name=windowName,buttons=windowButtons,layout=windowLayout,size=windowSize})
 gui.focus=-1
end

function gui.closeWindow()
 table.remove(gui.windows)
 gui.focus=-1
end

function gui.nbWindows()
 return #gui.windows
end

function gui.current()
 return gui.windows[#gui.windows]
end

function gui.paint(gc)
 for i,e in pairs(gui.windows) do
  gui[e.wtype].paint(gc,e,i)
 end
 gui.resized=false
end

function gui.resize()
 gui.resized=true
end




--GUI DRAWING

function gui.dialogBox.paint(gc,dialogBox,windowID)
 local sizeX,sizeY
 if not dialogBox.size then
  gc:setFont("sansserif","r",10)
  sizeX=improvedStr.width(gc,dialogBox.layout)+24
  sizeY=improvedStr.height(gc,dialogBox.layout)+17
  gui.windows[windowID].size={sizeX,sizeY}
 else
  sizeX,sizeY=unpack(dialogBox.size)
 end
 gui.paintWindowBG(gc,dialogBox.name,sizeX,sizeY)
 gui.paintTextArea(gc,dialogBox.layout,sizeX,sizeY)
 gui.paintButtons(gc,dialogBox.buttons,sizeX,sizeY,windowID)
 if windowID==#gui.windows then
  gui.paintFocus(gc,gui.focus,dialogBox.buttons,dialogBox.layout,sizeX,sizeY)
 end
end

function gui.custom.paint(gc,window,windowID)
 gui.paintWindowBG(gc,window.name,window.size[1],window.size[2])
 gui.paintLayout(gc,window.layout,window.size[1],window.size[2],windowID)
 gui.paintButtons(gc,window.buttons,window.size[1],window.size[2],windowID)
 if windowID==#gui.windows then
  gui.paintFocus(gc,gui.focus,window.buttons,window.layout,window.size[1],window.size[2])
 end
end





function gui.paintLayout(gc,layout,sizeX,sizeY,windowID)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 for i,e in pairs(layout) do
  if e[1]=="textBox" then
   gui.paintTextBox(gc,e,x,y)
  elseif e[1]=="label" then
   gc:setFont("sansserif","r",10)
   gc:setColorRGB(0,0,0)
   gc:drawString(e.text,x+e.x,y+e.y,"top")
  elseif e[1]=="colorSlider" then
   gui.paintColorSlider(gc,e,x,y)
  end
 end
end

function gui.paintTextBox(gc,textBox,x,y)
 gc:setColorRGB(255,255,255)
 gc:fillRect(x+textBox.x,y+textBox.y,textBox.sizeX,22)
 gc:setColorRGB(0,0,0)
 gc:drawRect(x+textBox.x,y+textBox.y,textBox.sizeX,22)
 gc:drawString(string.sub(textBox.text,1,textBox.cursor-1).."|"..string.sub(textBox.text,textBox.cursor),x+textBox.x+3,y+textBox.y,"top")
end

function gui.paintColorSlider(gc,slider,x,y)
 gc:setColorRGB(0,0,0)
 gc:fillRect(x+slider.x,y+slider.y,68,14)
 for i=0,63 do
  gc:setColorRGB(slider.color=="red" and i*4 or color[1],slider.color=="green" and i*4 or color[2],slider.color=="blue" and i*4 or color[3])
  gc:fillRect(x+slider.x+i+2,y+2+slider.y,1,10)
 end
 gc:setColorRGB(0,0,0)
 gc:fillRect(x+slider.x+slider.value/4+1,y+slider.y,1,12)
 gc:fillRect(x+slider.x+slider.value/4+3,y+slider.y,1,12)
end

function gui.paintButtons(gc,buttons,sizeX,sizeY,windowID)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if (not buttons[1].size) or gui.resized then
  local totalSize,size,pos=-7,{},{}
  for i,e in pairs(buttons) do
   size[i]=gc:getStringWidth(e[1])+10
   totalSize=totalSize+size[i]+7
  end
  pos[1]=(width()-totalSize)/2
  for i=2,#buttons do
   pos[i]=pos[i-1]+size[i-1]+7
  end
  for i,e in pairs(buttons) do
   gui.windows[windowID].buttons[i].size=size[i]
   gui.windows[windowID].buttons[i].pos=pos[i]
  end
  buttons=gui.windows[windowID].buttons
 end
 for i,e in pairs(buttons) do
  gc:setColorRGB(136,136,136)
  gc:fillRect(e.pos,y+sizeY+9,e.size,23)
  gc:fillRect(e.pos+1,y+sizeY+8,e.size-2,25)
  gc:fillRect(e.pos+2,y+sizeY+7,e.size-4,27)
  gc:setColorRGB(255,255,255)
  gc:fillRect(e.pos+2,y+sizeY+9,e.size-4,23)
  gc:setColorRGB(0,0,0)
  gc:drawString(e[1],e.pos+5,y+sizeY+20,"middle")
 end
end

function gui.paintTextArea(gc,text,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if isCX() then
  gc:setColorRGB(128,128,128)
 else
  gc:setColorRGB(255,255,255)
 end
 gc:drawRect(x+6,y+6,sizeX-13,sizeY-13)
 gc:setColorRGB(0,0,0)
 improvedStr.draw(gc,text,x+12,y+9)
end

function gui.paintWindowBG(gc,name,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if isCX() then
  gc:setColorRGB(100,100,100)
 else
  gc:setColorRGB(200,200,200)
 end
 gc:fillRect(x-1,y-23,sizeX+4,sizeY+65)
 gc:fillRect(x,y-22,sizeX+4,sizeY+65)
 gc:fillRect(x+1,y-21,sizeX+4,sizeY+65)
 if isCX() then
  gc:setColorRGB(128,128,128)
 else
  gc:setColorRGB(0,0,0)
 end
 gc:fillRect(x-2,y-24,sizeX+4,sizeY+65)
 if isCX() then
  for i=1,22 do
   gc:setColorRGB(32+i*3,32+i*3,32+i*3)
   gc:fillRect(x,y+i-23,sizeX,1)
  end
 else
  gc:setColorRGB(0,0,0)
  gc:fillRect(x,y-22,sizeX,22)
 end
 gc:setColorRGB(255,255,255)
 gc:setFont("sansserif","r",10)
 gc:drawString(name,x+2,y-9,"baseline")
 gc:setColorRGB(224,224,224)
 gc:fillRect(x,y,sizeX,sizeY+39)
 gc:setColorRGB(128,128,128)
 gc:fillRect(x+6,y+sizeY,sizeX-12,2)
end

function gui.paintFocus(gc,focus,buttons,layout,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if focus>0 then
  if type(layout)=="table" then

  end
 elseif focus<0 then
  local button=buttons[-focus]
  if isCX() then
   gc:setColorRGB(50,150,190)
  else
   gc:setColorRGB(0,0,0)
  end
  gc:drawRect(button.pos-3,y+sizeY+4,button.size+5,32)
  gc:drawRect(button.pos-2,y+sizeY+5,button.size+3,30)
 end
end




--GUI EVENTS
function gui.mouseDown(xPos,yPos)
 if gui.nbWindows()>=1 then
  local window=gui.current()
  if window.size then
   local sizeX,sizeY=unpack(window.size)
   local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
   if xPos>x and xPos<x+sizeX and yPos>y then
    if yPos<y+sizeY then
     gui.setFocus(xPos,yPos,window)
    elseif yPos<y+sizeY+39 then
     gui.buttonDown(xPos,yPos,window.buttons)
    end
   end
  end
 end
end

function gui.buttonDown(x,y,buttons)
 for i,e in pairs(buttons) do
  if x>e.pos and x<e.pos+e.size then
   gui.focus=-i
   e[2]()
  end
 end
end

function gui.setFocus(x,y,window)
 
end


--MULTIPLE LINE STRING GESTION
improvedStr={}

function improvedStr.draw(gc,str,x,y)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 for i,e in pairs(table1) do
  gc:drawString(e,x,y+(i-1)*gc:getStringHeight("a"),"top")
 end
end

function improvedStr.width(gc,str)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 local table2={}
 for i,e in pairs(table1) do
  table2[i]=gc:getStringWidth(e)
 end
 table.sort(table2)
 return table2[#table2]
end

function improvedStr.height(gc,str)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 return gc:getStringHeight("a")*#table1
end

function improvedStr.cut(str)
 local table1,finished={},false
 local posStart,posEnd,last=1,0,1
 while not finished do
  posStart,posEnd=string.find(str,"\n",posEnd+1)
  if posStart then
   table.insert(table1,string.sub(str,last,posStart-1))
   last=posEnd+1
  else
   table.insert(table1,string.sub(str,last))
   finished=true
  end
 end
 return unpack(table1)
end


* ScreenShot108.png (7.11 KB, 320x240 - viewed 239 times.)
« Last Edit: 06 January, 2012, 21:07:26 by Chockosta » Logged

Chockosta (Loic Pujet) - Sorry for my poor English...
Look at my projects :
in C code : Periodic table, Space invaders, Fall, Snake, Minesweeper, nCraft (WIP)
in Lua : Snake, Space invaders, Bobby Carrot, Minesweeper, Mazes 3D, nSpaint, FreeCell, Tiny3D-Viewer, CubeField, Gravity Guy
Nick
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: Today at 15:20:51
Date Registered: 05 June, 2011, 20:01:07
Location: 51° 12′ 34″ N, 3° 13′ 31″ E
Posts: 1179


Total Post Ratings: +158

View Profile WWW
« Reply #76 on: 06 January, 2012, 21:33:58 »
0

wow, amazing.. those look really native Shocked congratz
Logged

AzNg0d1030
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 19 May, 2013, 23:04:34
Date Registered: 26 October, 2011, 04:43:09
Location: Over the rainbow
Posts: 488


Total Post Ratings: +37

View Profile
« Reply #77 on: 07 January, 2012, 03:25:27 »
0

Dang I can't wait to update my 0.6 to this one you're working on.  Seems amazing!  All these little additions are making this one great app
Logged

What? WHAT? WHATTTT?Huh??

You just lost the game.

Suck it up.
Chockosta
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 19:34:35
Date Registered: 03 June, 2011, 20:14:17
Location: France
Posts: 440


Topic starter
Total Post Ratings: +159

View Profile
« Reply #78 on: 20 January, 2012, 23:37:49 »
0

I finished the GUI engine, it now handles mouse events and everything. (almost)
So now I start to write new functions !

If you are interested, here is the source code of a demo :

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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
--[[

window : {wtype,name,buttons,layout,size}
   --> wtype : "dialogBox","custom"
   --> size : {sizeX,sizeY} (only for custom)

buttons : {{"name",function1},{"name",function2},...}

layout : {{"type",...}}
   --> type : "label","textBox","colorSlider","list"

label : {text,x,y}

textBox : {text,x,y,sizeX,cursor}

colorSlider : {color,value,x,y}
   --> color : "red","green","blue"

list : {elements,scroll,x,y,sizeX,sizeY,selected}

]]


--GUI GESTION
gui={}
gui.windows={}
gui.dialogBox={}
gui.custom={}
gui.textBox={}
gui.colorSlider={}
gui.list={}
gui.resized=false
gui.img={}
gui.img.upButton=image.new("\011\000\000\000\010\000\000\000\000\000\000\000\022\000\000\000\016\000\001\0001\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\198\255\255\255\255\255\255\255\255\156\243\255\255\255\255\255\255\255\2551\1981\198\255\255\255\255\255\255\214\218\000\128\214\218\255\255\255\255\255\2551\1981\198\255\255\255\255\247\222B\136\000\128B\136\247\222\255\255\255\2551\1981\198\255\255\247\222B\136!\132\000\128!\132B\136\247\222\255\2551\1981\198\247\222B\136!\132B\136R\202B\136!\132B\136\247\2221\1981\198\132\144B\136B\136\247\222\255\255\247\222B\136B\136\132\1441\1981\198\156\243\132\144\247\222\255\255\255\255\255\255\247\222\132\144\189\2471\1981\198\255\255\222\251\255\255\255\255\255\255\255\255\255\255\222\251\255\2551\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\198")
gui.img.downButton=image.new("\011\000\000\000\010\000\000\000\000\000\000\000\022\000\000\000\016\000\001\0001\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\198\255\255\222\251\255\255\255\255\255\255\255\255\255\255\222\251\255\2551\1981\198\156\243\132\144\247\222\255\255\255\255\255\255\247\222\132\144\189\2471\1981\198\132\144B\136B\136\247\222\255\255\247\222B\136B\136\132\1441\1981\198\247\222B\136!\132B\136R\202B\136!\132B\136\247\2221\1981\198\255\255\247\222B\136!\132\000\128!\132B\136\247\222\255\2551\1981\198\255\255\255\255\247\222B\136\000\128B\136\247\222\255\255\255\2551\1981\198\255\255\255\255\255\255\214\218\000\128\214\218\255\255\255\255\255\2551\1981\198\255\255\255\255\255\255\255\255\156\243\255\255\255\255\255\255\255\2551\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\198")


--GUI UTILS


function gui.errorMessage(errorText)
 gui.addWindow("dialogBox","Error",{{"OK",function() gui.closeWindow() refresh() end}},errorText)
end

function gui.addWindow(windowType,windowName,windowButtons,windowLayout,windowSize)
 table.insert(gui.windows,{wtype=windowType,name=windowName,buttons=windowButtons,layout=windowLayout,size=windowSize})
 gui.focus=-1
 refresh()
end

function gui.closeWindow()
 table.remove(gui.windows)
 gui.focus=-1
 refresh()
end

function gui.nbWindows()
 return #gui.windows
end

function gui.current()
 return gui.windows[#gui.windows]
end

function gui.refreshCurrent()
 local current=gui.current()
 local sizeX,sizeY=unpack(current.size)
 local xPos,yPos=(width()-sizeX)/2,(height()-sizeY-15)/2
 refresh(xPos,yPos,sizeX,sizeY+39)
end



--GUI EVENTS
function gui.mouseDown(xPos,yPos)
 if gui.nbWindows()>=1 then
  local window=gui.current()
  if window.size then
   local sizeX,sizeY=unpack(window.size)
   local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
   if xPos>x and xPos<x+sizeX and yPos>y then
    if yPos<y+sizeY and gui.current().wtype=="custom" then
     gui.setFocus(xPos-x,yPos-y,window)
    elseif yPos>y+sizeY and yPos<y+sizeY+39 then
     gui.buttonDown(xPos,yPos,window.buttons)
    end
   end
  end
 end
end

function gui.paint(gc)
 for i,e in pairs(gui.windows) do
  gui[e.wtype].paint(gc,e,i)
 end
 gui.resized=false
end

function gui.resize()
 gui.resized=true
end

function gui.tabKey()
 if gui.nbWindows()>0 then
  gui.moveFocus(1)
  gui.refreshCurrent()
 end
end

function gui.backtabKey()
 if gui.nbWindows()>0 then
  gui.moveFocus(-1)
  gui.refreshCurrent()
 end
end

function gui.arrowKey(arrow)
 if gui.nbWindows()>0 then
  if gui.focus<0 then
   if arrow=="left" then
    gui.moveFocus(1)
    gui.refreshCurrent()
   elseif arrow=="right" then
    gui.moveFocus(-1)
    gui.refreshCurrent()
   end
  elseif gui.focus>0 then
   local currentElem=gui.current().layout[gui.focus]
   if gui[currentElem[1]].arrowKey then
    gui[currentElem[1]].arrowKey(arrow,currentElem)
    gui.refreshCurrent()
   end
  end
 end
end

function gui.enterKey()
 if gui.nbWindows()>0 then
  if gui.focus<0 then
   gui.current().buttons[-gui.focus][2]()
  end
 end
end

function gui.charIn(char)
 if gui.nbWindows()>0 then
  if gui.focus>0 then
   local currentElem=gui.current().layout[gui.focus]
   if gui[currentElem[1]].charIn then
    gui[currentElem[1]].charIn(char,currentElem)
    gui.refreshCurrent()
   end
  end
 end
end

function gui.backspaceKey()
 if gui.nbWindows()>0 then
  if gui.focus>0 then
   local currentElem=gui.current().layout[gui.focus]
   if gui[currentElem[1]].backspaceKey then
    gui[currentElem[1]].backspaceKey(currentElem)
    gui.refreshCurrent()
   end
  end
 end
end

function gui.escapeKey()
 if gui.nbWindows()>0 then
  gui.closeWindow()
 end
end



--GUI LAYOUT ELEMENTS EVENTS

function gui.textBox.charIn(char,textBox)
 if string.len(char)==1 then
  textBox.prev={textBox.text,textBox.cursor}
  textBox.text=string.usub(textBox.text,1,textBox.cursor)..char..string.usub(textBox.text,textBox.cursor+1)
  textBox.cursor=textBox.cursor+1
 end
end

function gui.textBox.arrowKey(arrow,textBox)
 if arrow=="right" and textBox.cursor<string.len(textBox.text) then
  textBox.cursor=textBox.cursor+1
 elseif arrow=="left" and textBox.cursor>0 then
  textBox.cursor=textBox.cursor-1
 end
end

function gui.textBox.mouseDown(textBox,x)
 textBox.setCursor=x-2
end

function gui.textBox.backspaceKey(textBox)
 if string.len(textBox.text)>0 then
  textBox.text=string.usub(textBox.text,1,textBox.cursor-1)..string.usub(textBox.text,textBox.cursor+1)
  textBox.cursor=textBox.cursor-1
 end
end

function gui.colorSlider.arrowKey(arrow,slider)
 if arrow=="right" then
  slider.value=slider.value<250 and slider.value+5 or 255
 elseif arrow=="left" then
  slider.value=slider.value>5 and slider.value-5 or 0
 end
end

function gui.colorSlider.mouseDown(slider,x)
 x=(x-2)*4
 x=x>0 and x or 0
 x=x<255 and x or 255
 slider.value=x
end

function gui.list.arrowKey(arrow,list)
 if arrow=="up" and list.selected>1 then
  list.selected=list.selected-1
 elseif arrow=="down" and list.selected<#list.elements then
  list.selected=list.selected+1
 end
end

function gui.list.mouseDown(list,x,y)
 if x>list.sizeX-17 then
  if y>list.sizeY/2 and list.selected<#list.elements then
   list.selected=list.selected+1
  elseif y<list.sizeY/2 and list.selected>1 then
   list.selected=list.selected-1
  end
 else
  list.setSelection=y
 end
end


--GUI MISC FUNCTIONS

function gui.moveFocus(nb)
 local currentWindow=gui.current()
 local test=false
 local originalFocus=gui.focus
 nb=gui.focus<0 and -nb or nb
 gui.focus=gui.focus+nb
 if #currentWindow.buttons==0 then
  gui.focus=-1
  test=true
 end
 while not test do
  if gui.focus<0 then
   if -gui.focus<=#currentWindow.buttons then
    test=true
   else
    gui.focus=1
    nb=1
   end
  elseif gui.focus==0 then
   if originalFocus<0 then
    if currentWindow.wtype=="dialogBox" then
     gui.focus=-#currentWindow.buttons
     test=true
    elseif #currentWindow.layout==0 then
     gui.focus=-#currentWindow.buttons
     test=true
    else
     gui.focus=#currentWindow.layout
    end
   else
    gui.focus=nb<0 and -1 or 1
   end
  else
   if currentWindow.wtype=="dialogBox" then
    test=true
    gui.focus=-1
   elseif currentWindow.wtype=="custom" then
    if gui.focus<=#currentWindow.layout then
     if currentWindow.layout[gui.focus][1]=="label" then
      gui.focus=gui.focus+(nb<0 and -1 or 1)
     else
      test=true
     end
    else
     test=true
     gui.focus=-1
    end
   end
  end
 end
end

function gui.buttonDown(x,y,buttons)
 for i,e in pairs(buttons) do
  if x>e.pos and x<e.pos+e.size then
   gui.focus=-i
   e[2]()
  end
 end
end

function gui.setFocus(x,y,window)
 for i,e in pairs(window.layout) do
  if e[1]=="list" then
   if x>e.x and y>e.y and x<e.x+e.sizeX and y<e.y+e.sizeY then
    gui.focus=i
    gui.list.mouseDown(e,x-e.x,y-e.y)
   end
  elseif e[1]=="textBox" then
   if x>e.x and y>e.y and x<e.x+e.sizeX and y<e.y+22 then
    gui.focus=i
    gui.textBox.mouseDown(e,x-e.x,y-e.y)
   end
  elseif e[1]=="colorSlider" then
   if x>e.x and y>e.y and x<e.x+68 and y<e.y+20 then
    gui.focus=i
    gui.colorSlider.mouseDown(e,x-e.x,y-e.y)
   end
  end
 end
 gui.refreshCurrent()
end



--GUI DRAWING

function gui.dialogBox.paint(gc,dialogBox,windowID)
 local sizeX,sizeY
 if not dialogBox.size then
  gc:setFont("sansserif","r",10)
  sizeX=improvedStr.width(gc,dialogBox.layout)+24
  sizeY=improvedStr.height(gc,dialogBox.layout)+17
  gui.windows[windowID].size={sizeX,sizeY}
 else
  sizeX,sizeY=unpack(dialogBox.size)
 end
 gui.paintWindowBG(gc,dialogBox.name,sizeX,sizeY)
 gui.paintTextArea(gc,dialogBox.layout,sizeX,sizeY)
 gui.paintButtons(gc,dialogBox.buttons,sizeX,sizeY,windowID)
end

function gui.custom.paint(gc,window,windowID)
 gui.paintWindowBG(gc,window.name,window.size[1],window.size[2])
 gui.paintLayout(gc,window.layout,window.size[1],window.size[2])
 gui.paintButtons(gc,window.buttons,window.size[1],window.size[2],windowID)
end





function gui.paintLayout(gc,layout,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 for i,e in pairs(layout) do
  if e[1]=="textBox" then
   gui.paintTextBox(gc,e,x,y,gui.focus==i)
  elseif e[1]=="label" then
   gui.paintLabel(gc,e,x,y)
  elseif e[1]=="colorSlider" then
   gui.paintColorSlider(gc,e,x,y,gui.focus==i)
  elseif e[1]=="list" then
   gui.paintList(gc,e,x,y,gui.focus==i)
  end
 end
end

function gui.paintLabel(gc,label,x,y)
 gc:setFont("sansserif","r",10)
 if label.text=="colorLabel" then
  gc:setColorRGB(0,0,0)
  gc:fillRect(x+label.x,y+label.y,30,20)
  gc:setColorRGB(unpack(color))
  gc:fillRect(x+label.x+1,y+label.y+1,28,18)
 else
  gc:setColorRGB(0,0,0)
  gc:drawString(label.text,x+label.x,y+label.y,"top")
 end
end

function gui.paintTextBox(gc,textBox,x,y,selected)
 if gc:getStringWidth(textBox.text)>textBox.sizeX-5 then
  textBox.prev=textBox.prev or {"",0}
  textBox.text,textBox.cursor=unpack(textBox.prev)
 end
 if textBox.setCursor then
  textBox.cursor=string.len(textBox.text)
  for i=string.len(textBox.text),1,-1 do
   if gc:getStringWidth(string.sub(textBox.text,1,i))>textBox.setCursor then
    textBox.cursor=i-1
   end
  end
  textBox.setCursor=nil
 end
 if selected then
  gc:setColorRGB(50,150,190)
  gc:fillRect(x+textBox.x-2,y+textBox.y-2,textBox.sizeX+5,27)
 end
 gc:setColorRGB(255,255,255)
 gc:fillRect(x+textBox.x,y+textBox.y,textBox.sizeX,22)
 gc:setColorRGB(0,0,0)
 gc:drawRect(x+textBox.x,y+textBox.y,textBox.sizeX,22)
 gc:setFont("sansserif","r",10)
 gc:drawString(textBox.text,x+textBox.x+3,y+textBox.y+1,"top")
 if selected then
  gc:fillRect(gc:getStringWidth(string.usub(textBox.text,1,textBox.cursor))+x+textBox.x+3,y+textBox.y+2,1,19)
 end
end

function gui.paintColorSlider(gc,slider,x,y,selected)
 if selected then
  gc:setColorRGB(50,150,190)
  gc:fillRect(x+slider.x-2,y+slider.y-2,72,24)
 end
 gc:setColorRGB(0,0,0)
 gc:fillRect(x+slider.x,y+slider.y,68,20)
 for i=0,63 do
  gc:setColorRGB(slider.color=="red" and i*4 or color[1],slider.color=="green" and i*4 or color[2],slider.color=="blue" and i*4 or color[3])
  gc:fillRect(x+slider.x+i+2,y+2+slider.y,1,16)
 end
 if isCX() then
  gc:setColorRGB(255-slider.value,255-slider.value,255-slider.value)
 else
  gc:setColorRGB(255,255,255)
 end
 gc:fillRect(x+slider.x+slider.value/4+1,y+slider.y-2,3,24)
end

function gui.paintList(gc,list,x,y,selected)
 if selected then
  gc:setColorRGB(50,150,190)
  gc:fillRect(x+list.x-2,y+list.y-2,list.sizeX+4,list.sizeY+4)
 end
 gc:setColorRGB(0,0,0)
 gc:fillRect(list.x+x,list.y+y,list.sizeX,list.sizeY)
 gc:setColorRGB(255,255,255)
 gc:fillRect(list.x+1+x,list.y+1+y,list.sizeX-2,list.sizeY-2)
 gc:setColorRGB(100,100,100)
 gc:drawImage(gui.img.upButton,list.x+x+list.sizeX-14,y+list.y+3)
 gc:drawImage(gui.img.downButton,list.x+x+list.sizeX-14,y+list.y+list.sizeY-13)
 gc:drawRect(list.x+x+list.sizeX-14,y+list.y+15,10,list.sizeY-31)
 gc:setFont("sansserif","r",10)
 local fontHeight=gc:getStringHeight("a")
 local capacity=math.floor(list.sizeY/fontHeight)
 if list.setSelection then
  list.selected=math.floor(list.setSelection/fontHeight)+1+list.scroll
  list.selected=list.selected<#list.elements and list.selected or #list.elements
  list.setSelection=nil
 end
 if list.selected<list.scroll+1 then
  list.scroll=list.selected-1
 elseif list.selected>list.scroll+capacity then
  list.scroll=list.selected-capacity
 end
 if list.scroll>#list.elements-capacity then
  local scroll=#list.elements-capacity
  scroll=scroll<0 and 0 or scroll
  list.scroll=scroll
 end
 if #list.elements*fontHeight>list.sizeY then
  local scrollBarSize=(list.sizeY-31)*list.sizeY/(#list.elements*fontHeight)
  gc:fillRect(list.x+x+list.sizeX-14,y+list.y+15+list.scroll*(list.sizeY-31)/#list.elements,11,scrollBarSize)
 end
 gc:setColorRGB(0,0,0)
 local step=0
 for i=list.scroll+1,list.scroll+capacity do
  if list.elements[i] then
   if list.selected==i then
    gc:setColorRGB(50,150,190)
    gc:fillRect(list.x+x+1,list.y+y+step*fontHeight+1,list.sizeX-16,fontHeight-2)
    gc:setColorRGB(0,0,0)
   end
   gc:drawString(list.elements[i],list.x+x+3,list.y+y+step*fontHeight,"top")
   step=step+1
  end
 end
end

function gui.paintButtons(gc,buttons,sizeX,sizeY,windowID)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 gc:setFont("sansserif","r",10)
 if (not buttons[1].size) or gui.resized then
  local totalSize,size,pos=-7,{},{}
  for i,e in pairs(buttons) do
   size[i]=gc:getStringWidth(e[1])+10
   totalSize=totalSize+size[i]+7
  end
  pos[1]=(width()-totalSize)/2
  for i=2,#buttons do
   pos[i]=pos[i-1]+size[i-1]+7
  end
  for i,e in pairs(buttons) do
   gui.windows[windowID].buttons[i].size=size[i]
   gui.windows[windowID].buttons[i].pos=pos[i]
  end
  buttons=gui.windows[windowID].buttons
 end
 for i,e in pairs(buttons) do
  gc:setColorRGB(136,136,136)
  gc:fillRect(e.pos,y+sizeY+9,e.size,23)
  gc:fillRect(e.pos+1,y+sizeY+8,e.size-2,25)
  gc:fillRect(e.pos+2,y+sizeY+7,e.size-4,27)
  gc:setColorRGB(255,255,255)
  gc:fillRect(e.pos+2,y+sizeY+9,e.size-4,23)
  gc:setColorRGB(0,0,0)
  gc:drawString(e[1],e.pos+5,y+sizeY+20,"middle")
 end
 if gui.focus<0 and windowID==gui.nbWindows() then
  local button=buttons[-gui.focus]
  if isCX() then
   gc:setColorRGB(50,150,190)
  else
   gc:setColorRGB(0,0,0)
  end
  gc:drawRect(button.pos-3,y+sizeY+4,button.size+5,32)
  gc:drawRect(button.pos-2,y+sizeY+5,button.size+3,30)
 end
end

function gui.paintTextArea(gc,text,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if isCX() then
  gc:setColorRGB(128,128,128)
 else
  gc:setColorRGB(255,255,255)
 end
 gc:drawRect(x+6,y+6,sizeX-13,sizeY-13)
 gc:setColorRGB(0,0,0)
 gc:setFont("sansserif","r",10)
 improvedStr.draw(gc,text,x+12,y+9)
end

function gui.paintWindowBG(gc,name,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if isCX() then
  gc:setColorRGB(100,100,100)
 else
  gc:setColorRGB(200,200,200)
 end
 gc:fillRect(x-1,y-23,sizeX+4,sizeY+65)
 gc:fillRect(x,y-22,sizeX+4,sizeY+65)
 gc:fillRect(x+1,y-21,sizeX+4,sizeY+65)
 if isCX() then
  gc:setColorRGB(128,128,128)
 else
  gc:setColorRGB(0,0,0)
 end
 gc:fillRect(x-2,y-24,sizeX+4,sizeY+65)
 if isCX() then
  for i=1,22 do
   gc:setColorRGB(32+i*3,32+i*3,32+i*3)
   gc:fillRect(x,y+i-23,sizeX,1)
  end
 else
  gc:setColorRGB(0,0,0)
  gc:fillRect(x,y-22,sizeX,22)
 end
 gc:setColorRGB(255,255,255)
 gc:setFont("sansserif","r",10)
 gc:drawString(name,x+2,y-9,"baseline")
 gc:setColorRGB(224,224,224)
 gc:fillRect(x,y,sizeX,sizeY+39)
 gc:setColorRGB(128,128,128)
 gc:fillRect(x+6,y+sizeY,sizeX-12,2)
end





--MULTIPLE LINE STRING GESTION
improvedStr={}

function improvedStr.draw(gc,str,x,y)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 for i,e in pairs(table1) do
  gc:drawString(e,x,y+(i-1)*gc:getStringHeight("a"),"top")
 end
end

function improvedStr.width(gc,str)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 local table2={}
 for i,e in pairs(table1) do
  table2[i]=gc:getStringWidth(e)
 end
 table.sort(table2)
 return table2[#table2]
end

function improvedStr.height(gc,str)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 return gc:getStringHeight("a")*#table1
end

function improvedStr.cut(str)
 local table1,finished={},false
 local posStart,posEnd,last=1,0,1
 while not finished do
  posStart,posEnd=string.find(str,"\n",posEnd+1)
  if posStart then
   table.insert(table1,string.sub(str,last,posStart-1))
   last=posEnd+1
  else
   table.insert(table1,string.sub(str,last))
   finished=true
  end
 end
 return unpack(table1)
end


















color={0,255,0}
 
function width() return platform.window:width() end
function height() return platform.window:height() end
function isCX() return platform.isColorDisplay() end
function refresh(x,y,width,height) platform.window:invalidate(x,y,width,height) end
 
function openCustom()
 gui.addWindow("custom","custom",{{"Close",function() gui.closeWindow() end}},{{"label",text="Hello !",x=15,y=5},{"textBox",text="type here",cursor=3,x=10,y=30,sizeX=80},{"colorSlider",color="red",value=200,x=15,y=70},{"list",x=100,y=10,sizeX=70,sizeY=80,scroll=0,selected=1,elements={"elem a","elem b","elem c","elem d","elem e","elem f","another","...","Blue","Yellow","Green"}}},{200,100})
end

gui.addWindow("dialogBox","Title",{{"Error message",function() gui.errorMessage("Error test") end},{"Open custom window",function() openCustom() end}},"This text shows multi-line text functions :\nLorem ipsum dolor sit amet\n...")

function on.paint(gc)
 gui.paint(gc)
end

function on.mouseDown(x,y)
 gui.mouseDown(x,y)
end

function on.resize()
 gui.resize()
end

function on.tabKey()
 gui.tabKey()
end

function on.backtabKey()
 gui.backtabKey()
end

function on.enterKey()
 gui.enterKey()
end

function on.arrowKey(ar)
 gui.arrowKey(ar)
end

function on.charIn(ch)
 gui.charIn(ch)
end

function on.escapeKey()
 gui.escapeKey()
end

function on.backspaceKey()
 gui.backspaceKey()
end
And a screenie is attached.


* ScreenShot109.png (7.84 KB, 320x240 - viewed 214 times.)
Logged

Chockosta (Loic Pujet) - Sorry for my poor English...
Look at my projects :
in C code : Periodic table, Space invaders, Fall, Snake, Minesweeper, nCraft (WIP)
in Lua : Snake, Space invaders, Bobby Carrot, Minesweeper, Mazes 3D, nSpaint, FreeCell, Tiny3D-Viewer, CubeField, Gravity Guy
Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: Today at 19:54:09
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7813


Total Post Ratings: +706

View Profile WWW
« Reply #79 on: 28 January, 2012, 01:46:55 »
0

That UI looks great ... almost native Shocked Nice job! Should the titles be shifted over a bit, though?
Logged




Chockosta
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 19:34:35
Date Registered: 03 June, 2011, 20:14:17
Location: France
Posts: 440


Topic starter
Total Post Ratings: +159

View Profile
« Reply #80 on: 28 January, 2012, 13:59:34 »
0

You're right, I just modified that.

Right now I'm busy integrating it to nSpaint...
It should be released next week.
Logged

Chockosta (Loic Pujet) - Sorry for my poor English...
Look at my projects :
in C code : Periodic table, Space invaders, Fall, Snake, Minesweeper, nCraft (WIP)
in Lua : Snake, Space invaders, Bobby Carrot, Minesweeper, Mazes 3D, nSpaint, FreeCell, Tiny3D-Viewer, CubeField, Gravity Guy
apcalc
The Game
Coder Of Tomorrow
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 20:41:21
Date Registered: 20 March, 2010, 16:31:47
Location: 2003 UB313
Posts: 1393


Total Post Ratings: +118

View Profile
« Reply #81 on: 30 January, 2012, 03:43:34 »
0

That UI looks great ... almost native Shocked Nice job! Should the titles be shifted over a bit, though?

Agreed, it looks great! Wink
Logged


Chockosta
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 19:34:35
Date Registered: 03 June, 2011, 20:14:17
Location: France
Posts: 440


Topic starter
Total Post Ratings: +159

View Profile
« Reply #82 on: 11 April, 2012, 18:33:28 »
+3

I don't know if anyone still use this, but I just finished it.
(I spent too much time on this to give up)

So, here is nSpaint 0.7. It features :


-The same tools and filters as in nSpaint 0.6
-A native-like GUI (in nAnima too)
-A file manager, which can be used to delete images (in nAnima too)
-A tool to copy the current image code to the clipboard (really useful to Lua developpers!)
-A tool to paste an image if there's one in the clipboard
-Undo and redo! (5 times max)
-A option to erase all the image
-A nice color selecter
-Tools to flip/rotate the image
-A filter which replace a color with another one
-A filter which erases a color
-Two filters to increase and decrease brightness
-A 'help' window for each tool
-A splash screen (in nAnima too)
-You can move the cursor with the mouse
-The image is automatically moved when the cursor goes off the screen
-The cursor is moved when you scroll

DOWNLOAD

Screenies:



* nSpaint 0.7.zip (47.77 KB - downloaded 80 times.)
« Last Edit: 11 April, 2012, 18:34:38 by Chockosta » Logged

Chockosta (Loic Pujet) - Sorry for my poor English...
Look at my projects :
in C code : Periodic table, Space invaders, Fall, Snake, Minesweeper, nCraft (WIP)
in Lua : Snake, Space invaders, Bobby Carrot, Minesweeper, Mazes 3D, nSpaint, FreeCell, Tiny3D-Viewer, CubeField, Gravity Guy
Jonius7
aka jhgenius
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 06:58:52
Date Registered: 03 September, 2010, 02:50:11
Location: Gold Coast, Australia
Posts: 1743


Total Post Ratings: +50

View Profile WWW
« Reply #83 on: 11 April, 2012, 18:38:59 »
0

Wow I was definitely not aware of this. This looks mega useful and very graphical too. How do you get those dialogue boxes up?
Logged



Userbars.com is down?
+9001
Intermediate TI-nspire Basic Programmer
Programmed some CASIO Basic in the past
DJ_O Music Discographist Wink
Userbars for these coming... in the process

My Released and Announced Projects (Updated 2013/01/29)
TI-nspire BASIC
TI-nspire Hold 'em | Health Bar | Scissors Paper Rock | Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled)

TI-nspire Lua
Numstrat | TI-nspire Hold 'em Lua | Terraria (coming soon)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Spoiler for Other Stuff:
Spoiler for Want your own HonestDownloads userbar?:
Hello! Do you want to show your affection for my website, HonestDownloads? Then here is a userbar I specially created earlier just for HonestDownloads users!

To add it to your signature just copy and paste the code below into your sig and you'll become an instant supporter of my website!

1
[URL=http://www.jhgenius01.webs.com][IMG]http://s1.bild.me/bilder/060112/3684792HDuserbaruser.png[/IMG][/URL]
Spoiler for My TI-nspire Basic Programs (Updated 2012/04/15):
***List of Programs in the TI-nspire Stadium***
Group Release 2012/04/07 on omnimaga.org

Games
   Noteable Release    ticalc.org Release Development/Not Publicly Released
2010/05/08 TI-nspire Hold 'em
   2012/04/07 v1.1.2   2012/04/10 v1.1.3  2012/04/14 v1.2.1
2010/08/03 Cosmic Legions
   2012/04/07 v0.2.2.2 (1st Release)
2010/08/12 Battle of 16s
   2012/04/07 v0.2.7
2010/09/10 Health Bar
   2012/04/07 v1.2     2012/04/02 v1.0   
2010/12/04 sTIck RPG
   2012/04/07 v0.1.5.2
2011/01/09 Monopoly
   2012/04/07 v0.16    (1st Release)
2012/04/09 Scissors Paper Rock
   2012/04/14 v0.8.1

Miscellaneous
2010/11/07 中文 (Chinese) Demonstration
   2012/04/07 v1.3     (1st Release)

Potential/Minor Programs
2010/09/26 Shanghai Metro
   2012/04/07 v0.2     (1st Release)
2010/12/22 TI-nspire Programming Tutorials
   2012/04/07 v0.1     (1st Release)
2010/12/28 Casino Games
   Was not released.
2011/04/22 Interlink
   2012/04/07 v0.0.4   (1st Release)
2012/03/22 Hierarchy
   2012/04/07 v0.01

Demo Programs (some may become Potential Programs)
2010/06/23 Monopoly (Board)
   2012/04/07 Prototype
2010/07/14 Strategy Battle
   2012/04/07 v0.12
2010/10/05 JRPG
   2012/04/07 v0.2
2010/11/02 PlotGrid
   2012/04/07 v0.2
2010/11/24 civilizaTIon™
   2012/04/07 v0.11

Purely Informational
2011/01/05 TI-nspire Stadium Changelog
   2012/04/07 v2
   Created to list significant releases of my programs. A page similar to this List of Programs in the TI-nspire Stadium was included in the documentation of most of my programs until sometime in Late 2011/Early 2012.

All games and programs coded in TI-nspire Basic.
© 2010-2012 Jason Ho.
Last Updated 14 April 2012

jhgenius01.webs.com
Will be moving! Stay tuned for updates.
Spoiler for Progress of Doodle God Axe:
2011/12/21 4% - Progress Suspended, ideas of graphical sprites still uncertain
Spoiler for Other Other You Know What Other Stuff I'm Talking About Stuff Stuff (Updated 2012/01/17):
Chockosta
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 19:34:35
Date Registered: 03 June, 2011, 20:14:17
Location: France
Posts: 440


Topic starter
Total Post Ratings: +159

View Profile
« Reply #84 on: 11 April, 2012, 18:46:45 »
0

I created a GUI lib which imitates TI's one...
But if you want to use it, I have to warn you : It will not be easy at all to use in your code.
Here is its code :

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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725

----------------------------------------------------------------------------------------------------
------------------------  Nspaint GUI engine by Loic Pujet (Chockosta) -----------------------------
----------------------------------------------------------------------------------------------------

--[[
window : {wtype,name,buttons,layout,size}
   --> wtype : "dialogBox","custom"
   --> size : {sizeX,sizeY} (only for custom)

buttons : {{"name",function1},{"name",function2},...}

layout : {{"type",...}}
   --> type : "label","textBox","colorSlider","list"

label : {text,x,y,color}
   --> if color is given, a color label is displayed

textBox : {text,x,y,sizeX,cursor,func}

colorSlider : {color,value,x,y,func}
   --> color : "red","green","blue"

list : {elements,scroll,x,y,sizeX,sizeY,selected,func}  ]]


--GUI DATA
gui={}
gui.windows={}
gui.dialogBox={}
gui.custom={}
gui.textBox={}
gui.colorSlider={}
gui.list={}
gui.resized=false
gui.img={}
gui.img.upButton=image.new("\011\000\000\000\010\000\000\000\000\000\000\000\022\000\000\000\016\000\001\0001\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\198\255\255\255\255\255\255\255\255\156\243\255\255\255\255\255\255\255\2551\1981\198\255\255\255\255\255\255\214\218\000\128\214\218\255\255\255\255\255\2551\1981\198\255\255\255\255\247\222B\136\000\128B\136\247\222\255\255\255\2551\1981\198\255\255\247\222B\136!\132\000\128!\132B\136\247\222\255\2551\1981\198\247\222B\136!\132B\136R\202B\136!\132B\136\247\2221\1981\198\132\144B\136B\136\247\222\255\255\247\222B\136B\136\132\1441\1981\198\156\243\132\144\247\222\255\255\255\255\255\255\247\222\132\144\189\2471\1981\198\255\255\222\251\255\255\255\255\255\255\255\255\255\255\222\251\255\2551\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\198")
gui.img.downButton=image.new("\011\000\000\000\010\000\000\000\000\000\000\000\022\000\000\000\016\000\001\0001\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\198\255\255\222\251\255\255\255\255\255\255\255\255\255\255\222\251\255\2551\1981\198\156\243\132\144\247\222\255\255\255\255\255\255\247\222\132\144\189\2471\1981\198\132\144B\136B\136\247\222\255\255\247\222B\136B\136\132\1441\1981\198\247\222B\136!\132B\136R\202B\136!\132B\136\247\2221\1981\198\255\255\247\222B\136!\132\000\128!\132B\136\247\222\255\2551\1981\198\255\255\255\255\247\222B\136\000\128B\136\247\222\255\255\255\2551\1981\198\255\255\255\255\255\255\214\218\000\128\214\218\255\255\255\255\255\2551\1981\198\255\255\255\255\255\255\255\255\156\243\255\255\255\255\255\255\255\2551\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\1981\198")



--------------------------------------------------------------------------------------------------------------
--------------------------------------------- USER FUNCTIONS -------------------------------------------------
--------------------------------------------------------------------------------------------------------------

function gui.errorMessage(errorText)
 gui.addWindow("dialogBox","Error",{{"OK",function() gui.closeWindow() end}},errorText)
end

function gui.addTextWindow(title,text)
 gui.addWindow("dialogBox",title,{},text)
end

function gui.addCustomWindow(title,width,height)
 gui.addWindow("custom",title,{},{},{width,height})
end

function gui.addButton(text,buttonFunction)
 table.insert(gui.current().buttons,{text,buttonFunction})
end

function gui.addTextBox(xPos,yPos,width,initialText,textBoxFunction)
 if gui.current().wtype=="custom" then
  table.insert(gui.current().layout,{"textBox",text=initialText,x=xPos,y=yPos,sizeX=width,cursor=0,func=textBoxFunction})
 end
end

function gui.addLabel(xPos,yPos,labelText,labelColor)
 if gui.current().wtype=="custom" then
  table.insert(gui.current().layout,{"label",text=labelText,x=xPos,y=yPos,color=labelColor})
 end
end

function gui.addSlider(xPos,yPos,sliderColor,initialValue,sliderFunction)
 if gui.current().wtype=="custom" then
  table.insert(gui.current().layout,{"colorSlider",value=initialValue,x=xPos,y=yPos,color=sliderColor,func=sliderFunction})
 end
end

function gui.addList(xPos,yPos,width,height,listElements,listFunction)
 if gui.current().wtype=="custom" then
  table.insert(gui.current().layout,{"list",x=xPos,y=yPos,sizeX=width,sizeY=height,scroll=0,selected=1,elements=listElements,func=listFunction})
 end
end

function gui.closeWindow()
 table.remove(gui.windows)
 gui.defaultFocus()
 refresh()
end

function gui.nbWindows()
 return #gui.windows
end

function gui.defaultFocus()
 if gui.nbWindows()>0 then
  gui.focus=-#gui.current().buttons
  gui.moveFocus(1)
  gui.focus=gui.focus>0 and gui.focus or -1
 end
end


--------------------------------------------------------------------------------------------------------------
--------------------------------------------END OF USER FUNCTIONS---------------------------------------------
--------------------------------------------------------------------------------------------------------------



--GUI UTILS

function gui.refreshCurrent()
 local current=gui.current()
 if current.size then
  local sizeX,sizeY=unpack(current.size)
  local xPos,yPos=(width()-sizeX)/2,(height()-sizeY-15)/2
  refresh(xPos,yPos,sizeX,sizeY+39)
 else
  refresh()
 end
end

function gui.addWindow(windowType,windowName,windowButtons,windowLayout,windowSize)
 table.insert(gui.windows,{wtype=windowType,name=windowName,buttons=windowButtons,layout=windowLayout,size=windowSize})
 gui.focus=-1
 refresh()
end

function gui.current()
 return gui.windows[#gui.windows]
end



--GUI EVENTS
function gui.mouseDown(xPos,yPos)
 if gui.nbWindows()>=1 then
  local window=gui.current()
  if window.size then
   local sizeX,sizeY=unpack(window.size)
   local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
   if xPos>x and xPos<x+sizeX and yPos>y then
    gui.saveTextBox()
    if yPos<y+sizeY and gui.current().wtype=="custom" then
     gui.setFocus(xPos-x,yPos-y,window)
    elseif yPos>y+sizeY and yPos<y+sizeY+39 then
     gui.buttonDown(xPos,yPos,window.buttons)
    end
   end
  end
 end
end

function gui.paint(gc)
 for i,e in pairs(gui.windows) do
  gui[e.wtype].paint(gc,e,i)
 end
 gui.resized=false
end

function gui.resize()
 gui.resized=true
end

function gui.tabKey()
 if gui.nbWindows()>0 then
  gui.saveTextBox()
  gui.moveFocus(1)
  gui.refreshCurrent()
 end
end

function gui.backtabKey()
 if gui.nbWindows()>0 then
  gui.saveTextBox()
  gui.moveFocus(-1)
  gui.refreshCurrent()
 end
end

function gui.arrowKey(arrow)
 if gui.nbWindows()>0 then
  if gui.focus<0 then
   if arrow=="left" then
    gui.moveFocus(-1)
    gui.refreshCurrent()
   elseif arrow=="right" then
    gui.moveFocus(1)
    gui.refreshCurrent()
   end
  elseif gui.focus>0 then
   local currentElem=gui.current().layout[gui.focus]
   if gui[currentElem[1]].arrowKey then
    gui[currentElem[1]].arrowKey(arrow,currentElem)
    gui.refreshCurrent()
   end
  end
 end
end

function gui.enterKey()
 if gui.nbWindows()>0 then
  if gui.focus<0 then
   gui.current().buttons[-gui.focus][2]()
  elseif gui.current().wtype=="custom" then
   gui.OKButton()
  end
 end
end

function gui.charIn(char)
 if gui.nbWindows()>0 then
  if gui.focus>0 then
   local currentElem=gui.current().layout[gui.focus]
   if gui[currentElem[1]].charIn then
    gui[currentElem[1]].charIn(char,currentElem)
    gui.refreshCurrent()
   end
  end
 end
end

function gui.backspaceKey()
 if gui.nbWindows()>0 then
  if gui.focus>0 then
   local currentElem=gui.current().layout[gui.focus]
   if gui[currentElem[1]].backspaceKey then
    gui[currentElem[1]].backspaceKey(currentElem)
    gui.refreshCurrent()
   end
  end
 end
end

function gui.escapeKey()
 if gui.nbWindows()>0 then
  gui.closeWindow()
 end
end



--GUI LAYOUT ELEMENTS EVENTS

function gui.textBox.charIn(char,textBox)
 if string.len(char)==1 then
  textBox.prev={textBox.text,textBox.cursor}
  textBox.text=string.usub(textBox.text,1,textBox.cursor)..char..string.usub(textBox.text,textBox.cursor+1)
  textBox.cursor=textBox.cursor+1
 end
end

function gui.textBox.arrowKey(arrow,textBox)
 if arrow=="right" and textBox.cursor<string.len(textBox.text) then
  textBox.cursor=textBox.cursor+1
 elseif arrow=="left" and textBox.cursor>0 then
  textBox.cursor=textBox.cursor-1
 end
end

function gui.textBox.mouseDown(textBox,x)
 textBox.setCursor=x-2
end

function gui.textBox.backspaceKey(textBox)
 if string.len(textBox.text)>0 and textBox.cursor>0 then
  textBox.text=string.usub(textBox.text,1,textBox.cursor-1)..string.usub(textBox.text,textBox.cursor+1)
  textBox.cursor=textBox.cursor-1
 end
end

function gui.colorSlider.arrowKey(arrow,slider)
 if arrow=="right" then
  slider.value=slider.value<250 and slider.value+5 or 255
  gui.executeFunction(slider,slider.value)
 elseif arrow=="left" then
  slider.value=slider.value>5 and slider.value-5 or 0
  gui.executeFunction(slider,slider.value)
 end
end

function gui.colorSlider.mouseDown(slider,x)
 x=(x-2)*4
 x=x>0 and x or 0
 x=x<255 and x or 255
 slider.value=x
 gui.executeFunction(slider,slider.value)
end

function gui.list.arrowKey(arrow,list)
 if arrow=="up" and list.selected>1 then
  list.selected=list.selected-1
  gui.executeFunction(list,list.elements[list.selected])
 elseif arrow=="down" and list.selected<#list.elements then
  list.selected=list.selected+1
  gui.executeFunction(list,list.elements[list.selected])
 end
end

function gui.list.mouseDown(list,x,y)
 if #list.elements>0 then
  if x>list.sizeX-17 then
   if y>list.sizeY/2 and list.selected<#list.elements then
    list.selected=list.selected+1
    gui.executeFunction(list,list.elements[list.selected])
   elseif y<list.sizeY/2 and list.selected>1 then
    list.selected=list.selected-1
    gui.executeFunction(list,list.elements[list.selected])
   end
  elseif list.fontHeight  then
   list.selected=math.floor(y/list.fontHeight)+1+list.scroll
   list.selected=list.selected<#list.elements and list.selected or #list.elements
   gui.executeFunction(list,list.elements[list.selected])
  end
 end
end


--GUI MISC FUNCTIONS

function gui.executeFunction(element,arg)
 if element.func then
  element.func(arg)
 end
end

function gui.saveTextBox()
 local elem=gui.current().layout[gui.focus]
 if elem then
  if elem[1]=="textBox" then
   gui.executeFunction(elem,elem.text)
  end
 end
end

function gui.moveFocus(nb)
 local currentWindow=gui.current()
 local test=false
 local originalFocus=gui.focus
 nb=gui.focus<0 and -nb or nb
 gui.focus=gui.focus+nb
 if #currentWindow.buttons==0 then
  gui.focus=-1
  test=true
 end
 while not test do
  if gui.focus<0 then
   if -gui.focus<=#currentWindow.buttons then
    test=true
   else
    gui.focus=1
    nb=1
   end
  elseif gui.focus==0 then
   if originalFocus<0 then
    if currentWindow.wtype=="dialogBox" then
     gui.focus=-#currentWindow.buttons
     test=true
    elseif #currentWindow.layout==0 then
     gui.focus=-#currentWindow.buttons
     test=true
    else
     gui.focus=#currentWindow.layout
     nb=-1
    end
   else
    gui.focus=nb<0 and -#currentWindow.buttons or 1
   end
  else
   if currentWindow.wtype=="dialogBox" then
    test=true
    gui.focus=-1
   elseif currentWindow.wtype=="custom" then
    if gui.focus<=#currentWindow.layout then
     if currentWindow.layout[gui.focus][1]=="label" then
      gui.focus=gui.focus+(nb<0 and -1 or 1)
     else
      test=true
     end
    else
     test=true
     gui.focus=-1
    end
   end
  end
 end
end

function gui.buttonDown(x,y,buttons)
 for i,e in pairs(buttons) do
  if x>e.pos and x<e.pos+e.size then
   gui.focus=-i
   e[2]()
  end
 end
end

function gui.OKButton()
 local buttons=gui.current().buttons
 for i=1,#buttons do
  if buttons[i][1]=="OK" then
   gui.saveTextBox()
   buttons[i][2]()
  end
 end
end

function gui.setFocus(x,y,window)
 for i,e in pairs(window.layout) do
  if e[1]=="list" then
   if x>e.x and y>e.y and x<e.x+e.sizeX and y<e.y+e.sizeY then
    gui.focus=i
    gui.list.mouseDown(e,x-e.x,y-e.y)
    gui.refreshCurrent()
   end
  elseif e[1]=="textBox" then
   if x>e.x and y>e.y and x<e.x+e.sizeX and y<e.y+22 then
    gui.focus=i
    gui.textBox.mouseDown(e,x-e.x,y-e.y)
    gui.refreshCurrent()
   end
  elseif e[1]=="colorSlider" then
   if x>e.x and y>e.y and x<e.x+68 and y<e.y+20 then
    gui.focus=i
    gui.colorSlider.mouseDown(e,x-e.x,y-e.y)
    gui.refreshCurrent()
   end
  end
 end
end



--GUI DRAWING

function gui.dialogBox.paint(gc,dialogBox,windowID)
 local sizeX,sizeY
 if not dialogBox.size then
  gc:setFont("sansserif","r",10)
  sizeX=improvedStr.width(gc,dialogBox.layout)+24
  sizeY=improvedStr.height(gc,dialogBox.layout)+17
  gui.windows[windowID].size={sizeX,sizeY}
 else
  sizeX,sizeY=unpack(dialogBox.size)
 end
 gui.paintWindowBG(gc,dialogBox.name,sizeX,sizeY)
 gui.paintTextArea(gc,dialogBox.layout,sizeX,sizeY)
 gui.paintButtons(gc,dialogBox.buttons,sizeX,sizeY,windowID)
end

function gui.custom.paint(gc,window,windowID)
 gui.paintWindowBG(gc,window.name,window.size[1],window.size[2])
 gui.paintLayout(gc,window.layout,window.size[1],window.size[2])
 gui.paintButtons(gc,window.buttons,window.size[1],window.size[2],windowID)
end





function gui.paintLayout(gc,layout,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 for i,e in pairs(layout) do
  if e[1]=="textBox" then
   gui.paintTextBox(gc,e,x,y,gui.focus==i)
  elseif e[1]=="label" then
   gui.paintLabel(gc,e,x,y)
  elseif e[1]=="colorSlider" then
   gui.paintColorSlider(gc,e,x,y,gui.focus==i)
  elseif e[1]=="list" then
   gui.paintList(gc,e,x,y,gui.focus==i)
  end
 end
end

function gui.paintLabel(gc,label,x,y)
 gc:setFont("sansserif","r",10)
 if label.color then
  gc:setColorRGB(0,0,0)
  gc:fillRect(x+label.x,y+label.y,30,20)
  gc:setColorRGB(unpack(label.color))
  gc:fillRect(x+label.x+1,y+label.y+1,28,18)
 else
  gc:setColorRGB(0,0,0)
  gc:drawString(label.text,x+label.x,y+label.y,"top")
 end
end

function gui.paintTextBox(gc,textBox,x,y,selected)
 if gc:getStringWidth(textBox.text)>textBox.sizeX-5 then
  textBox.prev=textBox.prev or {"",0}
  textBox.text,textBox.cursor=unpack(textBox.prev)
 end
 if textBox.setCursor then
  textBox.cursor=string.len(textBox.text)
  for i=string.len(textBox.text),1,-1 do
   if gc:getStringWidth(string.sub(textBox.text,1,i))>textBox.setCursor then
    textBox.cursor=i-1
   end
  end
  textBox.setCursor=nil
 end
 if selected then
  gc:setColorRGB(50,150,190)
  gc:fillRect(x+textBox.x-2,y+textBox.y-2,textBox.sizeX+5,27)
 end
 gc:setColorRGB(255,255,255)
 gc:fillRect(x+textBox.x,y+textBox.y,textBox.sizeX,22)
 gc:setColorRGB(0,0,0)
 gc:drawRect(x+textBox.x,y+textBox.y,textBox.sizeX-1,22)
 gc:setFont("sansserif","r",10)
 gc:drawString(textBox.text,x+textBox.x+3,y+textBox.y+1,"top")
 if selected then
  gc:fillRect(gc:getStringWidth(string.usub(textBox.text,1,textBox.cursor))+x+textBox.x+3,y+textBox.y+2,1,19)
 end
end

function gui.paintColorSlider(gc,slider,x,y,selected)
 if selected then
  gc:setColorRGB(50,150,190)
  gc:fillRect(x+slider.x-2,y+slider.y-2,72,24)
 end
 gc:setColorRGB(0,0,0)
 gc:fillRect(x+slider.x,y+slider.y,68,20)
 for i=0,63 do
  gc:setColorRGB(slider.color=="red" and i*4 or newColor[1],slider.color=="green" and i*4 or newColor[2],slider.color=="blue" and i*4 or newColor[3])
  gc:fillRect(x+slider.x+i+2,y+2+slider.y,1,16)
 end
 if isCX() then
  gc:setColorRGB(255-slider.value,255-slider.value,255-slider.value)
 else
  gc:setColorRGB(255,255,255)
 end
 gc:fillRect(x+slider.x+slider.value/4+1,y+slider.y-2,3,24)
end

function gui.paintList(gc,list,x,y,selected)
 if selected then
  gc:setColorRGB(50,150,190)
  gc:fillRect(x+list.x-2,y+list.y-2,list.sizeX+4,list.sizeY+4)
 end
 gc:setColorRGB(0,0,0)
 gc:fillRect(list.x+x,list.y+y,list.sizeX,list.sizeY)
 gc:setColorRGB(255,255,255)
 gc:fillRect(list.x+1+x,list.y+1+y,list.sizeX-2,list.sizeY-2)
 gc:setColorRGB(100,100,100)
 gc:drawImage(gui.img.upButton,list.x+x+list.sizeX-14,y+list.y+3)
 gc:drawImage(gui.img.downButton,list.x+x+list.sizeX-14,y+list.y+list.sizeY-13)
 gc:drawRect(list.x+x+list.sizeX-14,y+list.y+15,10,list.sizeY-31)
 gc:setFont("sansserif","r",10)
 local fontHeight=list.fontHeight
 if not fontHeight then
  list.fontHeight=gc:getStringHeight("a")
  fontHeight=list.fontHeight
 end
 local capacity=math.floor(list.sizeY/fontHeight)
 if list.selected<list.scroll+1 then
  list.scroll=list.selected-1
 elseif list.selected>list.scroll+capacity then
  list.scroll=list.selected-capacity
 end
 if list.scroll>#list.elements-capacity then
  local scroll=#list.elements-capacity
  scroll=scroll<0 and 0 or scroll
  list.scroll=scroll
 end
 if #list.elements*fontHeight>list.sizeY then
  local scrollBarSize=(list.sizeY-31)*list.sizeY/(#list.elements*fontHeight)
  gc:fillRect(list.x+x+list.sizeX-14,y+list.y+15+list.scroll*(list.sizeY-31)/#list.elements,11,scrollBarSize)
 end
 gc:setColorRGB(0,0,0)
 local step=0
 for i=list.scroll+1,list.scroll+capacity do
  if list.elements[i] then
   if list.selected==i then
    gc:setColorRGB(unpack(selected and {50,150,190} or {200,200,200}))
    gc:fillRect(list.x+x+1,list.y+y+step*fontHeight+1,list.sizeX-16,fontHeight-2)
    gc:setColorRGB(0,0,0)
   end
   gc:drawString(list.elements[i],list.x+x+3,list.y+y+step*fontHeight,"top")
   step=step+1
  end
 end
end

function gui.paintButtons(gc,buttons,sizeX,sizeY,windowID)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 gc:setFont("sansserif","r",10)
 if (not buttons[1].size) or gui.resized then
  local totalSize,size,pos=-7,{},{}
  for i,e in pairs(buttons) do
   size[i]=gc:getStringWidth(e[1])+10
   totalSize=totalSize+size[i]+7
  end
  pos[1]=(width()-totalSize)/2
  for i=2,#buttons do
   pos[i]=pos[i-1]+size[i-1]+7
  end
  for i,e in pairs(buttons) do
   gui.windows[windowID].buttons[i].size=size[i]
   gui.windows[windowID].buttons[i].pos=pos[i]
  end
  buttons=gui.windows[windowID].buttons
 end
 for i,e in pairs(buttons) do
  gc:setColorRGB(136,136,136)
  gc:fillRect(e.pos,y+sizeY+9,e.size,23)
  gc:fillRect(e.pos+1,y+sizeY+8,e.size-2,25)
  gc:fillRect(e.pos+2,y+sizeY+7,e.size-4,27)
  gc:setColorRGB(255,255,255)
  gc:fillRect(e.pos+2,y+sizeY+9,e.size-4,23)
  gc:setColorRGB(0,0,0)
  gc:drawString(e[1],e.pos+5,y+sizeY+20,"middle")
 end
 if gui.focus<0 and windowID==gui.nbWindows() then
  local button=buttons[-gui.focus]
  if isCX() then
   gc:setColorRGB(50,150,190)
  else
   gc:setColorRGB(0,0,0)
  end
  gc:drawRect(button.pos-3,y+sizeY+4,button.size+5,32)
  gc:drawRect(button.pos-2,y+sizeY+5,button.size+3,30)
 end
end

function gui.paintTextArea(gc,text,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if isCX() then
  gc:setColorRGB(128,128,128)
 else
  gc:setColorRGB(255,255,255)
 end
 gc:drawRect(x+6,y+6,sizeX-13,sizeY-13)
 gc:setColorRGB(0,0,0)
 gc:setFont("sansserif","r",10)
 improvedStr.draw(gc,text,x+12,y+9)
end

function gui.paintWindowBG(gc,name,sizeX,sizeY)
 local x,y=(width()-sizeX)/2,(height()-sizeY-15)/2
 if isCX() then
  gc:setColorRGB(100,100,100)
 else
  gc:setColorRGB(200,200,200)
 end
 gc:fillRect(x-1,y-23,sizeX+4,sizeY+65)
 gc:fillRect(x,y-22,sizeX+4,sizeY+65)
 gc:fillRect(x+1,y-21,sizeX+4,sizeY+65)
 if isCX() then
  gc:setColorRGB(128,128,128)
 else
  gc:setColorRGB(0,0,0)
 end
 gc:fillRect(x-2,y-24,sizeX+4,sizeY+65)
 if isCX() then
  for i=1,22 do
   gc:setColorRGB(32+i*3,32+i*3,32+i*3)
   gc:fillRect(x,y+i-23,sizeX,1)
  end
 else
  gc:setColorRGB(0,0,0)
  gc:fillRect(x,y-22,sizeX,22)
 end
 gc:setColorRGB(255,255,255)
 gc:setFont("sansserif","r",10)
 gc:drawString(name,x+4,y-9,"baseline")
 gc:setColorRGB(224,224,224)
 gc:fillRect(x,y,sizeX,sizeY+39)
 gc:setColorRGB(128,128,128)
 gc:fillRect(x+6,y+sizeY,sizeX-12,2)
end




--MULTIPLE LINE STRING GESTION
improvedStr={}

function improvedStr.draw(gc,str,x,y)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 for i,e in pairs(table1) do
  gc:drawString(e,x,y+(i-1)*gc:getStringHeight("a"),"top")
 end
end

function improvedStr.width(gc,str)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 local table2={}
 for i,e in pairs(table1) do
  table2[i]=gc:getStringWidth(e)
 end
 table.sort(table2)
 return table2[#table2]
end

function improvedStr.height(gc,str)
 str=tostring(str)
 local table1={improvedStr.cut(str)}
 return gc:getStringHeight("a")*#table1
end

function improvedStr.cut(str)
 local table1,finished={},false
 local posStart,posEnd,last=1,0,1
 while not finished do
  posStart,posEnd=string.find(str,"\n",posEnd+1)
  if posStart then
   table.insert(table1,string.sub(str,last,posStart-1))
   last=posEnd+1
  else
   table.insert(table1,string.sub(str,last))
   finished=true
  end
 end
 return unpack(table1)
end


----------------------------------------------------------------------------------------------------
------------------------------------- End of Nspaint GUI engine ------------------------------------
----------------------------------------------------------------------------------------------------
Logged

Chockosta (Loic Pujet) - Sorry for my poor English...
Look at my projects :
in C code : Periodic table, Space invaders, Fall, Snake, Minesweeper, nCraft (WIP)
in Lua : Snake, Space invaders, Bobby Carrot, Minesweeper, Mazes 3D, nSpaint, FreeCell, Tiny3D-Viewer, CubeField, Gravity Guy
adriweb
Editor
LV9 Veteran (Next: 1337)
*
Offline Offline

Gender: Male
Last Login: 23 May, 2013, 12:02:44
Date Registered: 13 April, 2011, 18:42:59
Location: South of France
Posts: 1197


Total Post Ratings: +185

View Profile WWW
« Reply #85 on: 11 April, 2012, 18:54:25 »
0

Very, very nice looking gui.

I wonder how it compares to EEPro's one in term of extensibility/power.
I know jim's way was amazing Tongue
Logged


TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation
cyanophycean314
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 03 May, 2013, 19:28:34
Date Registered: 07 December, 2011, 02:44:32
Location: Somewhere?
Posts: 363


Total Post Ratings: +42

View Profile
« Reply #86 on: 12 April, 2012, 10:01:36 »
0

The long awaited update is here! The screenies look very pretty.  Cheesy
Logged

Yeong
Eternally Young Scarlet Moon
LV12 Extreme Poster (Next: 5000)
************
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 01:44:48
Date Registered: 15 October, 2010, 04:29:49
Location: Arden, NC
Posts: 3694


Total Post Ratings: +260

View Profile
« Reply #87 on: 12 April, 2012, 10:48:27 »
0

Wow this now looks epic! Shocked
Logged

Project Redemption....

My project progresses:HERE
My Pastebin stuffs:HERE
Check your rate: HERE
My Animations: HERE
Spoiler for Images :D:

ノ◕ヮ◕)ノ:・゚ PENGUIN WAVE!!:„ø¤º°¨ ¨°º¤KEEP THE PENGUIN GOING ¸„ø¤º°¨ ¨°º¤øº LETS GO PENGUIN !¤¤º°¨¨°º¤øº¤ø„¸¸ø¤º°¨„ ø¤º°¨¨°º
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 19:28:54
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #88 on: 13 April, 2012, 02:07:58 »
0

Very nice work Smiley

I'm also working on a similar library for EEPro.
But my structure is a bit different than yours, it's closer to an actual graphical toolkit like gtk.
Your's will be much more lighter though, so that's also very good.
Logged

Chockosta
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 19:34:35
Date Registered: 03 June, 2011, 20:14:17
Location: France
Posts: 440


Topic starter
Total Post Ratings: +159

View Profile
« Reply #89 on: 13 April, 2012, 03:15:57 »
0

Yes, my "library" is just a tool to make window display and events easier, not a graphical toolkit.
It is obviously way more basic than a real GUI engine.
By the way, is there a way to have a look at your library's code ?
EDIT : Oh, I just saw the link in your signature, sorry Smiley
« Last Edit: 13 April, 2012, 03:20:12 by Chockosta » Logged

Chockosta (Loic Pujet) - Sorry for my poor English...
Look at my projects :
in C code : Periodic table, Space invaders, Fall, Snake, Minesweeper, nCraft (WIP)
in Lua : Snake, Space invaders, Bobby Carrot, Minesweeper, Mazes 3D, nSpaint, FreeCell, Tiny3D-Viewer, CubeField, Gravity Guy
Pages: 1 ... 4 5 [6] 7   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.475 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.