Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
24 May, 2013, 05:21:23 *
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 6244 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: 22 May, 2013, 20:19:59
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 238 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
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.163 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.