[bb] Vein R3 GUI by N [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

Title : Vein R3 GUI
Author : N
Posted : 1+ years ago

Description : This is the GUI I designed for Vein R3 (back when I still had Blitz3D).  This is an old hacked standalone version I had made for a friend, so might as well throw it up here.

Most of the functions are fairly self-explanatory.  E.g., Button creates a button, Window creates a window, so on and so forth.

<a href="codearcs96c7.html?code=1160" target="_blank">Requires my stack code.</a>


Code :
Code (blitzbasic) Select
;#Region DESCRIPTION
;; Functions for grabbing input
;#End Region

;#Region CLASSES
Type InputEngine
Field MX%,MY%,MZ%,MXS%,MYS%,MZS%
Field MD1%,MD2%,MD3%,OMD1%,OMD2%,OMD3%

Field Key%[255]
Field OldKey%[255]
End Type

Global InEngine.InputEngine = New InputEngine
;#End Region

;#Region PROCEDURES
Function GrabInput()
For i = 1 To 237
InEngineOldKey[i] = InEngineKey[i]
InEngineKey[i] = KeyDown(i)
Next

InEngineMXS = MouseXSpeed()
InEngineMYS = MouseYSpeed()
InEngineMZS = MouseZSpeed()

InEngineMX = MouseX()
InEngineMY = MouseY()
InEngineMZ = MouseZ()

InEngineOMD1 = InEngineMD1
InEngineOMD2 = InEngineMD2
InEngineOMD3 = InEngineMD3

InEngineMD1 = MouseDown(1)
InEngineMD2 = MouseDown(2)
InEngineMD3 = MouseDown(3)
End Function

Function iMouseXSpeed()
Return InEngineMXS
End Function

Function iMouseYSpeed()
Return InEngineMYS
End Function

Function iMouseZSpeed()
Return InEngineMZS
End Function

Function iMouseX()
Return InEngineMX
End Function

Function iMouseY()
Return InEngineMY
End Function

Function iMouseZ()
Return InEngineMZ
End Function

Function iMouseDown(Mouse)
Select Mouse
Case 1
md = InEngineMD1
Case 2
md = InEngineMD2
Case 3
md = InEngineMD3
End Select

Return md
End Function

Function iMouseHit(Mouse)
Select Mouse
Case 1
omd = InEngineOMD1
md = InEngineMD1
Case 2
omd = InEngineOMD2
md = InEngineMD2
Case 3
omd = InEngineOMD3
md = InEngineMD3
End Select

Return (omd = 0 And md = 1)
End Function

Function iMouseUp(Mouse)
Select Mouse
Case 1
omd = InEngineOMD1
md = InEngineMD1
Case 2
omd = InEngineOMD2
md = InEngineMD2
Case 3
omd = InEngineOMD3
md = InEngineMD3
End Select

Return (omd = 1 And md = 0)
End Function

Function iKeyHit(Key)
If InEngineKey[Key] = 1 And InEngineOldKey[Key] = 0 Then Return 1
Return 0
End Function

Function iKeyUp(Key)
If InEngineKey[Key] = 0 And InEngineOldKey[Key] = 1 Then Return 1
Return 0
End Function

Function iKeyDown(Key)
Return InEngineKey[Key]
End Function

Function iMouseInRect(X,Y,W,H)
If (InEnginemx >= X) And (InEnginemy >= Y) And (InEnginemx <= X+W) And (InEnginemy <= Y+H) Return 1
Return 0
End Function

Function iSendMouseHit(Mouse)
Select Mouse
Case 1
InEngineMD1 = 1
InEngineOMD1 = 0
Case 2
InEngineMD2 = 1
InEngineOMD2 = 0
Case 3
InEngineMD3 = 1
InEngineOMD3 = 0
End Select
End Function

Function iSendMouseUp(Mouse)
Select Mouse
Case 1
InEngineMD1 = 0
InEngineOMD1 = 1
Case 2
InEngineMD2 = 0
InEngineOMD2 = 1
Case 3
InEngineMD3 = 0
InEngineOMD3 = 1
End Select
End Function

Function iSendMouseDown(Mouse)
Select Mouse
Case 1
InEngineMD1 = 1
Case 2
InEngineMD2 = 1
Case 3
InEngineMD3 = 1
End Select
End Function
;#End Region


;#Region CLASSES
Type Event
Field GadgetID
Field Info$
End Type
;#End Region

;#Region PROCEDURES
Function Event(i.Gadget,Info$)
Local e.Event = New Event
eGadgetID = Handle(i)
eInfo = Info
Return Handle(e)
End Function
;#End Region


;#Region CLASSES
Type Gadget
Field X%,Y%,Z% ;; Local X position, local Y position, Z stack height
Field Width%,Height%
Field Parent.Gadget ;; Parent gadget

Field Gadgets ;; Stack

Field Class ;; Gadget class (refer to GUI_ constants)
Field State%[32] ;; State
Field Params%[32] ;; Parameters

Field Content$
Field Caption$

Field MenuStrip.Gadget
Field ToolStrip.Gadget

Field GroupID%

Field Min#
Field Max#
Field Val#

Field Over%

Field Image ;; Image used in gadget drawing

Field Mode

Field Name$

Field Icon%
End Type

;#Region GADGET CLASSES
Const GUI_WINDOW = $4000

Const GUI_LABEL = $4001
Const GUI_BUTTON = $4002

Const GUI_GROUPBOX = $4003
Const GUI_ROLLOUT = $4004
Const GUI_VIEWPORT = $4013

Const GUI_PROGRESSBAR = $4005
Const GUI_HORSCROLL = $4006
Const GUI_VERSCROLL = $4007
Const GUI_TRACKBAR = $4008
Const GUI_SLIDER = $4009

Const GUI_RADIO = $400A
Const GUI_CHECKBOX = $400B

Const GUI_MENUSTRIP = $400C
Const GUI_MENUTITLE = $400D
Const GUI_MENUITEM = $400E
Const GUI_MENUBAR = $400F

Const GUI_CONTEXTMENU = $40010
Const GUI_CONTEXTMENUITEM = $4011
Const GUI_CONTEXTMENUBAR = $4012

Const GUI_DIAL = $4013

Const GUI_LISTBOX = $4014
Const GUI_LISTBOXITEM = $4015

Const GUI_COMBOBOX = $4016
Const GUI_COMBOBOXITEM = $4017

Const GUI_TREEVIEW = $4018
Const GUI_TREEVIEWNODE = $4019

Const GUI_TEXTBOX = $401A

Const GUI_TABSTRIP = $401B
Const GUI_TABPAGE = $401C

Const GUI_STATUSSTRIP = $401D
Const GUI_STATUSITEM = $401E

Const GUI_TOOLSTRIP = $401F
Const GUI_TOOLITEM = $4020
Const GUI_TOOLBAR  = $4021

Const GUI_PANEL = $4022

Const GUI_IMAGEBOX = $4023
;#End Region

;#Region WINDOW MODES
Const WM_TITLEBAR = 1
Const WM_CLOSEBTN = 2
Const WM_MINBTN = 4
Const WM_TITLEBARSHADOW = 8
;#End Region

;#Region PROGRESS BAR MODES
Const SLIDER_HOR = 1
Const SLIDER_VER = 2

Const SLIDER_INTEGER = 4
Const SLIDER_FLOAT = 8
;#End Region

;#Region STATES
Const GADGET_HIDDEN = 30 ;; Globally used

Const WINDOW_DRAG = 0
Const WINDOW_DRAGX = 1
Const WINDOW_DRAGY = 2
Const WINDOW_DROPX = 3
Const WINDOW_DROPY = 4
Const WINDOW_LOCKED = 5
Const WINDOW_CLOSEBUTTON = 6
Const WINDOW_MINBUTTON = 7
Const WINDOW_MINIMIZED = 8
Const WINDOW_CLOSED = 9

Const BUTTON_DOWN = 0

Const ROLLOUT_CLOSED = 0

Const TEXTBOX_ACTIVE = 0

Const TICK_CHECKED = 0
;#End Region

;#Region COLORS
Const WINDOW_TITLE_INACTIVE_F = $FF8DE1EB
Const WINDOW_TITLE_INACTIVE_T = $FF9EACBA
Const WINDOW_TITLE_ACTIVE_F = $FF97C1EB
Const WINDOW_TITLE_ACTIVE_T = $FF6790B9
Const WINDOW_DIALOG_F = $C8C8C8
Const WINDOW_DIALOG_T = $B4B4B4
;#End Region

Global GUI_RootGadgets ;; Gadgets with no parent (windows)
Global GUI_ActiveContextMenu.Gadget ;; Active (open) context menu
Global GUI_ContextMenus ;; Context menus
Global GUI_ContextMenuImage ;; Context menu graphic
Global GUI_ContextMenuItemImage ;; Context menu item graphic
Global GUI_ModalWindow.Gadget ;; Modal window
Global GUI_Font ;; Normal font
Global GUI_FontBold ;; Bold font
Global GUI_LFont ;; Large normal font
Global GUI_LFontBold ;; Large bold font
Global GUI_MouseCursor ;; Mouse cursor image
Global GUI_PointerHidden ;; Whether or not the cursor is visible
;#End Region

;#Region PROCEDURES
Function UpdateGUI()
If GUI_ModalWindow <> Null Then
z = GUI_ModalWindow
For g.Gadget = Each Gadget
If gClass = GUI_WINDOW And g <> GUI_ModalWindow And g > z
g = g - 1
EndIf
Next
GUI_ModalWindow = MoveObjectToBack(GUI_RootGadgets,GUI_ModalWindow)
EndIf

UpdateGadget(GUI_ActiveContextMenu)

If GUI_ActiveContextMenu <> Null Then
cm.Gadget = GUI_ActiveContextMenu
If cmOver = 1 Then Return
EndIf

For i = 0 To Objects(GUI_RootGadgets)-1
g.Gadget = Object.Gadget(GetObject(GUI_RootGadgets,i))
UpdateGadget(g)
Next
End Function

Function UpdateGadget(i.Gadget)
If i = Null Then Return

If iState[30] = 1 Then Return

Local x = GetGadgetSX(i)
Local y = GetGadgetSY(i) + (16*(iMenuStrip <> Null) + 20*(iToolStrip <> Null))*(iClass <> GUI_WINDOW)

Local r.Gadget = GetRoot(i)
Local isActive = (r = Objects(GUI_RootGadgets)-1)
If r <> Null Then
If rClass = GUI_CONTEXTMENU Then
isActive = 1
x = GetGadgetSX(iParent)
y = GetGadgetSY(iParent)+i*20
iWidth = rWidth
iHeight = 19
EndIf
EndIf

Local mh1 = iMouseHit(1)
Local mu1 = iMouseUp(1)
Local md1 = iMouseDown(1)
Local mx = iMouseX()
Local my = iMouseY()
Local mz = iMouseZ()

Local rStack

If iParent <> Null Then
rStack = iParentGadgets
Else
rStack = GUI_RootGadgets
EndIf

Local az = Objects(rStack)-1

Local over = iMouseInRect(x,y,iWidth,iHeight*(Not iState[WINDOW_MINIMIZED]) + (24*(iClass = GUI_WINDOW)*(iMode And WM_TITLEBAR))+(16*(iMenuStrip <> Null) + 20*(iToolStrip <> Null))*(iClass = GUI_WINDOW))
iOver = over

Local g.Gadget = Null

Select iClass

Case GUI_WINDOW
If iState[WINDOW_CLOSED] = 1 Then Return
If GUI_ModalWindow = Null Then
If mh1 And over And i < az Then
For g.Gadget = Each Gadget
If gClass = GUI_WINDOW And g > i And g <> i And gParent = iParent Then
gx = GetGadgetSX(g)
gy = GetGadgetSY(g)
If iMouseInRect(gx,gy,gWidth,gHeight*(Not gState[WINDOW_MINIMIZED])+24*((gMode And WM_TITLEBAR) = WM_TITLEBAR)) Then Exit
EndIf
Next

If g = Null Then
For g.Gadget = Each Gadget
If gClass = GUI_WINDOW And g > i And g <> i Then g = g - 1
Next
i = MoveObjectToBack(rStack,i)
EndIf
EndIf
EndIf

If (iMode And WM_TITLEBAR) = WM_TITLEBAR And i = az Then
overClose = MaxI(iMouseInRect(x+iWidth-20,y+4,16,16),((iMode And WM_CLOSEBTN) = WM_CLOSEBTN))
overMin = MaxI(iMouseInRect(x+iWidth-20-20*((iMode And WM_CLOSEBTN)=WM_CLOSEBTN),y+4,16,16),((iMode And WM_MINBTN) = WM_MINBTN))
If iState[5] = 0 Then
over = iMouseInRect(x,y,iWidth,24)

If mh1 And over And overClose = 0 And overMin = 0 Then
iState[0] = 1
iState[1] = iMouseX()
iState[2] = iMouseY()
iState[3] = iX
iState[4] = iY
ElseIf md1 And iState[0] = 1 Then
iX = iState[3] + (iMouseX()-iState[1])
iY = iState[4] + (iMouseY()-iState[2])
EndIf

If mu1 And iState[0] = 1 Then
iState[0] = 0
EndIf
EndIf

If (iMode And WM_CLOSEBTN) = WM_CLOSEBTN Then
over = overClose

If mh1 And over Then
iState[WINDOW_CLOSEBUTTON] = 1
ElseIf iState[WINDOW_CLOSEBUTTON] <> 1 And over Then
iState[WINDOW_CLOSEBUTTON] = 2
ElseIf iState[WINDOW_CLOSEBUTTON] = 1 And mu1 And over Then
iState[WINDOW_CLOSEBUTTON] = over*2
iState[WINDOW_CLOSED] = 1
Event(i,"Closed")
For g.Gadget = Each Gadget
If g <> i And gClass = GUI_WINDOW Then g = g + 1
Next
i = MoveObjectToFront(GUI_RootGadgets,i)
ElseIf (iState[WINDOW_CLOSEBUTTON] <> 1) Or (iState[WINDOW_CLOSEBUTTON] = 1 And mu1)
iState[WINDOW_CLOSEBUTTON] = over*2
EndIf
EndIf

If (iMode And WM_MINBTN) = WM_MINBTN Then
over = overMin

If mh1 And over Then ;; You know.. I could have avoided all these i = az things early on, but at the time I was hyped up on coffee and didn't think about it.
iState[WINDOW_MINBUTTON] = 1
ElseIf mu1 And over And iState[WINDOW_MINBUTTON] = 1 Then
iState[WINDOW_MINBUTTON] = over*2
iState[WINDOW_MINIMIZED] = Not iState[WINDOW_MINIMIZED]
If iState[WINDOW_MINIMIZED] = 1 Then
Event(i,"Shaded")
Else
Event(i,"Unshaded")
EndIf
ElseIf (iState[WINDOW_MINBUTTON] <> 1) Or (iState[WINDOW_MINBUTTON] = 1 And mu1)
iState[WINDOW_MINBUTTON] = over*2
EndIf
EndIf
EndIf

Case GUI_BUTTON
If isActive Then
If iState[0] = 3 Then
ElseIf mh1 And over
iState[0] = 2
ElseIf mu1 And iState[0] = 2
iState[0] = over
Event(i,"Pressed")
ElseIf md1 And iState[0] = 2
iState[0] = 2 ;; Pointless state check, but it's there for the sake of completeness
ElseIf over Then
iState[0] = 1
Else
iState[0] = 0
EndIf
EndIf

Case GUI_TEXTBOX
If isActive Then
If mh1 And over Then
iState[0] = 1
FlushKeys()
ElseIf iState[0] = 1
k = GetKey()

If k = 13 Then
iState[0] = 0
Event(i,iCaption)
ElseIf k = 8 Then
iCaption = Left(iCaption,MinI(Len(iCaption)-1,0))
ElseIf over = 0 And mh1 Then
iState[0] = 0
Event(i,iCaption)
ElseIf k > 31 Then
iCaption = iCaption + Chr(k)
EndIf
EndIf
EndIf

Case GUI_ROLLOUT
If isActive Then
over = iMouseInRect(x,y,iWidth,16)
If mh1 And over Then
iState[ROLLOUT_CLOSED] = Not iState[ROLLOUT_CLOSED]
For g.Gadget = Each Gadget
If gParent = iParent And g <> i And RectsOverlap(iX,iY,iWidth,2048,gX,gY,gWidth,gHeight) Then
gY = gY + (iHeight)*((iState[ROLLOUT_CLOSED] = 0)-(iState[ROLLOUT_CLOSED] = 1))
EndIf
Next
EndIf
EndIf

If iState[0] = 1 Then Return

Case GUI_RADIO
If isActive Then
If over And mh1 Then
iState[TICK_CHECKED] = 2
ElseIf md1 And iState[TICK_CHECKED] = 2
iState[TICK_CHECKED] = 2
ElseIf mu1 And iState[TICK_CHECKED] = 2 And over Then
For g.Gadget = Each Gadget
If gParent = iParent And g <> i And gClass = GUI_RADIO Then
gVal = 0
EndIf
Next
iVal = 1
Event(i,1)
Else
iState[TICK_CHECKED] = over
EndIf
EndIf

Case GUI_CHECKBOX
If isActive
If over And mh1 Then
iState[TICK_CHECKED] = 2
ElseIf md1 And iState[TICK_CHECKED] = 2
iState[TICK_CHECKED] = 2
ElseIf mu1 And iState[TICK_CHECKED] = 2 And over Then
iVal = Not iVal
Event(i,Int iVal)
Else
iState[TICK_CHECKED] = over
EndIf
EndIf

Case GUI_CONTEXTMENU
iHeight = 0
For n = 0 To Objects(iGadgets)-1
g.Gadget = Object.Gadget(GetObject(iGadgets,n))
width = MinI(ImageWidth(gImage)+20,width)
iHeight = iHeight + 16
Next
iWidth = width

iOver = iMouseInRect(iX,iY,iWidth,iHeight)

If (iMouseHit(1) Or iMouseHit(2) Or iMouseHit(3)) And (iOver=0) Then
GUI_ActiveContextMenu = Null
EndIf

Case GUI_CONTEXTMENUITEM
x = GetGadgetSX(iParent)
y = GetGadgetSY(iParent)+i*16
iState[0] = iMouseInRect(x,y,iWidth,iHeight-1)
If iState[0] And mu1 Then
Event(i,1)
GUI_ActiveContextMenu = Null
EndIf

Case GUI_SLIDER
d# = iMax-iMin
bar# = -(iVal/d)*(iState[1])

If (iMode And SLIDER_HOR) = SLIDER_HOR
p# = (iVal/d)*(iWidth-2)

over = iMouseInRect(x+p+bar+1,y+1,iState[1],iHeight-2)
If mh1 And over Then
iState[2] = 1
ElseIf mu1 And iState[2] = 1 Then
iState[2] = 0
v# = iVal
If (iMode And SLIDER_INTEGER) = SLIDER_INTEGER Then v# = Int v
Event(i,v)
ElseIf iState[2] = 1 And md1 Then
iVal = MaxF(MinF(iMin+(Float(mx-(x+1))/(iwidth-2))*d,iMin),iMax)
v# = iVal
If (iMode And SLIDER_INTEGER) = SLIDER_INTEGER Then v# = Int v
Event(i,v)
EndIf
Else
p# = (iVal/d)*(iHeight-2)

over = iMouseInRect(x+1,y+1+p+bar,iWidth-2,iState[1])
If mh1 And over Then
iState[2] = 1
ElseIf mu1 And iState[2] = 1 Then
iState[2] = 0
v# = iVal
If (iMode And SLIDER_INTEGER) = SLIDER_INTEGER Then v# = Int v
Event(i,v)
ElseIf iState[2] = 1 And md1 Then
iVal = MaxF(MinF(iMin+(Float(my-(y+1))/(iHeight-2))*d,iMin),iMax)
v# = iVal
If (iMode And SLIDER_INTEGER) = SLIDER_INTEGER Then v# = Int v
Event(i,v)
EndIf
EndIf

Case GUI_TRACKBAR
d# = iMax-iMin
pos = Int(( (iVal-iMin) / d )*iState[1])*iState[2]
bar = Int(((iVal-iMin)/d))*iState[2]
over = iMouseInRect(x+pos-bar+1,y+1,iState[2],iHeight-2)
If mh1 And over Then
iState[0] = 1
ElseIf md1 And iState[0] = 1
iVal = MinF(MaxF(( Float(mx-(x+1)) / iWidth )*d,iMax-(d/iState[1])),iMin)
If (iMode And 16) = 16 Then
Event(i,iMin+d-iVal)
Else
Event(i,iVal)
EndIf
ElseIf mu1 And iState[0] = 1
iState[0] = 0
If (iMode And 16) = 16 Then
Event(i,iMin+d-iVal)
Else
Event(i,iVal)
EndIf
EndIf

Case GUI_TABPAGE
over = iMouseInRect(x+iState[1],y-16,iWidth,iHeight)
If mh1 And over Then
iParentState[0] = i
EndIf

If iParentState[0] <> i Then Return

Case GUI_LISTBOXITEM
x = GetGadgetSX(iParent)
y = GetGadgetSY(iParent)+i*20
iOver = iMouseInRect(x,y,iParentWidth,20)
If iOver And mh1 Then
Event(i,iContent)
Event(iParent,Handle(i))
iParentState[LISTBOX_SELECTED] = i
iParentContent  = iName
EndIf

End Select

For n = 0 To Objects(iGadgets)-1
g.Gadget = Object.Gadget(GetObject(iGadgets,n))
UpdateGadget(g)
Next
End Function

Function Gadget.Gadget(Class,Parent=0,Mode=0,X=0,Y=0,W=0,H=0,Caption$="",GroupID%=0,Min#=0,Max#=0,Val#=0,Name$="",icon$="")
Local i.Gadget = New Gadget
iClass = Class
iParent = Object.Gadget(Parent)

If iParent <> Null Then
i = PushObject(iParentGadgets,Handle(i))
ElseIf iParent = Null And iClass = GUI_WINDOW
i = PushObject(GUI_RootGadgets,Handle(i))
ElseIf iParent = Null And iClass = GUI_CONTEXTMENU
i = PushObject(GUI_ContextMenus,Handle(i))
Else
Delete i
Return Null
EndIf
iX = X
iY = Y
iWidth = W
iHeight = H
iCaption = Caption
iMin = Min
iMax = Max
iVal = Val
iGadgets = CreateStack()
iMode = Mode
iIcon = LoadImage(icon)
If iIcon <> 0 Then
MaskImage iIcon,255,0,255
EndIf
If iClass = GUI_TOOLSTRIP Then
If iParent <> Null iParentToolStrip = i
EndIf

If iClass = GUI_MENUSTRIP Then
If iParent <> Null iParentMenuStrip = i
EndIf

If iClass = GUI_SLIDER Or iClass = GUI_TRACKBAR Then
iState[1] = GroupID
EndIf

If Name$ = "" Then
Select iClass
Case GUI_WINDOW
Name="wnd_"
Case GUI_BUTTON
Name="btn_"
Case GUI_ROLLOUT
Name="rol_"
Case GUI_SLIDER
Name="sld_"
Case GUI_PROGRESSBAR
Name="prg_"
Case GUI_TRACKBAR
Name="trk_"
Case GUI_HORSCROLL
Name="hrs_"
Case GUI_VERSCROLL
Name="vrs_"
Case GUI_PANEL
Name="pnl_"
Case GUI_LISTBOX
Name="lst_"
Case GUI_LISTBOXITEM
Name="lsi_"
Case GUI_COMBOBOX
Name="cmb_"
Case GUI_TREEVIEW
Name="trv_"
Case GUI_RADIO
Name="rad_"
Case GUI_CHECKBOX
Name="cbx_"
Case GUI_CONTEXTMENU
Name="cxm_"
Case GUI_CONTEXTMENUITEM
Name="cxi_"
Case GUI_CONTEXTMENUBAR
Name="cxb_"
Case GUI_TABSTRIP
Name="tab_"
Case GUI_TABPAGE
Name="pag_"
Case GUI_VIEWPORT
Name="v3d_"
End Select
index = 1
For g.Gadget = Each Gadget
If g <> i And gClass = iClass Then index = index + 1
Next
Name = Name+index
EndIf

iName = Name

CreateGUIImage(i)
Return i
End Function

Function GetGadgetSX(g.Gadget)
Local x
While g <> Null
x = x + gX
If gClass = GUI_MENUSTRIP Then
For i = 0 To Objects(gGadgets)-1
item.Gadget = Object.Gadget(GetObject(gGadgets,i))
x = x + itemWidth
Next
EndIf
g = gParent
Wend
Return x
End Function

Function GetGadgetSY(g.Gadget)
Local y
While g <> Null
y = y + gy
g = gParent
If g <> Null Then
y = y + ((gClass = GUI_WINDOW)*23*((gMode And WM_TITLEBAR)=WM_TITLEBAR)) + (gClass = GUI_ROLLOUT)*15 + 16*(gMenuStrip <> Null) + 20*(gToolStrip <> Null)
EndIf
Wend
Return y
End Function

Function GetRoot.Gadget(g.Gadget)
While g <> Null
If gParent = Null Then Exit
g = gParent
Wend
Return g
End Function

Function OverGadget(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
x = GetGadgetSX(i)
y = GetGadgetSY(i)

p.Gadget = GetRoot(i)
If p <> Null And p <> i Then
If pClass = GUI_WINDOW And p <> Objects(GUI_RootGadgets)-1 Then Return 0
If pClass = GUI_WINDOW And pState[WINDOW_MINIMIZED] = 1 Then Return 0
EndIf

If iClass = GUI_TABPAGE Then Return iMouseInRect(x,y,iParentWidth,iParentHeight)*(i = iParentState[0])

Return iOver

Select iClass
Case GUI_WINDOW
For g.Gadget = Each Gadget
If g > i And gClass = GUI_WINDOW And g <> i Then
If iMouseInRect(x,y,gWidth,gHeight*(Not gState[WINDOW_MINIMIZED])+24*((gMode And WM_TITLEBAR) = WM_TITLEBAR)) Then Return 0
EndIf
Next
Return iMouseInRect(x,y,iWidth,iHeight*(Not iState[WINDOW_MINIMIZED])+24*((iMode And WM_TITLEBAR) = WM_TITLEBAR))
Case GUI_ROLLOUT
Return iMouseInRect(x,y,iWidth,16+iHeight*(iState[ROLLOUT_CLOSED] = 0))
Case GUI_RADIO,GUI_CHECKBOX
Return iMouseInRect(x,y,16,16)
Case GUI_TABPAGE
Return iMouseInRect(x,y,iParentWidth,iParentHeight)*(i = iParentState[0])
Default
Return iMouseInRect(x,y,iWidth,iHeight)
End Select
End Function

Function Window(X,Y,Width,Height,Caption$="",Mode=WM_TITLEBAR Or WM_CLOSEBTN Or WM_MINBTN,icon$="",name$="")
Return Handle(Gadget(GUI_WINDOW,0,Mode,X,Y,Width,Height,Caption,0,0,0,0,name,icon))
End Function

Function Button(Parent,X,Y,Width,Height,Caption$="",icon$="",name$="")
Return Handle(Gadget(GUI_BUTTON,Parent,Mode,X,Y,Width,Height,Caption,0,0,0,0,name,icon))
End Function

Function Radio(Parent,X,Y,Caption$="",Group=0,Ticked=0,name$="")
Return Handle(Gadget(GUI_RADIO,Parent,Mode,X,Y,0,0,Caption,Group,0,0,Ticked,name))
End Function

Function Checkbox(Parent,X,Y,Caption$="",Ticked=0,name$="")
Return Handle(Gadget(GUI_CHECKBOX,Parent,Mode,X,Y,0,0,Caption,Group,0,0,Ticked,name))
End Function

Function Groupbox(Parent,X,Y,Width,Height,Caption$="",icon$="",name$="")
Return Handle(Gadget(GUI_GROUPBOX,Parent,Mode,X,Y,Width,Height,Caption,0,0,0,0,name,icon))
End Function

Function Rollout(Parent,X,Y,Width,Height,Caption$="",Closed=0,name$="")
Rollout = Handle(Gadget(GUI_ROLLOUT,Parent,Mode,X,Y,Width,Height,Caption,0,0,0,0,name))
If Closed = 1 Then
CloseGadget(Rollout)
EndIf
Return Rollout
End Function

Function Panel(Parent,X,Y,Width,Height,name$="")
Return Handle(Gadget(GUI_PANEL,Parent,Mode,X,Y,Width,Height,0,0,0,0,0,name))
End Function

Function Slider(Parent,X,Y,Width,Height,MinVal#=0,MaxVal#=1,Val#=0,Orientation=SLIDER_HOR,ValueType=SLIDER_INTEGER,SliderWidth=8,Invert=0,name$="")
Return Handle(Gadget(GUI_SLIDER,Parent,Orientation Or ValueType Or (Invert*16),X,Y,Width,Height,"",SliderWidth,MinVal,MaxVal,Val,name))
End Function

Function TrackBar(Parent,X,Y,Width,Height,MinVal#=0,MaxVal#=1,Val#=0,Segments=8,name$="")
Return Handle(Gadget(GUI_TRACKBAR,Parent,0,X,Y,Width,Height,"",Segments,MinVal,MaxVal,Val,name))
End Function

Function TabStrip(Parent,X,Y,Width,Height,name$="")
Return Handle(Gadget(GUI_TABSTRIP,Parent,0,X,Y,Width,Height,"",0,0,0,0,name))
End Function

Function TabPage(Strip,Caption$="",icon$="",name$="")
Return Handle(Gadget(GUI_TABPAGE,Strip,0,0,0,0,0,Caption,0,0,0,0,name,icon))
End Function

Function TextBox(Parent,X,Y,Width,Height,Caption$="",name$="")
Return Handle(Gadget(GUI_TEXTBOX,Parent,0,X,Y,Width,Height,Caption,0,0,0,0,name))
End Function

Function ContextMenu(name$="")
Return Handle(Gadget(GUI_CONTEXTMENU,0,0,0,0,0,0,"",0,0,0,0,name))
End Function

Function ContextMenuItem(Menu,Caption$,icon$="",name$="")
Return Handle(Gadget(GUI_CONTEXTMENUITEM,Menu,0,0,0,0,0,Caption,0,0,0,0,name,icon))
End Function

Function ContextMenuBar(Menu,name$="")
Return Handle(Gadget(GUI_CONTEXTMENUBAR,Menu,0,0,0,0,0,"",0,0,0,0,name))
End Function

Function Label(Parent,X,Y,Caption$,name$="")
Return Handle(Gadget(GUI_LABEL,Parent,0,X,Y,0,0,Caption,0,0,0,0,name))
End Function

Function Viewport3D(Parent,X,Y,Width,Height,name$="")
Return Handle(Gadget(GUI_VIEWPORT,Parent,0,X,Y,Width,Height,0,0,0,0,0,name))
End Function

Function GetGadget(Name$)
For g.Gadget = Each Gadget
If gName = Name Then Return Handle(g)
Next
Return 0
End Function

Function CloseGadget(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
Select iClass
Case GUI_WINDOW
iState[WINDOW_CLOSED] = 1
Case GUI_ROLLOUT
iState[ROLLOUT_CLOSED] = 1
End Select
End Function

Function OpenGadget(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
Select iClass
Case GUI_WINDOW
iState[WINDOW_CLOSED] = 0
Case GUI_ROLLOUT
iState[ROLLOUT_CLOSED] = 0
End Select
End Function

Function GetViewportCamera(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
Return iState[29]*(iClass=GUI_VIEWPORT)
End Function

Function LockWindow(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
If iClass = GUI_WINDOW Then iState[WINDOW_LOCKED] = 1
End Function

Function UnlockWindow(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
If iClass = GUI_WINDOW Then iState[WINDOW_LOCKED] = 0
End Function

Function OpenContextMenu(ID,X=65535,Y=65535)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
If iClass = GUI_CONTEXTMENU Then
GUI_ActiveContextMenu = i
iX = iMouseX()*(X=65535)+X*(X<>65535)
iY = iMouseY()*(Y=65535)+Y*(Y<>65535)
EndIf
End Function

Function ModalWindow(ID)
i.Gadget = Object.Gadget(ID)
GUI_ModalWindow = i
End Function

Function HideGadget(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
iState[GADGET_HIDDEN] = 1
End Function

Function ShowGadget(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return
iState[GADGET_HIDDEN] = 0
End Function

Function GadgetHidden(ID)
i.Gadget = Object.Gadget(ID)
If i = Null Then Return -1
Return iState[GADGET_HIDDEN]
End Function

Function HideUIPointer()
GUI_PointerHidden = 1
End Function

Function ShowUIPointer()
GUI_PointerHidden = 0
End Function
;#End Region


;#Region DESCRIPTION
;; Functions for drawing the GUI and other operations pertaining to the generation of images
;#End Region

;#Region CLASSES
Const GRAD_HOR = $5000 ;; Horizontal gradient
Const GRAD_VER = $5001 ;; Vertical gradient
Const GRAD_BOTH = $5002 ;; Square gradient
Const GRAD_RADIAL = $5003 ;; Radial gradient Starts in upper left corner
Const GRAD_RHOR = $5004 ;; Horizontal mirrored gradient
Const GRAD_RVER = $5005 ;; Vertical mirrored gradient
;#End Region

;#Region PROCEDURES
Function DrawGUI()
For i = 0 To Objects(GUI_RootGadgets)-1
g.Gadget = Object.Gadget(GetObject(GUI_RootGadgets,i))
DrawGadget(g)
Next

DrawGadget(GUI_ActiveContextMenu)

If GUI_PointerHidden=0 Then DrawImage GUI_MouseCursor,iMouseX(),iMouseY()
End Function

Function DrawGadget(i.Gadget)
If i = Null Then Return

If iState[30] = 1 Then Return

AX = GetGadgetSX(i)
AY = GetGadgetSY(i) + 16*(iMenuStrip <> Null) + 20*(iToolStrip <> Null)

r.Gadget = GetRoot(i)
If r <> Null And r <> i Then
If rClass = GUI_CONTEXTMENU Then
AX = GetGadgetSX(iParent)
AY = GetGadgetSY(iParent)+i*16

If iOver = 1 Then
DrawImageRect GUI_ContextMenuItemImage,AX,AY,0,0,3,16
DrawImageRect GUI_ContextMenuItemImage,AX+iWidth-3,AY,13,0,3,16
For x = AX+3 To AX+iWidth-3 Step 10
DrawImageRect GUI_ContextMenuItemImage,x,AY,3,0,MaxI(10,AX+iWidth-3-x),16
Next
EndIf
EndIf
EndIf

Select iClass
Case GUI_WINDOW
If iState[29] = 1 Then Return
If (iMode And WM_TITLEBAR) = WM_TITLEBAR Then
AY = AY-(16*(iMenuStrip <> Null) + 20*(iToolStrip <> Null))
If i = Objects(GUI_RootGadgets)-1 Then
DrawImageRect iImage,AX,AY,0,iHeight,iWidth,24
Else
DrawImageRect iImage,AX,AY,0,iHeight+24,iWidth,24
EndIf

If (iMode And WM_CLOSEBTN) = WM_CLOSEBTN
Select iState[WINDOW_CLOSEBUTTON]
Case 0
DrawImageRect iImage,AX+iWidth-20,AY+4,0,iHeight+48,16,16
Case 1
DrawImageRect iImage,AX+iWidth-20,AY+4,32,iHeight+48,16,16
Case 2
DrawImageRect iImage,AX+iWidth-20,AY+4,16,iHeight+48,16,16
End Select
EndIf

If (iMode And WM_MINBTN) = WM_MINBTN
Select iState[WINDOW_MINBUTTON]
Case 0
DrawImageRect iImage,AX+iWidth-20-20*((iMode And WM_CLOSEBTN) = WM_CLOSEBTN),AY+4,0,iHeight+48+16*(iState[WINDOW_MINIMIZED]+1),16,16
Case 1
DrawImageRect iImage,AX+iWidth-20-20*((iMode And WM_CLOSEBTN) = WM_CLOSEBTN),AY+4,32,iHeight+48+16*(iState[WINDOW_MINIMIZED]+1),16,16
Case 2
DrawImageRect iImage,AX+iWidth-20-20*((iMode And WM_CLOSEBTN) = WM_CLOSEBTN),AY+4,16,iHeight+48+16*(iState[WINDOW_MINIMIZED]+1),16,16
End Select
EndIf
AY = AY+(16*(iMenuStrip <> Null) + 20*(iToolStrip <> Null))
EndIf

If iState[WINDOW_MINIMIZED] = 1 Then Return

DrawImageRect iImage,AX,AY+24*((iMode And WM_TITLEBAR)=WM_TITLEBAR),0,0,iWidth,iHeight

Case GUI_GROUPBOX
DrawImage iImage,AX,AY

Case GUI_BUTTON
Select iState[0]
Case 0 ;; Normal
DrawImageRect iImage,AX,AY,0,0,iWidth,iHeight
Case 1 ;; Over
DrawImageRect iImage,AX,AY,0,iHeight,iWidth,iHeight
Case 2 ;; Down
DrawImageRect iImage,AX,AY,0,iHeight*2,iWidth,iHeight
Case 3 ;; Disabled
DrawImageRect iImage,AX,AY,0,iHeight*3,iWidth,iHeight
End Select

Case GUI_TEXTBOX
DrawImage iImage,AX,AY

b = GB()
SetBuffer(IB(iState[31]))
Color 255,255,255
Rect 0,0,256,256
SetFont GUI_Font
Color 0,0,0
Text 4,iHeight/2,iCaption,0,1
SetBuffer b

DrawImage iState[31],AX+1,AY+1

Case GUI_ROLLOUT
DrawImageRect iImage,AX,AY,0,0,iWidth,16+(iHeight*(iState[0] = 0))
DrawImageRect iImage,AX,AY,16*(iState[0]=0),iHeight+16,16,16

If iState[0] = 1 Then DrawGadget(iToolStrip) DrawGadget(iMenuStrip) Return 1

Case GUI_RADIO,GUI_CHECKBOX
Select iState[TICK_CHECKED]
Case 0
DrawImageRect iImage,AX,AY,0,0,ImageWidth(iImage),16
Case 1
DrawImageRect iImage,AX,AY,0,16,ImageWidth(iImage),16
Case 2
DrawImageRect iImage,AX,AY,0,32,ImageWidth(iImage),16
Case 3
DrawImageRect iImage,AX,AY,0,48,ImageWidth(iImage),16
End Select

If iVal Then
Color 255,255,255
Rect AX+4,AY+4,8,8,1
Color 0,0,0
Rect AX+4,AY+4,8,8,0
EndIf

iWidth = ImageWidth(iImage)
iHeight = 16

Case GUI_LABEL
DrawImage iImage,AX+(ImageWidth(iImage)/2)*(iState[0] = 1),AY+(ImageHeight(iImage)/2)*(iState[1] = 1)

Case GUI_VIEWPORT
DrawImage iImage,AX,AY

Case GUI_MENUSTRIP
If iParent <> Null Then
Select iParentClass
Case GUI_ROLLOUT
DrawImage iImage,AX,AY+1-16
Default
DrawImage iImage,AX,AY+1
End Select
Else
DrawImage iImage,0,0
EndIf

Case GUI_MENUITEM
DrawImage iImage,AX,AY

Case GUI_CONTEXTMENU
DrawImageRect iImage,iX-3,iY-3,0,0,3,3
DrawImageRect iImage,iX+16-3,iY-3,13,0,3,3
DrawImageRect iImage,iX-3,iY+iHeight,0,13,3,3
DrawImageRect iImage,iX+16-3,iY+iHeight,13,13,3,3

DrawImageRect iImage,iX+iWidth,iY-3,29,0,3,3
DrawImageRect iImage,iX+iWidth,iY+iHeight,29,13,3,3

For x = iX+16 To iX+iWidth Step 10
DrawImageRect iImage,x,iY-3,19,0,MaxI(10,iX+iWidth-x),3
DrawImageRect iImage,x,iY+iHeight,19,13,MaxI(10,iX+iWidth-x),3
For y = iY To iY+iHeight Step 10
DrawImageRect iImage,x,y,19,3,MaxI(10,iX+iWidth-x),MaxI(10,iY+iHeight-y)
Next
Next

For y = iY To iY+iHeight Step 10
DrawImageRect iImage,iX-3,y,0,3,3,MaxI(10,iY+iHeight-y)
DrawImageRect iImage,iX+iWidth,y,29,3,3,MaxI(10,iY+iHeight-y)
DrawImageRect iImage,iX+16-3,y,13,3,3,MaxI(10,iY+iHeight-y)
Next

For x = iX To iX+16-3
DrawImageRect iImage,x,iY-3,3,0,3,MaxI(10,iX+16-3-x)
DrawImageRect iImage,x,iY+iHeight,3,13,3,MaxI(10,iX+16-3-x)
For y = iY To iY+iHeight Step 10
DrawImageRect iImage,x,y,3,3,MaxI(10,iX+16-3-x),MaxI(10,iY+iHeight-y)
Next
Next

Case GUI_CONTEXTMENUITEM
DrawImage iImage,AX+2,AY+(16-ImageHeight(iImage))/2
If iIcon <> 0 Then DrawImage iIcon,AX-1,AY+(16-ImageHeight(iImage))/2

Case GUI_SLIDER
v# = iVal
If (iMode And SLIDER_INTEGER) = SLIDER_INTEGER Then v = Int v

DrawImageRect iImage,AX,AY,0,0,iWidth,iHeight
d# = iMax-iMin
If d# = 0 Then d# = .01
bar# = ((v-iMin)/d)*iState[1]
If bar+1 = bar Then bar = 0

If (iMode And SLIDER_HOR) = SLIDER_HOR Then
p# = (v/d)*(iWidth-2)
If p+1 = p Then p=0
DrawImageRect iImage,AX+1+p-bar,AY+1,iWidth,0,iState[1],iHeight-2
Else
p# = (v/d)*(iHeight-2)
If p+1 = p Then p=0
DrawImageRect iImage,AX+1,AY+1+p-bar,0,iHeight,iWidth-2,iState[1]
EndIf

Case GUI_TRACKBAR
DrawImageRect iImage,AX,AY,0,0,iWidth+1,iHeight+4
d# = iMax-iMin
bar = Int(((iVal-iMin)/d))*iState[2]
p = Int(( (iVal-iMin) / d )*iState[1])*iState[2]
DrawImageRect iImage,AX+p-bar+1,AY+1,iWidth+1,0,iState[2]-1,iHeight-2

Case GUI_TABSTRIP
DrawImage iImage,AX,AY

Case GUI_TABPAGE
If i <> iParentState[0] Then
DrawImageRect iImage,AX+iState[1],AY-(iHeight-2),0,iHeight,iWidth,iHeight-2
Return
Else
DrawImageRect iImage,AX+iState[1],AY-iHeight,0,0,iWidth,iHeight
EndIf

Case GUI_IMAGEBOX
DrawImage iImage,AX,AY

Case GUI_LISTBOX
DrawImage iImage,AX-1,AY-1

Case GUI_LISTBOXITEM
y = GetGadgetSY(iParent)
AX = GetGadgetSX(iParent)
AY = y+i*20-iState[LISTBOX_SCROLL]

If AY < y+iParentHeight Then
If i = iParentState[LISTBOX_SELECTED] Then
; Stop
Color 64,140,220
Rect AX,AY,iWidth,MinI(MaxI((y+iParentHeight)-(AY),20),0),1
EndIf

DrawImageRect iImage,AX,AY,0,0,iParentWidth,MinI(MaxI((y+iParentHeight)-(AY),20),0)
EndIf

End Select

For n = 0 To Objects(iGadgets)-1
g.Gadget = Object.Gadget(GetObject(iGadgets,n))
DrawGadget(g)
Next
End Function

Function CreateGUIImage(i.Gadget)
b = GraphicsBuffer()

Select iClass
Case GUI_WINDOW
If iState[WINDOW_CLOSED] = 1 Then Return
hasTitle = ((iMode And WM_TITLEBAR) = WM_TITLEBAR)
If hasTitle Then iHeight = iHeight - 24

iImage = CreateImage(iWidth,iHeight+96)

SetBuffer(ImageBuffer(iImage))

Color 64,64,64
Rect 0,0,MinI(iWidth,48),iHeight+96

GradientRect(1,Not hasTitle,iWidth-2,iHeight-(2-hasTitle),iWidth,iHeight,WINDOW_DIALOG_F,WINDOW_DIALOG_T,GRAD_VER,2,1)

Color 200,200,200
Line 1,1,iWidth-2,1
Line 1,iHeight-2,iWidth-2,iHeight-2
Line 1,1,1,iHeight-2
Line iWidth-2,1,iWidth-2,iHeight-2

Color 61*.75,99*.75,139*.75
Rect 0,iHeight,iWidth,24,1
GradientRect(1,iHeight+1,iWidth-2,23-hasTitle,iWidth,iHeight+24*2,WINDOW_TITLE_ACTIVE_F,WINDOW_TITLE_ACTIVE_T,GRAD_VER,2,1)
GradientRect(1,iHeight+1+24,iWidth-2,23-hasTitle,iWidth,iHeight+24*2,WINDOW_TITLE_INACTIVE_F,WINDOW_TITLE_INACTIVE_T,GRAD_VER,2,1)

SetFont GUI_LFontBold

If (iMode And WM_TITLEBARSHADOW) = WM_TITLEBARSHADOW Then
Color 0,0,0
For x = -1 To 1
For y = -1 To 1
Text 4+x,iHeight+12+y,iCaption,0,1
Text 4+x,iHeight+36+y,iCaption,0,1
Next
Next
Color 255,255,255
Else
Color 0,0,0
EndIf

Text 20*(iIcon <> 0)+4,iHeight+12,iCaption,0,1
Text 20*(iIcon <> 0)+4,iHeight+36,iCaption,0,1

If iIcon <> 0 Then
DrawImage iIcon,2,iHeight+4
DrawImage iIcon,2,iHeight+28
EndIf

Color 32,32,32

Rect 0,iHeight+48,iWidth,48

GradientRect 1,iHeight+49,14,14,iWidth,iHeight+96,ColorToInt(190,190,190),ColorToInt(210,210,210),GRAD_VER,2,1,0
GradientRect 1+16,iHeight+49,14,14,iWidth,iHeight+96,ColorToInt(190,190,190),ColorToInt(255,255,255),GRAD_VER,2,1,0
GradientRect 1+32,iHeight+49,14,14,iWidth,iHeight+96,ColorToInt(220,220,220),ColorToInt(160,160,160),GRAD_VER,2,1,0

GradientRect 1,iHeight+49+16,14,14,iWidth,iHeight+96,ColorToInt(190,190,190),ColorToInt(210,210,210),GRAD_VER,2,1,0
GradientRect 1+16,iHeight+49+16,14,14,iWidth,iHeight+96,ColorToInt(190,190,190),ColorToInt(255,255,255),GRAD_VER,2,1,0
GradientRect 1+32,iHeight+49+16,14,14,iWidth,iHeight+96,ColorToInt(220,220,220),ColorToInt(160,160,160),GRAD_VER,2,1,0

GradientRect 1,iHeight+49+16*2,14,14,iWidth,iHeight+96,ColorToInt(190,190,190),ColorToInt(210,210,210),GRAD_VER,2,1,0
GradientRect 1+16,iHeight+49+16*2,14,14,iWidth,iHeight+96,ColorToInt(190,190,190),ColorToInt(255,255,255),GRAD_VER,2,1,0
GradientRect 1+32,iHeight+49+16*2,14,14,iWidth,iHeight+96,ColorToInt(220,220,220),ColorToInt(160,160,160),GRAD_VER,2,1,0

Color 255,255,255
Line 4,iHeight+48+4+1,11,iHeight+48+11+1
Line 11,iHeight+48+4+1,4,iHeight+48+11+1

Line 4+16,iHeight+48+4+1,11+16,iHeight+48+11+1
Line 11+16,iHeight+48+4+1,4+16,iHeight+48+11+1

Line 4+32,iHeight+48+4+2,11+32,iHeight+48+11+2
Line 11+32,iHeight+48+4+2,4+32,iHeight+48+11+2

Rect 3,iHeight+48+3+1+16,10,3,0
Rect 3,iHeight+48+3+1+32,10,3,0
Rect 3,iHeight+48+3+1+32,10,9,0

Rect 3+16,iHeight+48+3+1+16,10,3,0
Rect 3+16,iHeight+48+3+1+32,10,3,0
Rect 3+16,iHeight+48+3+1+32,10,9,0

Rect 3+16*2,iHeight+48+3+2+16,10,3,0
Rect 3+16*2,iHeight+48+3+2+32,10,3,0
Rect 3+16*2,iHeight+48+3+2+32,10,9,0

Color 0,0,0

Rect 3,iHeight+48+3+16,10,3,0
Rect 3,iHeight+48+3+32,10,3,0
Rect 3,iHeight+48+3+32,10,9,0

Rect 3+16,iHeight+48+3+16,10,3,0
Rect 3+16,iHeight+48+3+32,10,3,0
Rect 3+16,iHeight+48+3+32,10,9,0

Rect 3+16*2,iHeight+48+3+1+16,10,3,0
Rect 3+16*2,iHeight+48+3+1+32,10,3,0
Rect 3+16*2,iHeight+48+3+1+32,10,9,0

Line 4,iHeight+48+4,11,iHeight+48+11
Line 11,iHeight+48+4,4,iHeight+48+11

Line 4+16,iHeight+48+4,11+16,iHeight+48+11
Line 11+16,iHeight+48+4,4+16,iHeight+48+11

Line 4+32,iHeight+48+4+1,11+32,iHeight+48+11+1
Line 11+32,iHeight+48+4+1,4+32,iHeight+48+11+1

Case GUI_BUTTON
iImage = CreateImage(iWidth+24*(iIcon<>0),iHeight*4)

SetBuffer(IB(iImage))

Color 64,64,64
Rect 0,0,iWidth+24*(iIcon<>0),iHeight+24*2

GradientRect(1,1,iWidth-2+24*(iIcon<>0),iHeight-2,iWidth+24*(iIcon<>0),iHeight*4,ColorToInt(190,190,190),ColorToInt(230,230,230),GRAD_VER,2,1)

GradientRect(1,1+iHeight*1,iWidth-2+24*(iIcon<>0),iHeight-2,iWidth+24*(iIcon<>0),iHeight*4,ColorToInt(190,190,190),ColorToInt(255,255,255),GRAD_VER,2,1)

GradientRect(1,1+iHeight*2,iWidth-2+24*(iIcon<>0),iHeight-2,iWidth+24*(iIcon<>0),iHeight*4,ColorToInt(230,230,230),ColorToInt(190,190,190),GRAD_VER,1,1)

GradientRect(1,1+iHeight*3,iWidth-2+24*(iIcon<>0),iHeight-2,iWidth+24*(iIcon<>0),iHeight*4,ColorToInt(130,130,130),ColorToInt(150,150,150),GRAD_VER,2,1)

SetFont GUI_Font
Color 48,48,48
Text iWidth/2+24*(iIcon<>0),iHeight/2,iCaption,1,1
Color 0,0,0
Text iWidth/2+24*(iIcon<>0),iHeight/2+iHeight,iCaption,1,1
Color 128,128,128
Text iWidth/2+24*(iIcon<>0),iHeight/2+iHeight*3,iCaption,1,1
Color 0,0,0
Text iWidth/2+1+24*(iIcon<>0),iHeight/2+iHeight*2+1,iCaption,1,1

If iIcon <> 0 Then
DrawImage iIcon,2,4
DrawImage iIcon,2,iHeight+4
DrawImage iIcon,2,iHeight*2+4
DrawImage iIcon,2,iHeight*3+4
EndIf

Case GUI_GROUPBOX
iImage = CreateImage(iWidth,iHeight+1)

SetBuffer(IB(iImage))

Color 255,0,255
Rect 0,0,iWidth,iHeight+1,1

SetFont GUI_Font
bLine 1,4,8,4
bLine 1,4,1,iHeight-1
bLine 14+StringWidth(iCaption)+24*(iIcon <> 0),4,iWidth-3,4
bLine iWidth-2,4,iWidth-2,iHeight-1
bLine 1,iHeight-1,iWidth-2,iHeight-1
Color 0,0,0
Text 12+24*(iIcon <> 0),4,iCaption,0,1

Case GUI_TEXTBOX
iImage = CreateImage(iWidth,iHeight)

Color 0,0,0
Rect 0,0,iWidth,iHeight,1

Color 255,255,255
Rect 1,1,256,256,1

iState[31] = CreateImage(iWidth-2,iHeight-2)
MaskImage iState[31],255,0,255

Case GUI_RADIO,GUI_CHECKBOX
SetFont GUI_Font
iImage = CreateImage(18+StringWidth(iCaption),64)

w = ImageWidth(iImage)

SetBuffer(IB(iImage))

Color 255,0,255
Rect 0,0,w,64,1

Color 0,0,0
SetFont GUI_Font
Text 18,8,iCaption,0,1
Text 18,8+16,iCaption,0,1
Text 18,8+16*2,iCaption,0,1
Color 128,128,128
Text 18,8+16*3,iCaption,0,1

;; Normal
Color 0,0,0
Rect 1,1,14,14,1

Color 110,190,255
Rect 2,2,12,12,1

Color 100,120,150
Rect 4,4,8,8,1

;; Over
Color 0,0,0
Rect 1,1+16,14,14,1

Color 160,220,255
Rect 2,2+16,12,12,1

Color 100,120,150
Rect 4,4+16,8,8,1

;; Down
Color 0,0,0
Rect 1,1+16*2,14,14,1

Color 110,190,255
Rect 2,2+16*2,12,12,1

Color 100,120,150
Rect 4,4+16*2,8,8,1

;; Disabled
Color 0,0,0
Rect 1,1+16*3,14,14,1

Color 110,190,255
Rect 2,2+16*3,12,12,1

Color 100,120,150
Rect 4,4+16*3,8,8,1

Case GUI_ROLLOUT
iImage = CreateImage(iWidth,iHeight+32)
SetBuffer(IB(iImage))
Color 0,0,0
Rect 0,0,iWidth,iHeight+16,1
GradientRect 1,1,iWidth-2,14,iWidth,iHeight+16,ColorToInt(250,250,250),ColorToInt(230,230,230),GRAD_VER,2,2,0
Color 255,0,255
Rect 0,iHeight+16,iWidth,16
Color 0,0,0
SetFont GUI_Font
Text iWidth/2,8,iCaption,1,1

Color 0,0,0
Rect 4,-1+iHeight+16+7,8,2,1
Rect 4+16,-1+iHeight+16+7,8,2,1
Rect 16+7,-1+iHeight+16+4,2,8,1

Color 255,255,255
Rect 4,1+iHeight+16+7,8,2,1
Rect 4+16,1+iHeight+16+7,8,2,1
Rect 16+7,1+iHeight+16+4,2,8,1

Color 96,96,96
Rect 4,iHeight+16+7,8,2,1
Rect 4+16,iHeight+16+7,8,2,1
Rect 16+7,iHeight+16+4,2,8,1

Color 255,0,255
Rect 1,16,iWidth-2,iHeight-1

Case GUI_LABEL
SetFont GUI_Font
iImage = CreateImage(StringWidth(iCaption),FontHeight())
SetBuffer(IB(iImage))
Color 255,0,255
Rect 0,0,ImageWidth(iImage),ImageHeight(iImage),1
Color 0,0,0
Text 0,0,iCaption,0,0

Case GUI_VIEWPORT
iState[29] = CreateCamera()
iImage = CreateImage(iWidth,iHeight+1)
CameraViewport iState[29],0,0,iWidth-2,iHeight-2
HideEntity iState[29]

SetBuffer(IB(iImage))
Color 230,230,230
Rect 0,0,iWidth,iHeight+1,1
Color 0,0,0
Rect 0,0,iWidth,iHeight,1

Case GUI_MENUSTRIP
If iParent <> Null Then
iWidth = iParentWidth
Else
iWidth = GraphicsWidth( )
EndIf
iHeight = 16
iX = 0
iY = -16
iImage = CreateImage(iWidth,iHeight)

SetBuffer(IB(iImage))
Color 0,0,0
Rect 0,0,iWidth,iHeight,1
GradientRect 1,1,iWidth-2,iHeight-1,iWidth,iHeight,ColorToInt(240,240,240),ColorToInt(220,220,220),GRAD_VER,2,1,0

Case GUI_CONTEXTMENU
iImage = GUI_ContextMenuImage

Case GUI_CONTEXTMENUITEM
iParentWidth = MinI(iParentWidth,20+StringWidth(iCaption))
iImage = CreateImage(20+StringWidth(iCaption),16)
Color 255,0,255
SetBuffer(IB(iImage))
Rect 0,0,ImageWidth(iImage),16,1
Color 0,0,0
SetFont GUI_Font
Text 18,8,iCaption,0,1

Case GUI_SLIDER
If (iMode And SLIDER_HOR) Then
iImage = CreateImage(iState[1]+iWidth,iHeight)
w = iWidth+iState[1]
h = iHeight
SetBuffer(IB(iImage))

Color 64,64,64

Rect 0,0,ImageWidth(iImage),ImageHeight(iImage)

GradientRect 1,1,iWidth-2,iHeight-2,iWidth,iHeight,ColorToInt(170,230,255),ColorToInt(130,175,210),GRAD_HOR,1,1,0

GradientRect iWidth+1,0,iState[1]-2,iHeight-2,w*2,h*2,ColorToInt(220,220,220),ColorToInt(190,190,190),GRAD_VER,2,1,0
Else
iImage = CreateImage(iWidth,iHeight+iState[1])
w = iWidth
h = iHeight+iState[1]
SetBuffer(IB(iImage))

Color 64,64,64

Rect 0,0,ImageWidth(iImage),ImageHeight(iImage)

GradientRect 1,1,iWidth-2,iHeight-2,iWidth,iHeight,ColorToInt(170,230,255),ColorToInt(130,175,210),GRAD_VER,1,1,0

GradientRect 0,iHeight+1,iWidth-2,iState[1]-2,w*2,h*2,ColorToInt(220,220,220),ColorToInt(190,190,190),GRAD_VER,2,1,0
EndIf

Case GUI_TRACKBAR
st = Float iWidth/iState[1]

iImage = CreateImage(iWidth+1+st,iHeight+4)
SetBuffer(IB(iImage))

Color 255,0,255
Rect 0,0,iWidth+st,iHeight+4,1

GradientRect 1,1,iWidth-2,iHeight-2,iWidth,iHeight,ColorToInt(200,200,200),ColorToInt(220,220,220),GRAD_VER,0

iState[2] = st
x=st
While x < iWidth
Color 255,255,255
Rect x+1,0,1,iHeight,1
Color 64,64,64
Rect x,0,1,iHeight,1
x = x + st
Wend

Color 255,255,255
Rect 0,0,iWidth+1,iHeight+1,0
Color 64,64,64
Rect 0,0,iWidth,iHeight,0

x=0
While x < iWidth
Color 255,255,255
Rect x+1,iHeight,1,4,1
Color 64,64,64
Rect x,iHeight,1,3,1
x = x + st
Wend
x = x - 1
Color 255,255,255
Rect x+1,iHeight,1,4,1
Color 64,64,64
Rect x,iHeight,1,3,1

GradientRect iWidth+1,0,st-1,iHeight-2,iWidth+st+2,iHeight+4,ColorToInt(66,157,221),ColorToInt(32,116,175),GRAD_BOTH,2,1,0

Case GUI_TABSTRIP
iImage = CreateImage(iWidth,iHeight)
SetBuffer(IB(iImage))
Color 64,64,64
Rect 0,0,iWidth,iHeight,1
GradientRect 1,1,iWidth-2,iHeight-2,iWidth,iHeight,ColorToInt(180,180,180),ColorToInt(170,170,170),GRAD_VER,0,0,0

Case GUI_TABPAGE
SetFont GUI_Font
iImage = CreateImage(8+StringWidth(iCaption)+20*(iIcon <> 0),44)
SetBuffer(IB(iImage))
iWidth = 8+StringWidth(iCaption)+20*(iIcon <> 0)
iHeight = 22
Color 64,64,64
Rect 0,0,iWidth,iHeight*2,1
GradientRect 1,1,iWidth-2,iHeight-1,iWidth,iHeight*2,ColorToInt(220,220,220),ColorToInt(225,225,225),GRAD_VER,2,1,0
GradientRect 1,iHeight+1,iWidth-2,iHeight-1,iWidth,iHeight*2,ColorToInt(190,190,190),ColorToInt(198,198,198),GRAD_VER,2,1,0
Text 4+18*(iIcon <> 0),iHeight/2,iCaption,0,1
Text 4+18*(iIcon <> 0),iHeight*1.5,iCaption,0,1

iState[1] = 0
iX = 0
iY = 0
For g.Gadget = Each Gadget
If g <> i And gParent = iParent And gClass = iClass Then
iState[1] = iState[1] + gWidth-1
EndIf
Next

If iIcon <> 0 Then
DrawImage iIcon,3,3
DrawImage iIcon,3,3+22
EndIf

Case GUI_IMAGEBOX
iImage = CreateImage(ImageWidth(iGroupID)+2,ImageHeight(iGroupID)+2)
iWidth = ImageWidth(iImage)
iHeight = ImageWidth(iImage)
SetBuffer(IB(iImage))
Color 64,64,64
Rect 0,0,iWidth,iHeight,0

Case GUI_LISTBOX
iImage = CreateImage(iWidth+2,iHeight+2)
SetBuffer(IB(iImage))
Color 0,0,0
Rect 0,0,iWidth+2,iHeight+2,1
Color 255,255,255
Rect 1,1,iWidth,iHeight,1

Case GUI_LISTBOXITEM
iImage = CreateImage(iParentWidth,20)
SetBuffer(IB(iImage))
Color 255,0,255
Rect 0,0,iParentWidth,20,1
Color 0,0,0
SetFont GUI_Font
Text 2+18*(iIcon <> 0),10,iCaption,0,1
If iIcon <> 0 Then
DrawImage iIcon,2,2
EndIf

End Select

If iImage <> 0 Then MaskImage iImage,255,0,255

SetBuffer b
End Function

Function UpdateViewport(ID,Tween#=1,ClearColor=1,ClearDepth=1,CopyToBuffer=1)
g.Gadget = Object.Gadget(ID)
If g <> Null Then
If gClass = GUI_VIEWPORT Then
ShowEntity gState[29]
CameraClsMode gState[29],ClearColor,ClearDepth
RenderWorld Tween
If CopyToBuffer Then CopyRect 0,0,gWidth-2,gHeight-2,1,1,BackBuffer(),ImageBuffer(gImage)
HideEntity gState[29]
EndIf
EndIf
End Function

Function GradientRect(X,Y,W,H,Mx,My,CF,CT,Dir=GRAD_HOR,Bevel=0,BevelSize=1,Blend=0)
Local RF = CF Shr 16 And 255
Local GF = CF Shr 8 And 255
Local BF = CF And 255

Local RT = CT Shr 16 And 255
Local GT = CT Shr 8 And 255
Local BT = CT And 255

Local ix,iy

Local b = GraphicsBuffer()

LockBuffer(b)

Local d# = 0

For ix = 0 To W-1
For iy = 0 To H-1
If X+ix < Mx And Y+iy < My And X+ix > -1 And Y+iy > -1 Then
Select Dir
Case GRAD_HOR
d# = 1.0 - Float ix/W
Case GRAD_VER
d# = 1.0 - Float iy/H
Case GRAD_BOTH,GRAD_RADIAL
d# = 1.0 - (Float iy/H + Float ix/W)/2
Case GRAD_RHOR
d# = Float Abs(ix-w/2)/(W/2)
Case GRAD_RVER
d# = Float Abs(iy-h/2)/(H/2)
End Select

cr = RF*d + RT*(1.0-d)
cg = GF*d + GT*(1.0-d)
cb = BF*d + BT*(1.0-d)

Select Blend
Case 1 ;; Multiply
pix = ReadPixelFast(X+ix,Y+iy)
pr = pix Shr 16 And 255
pg = pix Shr 8 And 255
pb = pix And 255
cr = cr*(Float pr/255)
cg = cg*(Float pg/255)
cb = cb*(Float pb/255)
Case 2 ;; Additive
pix = ReadPixelFast(X+ix,Y+iy)
pr = pix Shr 16 And 255
pg = pix Shr 8 And 255
pb = pix And 255
cr = cr + pr
cg = cg + pg
cb = cb + pb
Case 3 ;; The two combined
pix = ReadPixelFast(X+ix,Y+iy)
pr = pix Shr 16 And 255
pg = pix Shr 8 And 255
pb = pix And 255
If pr > 127 Then
cr = cr + pr
Else
cr = cr*(Float pr/128)
EndIf

If pg > 127 Then
cg = cg + pg
Else
cg = cg*(Float pg/128)
EndIf

If pb > 127 Then
cb = cb + pb
Else
cb = cb*(Float pb/128)
EndIf
End Select


Select Bevel
Case 1
If ix <= BevelSize-1 Or iy <= BevelSize-1
cr = MaxI(cr * .6,255)
cg = MaxI(cg * .6,255)
cb = MaxI(cb * .6,255)
EndIf
If ix => W-BevelSize+1 Or iy => H-BevelSize+1
cr = MaxI(cr * 1.4,255)
cg = MaxI(cg * 1.4,255)
cb = MaxI(cb * 1.4,255)
EndIf
Case 2
If ix => W-BevelSize+1 Or iy => H-BevelSize+1
cr = MaxI(cr * .6,255)
cg = MaxI(cg * .6,255)
cb = MaxI(cb * .6,255)
EndIf
If ix <= BevelSize-1 Or iy <= BevelSize-1
cr = MaxI(cr * 1.4,255)
cg = MaxI(cg * 1.4,255)
cb = MaxI(cb * 1.4,255)
EndIf
End Select


c = 255 Shl 24 Or MaxI(cr,255) Shl 16 Or MaxI(cg,255) Shl 8 Or MaxI(cb,255)

WritePixelFast X+ix,Y+iy,c,b
EndIf
Next
Next

UnlockBuffer(b)

Return
End Function

Function bLine(X,Y,TX,TY)
Color 64,64,64
Line X,Y,TX,TY
Color 225,225,225
Line X+1,Y+1,TX+1,TY+1
End Function

Function ColorToInt(R%,G%,B%,A%=255)
Return A Shl 24 Or R Shl 16 Or G Shl 8 Or B
End Function
;#End Region

;#Region DESCRIPTION
;; Convenience functions for returning buffer addresses
;#End Region

;#Region PROCEDURES
Function IB(Image)
Return ImageBuffer(Image)
End Function

Function TB(Texture)
Return TextureBuffer(Texture)
End Function

Function GB()
Return GraphicsBuffer()
End Function

Function BB()
Return BackBuffer()
End Function

Function FB()
Return FrontBuffer()
End Function
;#End Region

;#Region DESCRIPTION
;; Convenience functions for getting the minimum/maximum values of two values
;#End Region

;#Region PROCEDURES
Function MinF#(A#,B#)
If A < B Then Return B
Return A
End Function

Function MinI%(A%,B%)
If A < B Then Return B
Return A
End Function

Function MaxF#(A#,B#)
If A > B Then Return B
Return A
End Function

Function MaxI%(A%,B%)
If A > B Then Return B
Return A
End Function

;#End Region


Comments :


OJay(Posted 1+ years ago)

 any chance of getting a small sample-code that shows the usage of at least the very important functions?


N(Posted 1+ years ago)

 Nope.The basic idea is that you create your gadgets, update the GUI, iterate over events, and draw the GUI.All the important functions are self explanatory.


jfk EO-11110(Posted 1+ years ago)

 Because the functions are not declared at the beginning of the lines, they are not listed in the IDE (at least in the default IDE, making it a little hard to test things. Besides, a list of the functions with Parameters would also be helpful.


Blitzplotter(Posted 1+ years ago)

 This is cool, I inserted the following at the start to make the GUI persistent:-<div class="quote"> ;#Region DESCRIPTION   ;; Functions for grabbing input;#End RegionInclude "include.bb"While 1      Print "alive"      VWait 10   Wend </div>