PureBasic
;
; ------------------------------------------------------------
;
;   PureBasic - Gadget 3D
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

Enumeration ; Window3D
  #MainWindow
  #SecondWindow
EndEnumeration


Enumeration ; Gadget3D
  #ActiveWindowLabel
  #CloseButton
  #ProgressBar
  #ComboBox
  #Panel
  #ListView
  #Image
  #Image2
  #ScrollArea
  #ScrollBar
  #String
  #Spin
  #Container
  #CheckBox
  #Editor
  #Option1
  #Option2
  #Option3
  #Button
EndEnumeration

If InitEngine3D()

  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
    
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    SkyBox("desert07.jpg")
        
        CreateCamera(0, 0, 0, 100, 100)  ; Главная камера
    MoveCamera(0, 0, 0, 100, #PB_Absolute)
    
    OpenWindow3D(#MainWindow, 50, 20, 280, 400, "Привет в 3D !", #PB_Window3D_SizeGadget)
        
    Top = 10
    TextGadget3D(#ActiveWindowLabel, 10, Top, 250, 25, "Активное окно: ") : Top + 30
    
    ;- ProgressBar ("Индикатор Прогресса")
    TextGadget3D(#PB_Any, 10, Top, 100, 25, "Progress bar: ")
    ProgressBarGadget3D(#ProgressBar, 110, Top, 150, 25, 0, 100) : Top + 30
    SetGadgetState3D(#ProgressBar, 30)
    GadgetToolTip3D(#ProgressBar, "Индикатор Прогресса")
    
    ;- ComboBox ("Комбо-бокс")
    TextGadget3D(#PB_Any, 10, Top, 100, 25, "Combo box: ")
    ComboBoxGadget3D(#ComboBox, 110, Top, 150, 25) : Top + 30
    GadgetToolTip3D(#ComboBox, "Комбо-бокс !")
    AddGadgetItem3D(#ComboBox, -1, "Item 1")
    AddGadgetItem3D(#ComboBox, -1, "Item 2")
    AddGadgetItem3D(#ComboBox, -1, "Item 3")
    AddGadgetItem3D(#ComboBox, -1, "Item 4")
    
     ;- ScrollBar ("Полоса Прокрутки")
    TextGadget3D(#PB_Any, 10, Top, 100, 25, "Scroll bar: ")
    ScrollBarGadget3D(#ScrollBar, 110, Top+7, 150, 10, 0, 100, 20) : Top + 30
    SetGadgetState3D(#ScrollBar, 30)
    GadgetToolTip3D(#ScrollBar, "Полоса Прокрутки !")
    
    ;- String ("Строка Ввода")
    TextGadget3D(#PB_Any, 10, Top, 100, 25, "String: ")
    StringGadget3D(#String, 110, Top, 150, 25, "Modify me") : Top + 30
    GadgetToolTip3D(#String, "Строка Ввода !")
    
    ;- CheckBox ("Флажок")
    TextGadget3D(#PB_Any, 10, Top, 100, 25, "Check box: ")
    CheckBoxGadget3D(#CheckBox, 110, Top, 150, 25, "Enable something") : Top + 30
    GadgetToolTip3D(#CheckBox, "Флажок !")
    SetGadgetState3D(#CheckBox, 1)
    
    ;- Spinner ("Диск Значений")
    TextGadget3D(#PB_Any, 10, Top, 100, 25, "Spinner: ")
    SpinGadget3D(#Spin, 110, Top, 150, 25, 0, 100) : Top + 30
    GadgetToolTip3D(#Spin, "Диск Значений !")
    
    ;- Options ("Опция")
    TextGadget3D(#PB_Any, 10, Top, 100, 25, "Options: ")
    OptionGadget3D(#Option1, 110, Top, 150, 25, "Choice 1") : Top + 30
    OptionGadget3D(#Option2, 110, Top, 150, 25, "Choice 2") : Top + 30
    OptionGadget3D(#Option3, 110, Top, 150, 25, "Choice 3") : Top + 30
    GadgetToolTip3D(#Option1, "Опция 1 !")
    SetGadgetState3D(#Option2, 1)
    
    ;- Button ("Кнопка")
    TextGadget3D(#PB_Any, 10, Top, 100, 25, "Button: ")
    ButtonGadget3D(#Button, 110, Top, 150, 25, "Click me !") : Top + 30
    GadgetToolTip3D(#Button, "Кнопка !")
        
    
    OpenWindow3D(#SecondWindow, 400, 150, 400, 400, "Ещё 3D-Гаджеты", #PB_Window3D_SizeGadget)
    
    PanelGadget3D(#Panel, 10, 10, 370, 350)
      GadgetToolTip3D(#Panel, "Панель !")
      AddGadgetItem3D(#Panel, -1, "First")
        ListViewGadget3D(#ListView, 10, 10, 200, 200, #PB_ListView3D_Multiselect) 
          For k = 0 To 20
            AddGadgetItem3D(#ListView, -1, "Item "+Str(k))
          Next
          
      AddGadgetItem3D(#Panel, -1, "Second")
        ContainerGadget3D(#Container, 0, 0, 400, 400)
          GadgetToolTip3D(#Container, "Контейнер !")
      
          LoadTexture(0, "clouds.jpg")
          ImageGadget3D(#Image, 10, 10, 128, 128, TextureID(0))
      
          ScrollAreaGadget3D(#ScrollArea, 10, 150, 100, 100, 256, 256, 30)
          GadgetToolTip3D(#ScrollArea, "Область Прокрутки !")
            ImageGadget3D(#Image2, 10, 10, 256, 256, TextureID(0))
          CloseGadgetList3D()
        
        CloseGadgetList3D()
    
      AddGadgetItem3D(#Panel, -1, "Third")
        EditorGadget3D(#Editor, 10, 10, 300, 200)
        SetGadgetText3D(#Editor, "Multi" + #LF$ + "Line" + #LF$ + "Editor !")
      
    CloseGadgetList3D()
    
    Repeat
      Screen3DEvents()
      
      If ExamineKeyboard() And ExamineMouse()
        Input$ = KeyboardInkey()
        
        SpecialKey = 0
        If     KeyboardPushed(#PB_Key_Back)   :  SpecialKey = #PB_Key_Back
        ElseIf KeyboardPushed(#PB_Key_Return) : SpecialKey = #PB_Key_Return
        ElseIf KeyboardPushed(#PB_Key_Left)   : SpecialKey = #PB_Key_Left
        ElseIf KeyboardPushed(#PB_Key_Right)  : SpecialKey = #PB_Key_Right
        ElseIf KeyboardPushed(#PB_Key_Up)     : SpecialKey = #PB_Key_Up
        ElseIf KeyboardPushed(#PB_Key_Down)   : SpecialKey = #PB_Key_Down
        ElseIf KeyboardPushed(#PB_Key_Delete) : SpecialKey = #PB_Key_Delete
        EndIf
        
        InputEvent3D(MouseX(), MouseY(), MouseButton(#PB_MouseButton_Left), Input$, SpecialKey)
      EndIf
      
      ; Обработка событий GUI 3D, это очень похоже на обычные события GUI
      ;
      Repeat
          Event = WindowEvent3D()
          
          SetGadgetText3D(#ActiveWindowLabel, "Active #Window3D: "+Str(GetActiveWindow3D()))
          
          Select Event
              Case #PB_Event3D_Gadget
                If EventGadget3D() = #CloseButton
                  CloseWindow3D(#MainWindow)
                EndIf
                  
          EndSelect
      Until Event = 0
      
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Ошибка", "3D Движок не может быть инициализирован",0)
EndIf