January 16, 2021, 05:25:04 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
BlitzPlus Gui
»
[bmx] CheckBox by JoshK [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bmx] CheckBox by JoshK [ 1+ years ago ] (Read 545 times)
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
SuperStrict
Import
maxgui.drivers
Type
TCheckBox
Extends
TProxyGadget
Field
button:TGadget
Method
Cleanup
(
)
RemoveHook
(
EmitEventHook,EventHook,
Self
)
Super
.cleanup
(
)
EndMethod
Method
UpdateText
(
state:
Int
)
If
state
SetGadgetText button,
"True"
Else
SetGadgetText button,
"False"
EndIf
EndMethod
Function
EventHook:
Object
(
id:
Int
,data:
Object
,context:
Object
)
Local
event:TEvent
Local
checkbox:TCheckBox
event=TEvent
(
data
)
If
event
Select
event.id
Case
EVENT_GADGETACTION
checkbox=TCheckBox
(
context
)
If
checkbox
If
event.source=checkbox
checkbox.UpdateText event.data
EndIf
EndIf
EndSelect
EndIf
Return
data
EndFunction
Method
SetSelected
(
state:
Int
)
button.SetSelected state
UpdateText state
EndMethod
Function
Create:TCheckBox
(
x:
Int
,y:
Int
,width:
Int
,height:
Int
,group:TGadget,style:
Int
=
0
)
Local
checkbox:TCheckBox=
New
TCheckBox
checkbox.button=CreateButton
(
"False"
,x,y,width,height,group,BUTTON_CHECKBOX
)
checkbox.SetProxy checkbox.button
AddHook EmitEventHook,EventHook,checkbox
Return
checkbox
EndFunction
EndType
Function
CreateCheckBox:TCheckBox
(
x:
Int
,y:
Int
,width:
Int
,height:
Int
,group:TGadget,style:
Int
=
0
)
Return
TCheckBox.Create
(
x,y,width,height,group,style
)
EndFunction
'Example
Rem
Global
window:TGadget = CreateWindow
(
"MaxGUI Buttons"
,
40
,
40
,
400
,
330
,
Null
,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS
)
Local
checkbox:TGadget = CreateCheckBox
(
20
,
20
,
60
,
22
,window
)
SetButtonState checkbox,
True
Repeat
Select
WaitEvent
(
)
Case
EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
End
Case
EVENT_GADGETACTION
Print
"EVENT_GADGETACTION~n"
+ ..
"GadgetText(): ~q"
+ GadgetText
(
TGadget
(
EventSource
(
)
)
)
+
"~q ~t "
+ ..
"ButtonState(): "
+ ButtonState
(
TGadget
(
EventSource
(
)
)
)
EndSelect
Forever
EndRem
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
BlitzPlus Gui
»
[bmx] CheckBox by JoshK [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal