December 04, 2020, 11:26:44 AM

Author Topic: [bmx] blitzmax GUI by slenkar [ 1+ years ago ]  (Read 904 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] blitzmax GUI by slenkar [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : blitzmax GUI
Author : slenkar
Posted : 1+ years ago

Description : <a href="http://www.mediafire.com/?y1ytomjmtkz" target="_blank">http://www.mediafire.com/?y1ytomjmtkz[/url]

this is the download with images and demo


Code :
Code: BlitzMax
  1. Strict
  2.  
  3. Module keef.customgui
  4. Import brl.max2d
  5. Import brl.retro
  6. 'Import keef.gldraw
  7.  
  8.  
  9. Global time
  10. Global mouse_x
  11. Global mouse_y
  12. Global mouse_hit1
  13. Global mouse_hit2
  14. Global mouse_down1
  15.  
  16.  
  17.  
  18. Type gui_type
  19.  
  20. Field up_arrow:TImage
  21. Field down_arrow:TImage
  22. Field button_img:TImage
  23. Field button_over_img:TImage
  24. Field window_image:TImage
  25. Field border_image:TImage
  26. Field font:Timagefont
  27. Global gui_pointer:gui_type
  28. Field textr
  29. Field textg
  30. Field textb
  31.  
  32.  
  33.  
  34. Function init_gui(r,g,b,incstring$="",font:Timagefont=Null)
  35. gui_pointer:gui_type=New gui_type
  36. gui_pointer.font=font
  37. gui_pointer.down_arrow = LoadImage(incstring+"guiskindownarrow.png")
  38. gui_pointer.up_arrow=LoadImage(incstring+"guiskinuparrow.png")
  39. gui_pointer.window_image = LoadImage(incstring+"guiskinpaper.png")
  40. gui_pointer.button_img = LoadImage(incstring+"guiskinutton.png")
  41. gui_pointer.button_over_img=LoadImage(incstring+"guiskinuttonpressed.png")
  42. gui_pointer.border_image=LoadImage(incstring+"guiskinorder.png")
  43. gui_pointer.textr=r
  44. gui_pointer.textg=g
  45. gui_pointer.textb=b
  46. EndFunction
  47.  
  48.  
  49.  
  50. EndType
  51.  
  52. Function change_gui_text_color(r,g,b)
  53. If gui_type.gui_pointer<>Null
  54. gui_type.gui_pointer.textr=r
  55. gui_type.gui_pointer.textg=g
  56. gui_type.gui_pointer.textb=b
  57. EndIf
  58. EndFunction
  59.  
  60. Type gui_element Abstract
  61. Field x
  62. Field y
  63. Field width:Float
  64. Field height:Float
  65. Field mouse_over
  66. Field parent:gui_element
  67. Field up_arrow:gui_element
  68. Field down_arrow:gui_element
  69. Field text$
  70. Field rendered
  71. Field hidden
  72. Field gadget_list:TList=New TList
  73. Field active
  74. Field green,red,blue
  75. Field pressed
  76. Field pressed_timer
  77. Field font:Timagefont
  78. Global list:TList = New TList
  79. Global clicked
  80.  
  81. Method destroy()
  82. list.remove(Self)
  83. EndMethod
  84.  
  85. Method After:gui_element(the_list:TList)
  86.         Local link:TLink = the_List.FindLink(Self)
  87. If link <> Null
  88. link=link.NextLink()
  89. EndIf
  90.  
  91.         If link<>Null
  92.                 Return gui_element(link.Value())
  93.         Else
  94.                 Return Null
  95.         EndIf
  96. EndMethod
  97.  
  98.  
  99. Method ispressed()
  100. If Self.pressed=True
  101. Self.pressed=False
  102. Return True
  103. EndIf
  104. EndMethod
  105.  
  106. Method Before:gui_element(the_list:TList)
  107.         Local link:TLink = the_List.FindLink(Self)
  108. If link <> Null
  109. link=link.PrevLink()
  110. EndIf
  111.         If link<>Null
  112.  
  113.                 Return gui_element(link.Value())
  114.         Else
  115.                 Return Null
  116.         EndIf
  117. EndMethod
  118.  
  119. Method New()
  120. red=255
  121. blue=255
  122. green=255
  123. EndMethod
  124.  
  125. Method update(mouse_hit1,mouse_X,mouse_y)
  126. If detect_mouse_over(mouse_x,mouse_y)
  127. mouse_over = True
  128. Else
  129. mouse_over=False
  130. EndIf
  131. EndMethod
  132.  
  133. Method detect_mouse_over(mouse_X,Mouse_Y)
  134. If Mouse_X > x
  135. If Mouse_X < (x + width)
  136. If Mouse_Y > y
  137. If Mouse_Y < (y + height)
  138. Return True
  139. EndIf
  140. EndIf
  141. EndIf
  142. EndIf
  143.  
  144.  
  145.  
  146. EndMethod
  147.  
  148. Method render()
  149.  
  150. EndMethod
  151.  
  152. EndType
  153.  
  154.  
  155.  
  156. Type window Extends gui_element
  157.  
  158.  
  159.  
  160. Function Create:window(x,y,width,height)
  161. Local w:window = New window
  162. w.x = x
  163. w.y = y
  164. w.width = width
  165. w.height=height
  166. w.gadget_list = New TList
  167. w.hidden=True
  168. gui_element.list.addlast(w)
  169. Return w
  170. EndFunction
  171.  
  172.  
  173. Method update(mouse_hit1,mouse_x,mouse_y)
  174. For Local t:gui_element = EachIn Self.gadget_list
  175. If t.hidden = False
  176. t.update(mouse_hit1,mouse_x,mouse_Y)
  177. EndIf
  178. Next
  179. EndMethod
  180.  
  181. Method render()
  182. For Local t:gui_element = EachIn Self.gadget_list
  183. If t.hidden = False
  184. t.render()
  185. EndIf
  186. Next
  187. EndMethod
  188.  
  189. EndType
  190.  
  191. Type label Extends gui_element
  192. Method render()
  193. SetColor (gui_type.gui_pointer.textr , gui_type.gui_pointer.textg , gui_type.gui_pointer.textb)
  194. DrawText Self.text,Self.x,Self.y
  195. EndMethod
  196.  
  197. Function Create:label(x,y,text$,parent:gui_element)
  198. Local l:label=New label
  199. l.x=x
  200. l.y=y
  201. l.text=text
  202. l.height=TextHeight(text)
  203. If parent<>Null
  204. l.parent = parent
  205. l.parent.gadget_list.addlast(l)
  206. EndIf
  207. Return l
  208. EndFunction
  209.  
  210. EndType
  211.  
  212. Type img_button Extends gui_element
  213.  
  214. Field image:TImage
  215. Field radio_list:TList
  216. Function Create:img_button(x , y , used_image:TImage , text$,parent:gui_element,radio_list:TList=Null)
  217.  
  218. Local t:img_button=New img_button
  219. t.x = x
  220. t.y = y
  221. t.text=text$
  222. t.width = ImageWidth(used_image)
  223. t.height = ImageHeight(used_image)
  224. t.image=used_image
  225. t.radio_list=radio_list
  226. If parent<>Null
  227. t.parent = parent
  228. t.parent.gadget_list.addlast(t)
  229. EndIf
  230.  
  231. If radio_list<>Null
  232. radio_list.addlast(t)
  233. EndIf
  234.  
  235. Return t
  236. EndFunction
  237.  
  238. Method update(mouse_hit1,mouse_x,mouse_y)
  239.  
  240. Super.update(mouse_hit1,mouse_x,mouse_y)
  241. Self.pressed=False
  242. If gui_element.clicked=False
  243. If mouse_hit1
  244. If mouse_over= True
  245. pressed_timer=MilliSecs()
  246. pressed = True
  247. gui_element.clicked=True
  248. If Self.radio_list<>Null
  249. For Local t:img_button=EachIn Self.radio_list
  250. t.active=False
  251. Next
  252. Self .active=True
  253. EndIf
  254.  
  255. EndIf
  256. EndIf
  257. EndIf
  258. EndMethod
  259.  
  260. Method render()
  261.  
  262. SetColor(255,255,255)
  263. SetScale (Self.width / ImageWidth(image) , height / ImageHeight(image))
  264. Local draw_x
  265. Local draw_y
  266. 'SetImageHandle(image,0,0)
  267.  
  268.  
  269.  
  270.  
  271.  
  272. SetColor (170,100,100)
  273. If active = False And mouse_over=False
  274. SetColor (255 ,255 ,255)
  275. EndIf
  276.  
  277. If pressed_timer+300>MilliSecs()
  278. DrawImage image , x , y+2
  279. Else
  280. DrawImage image,x,y
  281. EndIf
  282.  
  283. If active=True
  284. SetColor 100,100,100
  285. DrawRect (Self.x,Self.y,ImageWidth(image),5)
  286. SetColor 160,160,160
  287. DrawRect (Self.x,Self.y,5,ImageHeight(image))
  288. SetColor 160,160,160
  289. DrawRect (Self.x,Self.y+(ImageHeight(image)-5),ImageHeight(image),5)
  290. SetColor 220,220,220
  291. DrawRect (Self.x+ImageWidth(image)-5,Self.y,5,ImageHeight(image))
  292. EndIf
  293.  
  294. SetScale(1 , 1)
  295. SetColor(255 , 255 , 255)
  296. If text<>""
  297. DrawText (text,(Self.x+Self.width/2)-(TextWidth(Self.text)/2),Self.y+Self.height)
  298. EndIf
  299. EndMethod
  300.  
  301. EndType
  302.  
  303. Function gui_input()
  304. mouse_X=MouseX()
  305. mouse_y=MouseY()
  306. mouse_hit1=MouseHit(1)
  307. For Local t:gui_element = EachIn gui_element.list
  308. If t.hidden=False
  309. t.update(mouse_hit1 , mouse_x , mouse_y)
  310. EndIf
  311. Next
  312. EndFunction
  313.  
  314. Function draw_gui()
  315. For Local t:gui_element = EachIn gui_element.list
  316. If t.hidden=False
  317. t.render()
  318. EndIf
  319. Next
  320. EndFunction
  321.  
  322. Function is_Gui_clicked()
  323. Return gui_element.clicked
  324. EndFunction
  325.  
  326. Function add_button_to_gadget_Scroller(name$,radio:Int=False,g:gadget_scroller)
  327. g.add_button(name,radio)
  328. EndFunction
  329.  
  330. Function create_textbox:textbox(x:Int,y:Int,width:Float,height:Float)
  331. Return textbox.Create(x,y,width,height)
  332. EndFunction
  333.  
  334. Function Create_gadget_Scroller:gadget_scroller(x:Int,y:Int,width:Float,height:Float,parent:window)
  335. Return gadget_Scroller.Create(x,y,width,height,parent:window)
  336. EndFunction
  337.  
  338. Function Create_window:window(x:Int,y:Int,width:Float,height:Float)
  339. Return window.Create(x,y,width,height)
  340. EndFunction
  341.  
  342. Function Create_button:button(x:Int , y:Int , width:Float , height:Float , text$,parent:gui_element,font:Timagefont=Null)
  343. Return button.Create(x , y , width:Float , height:Float , text$,parent:gui_element,font)
  344. EndFunction
  345.  
  346. Type button Extends gui_element
  347.  
  348. Global img:TImage
  349. Global img2:TImage
  350. Field disabled
  351. Method disable()
  352. Self.disabled=True
  353. EndMethod
  354.  
  355.  
  356. Function Create:button(x , y , width:Float , height:Float , text$,parent:gui_element,font:Timagefont=Null)
  357. If font=Null
  358. font=gui_type.gui_pointer.font
  359. EndIf
  360.  
  361. Local t:button=New button
  362. t.x=x
  363. t.y=y
  364. t.width=width
  365. t.height=height
  366. t.text=text
  367. t.font=font
  368. If img = Null
  369. img=gui_type.gui_pointer.button_img
  370. img2=gui_type.gui_pointer.button_over_img
  371. EndIf
  372.  
  373. If parent<>Null
  374. t.parent = parent
  375. t.parent.gadget_list.addlast(t)
  376. EndIf
  377.  
  378. Return t
  379. EndFunction
  380.  
  381. Method update(mouse_hit1,mouse_x,mouse_y)
  382. Super.update(mouse_hit1,mouse_x,mouse_y)
  383. Self.pressed=False
  384. If gui_element.clicked=False
  385. If mouse_hit1
  386. If mouse_over= True
  387. If disabled=False
  388. pressed_timer=MilliSecs()
  389. pressed = True
  390. gui_element.clicked=True
  391. EndIf
  392. EndIf
  393. EndIf
  394. EndIf
  395. EndMethod
  396.  
  397. Method render()
  398. SetImageFont(Self.font)
  399. SetColor(255,255,255)
  400. Local draw_x
  401. Local draw_y
  402.  
  403.  
  404. If pressed_timer+300>MilliSecs()
  405. SetScale (Self.width / ImageWidth(img) , height / ImageHeight(img))
  406. DrawImage img2 , x , y
  407. SetScale (1,1)
  408.  draw_x=(x+(width/2))-(TextWidth(text)/2)
  409.  draw_y = ((y + (height / 2) ) - (TextHeight(text)/3))+2
  410. Else
  411. SetScale (1,1)
  412.  draw_x=(x+(width/2))-(TextWidth(text)/2)
  413.  draw_y = (y + (height / 2) ) - (TextHeight(text)/3)
  414. SetScale (Self.width / ImageWidth(img) , height / ImageHeight(img))
  415. DrawImage img,x,y
  416. EndIf
  417.  
  418.  
  419. SetScale (1,1)
  420.  
  421. If disabled=False
  422. If active = False And mouse_over=False
  423. SetColor (gui_type.gui_pointer.textr , gui_type.gui_pointer.textg , gui_type.gui_pointer.textb)
  424. Else
  425. SetColor (170,0,0)
  426. EndIf
  427. EndIf
  428.  
  429. If disabled=True
  430. SetColor 50,50,50
  431. EndIf
  432.  
  433. DrawText text,draw_x,draw_y',149,149,149
  434. SetColor(255 , 255 , 255)
  435.  
  436. EndMethod
  437.  
  438. EndType
  439.  
  440.  
  441. Type Inputbox Extends gui_element
  442. Field the_string$
  443. Field has_focus
  444. Field lastinput
  445. Field blink
  446.  
  447. Function Create:inputbox(x# , y# , width# , height#,parent:gui_element,the_string$)
  448.         Local i:inputbox = New inputbox
  449.         i.x = x
  450.         i.y = y
  451.         i.width = width
  452.         i.height = height
  453.         If parent<>Null
  454.         i.parent = parent
  455.         i.parent.gadget_list.addlast(i)
  456.         EndIf
  457.         i.has_focus = True
  458.         i.the_string=the_string
  459.         FlushKeys()
  460. Return i
  461. EndFunction
  462.  
  463. Method changetext(the_text$)
  464.         the_string=the_text
  465. EndMethod
  466.  
  467. Method last_input()
  468.         Return lastinput
  469. EndMethod
  470.  
  471. Method render()
  472.  
  473. Local end_string$=""
  474.  
  475. If has_focus = True
  476. If blink=False
  477. blink=True
  478. end_string="|"
  479. Else
  480. blink=False
  481. end_string=""
  482. EndIf
  483. EndIf
  484.  
  485. SetColor 255,255,255
  486. SetScale (width/ImageWidth(gui_type.gui_pointer.window_image),height/ImageHeight(gui_type.gui_pointer.window_image))
  487. DrawImage gui_type.gui_pointer.window_image,x,y
  488. SetScale(1,1)
  489. SetColor gui_type.gui_pointer.textr , gui_type.gui_pointer.textg ,gui_type.gui_pointer.textb
  490. Local x1 = x + 10
  491. Local y1 = y + 5
  492.  
  493. If TextWidth(the_String)<(width-10)
  494. DrawText the_string+end_string ,x1 , y1
  495. Else
  496.  
  497. For Local x=1 To the_string.length
  498. Local temp_string$=Right(the_string,x)
  499. If TextWidth(temp_string)>(width-10)
  500. DrawText Right(temp_string,temp_string.length-1)+end_string,x1,y1
  501. Exit
  502. EndIf
  503. Next
  504.  
  505. EndIf
  506.  
  507. SetColor 255,255,255
  508. EndMethod
  509.  
  510. Method update(mouse_hit1,mouse_x,mouse_y)
  511.  
  512. Super.update(mouse_hit1,mouse_x,mouse_y)
  513.  
  514. Self.pressed=False
  515.  
  516. If gui_element.clicked=False
  517. If mouse_hit1
  518. FlushKeys()
  519. If mouse_over= True
  520. Self.pressed=True
  521. gui_element.clicked = True
  522. has_focus=True
  523. Else
  524. has_focus=False
  525. EndIf
  526. EndIf
  527. EndIf
  528. If has_focus = True
  529. Local char = GetChar()
  530.  
  531.  
  532. lastinput = char
  533.  
  534. If char>8 And char<>13
  535. the_string = the_string + Chr(char)
  536. EndIf
  537.  
  538. If char=8
  539. the_string = Left(the_string, Len(the_string)-1)
  540. EndIf
  541.  
  542. Self.text=the_string
  543. EndIf
  544.  
  545. EndMethod
  546.  
  547. EndType
  548.  
  549. Type textbox Extends gui_element
  550.  
  551. Field lines$[400]
  552. Field line_list:TList = New TList
  553. Field current_line
  554.  
  555. Global img
  556.  
  557.  
  558. Function Create:textbox(x,y,width,height)
  559. Local t:textbox=New textbox
  560. t.x = x
  561. t.y = y
  562. t.width = width
  563. t.height = height
  564. Local u:up_arrow=up_arrow.Create(t)
  565. Local d:down_arrow=down_arrow.Create(t)
  566. t.gadget_list = New TList
  567. t.gadget_list.addlast(u)
  568. t.gadget_list.addlast(d)
  569. t.list.addlast(t)
  570. Return t
  571. End Function
  572.  
  573.  
  574. Method clear()
  575. line_list.clear()
  576. EndMethod
  577.  
  578. Method add_text(the_text$,flash)
  579.  
  580. Self.text=the_text
  581. Local iter = 0
  582. If TextWidth(the_text) > width - 9
  583. Local word_array$[] = the_text.split(" ")
  584. Local new_string$
  585. Local long_string$
  586.  
  587.  
  588. While iter<word_array.length
  589. Local a$ = word_array[iter]
  590.  
  591. long_string$ = new_string + A$
  592.  
  593. If TextWidth(long_string)>width-9
  594. line_list.addlast(new_string)
  595.  
  596. new_string = a+" "
  597. long_string=""
  598.  
  599. If iter = word_array.length-1
  600. line_list.addlast(New_String)
  601. EndIf
  602.  
  603. Else
  604. new_string = new_string + a + " "
  605.  
  606. If iter=word_array.length-1
  607. line_list.addlast(new_string)
  608. EndIf
  609.  
  610. EndIf
  611.  
  612. iter = iter + 1
  613.  
  614. Wend
  615. Else
  616. line_list.addlast(the_text)
  617. EndIf
  618.  
  619. If line_list.count()>(height/TextHeight("HA"))
  620. current_line = Int(Float(line_list.count()) -(Float(height)/Float(TextHeight("HA"))))+1
  621. Else
  622. Current_line=0
  623. EndIf
  624. DebugLog "current_ line: "+current_line
  625.  
  626. If flash=1
  627. Self.red=0
  628. Self.blue=0
  629. Self.green=255
  630. EndIf
  631. If flash=2
  632. Self.green=0
  633. Self.blue=0
  634. Self.red=255
  635. EndIf
  636. EndMethod
  637.  
  638. Method update(mouse_hit1 , mouse_x , mouse_y)
  639.  
  640. For Local t:gui_element = EachIn gadget_list
  641. t.update(mouse_hit1,mouse_x,mouse_y)
  642. Next
  643.  
  644. Super.update(mouse_hit1,mouse_x,mouse_y)
  645.  
  646. If gui_element.clicked=False
  647. If mouse_hit1
  648. If Self.mouse_over=True
  649. gui_element.clicked=True
  650. EndIf
  651.  
  652. If Self.up_arrow.mouse_over = True
  653. gui_element.clicked=True
  654. If current_line>0
  655. current_line = current_line - 1
  656. EndIf
  657. EndIf
  658.  
  659.  
  660. If Self.down_arrow.mouse_over = True
  661. gui_element.clicked=True
  662. If current_line<line_list.count()-1
  663. current_line = current_line + 1
  664. EndIf
  665. EndIf
  666.  
  667.  
  668. EndIf
  669. EndIf
  670.  
  671. If red<255
  672. red:+6
  673. EndIf
  674. If blue<255
  675. blue:+6
  676. EndIf
  677. If green<255
  678. green:+6
  679. EndIf
  680. EndMethod
  681.  
  682. Method render()
  683. If hidden=False
  684. SetColor red,green,blue
  685. SetScale (width/ImageWidth(gui_type.gui_pointer.window_image),height/ImageHeight(gui_type.gui_pointer.window_image))
  686. DrawImage gui_type.gui_pointer.window_image,x,y
  687. Local border_width#=10
  688.  
  689. SetScale (border_width/ImageWidth(gui_type.gui_pointer.border_image),height/ImageWidth(gui_type.gui_pointer.border_image))
  690. DrawImage (gui_type.gui_pointer.border_image,x-border_width,y)
  691. DrawImage (gui_type.gui_pointer.border_image,x+width,y)
  692. SetScale(width/ImageWidth(gui_type.gui_pointer.border_image),border_width/ImageHeight(gui_type.gui_pointer.border_image))
  693. DrawImage (gui_type.gui_pointer.border_image,x,y-border_width)
  694. DrawImage (gui_type.gui_pointer.border_image,x,y+height)
  695.  
  696. SetScale(border_width/ImageWidth(gui_type.gui_pointer.border_image),border_width/ImageHeight(gui_type.gui_pointer.border_image))
  697.  
  698. DrawImage(gui_Type.gui_pointer.border_image,x-border_width,y-border_width)
  699. DrawImage(gui_Type.gui_pointer.border_image,x+width,y-border_width)
  700. DrawImage(gui_Type.gui_pointer.border_image,x-border_width,y+height)
  701. DrawImage(gui_Type.gui_pointer.border_image,x+width,y+height)
  702.  
  703.  
  704. SetScale(1,1)
  705. SetColor gui_type.gui_pointer.textr , gui_type.gui_pointer.textg ,gui_type.gui_pointer.textb
  706.  
  707. Local line_position=0
  708. Local iter=0
  709. For Local a$ = EachIn line_list
  710.  
  711. If line_position > current_line - 1
  712. If line_position < (current_line + (height / TextHeight(a)) )-1
  713. DrawText a,x+9,y+((iter*TextHeight("HA"))+5)
  714. iter=iter+1
  715. EndIf
  716. EndIf
  717.  
  718. line_position=line_position+1
  719. Next
  720.  
  721. For Local t:gui_element = EachIn gadget_list
  722. t.render
  723. Next
  724.  
  725. SetColor(255,255,255)
  726.  
  727. EndIf
  728. EndMethod
  729.  
  730. EndType
  731.  
  732.  
  733. Type draggable_image Extends gui_element
  734.  
  735. Field image:TImage
  736. Field being_dragged
  737. Field offset_x
  738. Field offset_y
  739. Field dropped
  740.  
  741. Function Create:draggable_image(x,y,offset_x,offset_y,used_image:TImage,parent:gui_element)
  742. Local d:draggable_image=New draggable_image
  743. d.x=x
  744. d.y=y
  745. d.width=ImageWidth(used_image)
  746. d.height=ImageHeight(used_image)
  747. d.image=used_image
  748. d.offset_x=offset_x
  749. d.offset_y=offset_y
  750. If parent<>Null
  751. d.parent=parent
  752. If d.parent.gadget_list=Null
  753. d.parent.gadget_list=New TList
  754. EndIf
  755. d.parent.gadget_list.addlast(d)
  756. EndIf
  757. Return d
  758. EndFunction
  759.  
  760. Method render()
  761.  
  762. SetColor 255,255,255
  763. SetScale 1,1
  764. SetRotation 0
  765.  
  766. If being_dragged=True
  767. SetViewport(0,0,GraphicsWidth(),GraphicsHeight())
  768. DrawImage image,mouse_x,mouse_y
  769. EndIf
  770.  
  771. DrawImage image,x+offset_x,y+offset_y
  772.  
  773. EndMethod
  774.  
  775.  
  776. Method update(mouse_hit1,mouse_x,mouse_y)
  777.  
  778. Super.update(mouse_hit1,mouse_x,mouse_y)
  779.  
  780. If being_dragged=True
  781. If Not Mouse_Down1
  782. being_dragged=False
  783. dropped=True
  784. EndIf
  785. EndIf
  786.  
  787. Local an_image_dragged
  788.  
  789. For Local d:draggable_image=EachIn Self.parent.gadget_list
  790. If d.being_dragged=True
  791. an_image_dragged=True
  792. EndIf
  793. Next
  794.  
  795. If an_image_dragged=False
  796. If mouse_over= True
  797. If mouse_down1=True
  798. If being_dragged=False
  799. being_dragged=True
  800. pressed_timer=MilliSecs()
  801. pressed = True
  802. gui_element.clicked=True
  803. EndIf
  804. EndIf
  805. EndIf
  806. EndIf
  807. EndMethod
  808.  
  809. EndType
  810.  
  811. Type gadget_scroller Extends gui_element
  812.  
  813. Field radio_list:TList=New TList
  814. Field current_gadget:gui_element
  815. Field virtual_height
  816.  
  817. Method add_button:button(name$,radio=False)
  818. Local but:button=Button.Create(25 , 25 , width-10 , 25 , name,Null)
  819. add_gadget(but,radio)
  820. Return but
  821. EndMethod
  822.  
  823. Method add_gadget(o:gui_element,radio=False,column=1)
  824.  
  825. If o.parent<>Null
  826. o.parent.gadget_list.remove(o)
  827. EndIf
  828.  
  829. gui_element.list.remove(o)
  830.  
  831. If gadget_list.count()=0 And radio=True
  832. o.active=True
  833. EndIf
  834.  
  835.  
  836. If radio=False
  837. gadget_list.addlast(o)
  838. EndIf
  839.  
  840. If radio=True
  841. Self.radio_list.addlast(o)
  842. gadget_list.addlast(o)
  843. EndIf
  844.  
  845. If current_gadget=Null
  846. current_gadget = o
  847. EndIf
  848.  
  849. o.x = x+5
  850. o.y = y
  851. 'o.width=width-10
  852.  
  853. EndMethod
  854.  
  855. Method remove_all()
  856. Self.current_gadget=Null
  857. Self.gadget_List.clear()
  858. Self.radio_list.clear()
  859. EndMethod
  860.  
  861. Function Create:gadget_scroller(x,y,width,height,parent:window)
  862.  
  863. Local o:gadget_scroller = New gadget_scroller
  864. o.x = x
  865. o.y = y
  866. o.width = width
  867. o.height=height
  868. o.gadget_list = New TList
  869. parent.gadget_list.addlast(o)
  870. o.up_arrow=up_arrow.Create(o)
  871. o.down_arrow=down_arrow.Create(o)
  872.  
  873. Return o
  874.  
  875. EndFunction
  876.  
  877. Method render()
  878. SetViewport(0,0,GraphicsWidth(),GraphicsHeight())
  879. SetColor 255,255,255
  880. SetScale (width/ImageWidth(gui_type.gui_pointer.window_image),height/ImageHeight(gui_type.gui_pointer.window_image))
  881. DrawImage gui_type.gui_pointer.window_image,x,y
  882. Local border_width#=10
  883. SetScale (border_width/ImageWidth(gui_type.gui_pointer.border_image),height/ImageWidth(gui_type.gui_pointer.border_image))
  884. DrawImage (gui_type.gui_pointer.border_image,x-border_width,y)
  885. DrawImage (gui_type.gui_pointer.border_image,x+width,y)
  886. SetScale(width/ImageWidth(gui_type.gui_pointer.border_image),border_width/ImageHeight(gui_type.gui_pointer.border_image))
  887. DrawImage (gui_type.gui_pointer.border_image,x,y-border_width)
  888. DrawImage (gui_type.gui_pointer.border_image,x,y+height)
  889.  
  890.  
  891. SetScale(border_width/ImageWidth(gui_type.gui_pointer.border_image),border_width/ImageHeight(gui_type.gui_pointer.border_image))
  892.  
  893. DrawImage(gui_Type.gui_pointer.border_image,x-border_width,y-border_width)
  894. DrawImage(gui_Type.gui_pointer.border_image,x+width,y-border_width)
  895. DrawImage(gui_Type.gui_pointer.border_image,x-border_width,y+height)
  896. DrawImage(gui_Type.gui_pointer.border_image,x+width,y+height)
  897.  
  898.  
  899. SetScale(1,1)
  900.  
  901. For Local o:gui_element = EachIn gadget_list
  902. o.rendered = False
  903. Next
  904.  
  905. Local render_height=0
  906. Local render_width=0
  907. Local found_first
  908.  
  909.  
  910. For Local o:gui_element = EachIn gadget_list
  911. If o.hidden = False
  912.  
  913.  
  914. If o = Self.current_gadget
  915. found_first=True
  916. EndIf
  917.  
  918. If found_first=True
  919. If render_height < height
  920. 'SetViewport (x , y , width , height)
  921. o.y=render_height+5+y
  922.  
  923. If o.active=True
  924. SetColor 170,0,0
  925. EndIf
  926.  
  927. o.x=Self.x+5
  928. o.render()
  929. o.rendered=True
  930. render_height = render_height + o.height+3
  931.  
  932. If o.width>render_width
  933. render_width=o.width
  934. EndIf
  935.  
  936.  
  937. EndIf
  938. EndIf
  939.  
  940. EndIf
  941. Next
  942.  
  943.  
  944. For Local o:gui_element=EachIn gadget_list
  945. If o.gadget_list<>Null
  946. For Local i:gui_element=EachIn o.gadget_list
  947. i.x=render_width+5
  948. i.y=(o.y+(o.height/2))
  949. i.render()
  950. i.rendered=True
  951. Next
  952. EndIf
  953. Next
  954.  
  955.  
  956. SetViewport(0,0,GraphicsWidth(),GraphicsHeight())
  957. Self.up_arrow.render()
  958. Self.down_arrow.render()
  959. EndMethod
  960.  
  961.  
  962.  
  963. Method update(mouse_hit1,mouse_X,mouse_y)
  964.  
  965.  
  966. For Local o:gui_element = EachIn gadget_list
  967. If o.hidden=False
  968. If o.rendered = True
  969. o.update(mouse_hit1,mouse_x,mouse_Y)
  970. EndIf
  971. EndIf
  972. Next
  973.  
  974.  
  975. For Local o:gui_element = EachIn radio_list
  976.  
  977. If o.hidden=False
  978. If o.rendered = True
  979. If o.pressed=True
  980. o.active=True
  981. For Local j:gui_element=EachIn radio_List
  982. If j<>o
  983. j.active=False
  984. EndIf
  985. Next
  986.  
  987. EndIf
  988. EndIf
  989. EndIf
  990.  
  991. Next
  992.  
  993.  
  994. Self.down_arrow.update(mouse_hit1,mouse_x,mouse_y)
  995. Self.up_arrow.update(mouse_hit1 , mouse_x , mouse_y)
  996.  
  997. If gui_element.clicked=False
  998. If mouse_hit1
  999.  
  1000. If Self.up_arrow.mouse_over = True
  1001. gui_element.clicked = True
  1002. If current_gadget<>Null
  1003. If current_gadget.before(gadget_list) <> Null
  1004. current_gadget=current_gadget.before(gadget_list)
  1005. EndIf
  1006. EndIf
  1007. EndIf
  1008.  
  1009. If Self.down_arrow.mouse_over = True
  1010. gui_element.clicked = True
  1011. If current_gadget<>Null
  1012. If current_gadget.after(gadget_list) <> Null
  1013. current_gadget=current_gadget.after(gadget_list)
  1014. EndIf
  1015. EndIf
  1016. EndIf
  1017. If Self.detect_mouse_over(mouse_x,Mouse_Y) = True
  1018. gui_element.clicked = True
  1019. EndIf
  1020.  
  1021.  
  1022. EndIf
  1023. EndIf
  1024. EndMethod
  1025.  
  1026. EndType
  1027.  
  1028. Type up_arrow Extends gui_element
  1029.  
  1030.  
  1031. Function Create:up_arrow(parent:gui_element)
  1032. Local u:up_arrow = New up_arrow
  1033. u.x = (parent.x + parent.width)+10
  1034. u.y=parent.y
  1035. u.width = 29
  1036. u.height = 29
  1037. u.parent = parent
  1038. parent.up_arrow = u
  1039. Return u
  1040. EndFunction
  1041.  
  1042. Method render()
  1043. SetRotation(0)
  1044. SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
  1045. SetColor 255 , 255 , 255
  1046. SetScale 0.5 , 0.5
  1047. DrawImage gui_type.gui_pointer.up_arrow,x,y
  1048. SetScale(1,1)
  1049. EndMethod
  1050.  
  1051. Method update(mouse_hit1,mouse_x,mouse_y)
  1052. x = (parent.x + parent.width)+10
  1053. y = parent.y
  1054. Super.update(mouse_hit1,mouse_x,mouse_y)
  1055. EndMethod
  1056.  
  1057. EndType
  1058.  
  1059. Type down_arrow Extends gui_element
  1060.  
  1061.  
  1062. Function Create:down_arrow(parent:gui_element)
  1063. Local u:down_arrow = New down_arrow
  1064. u.width = 29
  1065. u.height = 29
  1066. u.x = (parent.x + parent.width)+10
  1067. u.y=(parent.y + parent.height) - 58
  1068. u.parent = parent
  1069. parent.down_arrow = u
  1070. Return u
  1071. EndFunction
  1072.  
  1073. Method render()
  1074.  
  1075. SetRotation(0)
  1076. SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
  1077. SetColor 255 , 255 , 255
  1078. SetScale 0.5 , 0.5
  1079. DrawImage gui_type.gui_pointer.down_arrow,x,y
  1080. SetScale(1,1)
  1081. EndMethod
  1082.  
  1083. Method update(mouse_hit1 , mouse_x , mouse_y)
  1084. x = (parent.x + parent.width)+10
  1085. y = (parent.y + parent.height) - 29
  1086. Super.update(mouse_hit1 , mouse_x , mouse_y)
  1087. EndMethod
  1088.  
  1089. EndType
  1090.  
  1091.  
  1092. Type toggle_button Extends gui_element
  1093.  
  1094. Global img:TImage
  1095. Global img2:TImage
  1096. Field active
  1097. Field pressed
  1098.  
  1099. Function Create:toggle_button(x , y , width:Float , height:Float , text$,parent:gui_element)
  1100. Local t:toggle_button=New toggle_button
  1101. t.x = x
  1102. t.y = y
  1103. t.width = width
  1104. t.height = height
  1105. t.text = text
  1106.  
  1107. If img = Null
  1108. img=gui_type.gui_pointer.button_img
  1109. img2=gui_type.gui_pointer.button_over_img
  1110. EndIf
  1111.  
  1112. parent.gadget_list.addlast(t)
  1113.  
  1114. Return t
  1115. EndFunction
  1116.  
  1117. Method update(mouse_hit1,mouse_x,mouse_y)
  1118. Super.update(mouse_hit1,mouse_x,mouse_y)
  1119.  
  1120. If gui_element.clicked=False
  1121. If mouse_hit1
  1122. If mouse_over = True
  1123. If active = False
  1124. active = True
  1125. Else
  1126. active=False
  1127. EndIf
  1128. gui_element.clicked=True
  1129. pressed = True
  1130. EndIf
  1131. EndIf
  1132. EndIf
  1133. EndMethod
  1134.  
  1135. Method render()
  1136.  
  1137. SetColor(255,255,255)
  1138. SetScale (Self.width / ImageWidth(img) , height / ImageHeight(img))
  1139.  
  1140. If active=True
  1141. DrawImage img2 , x , y
  1142. Else
  1143. DrawImage img,x,y
  1144. EndIf
  1145.  
  1146. SetScale(1 , 1)
  1147.  
  1148. If active=False
  1149. SetColor (gui_type.gui_pointer.textr , gui_type.gui_pointer.textg , gui_type.gui_pointer.textb)
  1150. Else
  1151. SetColor (170,0,0)
  1152. EndIf
  1153.  
  1154. Local draw_x=(x+(width/2))-(TextWidth(text)/2)
  1155. Local draw_y=(y+(height/2))-(TextHeight(text)/2)
  1156. DrawText text,draw_x,draw_y
  1157. SetColor(255 , 255 , 255)
  1158.  
  1159. EndMethod
  1160.  
  1161. EndType


Comments :


N(Posted 1+ years ago)

 Do you actually write code without any indentation?


slenkar(Posted 1+ years ago)

 yeah, I dont usually need it


N(Posted 1+ years ago)

 Well, for the sake of organization, here's one with indentation, folks:
Code: [Select]
Strict

Module keef.customgui

Import brl.max2d
Import brl.retro



Global time
Global mouse_x
Global mouse_y
Global mouse_hit1
Global mouse_hit2
Global mouse_down1



Type gui_type

Field up_arrow:Timage
Field down_arrow:Timage
Field button_img:Timage
Field button_over_img:Timage
Field window_image:timage
Field border_image:Timage

Global gui_pointer:gui_type
Field textr
Field textg
Field textb



Function init_gui(r,g,b)
gui_pointer:gui_type=New gui_type
gui_pointer.down_arrow = LoadImage("incbin::guiskindownarrow.png")
gui_pointer.up_arrow=LoadImage("incbin::guiskinuparrow.png")
gui_pointer.window_image = LoadImage("incbin::guiskinpaper.png")
gui_pointer.button_img = LoadImage("incbin::guiskinutton.png")
gui_pointer.button_over_img=LoadImage("incbin::guiskinuttonpressed.png")
gui_pointer.border_image=LoadImage("incbin::guiskinorder.png")
gui_pointer.textr=r
gui_pointer.textg=g
gui_pointer.textb=b
EndFunction



EndType

Function change_gui_text_color(r,g,b)

If gui_type.gui_pointer<>Null
gui_type.gui_pointer.textr=r
gui_type.gui_pointer.textg=g
gui_type.gui_pointer.textb=b
EndIf


EndFunction

Type gui_element Abstract
Field x
Field y
Field width:Float
Field height:Float
Field mouse_over
Field parent:gui_element
Field up_arrow:gui_element
Field down_arrow:gui_element
Field text$
Field rendered
Field hidden
Field gadget_list:TList=New TList
Field active
Field green,red,blue
Field pressed
Field pressed_timer

Global list:TList = New TList
Global clicked

Method After:gui_element(the_list:TList)
Local link:TLink = the_List.FindLink(Self)
If link <> Null
link=link.NextLink()
EndIf

If link<>Null
Return gui_element(link.Value())
Else
Return Null
EndIf
EndMethod


Method ispressed()
If Self.pressed=True
Self.pressed=False
Return True
EndIf
EndMethod

Method Before:gui_element(the_list:TList)
Local link:TLink = the_List.FindLink(Self)
If link <> Null
link=link.PrevLink()
EndIf
If link<>Null

Return gui_element(link.Value())
Else
Return Null
EndIf
EndMethod

Method New()
red=255
blue=255
green=255
EndMethod

Method update(mouse_hit1,mouse_X,mouse_y)
If detect_mouse_over(mouse_x,mouse_y)
mouse_over = True
Else
mouse_over=False
EndIf
EndMethod

Method detect_mouse_over(mouse_X,Mouse_Y)
If Mouse_X > x
If Mouse_X < (x + width)
If Mouse_Y > y
If Mouse_Y < (y + height)
Return True
EndIf
EndIf
EndIf
EndIf



EndMethod

Method render()

EndMethod

EndType



Type window Extends gui_element



Function Create:window(x,y,width,height)
Local w:window = New window
w.x = x
w.y = y
w.width = width
w.height=height
w.gadget_list = New TList
w.hidden=True
gui_element.list.addlast(w)
Return w
EndFunction

Method update(mouse_hit1,mouse_x,mouse_y)
For Local t:gui_element = EachIn Self.gadget_list
If t.hidden = False
t.update(mouse_hit1,mouse_x,mouse_Y)
EndIf
Next
EndMethod

Method render()
For Local t:gui_element = EachIn Self.gadget_list
If t.hidden = False
t.render()
EndIf
Next
EndMethod

EndType
Type label Extends gui_element
Method render()
DrawText Self.text,Self.x,Self.y
EndMethod

Function Create:label(x,y,text$,parent:gui_element)
Local l:label=New label
l.x=x
l.y=y
l.text=text
l.height=TextHeight(text)
If parent<>Null
l.parent = parent
l.parent.gadget_list.addlast(l)
EndIf
Return l
EndFunction

EndType

Type img_button Extends gui_element

Field image:timage

Function Create:img_button(x , y , used_image:timage , text$,parent:gui_element)
Local t:img_button=New img_button
t.x = x
t.y = y
t.text=text$
t.width = ImageWidth(used_image)
t.height = ImageHeight(used_image)
t.image=used_image
If parent<>Null
t.parent = parent
t.parent.gadget_list.addlast(t)
EndIf

Return t
EndFunction

Method update(mouse_hit1,mouse_x,mouse_y)
Super.update(mouse_hit1,mouse_x,mouse_y)
Self.pressed=False
If mouse_hit1
If mouse_over= True
pressed_timer=MilliSecs()
pressed = True
gui_element.clicked=True
EndIf
EndIf
EndMethod

Method render()


SetColor(255,255,255)
SetScale (Self.width / ImageWidth(image) , height / ImageHeight(image))
Local draw_x
Local draw_y
SetImageHandle(image,0,0)

If active = False And mouse_over=False
SetColor (255 ,255 ,255)
Else
SetColor (170,0,0)
EndIf

If pressed_timer+300>MilliSecs()
DrawImage image , x , y+2
Else
DrawImage image,x,y
EndIf

SetScale(1 , 1)
SetColor(255 , 255 , 255)

EndMethod

EndType

Function gui_input()
mouse_X=MouseX()
mouse_y=MouseY()
mouse_hit1=MouseHit(1)
For Local t:gui_element = EachIn gui_element.list
If t.hidden=False
t.update(mouse_hit1 , mouse_x , mouse_y)
EndIf
Next
EndFunction

Function draw_gui()
For Local t:gui_element = EachIn gui_element.list
If t.hidden=False
t.render()
EndIf
Next
EndFunction

Function is_Gui_clicked()
Return gui_element.clicked
EndFunction

Function add_button_to_gadget_Scroller(name$,radio:Int=False,g:gadget_scroller)
g.add_button(name,radio)
EndFunction

Function create_textbox:textbox(x:Int,y:Int,width:Float,height:Float)
Return textbox.Create(x,y,width,height)
EndFunction

Function Create_gadget_Scroller:gadget_scroller(x:Int,y:Int,width:Float,height:Float,parent:window)
Return gadget_Scroller.Create(x,y,width,height,parent:window)
EndFunction

Function Create_window:window(x:Int,y:Int,width:Float,height:Float)
Return window.Create(x,y,width,height)
EndFunction

Function Create_button:button(x:Int , y:Int , width:Float , height:Float , text$,parent:gui_element)
Return button.Create(x , y , width:Float , height:Float , text$,parent:gui_element)
EndFunction

Type button Extends gui_element

Global img:timage
Global img2:timage
Field disabled
Method disable()
Self.disabled=True
EndMethod


Function Create:button(x , y , width:Float , height:Float , text$,parent:gui_element)
Local t:button=New button
t.x = x
t.y = y
t.width = width
t.height = height
t.text = text

If img = Null
img=gui_type.gui_pointer.button_img
img2=gui_type.gui_pointer.button_over_img
EndIf

If parent<>Null
t.parent = parent
t.parent.gadget_list.addlast(t)
EndIf

Return t
EndFunction

Method update(mouse_hit1,mouse_x,mouse_y)
Super.update(mouse_hit1,mouse_x,mouse_y)
Self.pressed=False
If mouse_hit1
If mouse_over= True
If disabled=False
pressed_timer=MilliSecs()
pressed = True
gui_element.clicked=True
EndIf
EndIf
EndIf
EndMethod

Method render()

SetColor(255,255,255)
SetScale (Self.width / ImageWidth(img) , height / ImageHeight(img))
Local draw_x
Local draw_y

If pressed_timer+300>MilliSecs()
DrawImage img2 , x , y
draw_x=(x+(width/2))-(TextWidth(text)/2)
draw_y = ((y + (height / 2) ) - (TextHeight(text) / 2))+2
Else
draw_x=(x+(width/2))-(TextWidth(text)/2)
draw_y = (y + (height / 2) ) - (TextHeight(text) / 2)

DrawImage img,x,y
EndIf

SetScale(1 , 1)


If disabled=False
If active = False And mouse_over=False
SetColor (gui_type.gui_pointer.textr , gui_type.gui_pointer.textg , gui_type.gui_pointer.textb)
Else
SetColor (170,0,0)
EndIf
EndIf

If disabled=True
SetColor 50,50,50
EndIf

DrawText text,draw_x,draw_y
SetColor(255 , 255 , 255)

EndMethod

EndType


Type Inputbox Extends gui_element
Field the_string$
Field has_focus
Field lastinput
Field blink

Function Create:inputbox(x# , y# , width# , height#,parent:gui_element,the_string$)
Local i:inputbox = New inputbox
i.x = x
i.y = y
i.width = width
i.height = height
If parent<>Null
i.parent = parent
i.parent.gadget_list.addlast(i)
EndIf
i.has_focus = True
i.the_string=the_string
FlushKeys()
Return i
EndFunction

Method changetext(the_text$)
the_string=the_text
EndMethod

Method last_input()
Return lastinput
EndMethod

Method render()

Local end_string$

If blink=False
blink=True
end_string="|"
Else
blink=False
end_string=""
EndIf

SetColor 255,255,255
SetScale (width/ImageWidth(gui_type.gui_pointer.window_image),height/ImageHeight(gui_type.gui_pointer.window_image))
DrawImage gui_type.gui_pointer.window_image,x,y
SetScale(1,1)
SetColor gui_type.gui_pointer.textr , gui_type.gui_pointer.textg ,gui_type.gui_pointer.textb
Local x1 = x + 10
Local y1 = y + 5

If TextWidth(the_String)<(width-10)
DrawText the_string+end_string ,x1 , y1
Else

For Local x=1 To the_string.length
Local temp_string$=Right(the_string,x)
If TextWidth(temp_string)>(width-10)
DrawText Right(temp_string,temp_string.length-1)+end_string,x1,y1
Exit
EndIf
Next

EndIf

SetColor 255,255,255
EndMethod

Method update(mouse_hit1,mouse_x,mouse_y)

Super.update(mouse_hit1,mouse_x,mouse_y)

Self.pressed=False
If mouse_hit1
FlushKeys()
If mouse_over= True
Self.pressed=True
gui_element.clicked = True
has_focus=True
Else
has_focus=False
EndIf
EndIf

If has_focus = True
Local char = GetChar()


lastinput = char

If char>8 And char<>13
the_string = the_string + Chr(char)
EndIf

If char=8
the_string = Left(the_string, Len(the_string)-1)
EndIf

Self.text=the_string
EndIf

EndMethod

EndType

Type textbox Extends gui_element

Field lines$[400]
Field line_list:TList = New TList
Field current_line

Global img


Function Create:textbox(x,y,width,height)
Local t:textbox=New textbox
t.x = x
t.y = y
t.width = width
t.height = height
Local u:up_arrow=up_arrow.Create(t)
Local d:down_arrow=down_arrow.Create(t)
t.gadget_list = New TList
t.gadget_list.addlast(u)
t.gadget_list.addlast(d)
t.list.addlast(t)
Return t
End Function

Method clear()
line_list.clear()
EndMethod

Method add_text(the_text$,flash)

Self.text=the_text

If TextWidth(the_text) > width - 9
Local word_array$[] = the_text.split(" ")
Local new_string$
Local long_string$
Local iter = 0

While iter<word_array.length
Local a$ = word_array[iter]

long_string$ = new_string + A$

If TextWidth(long_string)>width-9
line_list.addlast(new_string)

new_string = a+" "
long_string=""

If iter = word_array.length-1
line_list.addlast(New_String)
EndIf

Else
new_string = new_string + a + " "

If iter=word_array.length-1
line_list.addlast(new_string)
EndIf

EndIf

iter = iter + 1

Wend
Else
line_list.addlast(the_text)
EndIf

current_line = (line_list.count() - (height /TextHeight("hi")))+2

If flash=1
Self.red=0
Self.blue=0
Self.green=255
EndIf
If flash=2
Self.green=0
Self.blue=0
Self.red=255
EndIf
EndMethod

Method update(mouse_hit1 , mouse_x , mouse_y)

For Local t:gui_element = EachIn gadget_list
t.update(mouse_hit1,mouse_x,mouse_y)
Next

Super.update(mouse_hit1,mouse_x,mouse_y)

If mouse_hit1
If Self.mouse_over=True
gui_element.clicked=True
EndIf

If Self.up_arrow.mouse_over = True
gui_element.clicked=True
If current_line>0
current_line = current_line - 1
EndIf
EndIf


If Self.down_arrow.mouse_over = True
gui_element.clicked=True
If current_line<line_list.count()-1
current_line = current_line + 1
EndIf
EndIf


EndIf

If red<255
red:+6
EndIf
If blue<255
blue:+6
EndIf
If green<255
green:+6
EndIf
EndMethod

Method render()
If hidden=False
SetColor red,green,blue
SetScale (width/ImageWidth(gui_type.gui_pointer.window_image),height/ImageHeight(gui_type.gui_pointer.window_image))
DrawImage gui_type.gui_pointer.window_image,x,y
Local border_width#=10

SetScale (border_width/ImageWidth(gui_type.gui_pointer.border_image),height/ImageWidth(gui_type.gui_pointer.border_image))
DrawImage (gui_type.gui_pointer.border_image,x-border_width,y)
DrawImage (gui_type.gui_pointer.border_image,x+width,y)
SetScale(width/ImageWidth(gui_type.gui_pointer.border_image),border_width/ImageHeight(gui_type.gui_pointer.border_image))
DrawImage (gui_type.gui_pointer.border_image,x,y-border_width)
DrawImage (gui_type.gui_pointer.border_image,x,y+height)

SetScale(border_width/ImageWidth(gui_type.gui_pointer.border_image),border_width/ImageHeight(gui_type.gui_pointer.border_image))

DrawImage(gui_Type.gui_pointer.border_image,x-border_width,y-border_width)
DrawImage(gui_Type.gui_pointer.border_image,x+width,y-border_width)
DrawImage(gui_Type.gui_pointer.border_image,x-border_width,y+height)
DrawImage(gui_Type.gui_pointer.border_image,x+width,y+height)


SetScale(1,1)
SetColor gui_type.gui_pointer.textr , gui_type.gui_pointer.textg ,gui_type.gui_pointer.textb

Local line_position=0
Local iter=0
For Local a$ = EachIn line_list

If line_position > current_line - 1
If line_position < (current_line + (height / TextHeight(a)) )-1
DrawText a,x+9,y+(iter*TextHeight(a))+5
iter=iter+1
EndIf
EndIf

line_position=line_position+1
Next

For Local t:gui_element = EachIn gadget_list
t.render
Next

SetColor(255,255,255)

EndIf
EndMethod

EndType


Type draggable_image Extends gui_element

Field image:timage
Field being_dragged
Field offset_x
Field offset_y
Field dropped

Function Create:draggable_image(x,y,offset_x,offset_y,used_image:timage,parent:gui_element)
Local d:draggable_image=New draggable_image
d.x=x
d.y=y
d.width=ImageWidth(used_image)
d.height=ImageHeight(used_image)
d.image=used_image
d.offset_x=offset_x
d.offset_y=offset_y
If parent<>Null
d.parent=parent
If d.parent.gadget_list=Null
d.parent.gadget_list=New TList
EndIf
d.parent.gadget_list.addlast(d)
EndIf
Return d
EndFunction

Method render()

SetColor 255,255,255
SetScale 1,1
SetRotation 0

If being_dragged=True
SetViewport(0,0,GraphicsWidth(),GraphicsHeight())
DrawImage image,mouse_x,mouse_y
EndIf

DrawImage image,x+offset_x,y+offset_y

EndMethod


Method update(mouse_hit1,mouse_x,mouse_y)

Super.update(mouse_hit1,mouse_x,mouse_y)

If being_dragged=True
If Not Mouse_Down1
being_dragged=False
dropped=True
EndIf
EndIf

Local an_image_dragged

For Local d:draggable_image=EachIn Self.parent.gadget_list
If d.being_dragged=True
an_image_dragged=True
EndIf
Next

If an_image_dragged=False
If mouse_over= True
If mouse_down1=True
If being_dragged=False
being_dragged=True
pressed_timer=MilliSecs()
pressed = True
gui_element.clicked=True
EndIf
EndIf
EndIf
EndIf
EndMethod

EndType

Type gadget_scroller Extends gui_element

Field radio_list:TList=New TList
Field current_gadget:gui_element
Field virtual_height

Method add_button:button(name$,radio=False)
Local but:button=Button.Create(25 , 25 , 75 , 25 , name,Null)
add_gadget(but,radio)
Return but
EndMethod

Method add_gadget(o:gui_element,radio=False,column=1)

If o.parent<>Null
o.parent.gadget_list.remove(o)
EndIf

gui_element.list.remove(o)

If gadget_list.count()=0 And radio=True
o.active=True
EndIf


If radio=False
gadget_list.addlast(o)
EndIf

If radio=True
Self.radio_list.addlast(o)
gadget_list.addlast(o)
EndIf

If current_gadget=Null
current_gadget = o
EndIf

o.x = x+5
o.y = y
'o.width=width-10

EndMethod

Method remove_all()
Self.current_gadget=Null
Self.gadget_List.clear()
Self.radio_list.clear()
EndMethod

Function Create:gadget_scroller(x,y,width,height,parent:window)

Local o:gadget_scroller = New gadget_scroller
o.x = x
o.y = y
o.width = width
o.height=height
o.gadget_list = New TList
parent.gadget_list.addlast(o)
o.up_arrow=up_arrow.Create(o)
o.down_arrow=down_arrow.Create(o)

Return o

EndFunction

Method render()
SetViewport(0,0,GraphicsWidth(),GraphicsHeight())
SetColor 255,255,255
SetScale (width/ImageWidth(gui_type.gui_pointer.window_image),height/ImageHeight(gui_type.gui_pointer.window_image))
DrawImage gui_type.gui_pointer.window_image,x,y
Local border_width#=10
SetScale (border_width/ImageWidth(gui_type.gui_pointer.border_image),height/ImageWidth(gui_type.gui_pointer.border_image))
DrawImage (gui_type.gui_pointer.border_image,x-border_width,y)
DrawImage (gui_type.gui_pointer.border_image,x+width,y)
SetScale(width/ImageWidth(gui_type.gui_pointer.border_image),border_width/ImageHeight(gui_type.gui_pointer.border_image))
DrawImage (gui_type.gui_pointer.border_image,x,y-border_width)
DrawImage (gui_type.gui_pointer.border_image,x,y+height)


SetScale(border_width/ImageWidth(gui_type.gui_pointer.border_image),border_width/ImageHeight(gui_type.gui_pointer.border_image))

DrawImage(gui_Type.gui_pointer.border_image,x-border_width,y-border_width)
DrawImage(gui_Type.gui_pointer.border_image,x+width,y-border_width)
DrawImage(gui_Type.gui_pointer.border_image,x-border_width,y+height)
DrawImage(gui_Type.gui_pointer.border_image,x+width,y+height)


SetScale(1,1)

For Local o:gui_element = EachIn gadget_list
o.rendered = False
Next

Local render_height=0
Local render_width=0
Local found_first


For Local o:gui_element = EachIn gadget_list
If o.hidden = False


If o = Self.current_gadget
found_first=True
EndIf

If found_first=True
If render_height+y < height+y
SetViewport (x , y , width , height)
o.y=render_height+y+5

If o.active=True
SetColor 170,0,0
EndIf

o.x=Self.x+5
o.render()
o.rendered=True
render_height = render_height + o.height+3

If o.width>render_width
render_width=o.width
EndIf


EndIf
EndIf

EndIf
Next


For Local o:gui_element=EachIn gadget_list
If o.gadget_list<>Null
For Local i:gui_element=EachIn o.gadget_list
i.x=render_width+5
i.y=(o.y+(o.height/2))+y
i.render()
i.rendered=True
Next
EndIf
Next


SetViewport(0,0,GraphicsWidth(),GraphicsHeight())
Self.up_arrow.render()
Self.down_arrow.render()
EndMethod



Method update(mouse_hit1,mouse_X,mouse_y)


For Local o:gui_element = EachIn gadget_list
If o.hidden=False
If o.rendered = True
o.update(mouse_hit1,mouse_x,mouse_Y)
EndIf
EndIf
Next


For Local o:gui_element = EachIn radio_list

If o.hidden=False
If o.rendered = True
If o.pressed=True
o.active=True
For Local j:gui_element=EachIn radio_List
If j<>o
j.active=False
EndIf
Next

EndIf
EndIf
EndIf

Next


Self.down_arrow.update(mouse_hit1,mouse_x,mouse_y)
Self.up_arrow.update(mouse_hit1 , mouse_x , mouse_y)

If mouse_hit1

If Self.up_arrow.mouse_over = True
gui_element.clicked = True
If current_gadget<>Null
If current_gadget.before(gadget_list) <> Null
current_gadget=current_gadget.before(gadget_list)
EndIf
EndIf
EndIf

If Self.down_arrow.mouse_over = True
gui_element.clicked = True
If current_gadget<>Null
If current_gadget.after(gadget_list) <> Null
current_gadget=current_gadget.after(gadget_list)
EndIf
EndIf
EndIf
If Self.detect_mouse_over(mouse_x,Mouse_Y) = True
gui_element.clicked = True
EndIf


EndIf

EndMethod

EndType

Type up_arrow Extends gui_element


Function Create:up_arrow(parent:gui_element)
Local u:up_arrow = New up_arrow
u.x = (parent.x + parent.width)+10
u.y=parent.y
u.width = 29
u.height = 29
u.parent = parent
parent.up_arrow = u
Return u
EndFunction

Method render()
SetRotation(0)
SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
SetColor 255 , 255 , 255
SetScale 0.5 , 0.5
DrawImage gui_type.gui_pointer.up_arrow,x,y
SetScale(1,1)
EndMethod

Method update(mouse_hit1,mouse_x,mouse_y)
x = (parent.x + parent.width)+10
y = parent.y
Super.update(mouse_hit1,mouse_x,mouse_y)
EndMethod

EndType

Type down_arrow Extends gui_element


Function Create:down_arrow(parent:gui_element)
Local u:down_arrow = New down_arrow
u.width = 29
u.height = 29
u.x = (parent.x + parent.width)+10
u.y=(parent.y + parent.height) - 58
u.parent = parent
parent.down_arrow = u
Return u
EndFunction

Method render()

SetRotation(0)
SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
SetColor 255 , 255 , 255
SetScale 0.5 , 0.5
DrawImage gui_type.gui_pointer.down_arrow,x,y
SetScale(1,1)
EndMethod

Method update(mouse_hit1 , mouse_x , mouse_y)
x = (parent.x + parent.width)+10
y = (parent.y + parent.height) - 29
Super.update(mouse_hit1 , mouse_x , mouse_y)
EndMethod

EndType


Type toggle_button Extends gui_element

Global img:timage
Global img2:timage
Field active
Field pressed

Function Create:toggle_button(x , y , width:Float , height:Float , text$,parent:gui_element)
Local t:toggle_button=New toggle_button
t.x = x
t.y = y
t.width = width
t.height = height
t.text = text

If img = Null
img=gui_type.gui_pointer.button_img
img2=gui_type.gui_pointer.button_over_img
EndIf

parent.gadget_list.addlast(t)

Return t
EndFunction

Method update(mouse_hit1,mouse_x,mouse_y)
Super.update(mouse_hit1,mouse_x,mouse_y)
If mouse_hit1

If mouse_over = True
If active = False
active = True
Else
active=False
EndIf
gui_element.clicked=True
pressed = True
EndIf
EndIf
EndMethod

Method render()

SetColor(255,255,255)
SetScale (Self.width / ImageWidth(img) , height / ImageHeight(img))

If active=True
DrawImage img2 , x , y
Else
DrawImage img,x,y
EndIf

SetScale(1 , 1)

If active=False
SetColor (gui_type.gui_pointer.textr , gui_type.gui_pointer.textg , gui_type.gui_pointer.textb)
Else
SetColor (170,0,0)
EndIf

Local draw_x=(x+(width/2))-(TextWidth(text)/2)
Local draw_y=(y+(height/2))-(TextHeight(text)/2)
DrawText text,draw_x,draw_y
SetColor(255 , 255 , 255)

EndMethod

EndType
No guarantee the indentation is perfect, all I did was run it through the reformatting command in TextMate.


byo(Posted 1+ years ago)

 Nice. Thanks for sharing, Jeremy. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal