December 04, 2020, 10:26:54 AM

Author Topic: [bmx] MaxGUI Template by Filax [ 1+ years ago ]  (Read 433 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] MaxGUI Template by Filax [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : MaxGUI Template
Author : Filax
Posted : 1+ years ago

Description : This template allow the user to make maxgui apps :) The
program use less CPU but you can refresh graphics without
eat all CPU process :)

I hope that usefull for you :) It's not perfect, but it work.


Code :
Code: BlitzMax
  1. ' -----------------------------------------------
  2. ' Max GUI template by  Filax, u se as you want :)
  3. ' -----------------------------------------------
  4. SuperStrict
  5.  
  6. Local w:Int=400
  7. Local h:Int=400
  8. Local x:Int=(GadgetWidth(Desktop())-w)/2
  9. Local y:Int=(GadgetHeight(Desktop())-h)/2
  10.  
  11. Global MyWindow:TGadget=CreateWindow("EventHook Example", x,y,w,h,Null,WINDOW_TITLEBAR|WINDOW_ACCEPTFILES)
  12. Global MyCanvas:TGadget=CreateCanvas(0,0,380,360,MyWindow)
  13. SetGadgetAlpha( MyCanvas,0.5 )
  14.  
  15.  
  16. Global Button:TGadget=CreateButton("Test",10,10,80,20,MyCanvas,BUTTON_PUSH)
  17. Global Listbox:TGadget=CreateListBox(10,50,100,100,MyCanvas)
  18. AddGadgetItem(Listbox,"TRTERTER")
  19.  
  20. Global SmallWindow:TGadget=CreateWindow("Move Me", x+125, y+150, 150, 100, MyWindow, WINDOW_TITLEBAR)
  21.  
  22. AddHook EmitEventHook,UpdateHook
  23. CreateTimer(60) ' Refresh the graphics to 60 frames per seconds
  24.  
  25. ' ---------
  26. ' Main loop
  27. ' ---------
  28. Repeat
  29.         UpdateApp()
  30. Forever
  31.  
  32. ' --------------------
  33. ' App refresh function
  34. ' --------------------
  35. Function UpdateApp()
  36.   WaitEvent()
  37.        
  38.   Select EventID()
  39.         Case EVENT_TIMERTICK
  40.         UpdateGraphics()
  41.    End Select
  42. End Function
  43.  
  44. ' ------------------
  45. ' Gadget events hook
  46. ' ------------------
  47. Function UpdateHook:Object(iId:Int,tData:Object,tContext:Object)
  48.         Local Event:TEvent=TEvent(tData)
  49.  
  50.         Select Event.ID
  51.         Case EVENT_APPSUSPEND
  52.                 Print "APP SUSPEND"
  53.  
  54.         Case EVENT_APPRESUME
  55.                 Print "APP RESUME"
  56.                
  57.         Case EVENT_WINDOWMOVE
  58.                 Print "WIN MOVE"
  59.                
  60.         Case EVENT_MENUACTION
  61.                 Print "MENU ACTION"
  62.                
  63.         Case EVENT_WINDOWACCEPT
  64.                 Print "DRAG N DROP"
  65.                                
  66.         Case EVENT_WINDOWCLOSE
  67.                 End
  68.                
  69.         Case EVENT_GADGETPAINT
  70.                 UpdateGraphics()
  71.                                
  72.         Case EVENT_GADGETACTION
  73.                 Select Event.Source
  74.                 Case Button
  75.                         Notify "Yearrr"
  76.                 Case Listbox
  77.                         Notify "Listbox double click"
  78.                 EndSelect
  79.                
  80.         Case EVENT_GADGETSELECT
  81.                 Select Event.Source
  82.                 Case Listbox
  83.                         Notify "Listbox single click"
  84.                 EndSelect
  85.                                        
  86.         EndSelect
  87.        
  88.         Return tData
  89. End Function
  90.  
  91. ' -------------------------
  92. ' Update graphics if needed
  93. ' -------------------------
  94. Function UpdateGraphics:Int()
  95.         SetGraphics CanvasGraphics(MyCanvas)
  96.         Cls
  97.         SetColor Rnd(255),Rnd(255),Rnd(255)
  98.         DrawRect 0,0,GraphicsWidth(),GraphicsHeight()
  99.         Flip False
  100. End Function


Comments :


TikiDays(Posted 1+ years ago)

 Thanks for the template. Needed to add  "Import MaxGUI.Drivers" at the start though :)


Hardcoal(Posted 1+ years ago)

 Cool thing and useful


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal