GadgetState()
BlitzMax Forums/BlitzMax Module Tweaks/GadgetState()
| ||
Some of MaxGUI's commands have never made sense to me, like ButtonState(), and SliderValue(). PureBasic combines all these things with SelectedGadgetItem() into one command: GadgetState(). 1. In MaxGUI.mod/MaxGUI.mod/gadget.bmx, add this field to the TGadget type: Field class 2. Add this code in MaxGUI.mod/MaxGUI.mod/MaxGUI.bmx: Function GadgetState:Int(gadget:TGadget) Select gadget.class Case GADGET_MENUITEM Return MenuChecked(gadget) Case GADGET_SLIDER Return SliderValue(gadget) Case GADGET_BUTTON Return ButtonState(gadget) Case GADGET_COMBOBOX,GADGET_LISTBOX,GADGET_TABBER Return SelectedGadgetItem(gadget) EndSelect EndFunction Function SetGadgetState(gadget:TGadget,state:Int) Select gadget.class Case GADGET_MENUITEM If state CheckMenu gadget Else UncheckMenu gadget Case GADGET_SLIDER SetSliderValue gadget,state Case GADGET_BUTTON SetButtonState gadget,state Case GADGET_COMBOBOX,GADGET_LISTBOX,GADGET_TABBER SelectGadgetItem gadget,state Case GADGET_PROGBAR UpdateProgBar gadget,state/100.0 EndSelect EndFunction 3. In MaxGUI.mod/Win32MaxGUIEx.mod/win32maxguiex.bmx, add this line anywhere in the the TWindowsGadget Register() method: Self.class=class 4. One more thing; Menu items don't get run through the Register() method, so add this to the TWindowMenu Create() method: class=GADGET_MENUITEM Recompile MaxGUI.MaxGUI and MaxGUI.Win32MaxGUIEx. You can now use SetGadgetState() and GadgetState(), and it will replace the following commands: MenuChecked() ButtonState() MenuChecked() SelectedGadgetItem() SliderValue() SelectGadgetItem() CheckMenu() SetButtonState() UpdateProgBar() SetSliderValue() Use an integer percentage when using SetGadgetState() on a ProgBar. I didn't bother with the Mac version, but it would be easy to add the class setting into the Mac module, or into the main MaxGUI module. |