I've started working on a GUI for a level editor I'm making. It's going pretty good so far, but it's still pretty basic.
It supports:
-Windows.
-Buttons.
-Check boxes.
-Menu bars.
-Sliders.
-Right-Click menus.
It's fairly flexible as well. You can set everything from the color scheme used to the height of the window title bars to the the size of the window padding.
Oh, and windows which are children of other windows don't function very well right now.
Here's the code:
Rem Project: LIAR Editor GUI 2
Rem Created: Tuesday, January 13, 2009
Rem ***** Main Source File *****
#Constant _PRESSED 1
#Constant _DOWN 2
#Constant _RELEASED 3
#Constant _UP 4
#Constant _LEFT 0
#Constant _MIDDLE 1
#Constant _RIGHT 2
#Constant _DEBUGFILE 10
Type TGUIProperties
WindowTitleBarHeight as Integer
BorderWidth as Integer
WindowPadding as Integer
DrawStyle as Integer
EndType
Type TGUIWindow
ParentID as Integer
PosX as Integer
PosY as Integer
OldPosX as Integer
OldPosY as Integer
OldMouseX as Integer
OldMouseY as Integer
RealPosX as Integer
RealPosY as Integer
SizeX as Integer
SizeY as Integer
MinSizeX as Integer
MinSizeY as Integer
OldSizeX as Integer
OldSizeY as Integer
Title as String
IsActive as Boolean
IsVisible as Boolean
IsCurrentWindow as Boolean
IsDragging as Boolean
IsResizing as Integer
IsResizable as Integer
IsMovable as Integer
EndType
Type TGUIButton
ParentID as Integer
PosX as Integer
PosY as Integer
RealPosX as Integer
RealPosY as Integer
SizeX as Integer
SizeY as Integer
Txt as String
EndType
Type TGUICheckBox
ParentID as Integer
RealPosX as Integer
RealPosY as Integer
PosX as Integer
PosY as Integer
SizeX as Integer
SizeY as Integer
IsChecked as Integer
Txt as String
EndType
Type TGUISlider
ParentID as Integer
StartPos as Float
EndPos as Float
SliderPos as Float
RealSliderPos as Float
PosX as Integer
PosY as Integer
RealPosX as Integer
RealPosY as Integer
SliderSizeX as Integer
SliderSizeY as Integer
BarSizeX as Float
BarSizeY as Float
OldPos as Integer
OldMouse as Integer
Txt as String
IsSliding as Integer
EndType
Type TGUIMenuBar
ParentID as Integer
ParentPosX as Integer
ParentPosY as Integer
ParentSize as Integer
MenuWidth as Integer
MenuHeight as Integer
OptionHeight as Integer
NumMenus as Integer
EndType
Type TGUIMenuBarMenu
Name as String
NumOptions as Integer
ShowOptions as Integer
EndType
Type TGUIMenuBarOption
IsPressed as Integer
IsAvailable as Integer
Name as String
EndType
Type TGUIListBox
NumOptions as Integer
EndType
Type TGUIListBoxOption
Name as String
IsSelected as Integer
EndType
Type TGUIRightClickMenu
IsEnabled as Integer
ShowOptions as Integer
SelectedOption as Integer
PosX as Integer
PosY as Integer
EndType
Set Display Mode GetMaxXRes( ), GetMaxYRes( ), 32
Sync On
Sync Rate 0
Set Text Font "Microsoft Sans Serif"
Set Text Size 16
CreateDebugFile( )
InitGUI( )
SetWindowPadding( 8 )
SetTitleBarHeight( 35 )
SetGUIColorScheme( RGB( 1, 1, 1 ), RGB(44,104,172), RGB(46,128,221), RGB(165,197,237) )
SetGUIDrawStyle( 6 )
ReSize = AddWindow( -1, 100, 100, 500, 250, "This Window is Movable and Resizable" )
SetWindowMovable( ReSize, 1 )
SetWindowResizable( ReSize, 1 )
SetWindowMinWidth( ReSize, 360 )
SetWindowMinHeight( ReSize, 140 )
MenuBar = AddMenuBar( BarTest )
AddMenu( MenuBar, "File" )
AddOption( MenuBar, "File", "New" )
AddOption( MenuBar, "File", "Open" )
AddOption( MenuBar, "File", "Close" )
AddOption( MenuBar, "File", "Save" )
AddOption( MenuBar, "File", "Save As..." )
AddOption( MenuBar, "File", "Exit" )
AddMenu( MenuBar, "Edit" )
AddOption( MenuBar, "Edit", "Undo" )
AddOption( MenuBar, "Edit", "Redo" )
AddMenu( MenuBar, "Help" )
AddOption( MenuBar, "Help", "View Help" )
CheckBox = AddCheckBox( ReSize, 50, 100, 20, 20, "Check Me!" )
Button = AddButton( ReSize, 150, 100, 100, 20, "Click Me!" )
Slider = AddSlider( ReSize, 350, 110, 10, 15, 150, 10, 25, 110, "Slide Me!" )
SetRightClickMenu( 1 )
AddRightClickMenuOption( "Undo" )
AddRightClickMenuoption( "Redo" )
AddRightClickMenuOption( "Copy" )
Do
UpdateGUI( )
If OptionClicked( MenuBar, "File", "Exit" )
End
EndIf
If GetKeyState( 17 ) = _PRESSED
NULL = AddWindow( -1, Rnd( Screen Width( ) ), Rnd( Screen Height( ) ), Rnd( 500 ), Rnd( 350 ), "Window" )
SetWindowMovable( NULL, 1 )
SetWindowResizable( NULL, 1 )
EndIf
Sync
Loop
CloseDebugFile( )
Function SetGUIColorScheme( Col1 as DWORD, Col2 as DWORD, Col3 as DWORD, Col4 as DWORD )
Colors( 0 ) = Col1
Colors( 1 ) = Col2
Colors( 2 ) = Col3
Colors( 3 ) = Col4
EndFunction
Function SetGUIDrawStyle( Style as Integer )
GUI.DrawStyle = Style
EndFunction
Function SetTitleBarHeight( Height as Integer )
GUI.WindowTitleBarHeight = Height
EndFunction
Function SetWindowPadding( Pad as Integer )
GUI.WindowPadding = Pad
EndFunction
Function SetWindowMinHeight( ID as Integer, Height as Integer )
Windows( I ).MinSizeY = Height
EndFunction
Function SetWindowMinWidth( ID as Integer, Width as Integer )
Windows( I ).MinSizeX = Width
EndFunction
Function InitGUI( )
Global GUI as TGUIProperties
Global ActiveWindow = -1
Global DebugTime as Integer
Global DebugString as String
Dim Colors( 3 ) as DWORD
Dim Windows( -1 ) as TGUIWindow
Dim Buttons( -1 ) as TGUIButton
Dim ListBoxes( 10 ) as TGUIListBox
Dim ListBoxOptions( 10, 100 ) as TGUIListBoxOption
Dim CheckBoxes( -1 ) as TGUICheckBox
Dim MenuBars( 10 ) as TGUIMenuBar
Dim Menus( 10, 10 ) as TGUIMenuBarMenu
Global NumMenuBars as Integer : NumMenuBars = -1
Dim Options( 10, 10, 20 ) as TGUIMenuBarOption
Dim Sliders( -1 ) as TGUISlider
Global RightClickMenu as TGUIRightClickMenu
Dim RightClickMenuOptions( -1 ) as String
InitMouseEvents( )
D3D_Init
Colors( 0 ) = RGB( 1, 1, 1 )
Colors( 1 ) = RGB( 130, 130, 130 )
Colors( 2 ) = RGB( 200, 200, 200 )
Colors( 3 ) = RGB( 240, 240, 240 )
GUI.WindowTitleBarHeight = 25
GUI.BorderWidth = 1
GUI.WindowPadding = 5
GUI.DrawStyle = 1
EndFunction
Function UpdateGUI( )
UpdateMouseEvents( )
CLS RGB( 255, 255, 255 )
For ID = 0 to Array Count( Buttons( ) )
If Buttons( ID ).ParentID = -1
Buttons( ID ).RealPosX = Buttons( ID ).PosX
Buttons( ID ).RealPosY = Buttons( ID ).PosY
If MouseOverButton( ID ) = 1
DrawButton( ID, 1 )
Else
DrawButton( ID, 0 )
EndIf
EndIf
Next ID
For ID = 0 to Array Count( CheckBoxes( ) )
If CheckBoxes( ID ).ParentID = -1
CheckBoxes( ID ).RealPosX = CheckBoxes( ID ).PosX
CheckBoxes( ID ).RealPosY = CheckBoxes( ID ).PosY
DrawCheckBox( ID )
EndIf
Next ID
For ID = 0 to Array Count( MenuBars( ) )
If MenuBars( ID ).ParentID = -1
MenuBars( ID ).ParentPosX = 0
MenuBars( ID ).ParentPosY = 0
UpdateMenuBar( ID )
EndIf
Next ID
For ID = 0 to Array Count( Sliders( ) )
If Sliders( ID ).ParentID = -1
Sliders( ID ).RealPosX = Sliders( ID ).PosX
Sliders( ID ).RealPosY = Sliders( ID ).PosY
DrawSlider( ID )
EndIf
Next ID
For I = 0 to Array Count( Windows( ) )
If Windows( I ).IsMovable = 1
If MouseOverWindowTitleBar( I )
If GetLeftMouseState( ) = _PRESSED
Windows( I ).IsDragging = 1
Windows( I ).OldPosX = Windows( I ).PosX
Windows( I ).OldPosY = Windows( I ).PosY
Windows( I ).OldMouseX = MouseX( )
Windows( I ).OldMouseY = MouseY( )
EndIf
EndIf
EndIf
If Windows( I ).IsResizable = 1
If MouseOverWindowPadding( I ) = 1
If GetLeftMouseState( ) = _PRESSED
Windows( I ).IsResizing = 1
Windows( I ).OldSizeX = Windows( I ).SizeX
Windows( I ).OldSizeY = Windows( I ).SizeY
Windows( I ).OldPosX = Windows( I ).PosX
Windows( I ).OldPosY = Windows( I ).PosY
Windows( I ).OldMouseX = MouseX( )
Windows( I ).OldMouseY = MouseY( )
EndIf
EndIf
If MouseOverWindowPadding( I ) = 2
If GetLeftMouseState( ) = _PRESSED
Windows( I ).IsResizing = 2
Windows( I ).OldSizeX = Windows( I ).SizeX
Windows( I ).OldSizeY = Windows( I ).SizeY
Windows( I ).OldMouseX = MouseX( )
Windows( I ).OldMouseY = MouseY( )
EndIf
EndIf
EndIf
If Windows( I ).IsDragging = 1
Windows( I ).PosX = Windows( I ).OldPosX + ( MouseX( ) - Windows( I ).OldMouseX )
Windows( I ).PosY = Windows( I ).OldPosY + ( MouseY( ) - Windows( I ).OldMouseY )
If GetLeftMouseState( ) = _RELEASED
Windows( I ).IsDragging = 0
EndIf
EndIf
If Windows( I ).IsResizing = 2 or Windows( I ).IsResizing = 1
Windows( I ).SizeX = Windows( I ).OldSizeX + ( MouseX( ) - Windows( I ).OldMouseX )
Windows( I ).SizeY = Windows( I ).OldSizeY + ( MouseY( ) - Windows( I ).OldMouseY )
If GetLeftMouseState( ) = _RELEASED
Windows( I ).IsResizing = 0
EndIf
EndIf
If Windows( I ).ParentID > -1
Windows( I ).RealPosX = Windows( I ).PosX + Windows( Windows( I ).ParentID ).RealPosX
Windows( I ).RealPosY = Windows( I ).PosY + Windows( Windows( I ).ParentID ).RealPosY
Else
Windows( I ).RealPosX = Windows( I ).PosX
Windows( I ).RealPosY = Windows( I ).PosY
EndIf
X1 = Windows( I ).RealPosX
Y1 = Windows( I ).RealPosY
X2 = Windows( I ).RealPosX + Windows( I ).SizeX
Y2 = Windows( I ).RealPosY + Windows( I ).SizeY
If Windows( I ).SizeX < Windows( I ).MinSizeX
Windows( I ).SizeX = Windows( I ).MinSizeX
EndIf
If Windows( I ).SizeY < Windows( I ).MinSizeY
Windows( I ).SizeY = Windows( I ).MinSizeY
EndIf
If MouseOverWindow( I ) and GetLeftMouseState( ) = _PRESSED and MouseOverWindow( ActiveWindow ) = 0
ActiveWindow = I
EndIf
If I <> ActiveWindow
DrawWindow( I )
For ID = 0 to Array Count( Buttons( ) )
If Buttons( ID ).ParentID = I
Buttons( ID ).RealPosX = Buttons( ID ).PosX + Windows( Buttons( ID ).ParentID ).RealPosX
Buttons( ID ).RealPosY = Buttons( ID ).PosY + Windows( Buttons( ID ).ParentID ).RealPosY
If MouseOverButton( ID ) = 1
DrawButton( ID, 1 )
Else
DrawButton( ID, 0 )
EndIf
EndIf
Next ID
For ID = 0 to Array Count( CheckBoxes( ) )
If CheckBoxes( ID ).ParentID = I
CheckBoxes( ID ).RealPosX = CheckBoxes( ID ).PosX + Windows( CheckBoxes( ID ).ParentID ).RealPosX
CheckBoxes( ID ).RealPosY = CheckBoxes( ID ).PosY + Windows( CheckBoxes( ID ).ParentID ).RealPosY
DrawCheckBox( ID )
EndIf
Next ID
For ID = 0 to Array Count( MenuBars( ) )
If MenuBars( ID ).ParentID = I
MenuBars( ID ).ParentPosX = Windows( MenuBars( ID ).ParentID ).RealPosX + GUI.WindowPadding
MenuBars( ID ).ParentPosY = Windows( MenuBars( ID ).ParentID ).RealPosY + GUI.WindowTitleBarHeight
MenuBars( ID ).ParentSize = Windows( MenuBars( ID ).ParentID ).SizeX - ( GUI.WindowPadding * 2 )
UpdateMenuBar( ID )
EndIf
Next ID
For ID = 0 to Array Count( Sliders( ) )
If Sliders( ID ).ParentID = I
Sliders( ID ).RealPosX = Sliders( ID ).PosX + Windows( Sliders( ID ).ParentID ).RealPosX
Sliders( ID ).RealPosY = Sliders( ID ).PosY + Windows( Sliders( ID ).ParentID ).RealPosY
DrawSlider( ID )
EndIf
Next ID
EndIf
Next I
If ActiveWindow > -1
DrawWindow( ActiveWindow )
For ID = 0 to Array Count( Buttons( ) )
If Buttons( ID ).ParentID = ActiveWindow
Buttons( ID ).RealPosX = Buttons( ID ).PosX + Windows( Buttons( ID ).ParentID ).RealPosX
Buttons( ID ).RealPosY = Buttons( ID ).PosY + Windows( Buttons( ID ).ParentID ).RealPosY
If MouseOverButton( ID ) = 1
DrawButton( ID, 1 )
Else
DrawButton( ID, 0 )
EndIf
EndIf
Next ID
For ID = 0 to Array Count( CheckBoxes( ) )
If CheckBoxes( ID ).ParentID = ActiveWindow
CheckBoxes( ID ).RealPosX = CheckBoxes( ID ).PosX + Windows( CheckBoxes( ID ).ParentID ).RealPosX
CheckBoxes( ID ).RealPosY = CheckBoxes( ID ).PosY + Windows( CheckBoxes( ID ).ParentID ).RealPosY
DrawCheckBox( ID )
EndIf
Next ID
For ID = 0 to Array Count( MenuBars( ) )
If MenuBars( ID ).ParentID = ActiveWindow
MenuBars( ID ).ParentPosX = Windows( MenuBars( ID ).ParentID ).RealPosX + GUI.WindowPadding
MenuBars( ID ).ParentPosY = Windows( MenuBars( ID ).ParentID ).RealPosY + GUI.WindowTitleBarHeight
MenuBars( ID ).ParentSize = Windows( MenuBars( ID ).ParentID ).SizeX - ( GUI.WindowPadding * 2 )
UpdateMenuBar( ID )
EndIf
Next ID
For ID = 0 to Array Count( Sliders( ) )
If Sliders( ID ).ParentID = ActiveWindow
Sliders( ID ).RealPosX = Sliders( ID ).PosX + Windows( Sliders( ID ).ParentID ).RealPosX
Sliders( ID ).RealPosY = Sliders( ID ).PosY + Windows( Sliders( ID ).ParentID ).RealPosY
DrawSlider( ID )
EndIf
Next ID
EndIf
DrawRightClickMenu( )
EndFunction
Function SetRightClickMenu( Use as Integer )
RightClickMenu.IsEnabled = Use
RightClickMenu.SelectedOption = -2
EndFunction
Function AddRightClickMenuOption( Txt as String )
Array Insert at Bottom RightClickMenuOptions( )
ID = Array Count( RightClickMenuOptions( ) )
RightClickMenuOptions( ID ) = Txt
EndFunction
Function DrawRightClickMenu( )
Height as Integer
OptionHeight as Integer
OptionHeight = 25
Width as Integer
If RightClickMenu.IsEnabled
If GetRightMouseState( ) = _RELEASED
RightClickMenu.ShowOptions = 1
RightClickMenu.PosX = MouseX( )
RightClickMenu.PosY = MouseY( )
EndIf
EndIf
If RightClickMenu.ShowOptions = 1
Width = 100
Height = ( Array Count( RightClickMenuOptions( ) ) + 1 ) * OptionHeight
X = RightClickMenu.PosX
Y = RightClickMenu.PosY
DrawBorderedBox( X, Y, X + Width, Y + Height, Colors( 0 ), Colors( 2 ), GUI.DrawStyle )
For I = 0 to Array Count( RightClickMenuOptions( ) )
X1 = X + 3
X2 = X + Width - 3
Y1 = Y + ( I * OptionHeight ) + 3
Y2 = Y + ( ( I + 1 ) * OptionHeight ) - 3
If MouseX( ) > X1 and MouseY( ) > Y1 and MouseX( ) < X2 and MouseY( ) < Y2
If GetLeftMouseState( ) = _DOWN
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 1 ), GUI.DrawStyle )
Else
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 2 ), GUI.DrawStyle )
EndIf
If GetLeftMouseState( ) = _PRESSED
RightClickMenu.SelectedOption = I
Else
RightClickMenu.SelectedOption = -1
EndIf
EndIf
TX = ( X + X + Width ) / 2
TY = Y + ( ( ( I + 1 ) * OptionHeight ) - ( OptionHeight / 2 ) )
Ink Colors( 0 ), 0
CenterText( RightClickMenuOptions( I ), TX, TY )
Next I
If MouseX( ) < X - 50 or MouseY( ) < Y - 50 or MouseX( ) > X + Width + 50 or MouseY( ) > Y + Height + 50
RightClickMenu.ShowOptions = 0
EndIf
EndIf
EndFunction
Function GetRightClickMenuOptionSelected( Option as String )
If RightClickMenu.SelectedOption > -1
If RightClickMenuOptions( RightClickMenu.SelectedOption ) = Option
ExitFunction 1
EndIf
EndIf
EndFunction 0
Function AddWindow( ParentID as Integer, PosX as Integer, PosY as Integer, SizeX as Integer, SizeY as Integer, Title as String )
Array Insert At Bottom Windows( )
ID = Array Count( Windows( ) )
Windows( ID ).ParentID = ParentID
Windows( ID ).PosX = PosX
Windows( ID ).PosY = PosY
If ParentID > -1
Windows( ID ).RealPosX = PosX + Windows( ParentID ).RealPosX
Windows( ID ).RealPosY = PosY + Windows( ParentID ).RealPosY
Else
Windows( ID ).RealPosX = PosX
Windows( ID ).RealPosY = PosY
EndIf
Windows( ID ).SizeX = SizeX
Windows( ID ).SizeY = SizeY
Windows( ID ).MinSizeX = 100
Windows( ID ).MinSizeY = 60
Windows( ID ).Title = Title
Windows( ID ).IsActive = 1
Windows( ID ).IsVisible = 1
Windows( ID ).IsCurrentWindow = 1
EndFunction ID
Function DrawWindow( ID as Integer )
X1 = Windows( ID ).RealPosX
Y1 = Windows( ID ).RealPosY
X2 = Windows( ID ).RealPosX + Windows( ID ).SizeX
Y2 = Windows( ID ).RealPosY + Windows( ID ).SizeY
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 1 ), GUI.DrawStyle )
X1 = Windows( ID ).RealPosX + GUI.WindowPadding
Y1 = Windows( ID ).RealPosY + GUI.WindowTitleBarHeight
X2 = Windows( ID ).RealPosX + Windows( ID ).SizeX - GUI.WindowPadding
Y2 = Windows( ID ).RealPosY + Windows( ID ).SizeY - GUI.WindowPadding
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 2 ), GUI.DrawStyle )
X = Windows( ID ).RealPosX + ( Windows( ID ).SizeX / 2 )
Y = Windows( ID ).RealPosY + ( GUI.WindowTitleBarHeight / 2 )
Ink Colors( 0 ), 0
NewTitle as String
NewTitle = Left$( Windows( ID ).Title, Windows( ID ).SizeX / Text Width( "O" ) )
CenterText( NewTitle, X, Y )
EndFunction
Function MouseOverWindowTitleBar( ID as Integer )
X1 = Windows( ID ).RealPosX + GUI.WindowPadding
Y1 = Windows( ID ).RealPosY + GUI.WindowPadding
X2 = Windows( ID ).RealPosX + Windows( ID ).SizeX - GUI.WindowPadding
Y2 = Windows( ID ).RealPosY + GUI.WindowTitleBarHeight
If MouseX( ) > X1 and MouseX( ) < X2 and MouseY( ) > Y1 and MouseY( ) < Y2
ExitFunction 1
EndIf
EndFunction 0
Function MouseOverWindowPadding( ID as Integer )
X1 = Windows( ID ).RealPosX
X2 = Windows( ID ).RealPosX + GUI.WindowPadding
X3 = Windows( ID ).RealPosX + Windows( ID ).SizeX - GUI.WindowPadding
X4 = Windows( ID ).RealPosX + Windows( ID ).SizeX
Y1 = Windows( ID ).RealPosY
Y2 = Windows( ID ).RealPosY + GUI.WindowPadding
Y3 = Windows( ID ).RealPosY + Windows( ID ).SizeY - GUI.WindowPadding
Y4 = Windows( ID ).RealPosY + Windows( ID ).SizeY
OverPadding = 0
If MouseX( ) > X1 and MouseX( ) < X2
OverPadding = 1
EndIf
If MouseX( ) > X3 and MouseX( ) < X4
OverPadding = 2
EndIf
If MouseY( ) > Y1 and MouseY( ) < Y2
OverPadding = 1
EndIf
If Mousey( ) > Y3 and MouseY( ) < Y4
OverPadding = 2
EndIf
EndFunction OverPadding
Function MouseOverWindow( ID as Integer )
If ID > -1
X1 = Windows( ID ).RealPosX
Y1 = Windows( ID ).RealPosY
X2 = X1 + Windows( ID ).SizeX
Y2 = Y1 + Windows( ID ).SizeY
If MouseX( ) > X1 and MouseY( ) > Y1 and MouseX( ) < X2 and MouseY( ) < Y2
ExitFunction 1
EndIf
EndIf
EndFunction 0
Function GetWindowPositionX( ID as Integer )
TEMP = Windows( ID ).PosX
EndFunction TEMP
Function GetWindowPositionY( ID as Integer )
TEMP = Windows( ID ).PosY
EndFunction TEMP
Function SetWindowPosition( ID as Integer, NewX as Integer, NewY as Integer )
Windows( ID ).PosX = NewX
Windows( ID ).PosY = NewY
EndFunction
Function GetWindowSizeX( ID as Integer )
TEMP = Windows( ID ).SizeX
EndFunction TEMP
Function GetWindowSizeY( ID as Integer )
TEMP = Windows( ID ).SizeY
EndFunction TEMP
Function SetWindowSize( ID as Integer, NewX as Integer, NewY as Integer )
Windows( ID ).SizeX = NewX
Windows( ID ).SizeY = NewY
EndFunction
Function GetWindowTitle( ID as Integer )
TEMP$ = Windows( ID ).Title
EndFunction TEMP$
Function SetWindowTitle( ID as Integer, Title as String )
Windows( ID ).Title = Title
EndFunction
Function GetWindowMovable( ID as Integer )
TEMP = Windows( ID ).IsMovable
EndFunction TEMP
Function SetWindowMovable( ID as Integer, Movable as Integer )
Windows( ID ).IsMovable = Movable
EndFunction
Function GetWindowResizable( ID as Integer )
TEMP = Windows( ID ).IsResizable
EndFunction TEMP
Function SetWindowResizable( ID as Integer, Resize as Integer )
Windows( ID ).IsResizable = Resize
EndFunction
Function AddButton( ParentID as Integer, PosX as Integer, PosY as Integer, SizeX as Integer, SizeY as Integer, ButtonTxt as String )
Array Insert At Bottom Buttons( )
ID = Array Count( Buttons( ) )
Buttons( ID ).ParentID = ParentID
Buttons( ID ).PosX = PosX
Buttons( ID ).PosY = PosY
Buttons( ID ).SizeX = SizeX
Buttons( ID ).SizeY = SizeY
Buttons( ID ).Txt = ButtonTxt
EndFunction ID
Function DrawButton( ID as Integer, MouseOver as Integer )
X1 = Buttons( ID ).RealPosX
Y1 = Buttons( ID ).RealPosY
X2 = X1 + Buttons( ID ).SizeX
Y2 = Y1 + Buttons( ID ).SizeY
If MouseOver = 1
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 1 ), GUI.DrawStyle )
Else
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 3 ), GUI.DrawStyle )
EndIf
Ink Colors( 0 ), 0
CenterText( Buttons( ID ).Txt, ( X1 + X2 ) / 2, ( Y2 + Y1 ) / 2 )
EndFunction
Function MouseOverButton( ID as Integer )
X1 = Buttons( ID ).RealPosX
Y1 = Buttons( ID ).RealPosY
X2 = X1 + Buttons( ID ).SizeX
Y2 = Y1 + Buttons( ID ).SizeY
If MouseX( ) > X1 and MouseX( ) < X2 and MouseY( ) > Y1 and MouseY( ) < Y2
ExitFunction 1
EndIf
EndFunction 0
Function GetButtonClicked( ID as Integer )
If MouseOverButton( ID ) and GetLeftMouseState( ) = _PRESSED
ExitFunction 1
EndIf
EndFunction 0
Function GetButtonPositionX( ID as Integer )
TEMP = Buttons( ID ).PosX
EndFunction TEMP
Function GetButtonPositionY( ID as Integer )
TEMP = Buttons( ID ).PosY
EndFunction TEMP
Function GetButtonAbsolutePositionX( ID as Integer )
TEMP = Buttons( ID ).RealPosX
EndFunction TEMP
Function GetButtonAbsolutePositionY( ID as Integer )
TEMP = Buttons( ID ).RealPosY
EndFunction TEMP
Function SetButtonPosition( ID as Integer, X as Integer, Y as Integer )
Buttons( ID ).PosX = X
Buttons( ID ).PosY = Y
EndFunction
Function GetButtonSizeX( ID as Integer )
TEMP = Buttons( ID ).SizeX
EndFunction TEMP
Function GetButtonSizeY( ID as Integer )
TEMP = Buttons( ID ).SizeY
EndFunction
Function SetButtonSize( ID as Integer, X as Integer, Y as Integer )
Buttons( ID ).SizeX = X
Buttons( ID ).SizeY = Y
EndFunction
Function GetButtonText( ID as Integer )
TEMP as String
TEMP = Buttons( ID ).Txt
EndFunction TEMP
Function SetButtonText( ID as Integer, Txt as String )
Buttons( ID ).Txt = Txt
EndFunction
Function AddMenuBar( ParentID as Integer )
Array Insert At Bottom MenuBars( )
MenuBarID = Array Count( MenuBars( ) )
MenuBars( MenuBarID ).MenuWidth = 100
MenuBars( MenuBarID ).MenuHeight = 25
MenuBars( MenuBarID ).OptionHeight = 30
MenuBars( MenuBarID ).NumMenus = -1
MenuBars( MenuBarID ).ParentID = ParentID
If ParentID > -1
MenuBars( MenuBarID ).ParentSize = Windows( ParentID ).SizeX - ( 2 * GUI.WindowPadding ) - 2
Else
MenuBars( MenuBarID ).ParentSize = Screen Width( )
EndIf
EndFunction MenuBarID
Function AddMenu( MenuBarID as Integer, Name as String )
Inc MenuBars( MenuBarID ).NumMenus
Menus( MenuBarID, MenuBars( MenuBarID ).NumMenus ).Name = Name
Menus( MenuBarID, MenuBars( MenuBarID ).NumMenus ).NumOptions = -1
EndFunction
Function AddOption( ID as Integer, Menu as String, Option as String )
MenuID as Integer
For I = 0 to MenuBars( ID ).NumMenus
If Menus( ID, I ).Name = Menu
MenuID = I
Exit
EndIf
Next I
Inc Menus( ID, MenuID ).NumOptions
Options( ID, MenuID, Menus( ID, I ).NumOptions ).Name = Option
Options( ID, MenuID, Menus( ID, I ).NumOptions ).IsAvailable = 1
EndFunction
Function UpdateMenuBar( ID as Integer )
Ink Colors( 1 ), 0
DrawBorderedBox( MenuBars( ID ).ParentPosX, MenuBars( ID ).ParentPosY, MenuBars( ID ).ParentPosX + MenuBars( ID ).ParentSize, MenuBars( ID ).ParentPosY + MenuBars( ID ).MenuHeight, Colors( 0 ), Colors( 1 ), GUI.DrawStyle )
Ink Colors( 2 ), 0
For I = 0 to MenuBars( ID ).NumMenus
If MouseX( ) > MenuBars( ID ).ParentPosX + ( I * MenuBars( ID ).MenuWidth ) and MouseX( ) < MenuBars( ID ).ParentPosX + ( ( I * MenuBars( ID ).MenuWidth ) + MenuBars( ID ).MenuWidth )
If MouseY( ) > MenuBars( ID ).ParentPosY and Mousey( ) < MenuBars( ID ).ParentPosY + MenuBars( ID ).MenuHeight
DrawBorderedBox( MenuBars( ID ).ParentPosX + ( ( I * MenuBars( ID ).MenuWidth ) + 3 ), MenuBars( ID ).ParentPosY + 3, MenuBars( ID ).ParentPosX + ( ( I *MenuBars( ID ).MenuWidth ) + MenuBars( ID ).MenuWidth - 3 ), MenuBars( ID ).ParentPosY + ( MenuBars( ID ).MenuHeight - 3 ), Colors( 0 ), Colors( 1 ), GUI.DrawStyle )
If GetLeftMouseState( ) = _PRESSED
Menus( ID, I ).ShowOptions = 1
EndIf
EndIf
EndIf
If Menus( ID,I ).ShowOptions = 1
DrawBorderedBox( MenuBars( ID ).ParentPosX + ( I * MenuBars( ID ).MenuWidth ), MenuBars( ID ).ParentPosY + MenuBars( ID ).MenuHeight, MenuBars( ID ).ParentPosX + ( ( I *MenuBars( ID ).MenuWidth ) + MenuBars( ID ).MenuWidth ), MenuBars( ID ).ParentPosY + ( MenuBars( ID ).MenuHeight + ( ( Menus( ID, I ).NumOptions + 1 ) * MenuBars( ID ).OptionHeight ) ), Colors( 0 ), Colors( 2 ), GUI.DrawStyle )
For Option = 0 to Menus( ID, I ).NumOptions
If Options( ID, I, Option ).IsAvailable = 1
If MouseX( ) > MenuBars( ID ).ParentPosX + ( I * MenuBars( ID ).MenuWidth ) and MouseX( ) < MenuBars( ID ).ParentPosX + ( ( I *MenuBars( ID ).MenuWidth ) +MenuBars( ID ).MenuWidth )
If MouseY( ) > MenuBars( ID ).ParentPosY + ( MenuBars( ID ).MenuHeight + ( Option * MenuBars( ID ).OptionHeight ) ) and MouseY( ) < MenuBars( ID ).ParentPosY + ( MenuBars( ID ).MenuHeight + MenuBars( ID ).OptionHeight + ( ( Option ) *MenuBars( ID ).OptionHeight ) )
If GetLeftMouseState( ) = _PRESSED
Options( ID, I, Option ).IsPressed = 1
Else
Options( ID, I, Option ).IsPressed = 0
EndIf
If GetLeftMouseState( ) = _DOWN or GetLeftMouseState( ) = _PRESSED
DrawBorderedBox( MenuBars( ID ).ParentPosX + ( ( I * MenuBars( ID ).MenuWidth ) + 3 ), MenuBars( ID ).ParentPosY + ( (MenuBars( ID ).MenuHeight + 3 ) + ( ( Option ) *MenuBars( ID ).OptionHeight ) ), MenuBars( ID ).ParentPosX + ( ( I *MenuBars( ID ).MenuWidth ) +MenuBars( ID ).MenuWidth - 3 ), MenuBars( ID ).ParentPosY + ( ( MenuBars( ID ).MenuHeight + MenuBars( ID ).OptionHeight + ( ( Option ) * MenuBars( ID ).OptionHeight ) - 3 ) ), Colors( 0 ), Colors( 1 ), GUI.DrawStyle )
Else
DrawBorderedBox( MenuBars( ID ).ParentPosX + ( ( I * MenuBars( ID ).MenuWidth ) + 3 ), MenuBars( ID ).ParentPosY + ( (MenuBars( ID ).MenuHeight + 3 ) + ( ( Option ) *MenuBars( ID ).OptionHeight ) ), MenuBars( ID ).ParentPosX + ( ( I *MenuBars( ID ).MenuWidth ) +MenuBars( ID ).MenuWidth - 3 ), MenuBars( ID ).ParentPosY + ( ( MenuBars( ID ).MenuHeight + MenuBars( ID ).OptionHeight + ( ( Option ) * MenuBars( ID ).OptionHeight ) - 3 ) ), Colors( 0 ), Colors( 2 ), GUI.DrawStyle )
EndIf
Else
Options( ID, I, Option ).IsPressed = 0
EndIf
EndIf
Ink Colors( 0 ), 0
CenterText( Options( ID, I, Option ).Name, MenuBars( ID ).ParentPosX + ( ( I *MenuBars( ID ).MenuWidth ) + (MenuBars( ID ).MenuWidth / 2 ) ), MenuBars( ID ).ParentPosY + ( MenuBars( ID ).MenuHeight + ( ( Option *MenuBars( ID ).OptionHeight ) + (MenuBars( ID ).OptionHeight / 2 ) ) ) )
Else
Ink Colors( 1 ), 0
CenterText( Options( ID, I, Option ).Name, MenuBars( ID ).ParentPosX + ( ( I *MenuBars( ID ).MenuWidth ) + (MenuBars( ID ).MenuWidth / 2 ) ), MenuBars( ID ).ParentPosY + ( MenuBars( ID ).MenuHeight + ( ( Option *MenuBars( ID ).OptionHeight ) + (MenuBars( ID ).OptionHeight / 2 ) ) ) )
EndIf
Next Option
EndIf
If MouseX( ) < MenuBars( ID ).ParentPosX + ( I * MenuBars( ID ).MenuWidth ) or MouseX( ) > MenuBars( ID ).ParentPosX + ( ( I *MenuBars( ID ).MenuWidth ) +MenuBars( ID ).MenuWidth ) or MouseY( ) > MenuBars( ID ).ParentPosY + ( MenuBars( ID ).MenuHeight + ( ( Menus( ID, I ).NumOptions + 1 ) *MenuBars( ID ).OptionHeight ) ) or MouseY( ) < MenuBars( ID ).ParentPosY
Menus( ID, I ).ShowOptions = 0
EndIf
Ink Colors( 0 ), 0
If Text Width( Menus( ID, I ).Name ) + 10 > MenuBars( ID ).MenuWidth
MenuBars( ID ).MenuWidth = Text Width( Menus( ID, I ).Name ) + 10
EndIf
CenterText( Menus( ID, I ).Name, MenuBars( ID ).ParentPosX + ( (MenuBars( ID ).MenuWidth * I ) +MenuBars( ID ).MenuWidth / 2 ), MenuBars( ID ).ParentPosY + ( MenuBars( ID ).MenuHeight / 2 ) )
Next I
EndFunction
Function OptionClicked( MenuBarID as Integer, Menu as String, Option as String )
For I = 0 to MenuBars( MenuBarID ).NumMenus
If Menus( MenuBarID, I ).Name = Menu
MenuID = I
EndIf
Next I
For I = 0 to Menus( MenuBarID, MenuID ).NumOptions
If Options( MenuBarID, MenuID, I ).Name = Option
OptionID = I
EndIf
Next I
TEMP = Options( MenuBarID, MenuID, OptionID ).IsPressed
EndFunction TEMP
Function AddCheckBox( ParentID as Integer, PosX as Integer, PosY as Integer, SizeX as Integer, SizeY as Integer, Txt as String )
Array Insert At Bottom CheckBoxes( )
ID = Array Count( CheckBoxes( ) )
CheckBoxes( ID ).ParentID = ParentID
CheckBoxes( ID ).PosX = PosX
CheckBoxes( ID ).PosY = PosY
CheckBoxes( ID ).SizeX = SizeX
CheckBoxes( ID ).SizeY = SizeY
CheckBoxes( ID ).Txt = Txt
EndFunction ID
Function DrawCheckBox( ID as Integer )
X1 = CheckBoxes( ID ).RealPosX
Y1 = CheckBoxes( ID ).RealPosY
X2 = X1 + CheckBoxes( ID ).SizeX
Y2 = Y1 + CheckBoxes( ID ).SizeY
If MouseOverCheckBox( ID ) and GetLeftMouseState( ) = _PRESSED
CheckBoxes( ID ).IsChecked = 1 - CheckBoxes( ID ).IsChecked
EndIf
If MouseOverCheckBox( ID )
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 2 ), GUI.DrawStyle )
Else
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 3 ), GUI.DrawStyle )
EndIf
If CheckBoxes( ID ).IsChecked
DrawBorderedBox( X1 + 5, Y1 + 5, X2 - 5, Y2 - 5, Colors( 0 ), Colors( 1 ), GUI.DrawStyle )
EndIf
Ink Colors( 0 ), 0
Text X2 + 5, Y1 + ( CheckBoxes( ID ).SizeY / 2 ) - ( Text Height( CheckBoxes( ID ).Txt ) / 2 ), CheckBoxes( ID ).Txt
EndFunction
Function MouseOverCheckBox( ID as Integer )
X1 = CheckBoxes( ID ).RealPosX
Y1 = CheckBoxes( ID ).RealPosY
X2 = X1 + CheckBoxes( ID ).SizeX
Y2 = Y1 + CheckBoxes( ID ).SizeY
If MouseX( ) > X1 and MouseY( ) > Y1 and MouseX( ) < X2 and MouseY( ) < Y2
ExitFunction 1
EndIf
EndFunction 0
Function GetCheckBoxChecked( ID as Integer )
TEMP = CheckBoxes( ID ).IsChecked
EndFunction TEMP
Function SetCheckBoxChecked( ID as Integer, Check as Integer )
CheckBoxes( ID ).IsChecked = Check
EndFunction
Function GetCheckBoxPositionX( ID as Integer )
TEMP = CheckBoxes( ID ).PosX
EndFunction TEMP
Function GetCheckBoxPositionY( ID as Integer )
TEMP = CheckBoxes( ID ).PosY
EndFunction TEMP
Function GetCheckBoxAbsolutePositionX( ID as Integer )
TEMP = CheckBoxes( ID ).RealPosX
EndFunction TEMP
Function GetCheckBoxAbsolutePositionY( ID as Integer )
TEMP = CheckBoxes( ID ).RealPosY
EndFunction TEMP
Function SetCheckBoxPosition( ID as Integer, X as Integer, Y as Integer )
CheckBoxes( ID ).PosX = X
CheckBoxes( ID ).PosY = Y
EndFunction
Function GetCheckBoxSizeX( ID as Integer )
TEMP = CheckBoxes( ID ).SizeX
EndFunction TEMP
Function GetCheckBoxSizeY( ID as Integer )
TEMP = CheckBoxes( ID ).SizeY
EndFunction
Function SetCheckBoxSize( ID as Integer, X as Integer, Y as Integer )
CheckBoxes( ID ).SizeX = X
CheckBoxes( ID ).SizeY = Y
EndFunction
Function GetCheckBoxText( ID as Integer )
TEMP as String
TEMP = CheckBoxes( ID ).Txt
EndFunction TEMP
Function SetCheckBoxText( ID as Integer, Txt as String )
CheckBoxes( ID ).Txt = Txt
EndFunction
Function AddSlider( ParentID as Integer, PosX as Integer, PosY as Integer, SliderSizeX as Integer, SliderSizeY as Integer, BarSizeX as Integer, BarSizeY as Integer, StartPos as Integer, EndPos as Integer, Txt as String )
Array Insert at Bottom Sliders( )
ID = Array Count( Sliders( ) )
Sliders( ID ).ParentID = ParentID
Sliders( ID ).PosX = PosX
Sliders( ID ).PosY = PosY
Sliders( ID ).SliderSizeX = SliderSizeX
Sliders( ID ).SliderSizeY = SliderSizeY
Sliders( ID ).BarSizeX = BarSizeX
Sliders( ID ).BarSizeY = BarSizeY
Sliders( ID ).StartPos = StartPos
Sliders( ID ).EndPos = EndPos
Sliders( ID ).Txt = Txt
EndFunction ID
Function DrawSlider( ID as Integer )
MouseOver = MouseOverSlider( ID )
Length as Float
ActualSize as Float
RelPos as Float
Length = Sliders( ID ).EndPos - Sliders( ID ).StartPos
ActualSize = Sliders( ID ).BarSizeX
RelPos = Sliders( ID ).SliderPos - Sliders( ID ).StartPos
Percent as Float
Percent = RelPos / Length
Sliders( ID ).RealSliderPos = Percent * ActualSize
If MouseOver and GetLeftMouseState( ) = _PRESSED
Sliders( ID ).OldPos = Sliders( ID ).RealSliderPos
Sliders( ID ).OldMouse = MouseX( )
Sliders( ID ).IsSliding = 1
EndIf
If Sliders( ID ).IsSliding = 1
Sliders( ID ).RealSliderPos = Sliders( ID ).OldPos + ( MouseX( ) - Sliders( ID ).OldMouse )
If GetLeftMouseState( ) = _RELEASED
Sliders( ID ).IsSliding = 0
Sliders( ID ).SliderPos = ConvertToSliderCoords( ID, Sliders( ID ).RealSliderPos )
EndIf
EndIf
If ( Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 ) ) + Sliders( ID ).RealSliderPos < ( Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 ) )
Sliders( ID ).RealSliderPos = 0
Sliders( ID ).SliderPos = Sliders( ID ).StartPos
Endif
If ( Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 ) ) + Sliders( ID ).RealSliderPos > ( Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 ) ) + Sliders( ID ).BarSizeX
Sliders( ID ).RealSliderPos = Sliders( ID ).BarSizeX
Sliders( ID ).SliderPos = Sliders( ID ).EndPos
Endif
X1 = Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 )
Y1 = Sliders( ID ).RealPosY - ( Sliders( ID ).BarSizeY / 2 )
X2 = Sliders( ID ).RealPosX + ( Sliders( ID ).BarSizeX / 2 )
Y2 = Sliders( ID ).RealPosY + ( Sliders( ID ).BarSizeY / 2 )
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 2 ), GUI.DrawStyle )
X1 = ( Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 ) ) + Sliders( ID ).RealSliderPos - ( Sliders( ID ).SliderSizeX / 2 )
Y1 = Sliders( ID ).RealPosY - ( Sliders( ID ).SliderSizeY / 2 )
X2 = ( Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 ) ) + Sliders( ID ).RealSliderPos + ( Sliders( ID ).SliderSizeX / 2 )
Y2 = Sliders( ID ).RealPosY + ( Sliders( ID ).SliderSizeY / 2 )
If MouseOver
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 1 ), GUI.DrawStyle )
Else
DrawBorderedBox( X1, Y1, X2, Y2, Colors( 0 ), Colors( 2 ), GUI.DrawStyle )
EndIf
EndFunction
Function MouseOverSlider( ID as Integer )
Length as Float
ActualSize as Float
RelPos as Float
Length = Sliders( ID ).EndPos - Sliders( ID ).StartPos
ActualSize = Sliders( ID ).BarSizeX
RelPos = Sliders( ID ).SliderPos - Sliders( ID ).StartPos
Percent as Float
Percent = RelPos / Length
RealSliderPos as Float
RealSliderPos = Percent * ActualSize
X1 = ( Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 ) ) + RealSliderPos - ( Sliders( ID ).SliderSizeX / 2 )
Y1 = Sliders( ID ).RealPosY - ( Sliders( ID ).SliderSizeY / 2 )
X2 = ( Sliders( ID ).RealPosX - ( Sliders( ID ).BarSizeX / 2 ) ) + RealSliderPos + ( Sliders( ID ).SliderSizeX / 2 )
Y2 = Sliders( ID ).RealPosY + ( Sliders( ID ).SliderSizeY / 2 )
If MouseX( ) > X1 and MouseY( ) > Y1 and MouseX( ) < X2 and MouseY( ) < Y2
ExitFunction 1
EndIf
EndFunction 0
Function ConvertToSliderCoords( ID as Integer, C as Float )
S as Float
E as Float
L as Float
P as Float
A as Float
S = Sliders( ID ).StartPos
E = Sliders( ID ).EndPos
L = E - S
P = C / Sliders( ID ).BarSizeX
A = ( P * L ) + S
EndFunction A
Function GetSliderValue( ID as Integer )
Sliders( ID ).SliderPos = ConvertToSliderCoords( ID, Sliders( ID ).RealSliderPos )
TEMP = Sliders( ID ).SliderPos
EndFunction TEMP
Function SetSliderValue( ID as Integer, SliderPos as Integer )
Sliders( ID ).SliderPos = SliderPos
EndFunction
Function CenterText( Txt as String, X as Integer, Y as Integer )
Center Text X, Y - ( Text Height( Txt ) / 2 ), Txt
EndFunction
Function DrawBorderedBox( X1 as Integer, Y1 as Integer, X2 as Integer, Y2 as Integer, BorCol as DWORD, BoxCol as DWORD, Style as Integer )
by as Float
radius as Float
radius = 10
X1# = X1
Y1# = Y1
X2# = X2
Y2# = Y2
If Style = 1
//D3D_Box X1, Y1, X2, Y2, BorCol
D3D_Box X1, Y1, X2, Y2, BoxCol
D3D_Line X1, Y1, X2, Y1, BorCol
D3D_Line X1, Y1, X1, Y2, BorCol
D3D_Line X2, Y1, X2, Y2, BorCol
D3D_Line X1, Y2, X2, Y2, BorCol
//Ink BorCol, 0
//Box X1, Y1, X2, Y2
//Ink BoxCol, 0
//Box X1 + 1, Y1 + 1, X2 - 1, Y2 - 1
EndIf
If Style = 2
remstart
Ink BorCol, 0
for i = 1 to radius
by = sqrt(radius^2 - i^2)
box x1 + radius - i, y1 + radius - by, x1 + x2 - x1 - radius + i, y1 + y2 - y1 - radius + by
next i
inc x1, 1
inc y1, 1
dec x2, 1
dec y2, 1
Ink BoxCol, 0
for i = 1 to radius
by = sqrt(radius^2 - i^2)
box x1 + radius - i, y1 + radius - by, x1 + x2 - x1 - radius + i, y1 + y2 - y1 - radius + by
next i
remend
D3D_ROUNDED_BOX X1, Y1, X2, Y2, Radius, 1, BorCol
inc x1, 1
inc y1, 1
dec x2, 1
dec y2, 1
D3D_ROUNDED_BOX X1, Y1, X2, Y2, Radius, 1, BoxCol
EndIf
If Style = 3
remstart
Ink BorCol, 0
Box X1, Y1, X2, Y2
Box X1 + 2, Y1 + 2, X2 + 2, Y2 + 2
Ink BoxCol, 0
Box X1 + 1, Y1 + 1, X2 - 1, Y2 - 1
remend
D3D_Box X1, Y1, X2, Y2, BorCol
D3D_Box X1 + 2, Y1 + 2, X2 + 2, Y2 + 2, BorCol
D3D_Box X1 + 1, Y1 + 1, X2 - 1, Y2 - 1, BoxCol
EndIf
If Style = 4
Ink BorCol, 0
Box X1, Y1, X2, Y2
For I = 1 to 4
Box X1 + I, Y1 + I, X2 + I, Y2 + I
Next I
Ink BoxCol, 0
Box X1 + 1, Y1 + 1, X2 - 1, Y2 - 1
EndIf
If Style = 5
Ink BorCol, 0
Box X1, Y1, X2, Y2
Ink BoxCol, 0
Box X1 + 1, Y1 + 1, X2 - 1, Y2 - 1
Ink WhiteTint( BoxCol, 25 ), 0
Box X1 + 1, ( Y1 + Y2 ) / 2.0, X2 - 1, Y2 - 1
EndIf
If Style = 6
remstart
Ink BorCol, 0
Box X1, Y1, X2, Y2
Ink BoxCol, 0
Box X1 + 1, Y1 + 1, X2 - 1, Y2 - 1, BoxCol, WhiteTint( BoxCol, 70 ), BoxCol, WhiteTint( BoxCol, 70 )
remend
D3D_Box X1, Y1, X2, Y2, WhiteTint( BoxCol, 70 ), WhiteTint( BoxCol, 70 ), BoxCol, BoxCol
D3D_Line X1, Y1, X2, Y1, BorCol
D3D_Line X1, Y1, X1, Y2, BorCol
D3D_Line X2, Y1, X2, Y2, BorCol
D3D_Line X1, Y2, X2, Y2, BorCol
EndIf
If Style = 7
Ink BoxCol, 0
Box X1 + 1, Y1 + 1, X2 - 1, Y2 - 1
EndIf
EndFunction
Function WhiteTint( Col as DWORD, Percent as Float )
R# = RGBR( Col )
G# = RGBG( Col )
B# = RGBB( Col )
Divisor as Float
Divisor = 100 / Percent
If Divisor > 0
R# = R# + ( ( 255.0 - R# ) / Divisor )
G# = G# + ( ( 255.0 - G# ) / Divisor )
B# = B# + ( ( 255.0 - B# ) / Divisor )
EndIf
TEMP = RGB( R#, G#, B# )
EndFunction TEMP
Function InitMouseEvents( )
Dim MouseState( 2 ) as Integer
Dim KeyStates( 256 ) as Integer
For I = 0 to 2
MouseState( I ) = _UP
Next I
For I = 0 to 256
KeyStates( I ) = _UP
Next I
EndFunction
Function UpdateMouseEvents( )
If MouseClick( ) = 0
If MouseState( _LEFT ) = _RELEASED
MouseState( _LEFT ) = _UP
EndIf
If MouseState( _LEFT ) = _DOWN or MouseState( _LEFT ) = _PRESSED
MouseState( _LEFT ) = _RELEASED
EndIf
EndIf
If MouseClick( ) = 1
If MouseState( _LEFT ) = _PRESSED
MouseState( _LEFT ) = _DOWN
EndIf
If MouseState( _LEFT ) = _UP or MouseState( _LEFT ) = _RELEASED
MouseState( _LEFT ) = _PRESSED
EndIf
EndIf
If MouseClick( ) = 0
If MouseState( _MIDDLE ) = _RELEASED
MouseState( _MIDDLE ) = _UP
EndIf
If MouseState( _MIDDLE ) = _DOWN or MouseState( _MIDDLE ) = _PRESSED
MouseState( _MIDDLE ) = _RELEASED
EndIf
EndIf
If MouseClick( ) = 4
If MouseState( _MIDDLE ) = _PRESSED
MouseState( _MIDDLE ) = _DOWN
EndIf
If MouseState( _MIDDLE ) = _UP or MouseState( _MIDDLE ) = _RELEASED
MouseState( _MIDDLE ) = _PRESSED
EndIf
EndIf
If MouseClick( ) = 0
If MouseState( _RIGHT ) = _RELEASED
MouseState( _RIGHT ) = _UP
EndIf
If MouseState( _RIGHT ) = _DOWN or MouseState( _RIGHT ) = _PRESSED
MouseState( _RIGHT ) = _RELEASED
EndIf
EndIf
If MouseClick( ) = 2
If MouseState( _RIGHT ) = _PRESSED
MouseState( _RIGHT ) = _DOWN
EndIf
If MouseState( _RIGHT ) = _UP or MouseState( _RIGHT ) = _RELEASED
MouseState( _RIGHT ) = _PRESSED
EndIf
EndIf
For Key = 0 to 256
If KeyState( Key ) = 1
If KeyStates( Key ) = _PRESSED
KeyStates( Key ) = _DOWN
EndIf
If KeyStates( Key ) = _UP or KeyStates( Key ) = _RELEASED
KeyStates( Key ) = _PRESSED
EndIf
Else
If KeyStates( Key ) = _RELEASED
KeyStates( Key ) = _UP
EndIf
If KeyStates( Key ) = _DOWN or KeyStates( KEY ) = _PRESSED
KeyStates( Key ) = _RELEASED
EndIf
EndIf
Next Key
EndFunction
Function GetLeftMouseState( )
TEMP = MouseState( _LEFT )
EndFunction TEMP
Function GetMiddleMouseState( )
TEMP = MouseState( _MIDDLE )
EndFunction TEMP
Function GetRightMouseState( )
TEMP = MouseState( _RIGHT )
EndFunction TEMP
Function GetKeyState( Key as Integer )
TEMP = KeyStates( Key )
EndFunction TEMP
Function GetMaxXRes( )
Load DLL "user32.dll", 100
X = Call DLL( 100, "GetSystemMetrics", 0 )
Delete DLL 100
EndFunction X
Function GetMaxYRes( )
Load DLL "user32.dll", 100
Y = Call DLL( 100, "GetSystemMetrics", 1 )
Delete DLL 100
EndFunction Y
Function CreateDebugFile( )
If File Exist( "Debug.txt" )
Delete File "Debug.txt"
EndIf
Open to Write _DEBUGFILE, "Debug.txt"
EndFunction
Function StartDebug( Op as String )
DebugString = Op
DebugTime = Timer( )
EndFunction
Function EndDebug( )
DebugTime = Timer( ) - DebugTime
Write String _DEBUGFILE, DebugString + " - " + Str$( DebugTime ) + " ms"
EndFunction
Function CloseDebugFile( )
Close File _DEBUGFILE
EndFunction
How to use it:
Before you do anything you must call InitGUI( ).
Once that's done you can start creating GUI widgets. The GUI currently only supports four widgets: windows, buttons, check boxes and menu bars.
You create windows with AddWindow( ):
MyWindow = AddWindow( -1, 100, 100, 500, 250, "MyWindow" )
The first thing you'll notice is that the function returns a value. That value is a handle to the window; it's holds its ID. This way you don't have to keep track of IDs. The first parameter is the handle of the parent window you're adding this window to. If the first parameter is -1 then the window won't have a parent. The second two values are the starting position of the window. The next two values are the starting size of the window, and the last is the title of the window, which will be displayed in its title bar.
Now that we've created the window we'll set some properties of it:
SetWindowMovable( MyWindow, 1 )
SetWindowResizable( MyWindow, 1 )
SetWindowMinWidth( MyWindow, 360 )
SetWindowMinHeight( MyWindow, 140 )
The first two functions we'll set our window so that we can move and resize it. The last two set the minimum width and height of our window.
Now we can add some widgets to our window. We'll start with a menu bar:
MenuBar = AddMenuBar( MyWindow )
AddMenu( MenuBar, "File" )
AddOption( MenuBar, "File", "New" )
AddOption( MenuBar, "File", "Open" )
AddOption( MenuBar, "File", "Close" )
AddOption( MenuBar, "File", "Save" )
AddOption( MenuBar, "File", "Save As..." )
AddOption( MenuBar, "File", "Exit" )
AddMenu( MenuBar, "Edit" )
AddOption( MenuBar, "Edit", "Undo" )
AddOption( MenuBar, "Edit", "Redo" )
AddMenu( MenuBar, "Help" )
AddOption( MenuBar, "Help", "View Help" )
Once again the first function, 'AddMenuBar()', returns a handle to our menu bar. The only parameter is the parent window of our menu bar. If this value is set to -1 the menu bar will just be placed at the top of our screen, otherwise it will be put at the top of its parent window. The rest of the code just adds some menus and options to the menu bar, I think it's pretty self-explanatory.
Finally we'll add a check box and a button to our window:
CheckBox = AddCheckBox( MyWindow, 50, 100, 20, 20, "Check Me!" )
Button = AddButton( MyWindow, 150, 100, 100, 20, "Click Me!" )
Both these functions return handles to the element created. Also both functions have identical parameters. The first is the parent window of this widget. The second two are the starting positions. These positions are relative to the position of our parent window. The next two are the size of our widgets, and the last is the text used for the widget. To check if a button is clicked, use ButtonClicked( Button ), and to check if a check box is checked, use GetCheckBoxChecked( CheckBox ).
Oh and in our main loop we have to update our GUI with UpdateGUI( ):
And we'll check to see if the user presses 'Exit' on our menu bar like so:
If OptionClicked( MenuBar, "File", "Exit" )
End
EndIf
Ok, I hope that explained it somewhat well. If you still have any questions feel free to ask.
UPDATES:
Ok, I've added "draw styles". Draw styles basically change the appearance of the GUI; not the colors, but the GUI itself.
Here are some styles I've come up with:
"Rounded"
"Gradient Fill"
"Shadow"
"3D"
And obviously all the colors can be customized.
You can set the draw style with "SetGUIDrawStyle( )". It takes one integer parameter, from one through 7:
1 - Regular
2 - Rounded
3 - Shadow
4 - 3D
5 - Tint Fill
6 - Gradient Fill
7 - Borderless
UPDATE:
I've replaced all DBP drawing calls with D3DFunc functions. All draw styles have at least small improvement, and Rounded and Gradient Fill are over twice as fast.
UPDATE:
I've added right-click menus. To enable right-click menus, use:
SetRightClickMenu( UseIt as Integer )
Where UseIt is 1 if you want it enabled or 0 if you don't want it. It's off by default. To add options to this menu, use:
AddRightClickMenuOption( Txt as String )
Where Txt is the text displayed for the option. To see if an option has been selected/clicked use:
GetRightClickMenuOptionSelected( Option as String )
Where Option is the option you're checking to see if it's selected.
I have basically everything that I'm going to need for my editor, so this is pretty much done for the time being. However if you have a request for a certain widget I'd be glad to try and add it.
UPDATE:
I've added some fixes:
-I've fixed a bug where OptionClicked( ) didn't return correct values.
-I've fixed a bug where menubar parents weren't set correctly.