Gadgets + Screen

Just starting out? Need help? Post your questions and find answers here.
Grunz
User
User
Posts: 59
Joined: Sat Nov 12, 2011 7:21 pm

Gadgets + Screen

Post by Grunz »

One can not use any sprite,sprite3d,mouse,keyboard command together with gadgets.
It's kinda obvious for experienced programmers, but I still think the documentation should mention it in the overview pages for "gadgets" and "sprite and screen".
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Gadgets + Screen

Post by PMV »

Of course you can use a windowed screen and gadgets.

MFG PMV
Grunz
User
User
Posts: 59
Joined: Sat Nov 12, 2011 7:21 pm

Re: Gadgets + Screen

Post by Grunz »

Maybe works under windows. I doubt it though.
Try calling ExamineMouse() inside the gadget event loop for example.
Afaik that will teleport the mouse pointer under windows just the same as it does under Linux.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Gadget example file
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;

#WindowWidth  = 390
#WindowHeight = 350

If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration", #PB_Window_MinimizeGadget)

  If Not InitSprite()
    PrintN("init sprite failed")
  EndIf
  If Not OpenWindowedScreen(WindowID(0), 0, 0, #WindowWidth, #WindowHeight, 0, 0, 0) 
    PrintN("open screen failed")
  EndIf
  If InitMouse()
    ExamineMouse()
  Else
    PrintN("init mouse failed")
  EndIf

    
  Top = 10
  GadgetHeight = 24

  Frame3DGadget(#PB_Any, 10, Top, 370, 290, "Player...") : Top+20

  StringGadget(0,  20, Top, 200, GadgetHeight, "")
  ButtonGadget(1, 223, Top,  72, GadgetHeight, "Play")
  ButtonGadget(2, 295, Top,  72, GadgetHeight, "Stop")  : Top+35
  DisableGadget(2,1)
  
  GadgetToolTip(1,"Play the current song")
  
  PanelGadget(3, 20, Top, #WindowWidth-50, #WindowHeight-Top-60)
    AddGadgetItem(3, 0, "MP3 PlayList")
      ListViewGadget(4, 6, 10, 230, 148)

      For k=0 To 30
        AddGadgetItem(4, -1, "Music Song n° "+Str(k))
      Next

      ButtonGadget(5,  250, 10, 80, GadgetHeight, "Add")
      ButtonGadget(6,  250, 38, 80, GadgetHeight, "Remove")
      ButtonGadget(7,  250, 66, 80, GadgetHeight, "Select")
      GadgetToolTip(7, "Select the current song")
      
      TrackBarGadget(17, 10, 168, 310, 25, 0, 100)

    AddGadgetItem(3, 1, "Options")
      Top = 10
      CheckBoxGadget(10, 10, Top, 250, GadgetHeight, "Enable low-pass filter") : Top+30
      CheckBoxGadget(11, 10, Top, 250, GadgetHeight, "Enable visual plug-in")  : Top+30
      ComboBoxGadget(12, 10, Top, 250, 30) : Top+35
        AddGadgetItem(12, -1, "FireWorks")
        AddGadgetItem(12, -1, "OpenGL spectrum")
        AddGadgetItem(12, -1, "Bump bass")
      SetGadgetState(12,0)
      DisableGadget(12,1)
      
      OptionGadget(13, 10, Top, 180, GadgetHeight, "640*480") : Top+20
      OptionGadget(14, 10, Top, 180, GadgetHeight, "800*600") : Top+20
      OptionGadget(15, 10, Top, 180, GadgetHeight, "1024*768")
      SetGadgetState(13, 1)
      
      ButtonGadget(16, 150, Top, 80, GadgetHeight, "Info")
  CloseGadgetList()

  TextGadget  (9, 10, #WindowHeight-30, 250, 24, "PureBasic - Gadget demonstration")
  ButtonGadget(8, #WindowWidth-100, #WindowHeight-36, 80, 24, "Quit")

  SetGadgetState(3, 0)

  Repeat
    EventID = WaitWindowEvent()

    ExamineMouse()
    mouse_x = MouseX()
    mouse_y = MouseY()
    mouse_button_left  = MouseButton(#PB_MouseButton_Left)
    mouse_button_right = MouseButton(#PB_MouseButton_Right)
    
    If EventID = #PB_Event_Gadget

      Select EventGadget()
        Case 0
          If EventType() = #PB_EventType_ReturnKey
            MessageRequester("Info", "Return key pressed", 0)
            SetActiveGadget(0)
          EndIf
          
        Case 1 ; Play
          DisableGadget(2,0)  ; Enable the 'Stop' gadget
          DisableGadget(1,1)  ; Disable the 'Play' Gadget
      
        Case 2 ; Stop
          DisableGadget(1,0)  ; Enable the 'Play' gadget
          DisableGadget(2,1)  ; Disable the 'Stop' Gadget
        
        Case 4
          If EventType() = 2
            SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
          EndIf

        Case 5 ; Add
          AddGadgetItem(4, -1, "New Item Added...")

        Case 6 ; Remove
          RemoveGadgetItem(4, GetGadgetState(4)) ; Remove the current element of the ListView

        Case 7 ; Select
          SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
  
        Case 8 ; Quit...
          EventID = #PB_Event_CloseWindow

        Case 11 ; Enable PlugIn..
          DisableGadget(12, 1-GetGadgetState(11))
          
        Case 16 ;
          If GetGadgetState(13) : Result$ = GetGadgetText(13) : EndIf
          If GetGadgetState(14) : Result$ = GetGadgetText(14) : EndIf
          If GetGadgetState(15) : Result$ = GetGadgetText(15) : EndIf
         
          MessageRequester("Info", "Selected screen mode: "+Result$, 0)
        
        Case 17
          SetGadgetText(0, Str(GetGadgetState(17)))
          
      EndSelect

    EndIf

  Until EventID = #PB_Event_CloseWindow

EndIf

End  
This is the gadget example from the documentation with some screen commands added.
Under Linux this does not work.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Gadgets + Screen

Post by PMV »

If i create a windowed program and need mouse-coordinates,
i would use WindowMouseX/Y() :wink: ... it is just ... bad
practice to use DirectInput when you want to have an
application and not a game.

And additional, you can release the mouse from the screen,
and you can use it normal again ... so everything is working
just fine and there is no limitation like you see. :)

MFG PMV
Grunz
User
User
Posts: 59
Joined: Sat Nov 12, 2011 7:21 pm

Re: Gadgets + Screen

Post by Grunz »

If i create a windowed program and need mouse-coordinates,
i would use WindowMouseX/Y()
Yea, well except that you won't get mouse buttons this way. This only works under Linux, though there you can't access the mouse wheel UNLESS you use gadgets..
But you can't use gadgets if you want to use sprites as those won't work together...
Anyway I had already assumed that gadgets and screen don't work together and only cobbled them together to confirm it.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Gadgets + Screen

Post by PMV »

What do you think does a normal application do to get
that information? Event message system. :)

Just search a little bit around the forum and you will
find possibilities to get mouse events. It is more complicated
because you will need to use Win32 API and for
crossplatform support need something similar for linux
and mac ... but it is not because something isn't
possible for beginners that it is not designed to work.
:wink:

It makes no difference for a program, if it is designed
to be a application with a screen inside or not. And if
you have trouble to do something hard, you can always
ask the forum :D

MFG PMV
Post Reply