'' ----------------------------------------------------------------------------
'' 
'' 
'' ----------------------------------------------------------------------------
'' ----------------------------------------------------------------------------

'' Includes for extension libraries
#Include "MyFunctions.bi"

'' global variables
DIM GUIEvent as wGUI_EVENT PTR
DIM guiStatic as wGUIobject
DIM guiStatic_2 as wGUIobject

Dim Checkbox_1 as wGUIobject
Dim Checkbox_2 as wGUIobject
Dim Checkbox_3 as wGUIobject
Dim Checkbox_4 as wGUIobject

DIM guiListbox as wGUIobject
Dim guiMessagebox As wGUIobject

DIM imageTexture as wTexture
DIM fileName as string
DIM displayString as wstring * 32
DIM BitmapFont as wFont

Dim MesTex As wTexture

#define MY_GUI_BUTTON_FILE      101
#define MY_GUI_BUTTON_WINDOW    102
#define MY_GUI_BUTTON_QUIT      103
#define MY_GUI_BUTTON_CLOSE     104
#define MY_GUI_SCROLLBAR_RED    105
#define MY_GUI_SCROLLBAR_GREEN  106
'#define MY_GUI_LISTBOX          107
#define MY_GUI_CHECKBOX         108
#define MY_GUI_EDITBOX          109
#define MY_GUI_PASSWORD         110
#define MY_GUI_FILEOPEN         111
#define CHECKBOX_REN         112
#define CHECKBOX_BITS         113
#define CHECKBOX_REN_INFO         114


Dim fullscr As boolean = FALSE
''Dim scr_wid As uInt32 = 1024: Dim scr_hei As uInt32  = 768
Dim scr_wid As uInt32: Dim scr_hei As uInt32
''Dim cur_scr_res As Boolean = TRUE
wGetDesktopResolution (@scr_wid, @scr_hei)
Dim doublebuffer As Boolean = TRUE
Dim doublebuffer_mes As String = "Yes"
Dim bits_per_pix As uInt32 = 32
Dim bits_per_pix_info As String = " (True color, 24 million colors)"
Dim fullscr_mes As String = "No"
Dim ren_info As Boolean = TRUE
Dim ren_info_mes As String = "Yes"
' -----------------------------------------------------------------------------
' start the WorldSim3D interface. The scene will be rendered using the OpenGl
' renderer, the display will be a window 400 x 200 pixels in size, the
' display will not support shadows and we will not capture any keyboard and
' mouse events and finally vertical syncronisation to smoothen the display
' is switched on, by default it is off
wStart( wDT_OPENGL, 390, 300, 32, FALSE, FALSE, TRUE, TRUE )

''wLogoWS3D(true)

' Set the title of the display
wSetWindowCaption( "Options " )

'''''MesTex = wGetTexture ("../Assets/Sprites/planet_1.png")
' set the font used by the GUI
BitmapFont = wGetFont ( "Assets/Enigmatic.xml" )
wGUISetFont( BitmapFont )

' set the colors used by GUI controls
wGUISetColor( wGUI_CE_3D_FACE, 255, 255, 255, 255 )
wGUISetColor( wGUI_CE_BUTTON_TEXT, 20, 255, 220, 255 )
'wGUISetColor( wGUI_CE_3D_DARK_SHADOW, 255, 0, 0, 255 ) 

' add a static text object to the graphical user interface. The text will be
' drawn inside the defined rectangle, the box will not have a border and the
' text will not be wrapped around if it runs off the end
guiStatic = wAddLabel ( "(framerate, polygons drawn etc.)", _     ' Text to display
                   50,205,300,225, _        ' Size
                   FALSE, _ ' no border around the text
                   FALSE)    ' text does not wrap
guiStatic_2 = wAddLabel( _
                   "разрешение Screen resolution: " + Str(scr_wid)+ "x" +Str(scr_hei), _     ' Text to display
                   90, 20, 300, 40, _        ' Size
                   FALSE, _ ' no border around the text
                   FALSE)    ' text does not wrap
'guiStatic_3 = wAddLabel ( 

/'                   
guiStatic_2 = wAddLabel( _
                   "", _     ' Text to display
                   40, 330, 200, 350, _        ' Size
                   FALSE, _ ' no border around the text
                   FALSE)    ' text does not wrap
'/
' add a button to the graphical user interface
wAddButton( 150, 250, 230, 275, _                ' Size
                          MY_GUI_BUTTON_QUIT, _ ' ID of the button
                          "Apply", _      ' Text on the button
                          "Apply options" )   ' label when over button
/'
' add a couple of more buttons to the graphical user interface
wAddButton( 160, 30, 280, 55,   MY_GUI_BUTTON_WINDOW, "Open a window" )
wAddButton( 290, 30, 410, 55,  MY_GUI_BUTTON_QUIT, "Close the GUI" )

' add a horizontal scroll bar to the graphical user interface
wAddScrollBar( TRUE, _
                 32, 70, 320, 85, _       ' Size
                 MY_GUI_SCROLLBAR_RED, _  ' ID of the button
                 255, _                   ' The position of the scrollbar
                 255 )                    ' The maximum value of the scrollbar

' add a vertical scroll bar to the graphical user interface
wAddScrollBar( FALSE, _
                 16, 85, 32, 240, _         ' Size
                 MY_GUI_SCROLLBAR_GREEN, _  ' ID of the button
                 255, _                     ' The position of the scrollbar
                 255 )                      ' The maximum value of the scrollbar

' add a listbox to the display
guiListbox = wAddListBox ( 45, 100, 250, 255, _
                            MY_GUI_LISTBOX, _
                            FALSE)

' add three items to the listbox
wListBoxAddItem( guiListbox, "1366 x 768" )
wListBoxAddItem( guiListbox, "1360 x 768" )
wListBoxAddItem( guiListbox, "1280 x 768" )
wListBoxAddItem( guiListbox, "1280 x 720" )
wListBoxAddItem( guiListbox, "1024 x 768" )
wListBoxAddItem( guiListbox, "1024 x 600" )
wListBoxAddItem( guiListbox, "  800 x 600" )

' select item 1 oranges
wListBoxSetSelected( guiListbox, 4 )

'/
' add a checkbox to the display
Checkbox_3 = wAddCheckBox ( "Full Screen", 20, 60, 200, 80, MY_GUI_CHECKBOX, FALSE )                   
Checkbox_1 = wAddCheckBox ( "Doublebuffer: ", 20,100,130,120 , CHECKBOX_REN, TRUE )'Screen Resolution
Checkbox_2 = wAddCheckBox ( "Color depth: ", 20,140,130,160 , CHECKBOX_BITS, TRUE )'
Checkbox_4 = wAddCheckBox ( "Rendering info: ", 20,180,200,200 , CHECKBOX_REN_INFO, TRUE )'

'guiMessagebox = wAddMessageBox ("Hello", "Message", 1, 0, 0, 112, MesTex )
' while the scene is still running
WHILE wRunning
    ' begin the scene, erasing the canvas to white before rendering
    wBeginScene( 0, 30, 20 )
	
    ' draw the Graphical User Interface
    wDrawGUI

    ' if there are GUI events available
    If wGUIEventAvailable then

        ' read the GUI event out 
        GUIEvent = wReadGUIEvent
			

        ' process the particular control
        select case GUIEvent->id

        Case MY_GUI_BUTTON_QUIT
            ' if the button has been pressed
            If GUIEvent->event = wGUI_ET_BUTTON_CLICKED then
                ' all GUI elements from the display
              'wCloseESC()
              
            End If
	/'
        case MY_GUI_LISTBOX
            ' if the listbox selection has changed
            If GUIEvent->event = wGUI_ET_LISTBOX_CHANGED then
                ' change the text to show which item is selected
                if GUIEvent->x = 0 then wGUISetText( guiStatic, "Set resolution: 1366 x 768" ): scr_wid = 1366: scr_hei = 768
                if GUIEvent->x = 1 then wGUISetText( guiStatic, "Set resolution: 1360 x 768" ): scr_wid = 1360: scr_hei = 768
                if GUIEvent->x = 2 then wGUISetText( guiStatic, "Set resolution: 1280 x 768" ): scr_wid = 1280: scr_hei = 768
                if GUIEvent->x = 3 then wGUISetText( guiStatic, "Set resolution: 1366 x 720" ): scr_wid = 1280: scr_hei = 720
                if GUIEvent->x = 4 then wGUISetText( guiStatic, "Set resolution: 1024 x 768" ): scr_wid = 1024: scr_hei = 768
                if GUIEvent->x = 5 then wGUISetText( guiStatic, "Set resolution: 1024 x 600" ): scr_wid = 1024: scr_hei = 600
                if GUIEvent->x = 6 then wGUISetText( guiStatic, "Set resolution: 800 x 600" ):   scr_wid = 800:   scr_hei = 600
            End If
	'/ 
            case CHECKBOX_REN
            ' if the checkbox state has changed
            If GUIEvent->event = wGUI_ET_CHECKBOX_CHANGED then
                if GUIEvent->x = 0 then
                    doublebuffer = FALSE: doublebuffer_mes = "No"
                    ''wCheckBoxCheck ( Checkbox_2, TRUE )
                    'wGUISetEnabled (guiListbox, TRUE)
                else
                    doublebuffer = TRUE: doublebuffer_mes = "Yes"
                    ''wCheckBoxCheck ( Checkbox_2, FALSE )
                    
                    'If wGUIIsEnabled (guiListbox) = TRUE Then wGUISetEnabled (guiListbox, FALSE)
                End if
            End If
            
        	case CHECKBOX_BITS
            ' if the checkbox state has changed
            If GUIEvent->event = wGUI_ET_CHECKBOX_CHANGED then
                if GUIEvent->x = 0 then
                    bits_per_pix = 16: bits_per_pix_info = " (High color, 32 thousand colors)"
                else
                    bits_per_pix = 32: bits_per_pix_info = " (True color, 24 million colors)"
                End if
            End If
            
            
            case MY_GUI_CHECKBOX
            ' if the checkbox state has changed
            If GUIEvent->event = wGUI_ET_CHECKBOX_CHANGED then
                ' set the static text object to represent the checkbox state
                if GUIEvent->x = 0 then
                    fullscr_mes = "No": fullscr = FALSE
                else
                    fullscr_mes = "Yes": fullscr = TRUE
                End if
            End If
            
            
        	case CHECKBOX_REN_INFO
            ' if the checkbox state has changed
            If GUIEvent->event = wGUI_ET_CHECKBOX_CHANGED then
                if GUIEvent->x = 0 then
                    ren_info = FALSE: ren_info_mes = "No"
                else
                    ren_info = TRUE: ren_info_mes = "Yes"
                End if
            End If

        case MY_GUI_FILEOPEN
            ' if the event was from a file being selected
            If GUIEvent->event = wGUI_ET_FILE_SELECTED then
                imageTexture = wGetTexture( Str(*wGetLastSelectedFile ))
                if NOT imageTexture = 0 then
                    wAddGUIImage( imageTexture, 352, 16, TRUE, 140 )
                end if
            End If

        End Select
    End If
    
    w2DFontDraw ( BitmapFont, Str(fullscr_mes), 150, 60, 300, 80, 255, 0, 255, 0 )
    w2DFontDraw ( BitmapFont, Str(doublebuffer_mes), 150, 100, 300, 120, 255, 0, 255, 0  )
    w2DFontDraw ( BitmapFont, Str(bits_per_pix) + bits_per_pix_info, 150, 140, 300, 160, 255, 0, 255, 0 )
    w2DFontDraw ( BitmapFont, Str(ren_info_mes), 150, 180, 300, 200, 255, 0, 255, 0 )

    ' end drawing the scene and render it
    wEndScene
    ''wSetFPS
    wCloseESC()
WEND

' -----------------------------------------------------------------------------
' Stop the WorldSim3D engine and release resources
wStop
