Ooops
November 28, 2020, 02:21:11 PM

Author Topic: [bmx] CheckBox by JoshK [ 1+ years ago ]  (Read 539 times)

Offline BlitzBot

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

Description : Sometimes you may be lining up a lot of gadgets with text labels on the left, and the gadget on the right.  In this situation, it looks better to have a checkbox that simply says True or False depending on whether it is checked, and a label to the left of it.  With this proxy gadget, you don't have to code the label switching for each button.

Code :
Code: BlitzMax
  1. SuperStrict
  2.  
  3. Import maxgui.drivers
  4.  
  5. Type TCheckBox Extends TProxyGadget
  6.        
  7.         Field button:TGadget
  8.        
  9.         Method Cleanup()
  10.                 RemoveHook(EmitEventHook,EventHook,Self)
  11.                 Super.cleanup()
  12.         EndMethod      
  13.        
  14.         Method UpdateText(state:Int)
  15.                 If state
  16.                         SetGadgetText button,"True"
  17.                 Else
  18.                         SetGadgetText button,"False"
  19.                 EndIf
  20.         EndMethod
  21.        
  22.         Function EventHook:Object(id:Int,data:Object,context:Object)
  23.                 Local event:TEvent
  24.                 Local checkbox:TCheckBox
  25.                
  26.                 event=TEvent(data)
  27.                 If event
  28.                         Select event.id                
  29.                         Case EVENT_GADGETACTION        
  30.                                 checkbox=TCheckBox(context)
  31.                                 If checkbox
  32.                                         If event.source=checkbox
  33.                                                 checkbox.UpdateText event.data
  34.                                         EndIf
  35.                                 EndIf
  36.                         EndSelect
  37.                 EndIf
  38.                 Return data
  39.         EndFunction    
  40.        
  41.         Method SetSelected(state:Int)
  42.                 button.SetSelected state
  43.                 UpdateText state
  44.         EndMethod
  45.        
  46.         Function Create:TCheckBox(x:Int,y:Int,width:Int,height:Int,group:TGadget,style:Int=0)
  47.                 Local checkbox:TCheckBox=New TCheckBox
  48.                 checkbox.button=CreateButton("False",x,y,width,height,group,BUTTON_CHECKBOX)
  49.                 checkbox.SetProxy checkbox.button
  50.                 AddHook EmitEventHook,EventHook,checkbox
  51.                 Return checkbox
  52.         EndFunction
  53.        
  54. EndType
  55.  
  56. Function CreateCheckBox:TCheckBox(x:Int,y:Int,width:Int,height:Int,group:TGadget,style:Int=0)
  57.         Return TCheckBox.Create(x,y,width,height,group,style)
  58. EndFunction
  59.  
  60.  
  61. 'Example
  62. Rem
  63. Global window:TGadget = CreateWindow("MaxGUI Buttons",40,40,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
  64. Local checkbox:TGadget = CreateCheckBox(20,20,60,22,window)
  65. SetButtonState checkbox,True
  66.  
  67. Repeat
  68.         Select WaitEvent()
  69.                 Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
  70.                         End
  71.                 Case EVENT_GADGETACTION
  72.                         Print "EVENT_GADGETACTION~n" + ..
  73.                         "GadgetText(): ~q" + GadgetText(TGadget(EventSource())) + "~q ~t " + ..
  74.                         "ButtonState(): "+ ButtonState(TGadget(EventSource()))
  75.         EndSelect
  76. Forever
  77. EndRem


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal