GUI Object

'A very simple to program GUI class
'Start by adding controls, then open the form.  Each control has an index.
'the form can be modal or non-modal.
'non-modal panel should have an event loop which runs while a zero or positive conrol index is 'returnd.  A negative index means ok or cancel was pressed by the user.
'A modal panel won't return until the user pressed ok or cancel, so an event loop isn't needed.


Function
AddControl(ControlType As String, Caption As String, Value As Long, Min As Long, max As Long, Flags As Long) As Long

Sub
OpenPanel(Optional ByVal Modal As Boolean = False)

Sub
SetCaption(Caption As String)

Sub
SetSettings(Index As Long, Set_Value As Long, Set_String As String)

Sub
GetSettings(Index As Long, ByRef Returned_Value As Long, ByRef Returned_String As String)

Function
WaitOnEvent(ByRef Returned_Value As Long, ByRef Returned_String As String) As Long

Sub
ClosePanel()

Sub
SetList(Index As Long, element As Long, Set_List As String)

Sub
SetSpacing(Set_Spacing As Long)



'An example GUI script

function main()

msgbox "An example of creating a GUI with VBScript for Howler"

'this is most of the controls that the GUI object supports, not counting list and combo boxes
'each call returns the index of the control that is created.
'you can make up to 10 of each type of control, except the color box, which can have 4

'g1-g7 are variables that will recieve the index of each control, so we can access their settings later.

g1 = GUI.AddControl("Button", "First Button", 0, 0, 1, 0)
g2 = GUI.AddControl("Text", "Textbox", 10, 0, 100, 0)
g3 = GUI.AddControl("Scroller", "Scroller", 0, 0, 100, 0)
g4 = GUI.AddControl("Check", "Checkbox", 0, 0, 1, 0)
g5 = GUI.AddControl("Number", "Number", 0, 0, 100, 0)
g6 = GUI.AddControl("Line", "Line", 0, 0, 0, 0)
g7 = GUI.AddControl("Colorbox", "Colorbox", 0, 0, 0, 0)
GUI.OpenPanel

'***** this is one possible main event loop *****

'we need variables for return values
Dim idx,  retVal , retstr

While GUI.WaitOnEvent_v(retVal, retstr) >= 0
'btw, GUI.waitonevent returns the idx of what control is being utilized at this event by the user.
'a negative value of -1 or -2 means ok or cancel

 
  'we can get the settings for each control like this, using the index for the control you want to know about
    'GUI.GetSettings_v g1, retVal, retstr

    'run a function and update the screen everytime the user clicks a control.
    If idx >= 0 Then
    'call the function you want to perform
    'also refresh the screen
    End If
Wend

'close the window and finish anything up.
GUI.ClosePanel

end function
Example 2

'An addition was made to support variants in the datatype which can be used by VBScript


Sub
GetSettings_V Index As varient, ByRef Returned_Value As variant, ByRef Returned_String As String)



'Example using combo boxes and GetSettings_v to read settings

'Global variables
public Flower_Count, Tree_Count, Sun_Position, Time_of_Year


function main()

' Example of creating a GUI with VBScript for Howler to control scene parameters

' Declare variables to receive the index of each control
Dim flowersSlider, treesSlider, sunPositionDropdown, timeOfYearDropdown

' Create the GUI controls
GUI.SetCaption "Bing Copilot generated script"
GUI.AddControl "TextLabel","Render a nature scene",0,0,0,0 'add a label control because of a bug in the GUI class, the first control doesn't work with GetSettings_v. We could alternatively just add a null control. ""
'GUI.AddControl "","",0,0,0,0 'a null control

flowersSlider = GUI.AddControl("Scroller", "Flowers", 50, 0, 500, 0)
treesSlider = GUI.AddControl("Scroller", "Trees", 1, 0, 10, 0)
sunPositionDropdown = GUI.AddControl("Combobox", "Sun", 0, 0, 0, 0)
timeOfYearDropdown = GUI.AddControl("Combobox", "Season", 0, 0, 0, 0)

' Add items to the dropdown lists
GUI.SetList clng(sunPositionDropdown),0, "Dawn"
GUI.SetList clng(sunPositionDropdown),1, "Noon"
GUI.SetList clng(sunPositionDropdown),2, "Dusk"
GUI.SetSettings clng(sunPositionDropdown), clng(0), "Dawn" 'set the default string.
GUI.SetCaption "Bing Copilot generated script"

GUI.SetList clng(timeOfYearDropdown),0, "Spring"
GUI.SetList clng(timeOfYearDropdown),1, "Summer"
GUI.SetList clng(timeOfYearDropdown),2, "Autumn"
GUI.SetList clng(timeOfYearDropdown),3, "Winter"
GUI.SetSettings clng(timeOfYearDropdown), clng(0), "Spring"
'set the default string.

' Open the GUI panel

GUI.OpenPanel

' Main event loop
Dim idx, retVal, retstr
While GUI.WaitOnEvent_v(retVal, retstr) >= 0
     idx = retVal ' Get the index of the control that triggered the event


' Retrieve the number of flowers from the slider
GUI.GetSettings_v flowersSlider, Flower_Count, retstr
' Retrieve the number of trees from the slider
GUI.GetSettings_v treesSlider, Tree_Count, retstr
' Retrieve the selected sun position from the dropdown
GUI.GetSettings_v sunPositionDropdown, retVal, Sun_Position
' Retrieve the selected time of year from the dropdown
GUI.GetSettings_v timeOfYearDropdown, retVal, Time_of_Year

'call a function to execute your code
'render

Wend

' Close the GUI panel
GUI.ClosePanel


end function