I use one of the beta versions of the VD because I like the way it sets up the program loop. I think it is more structured that way and easier for the compiler to optimize the ASM, using the other format actually added 25% to the size of my program... when comparing the stack of elseifs in the original program loop.
basic window code with 1 button, as an example:
Code: Select all
Enumeration
#Window_0
EndEnumeration
Enumeration
#Text_0
#Button_1
#Button_0
EndEnumeration
Structure VisualDesignerGadgets
Gadget.l
EventFunction.l
EndStructure
Global NewList EventProcedures.VisualDesignerGadgets()
Procedure Text_0_Event(Window, Event, Gadget, Type)
Debug "#Text_0"
EndProcedure
Procedure Button_1_Event(Window, Event, Gadget, Type)
Debug "#Button_1"
SetGadgetText(#Text_0, "BUTTON ONE HAS BEEN PUSHED!")
EndProcedure
Procedure Button_0_Event(Window, Event, Gadget, Type)
Debug "#Button_0"
SetGadgetText(#Text_0, "BUTTON ZERO HAS BEEN PUSHED!")
EndProcedure
Procedure RegisterGadgetEvent(Gadget, *Function)
If IsGadget(Gadget)
AddElement(EventProcedures())
EventProcedures()\Gadget = Gadget
EventProcedures()\EventFunction = *Function
EndIf
EndProcedure
Procedure CallEventFunction(Window, Event, Gadget, Type)
ForEach EventProcedures()
If EventProcedures()\Gadget = Gadget
CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
LastElement(EventProcedures())
EndIf
Next
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 5, 5, 318, 155, "Window EXAMPLE", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Window_0))
ButtonGadget(#Button_0, 15, 55, 280, 35, "SET TEXT 0")
RegisterGadgetEvent(#Button_0, @Button_0_Event())
ButtonGadget(#Button_1, 15, 100, 280, 35, "SET TEXT 1")
RegisterGadgetEvent(#Button_1, @Button_1_Event())
TextGadget(#Text_0, 15, 15, 280, 20, "NADA", #PB_Text_Center | #PB_Text_Border)
RegisterGadgetEvent(#Text_0, @Text_0_Event())
EndIf
EndIf
EndProcedure
Open_Window_0()
Repeat
Event = WaitWindowEvent()
Gadget = EventGadget()
Type = EventType()
Window = EventWindow()
Select Event
Case #PB_Event_Gadget
CallEventFunction(Window, Event, Gadget, Type)
EndSelect
Until Event = #PB_Event_CloseWindow
End
While the organization and benefit are at a minimum in a tiny program like this... my POS Application has over 1000 buttons all told on 9 screens. Organization like this is mind numbingly easy at t hat point.
the other way:
Code: Select all
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
;- Window Constants
;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#Text_0
#Button_0
#Button_1
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 335, 160, "Window EXMAPLE 2", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Window_0))
TextGadget(#Text_0, 12, 18, 312, 18, "", #PB_Text_Center | #PB_Text_Border)
ButtonGadget(#Button_0, 12, 48, 312, 36, "SET TEXT ZERO")
ButtonGadget(#Button_1, 12, 96, 312, 36, "SET TEXT ONE")
EndIf
EndIf
EndProcedure
Open_Window_0()
Repeat ; Start of the event loop
Event = WaitWindowEvent() ; This line waits until an event is received from Windows
WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadget() ; Is it a gadget event?
EventType = EventType() ; The event type
;You can place code here, and use the result as parameters for the procedures
If Event = #PB_Event_Gadget
If GadgetID = #Button_0
SetGadgetText(#Text_0, "BUTTON ZERO PRESSED!")
ElseIf GadgetID = #Button_1 ; the elseif go on and on and on if you have a lot of buttons!!!
; better To have a Procedure For each
SetGadgetText(#Text_0, "BUTTON ONE PUSHED!")
EndIf
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
;
Is looser, and if you have a lot of buttons you have a stack of
ElseIfs running amuck in your program loop...
I think it is messy.
And with a lot of controls can be cumbersome.
