It is currently Thu Oct 22, 2020 7:56 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Problem with mouse in games
PostPosted: Sun Jan 19, 2020 6:20 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Dec 04, 2015 9:26 pm
Posts: 291
is there any way that when the user clicks only on the windowed screen area, it works only there ... and when the user drag the mouse out of the area that the windowed screen occupies, he can use other software?

because according to the example below, the mouse only starts to be "recognized" by the windowed screen when he clicks the "grab input" button, and only releases the mouse if you press f1 ...

is there any way so that the user does not need to press any button to get the mouse input and does not need to press any button to release the mouse input? as if it were a simple form?

example >
Code:
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "Can't open the sprite system", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 340, 285, "Gadget and sprites!", #PB_Window_ScreenCentered)
  ButtonGadget(1, 10,  10, 100, 25, "Grab input")
  ButtonGadget(2, 120,  10, 100, 25, "Button 2")
  ButtonGadget(3, 230,  10, 100, 25, "Button 3")
  TextGadget  (4, 10, 40, 300, 30, "Mouse and keyboard released")

  If OpenWindowedScreen(WindowID(0), 10, 70, 320, 200, 0, 0, 0)
    LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")
    StickyWindow(0,1)
    direction = 1
    playerX = 1
    playerY = 1
   
    ; Start with released input
    ReleaseMouse(#True)
    InputReleased = 1
   
    Repeat
      Repeat
        ; Always process all the events to flush the queue at every frame
        Event = WindowEvent()
       
        Select Event
          Case #PB_Event_CloseWindow
            Quit = 1
       
          Case #PB_Event_Gadget
           
            ; Do the normal application management here
            Gadget = EventGadget()
       
            Select Gadget
              Case 1
                InputReleased = 0
                ReleaseMouse(#False)
                SetGadgetText(4, "Press 'F1' to ungrab keyboard and mouse")
   
              Case 2, 3
                SetGadgetText(4, "Button "+Str(Gadget)+" pressed.")
            EndSelect
       
        EndSelect
       
      Until Event = 0 ; Quit the event loop only when no more events are available
     
      ExamineKeyboard()
     
      If InputReleased = 0
   
        ExamineMouse()
   
        ; do the sprite & screen management at every frame
        If KeyboardPushed(#PB_Key_Up)    And playerY > 0   : playerY -3 : EndIf 
        If KeyboardPushed(#PB_Key_Down)  And playerY < 280 : playerY +3 : EndIf 
        If KeyboardPushed(#PB_Key_Left)  And playerX > 0   : playerX -3 : EndIf 
        If KeyboardPushed(#PB_Key_Right) And playerX < 300 : playerX +3 : EndIf 
   
        If KeyboardPushed(#PB_Key_F1)
          ReleaseMouse(#True)
          InputReleased = 1
          SetGadgetText(4, "Mouse and keyboard released");
        EndIf
      EndIf
     
      ; Clear the screen and draw our sprites
      ClearScreen(RGB(0,0,0))
      ClipSprite(0, 0, 0, x, x/8)
      DisplaySprite(0, x, 100)
      DisplaySprite(0, x, x)
      DisplaySprite(0, 300-x, x)
      DisplaySprite(0, playerX, playerY)
   
      x + direction
      If x > 300 : direction = -1 : EndIf   ; moving back to the left with negative value
      If x < 0   : direction =  1 : EndIf   ; moving to the right with positive value
       
      FlipBuffers()       ; Inverse the buffers (the back become the front (visible)... and we can do the rendering on the back
   
    Until  Quit Or KeyboardPushed(#PB_Key_Escape)
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
  EndIf
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with mouse in games
PostPosted: Sun Jan 19, 2020 8:54 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1264
Location: right here
You can capture/release when the mouse is at the screen edges.
Maybe this works:
https://www.purebasic.fr/english/viewtopic.php?p=523759#p523759


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with mouse in games
PostPosted: Sun Jan 19, 2020 11:05 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 870
Location: Denmark
Use MouseDeltaX() and MouseDeltaY() together with MouseX() and MouseY()

Currently I have severe problems with Windowed mode and MouseDelta values, but you could
use something like this:

Code:
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "Can't open the sprite system", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 340, 285, "Gadget and sprites!", #PB_Window_ScreenCentered)
  ButtonGadget(1, 10,  10, 100, 25, "Grab input")
  ButtonGadget(2, 120,  10, 100, 25, "Button 2")
  ButtonGadget(3, 230,  10, 100, 25, "Button 3")
  TextGadget  (4, 10, 40, 300, 30, "Mouse and keyboard released")

  If OpenWindowedScreen(WindowID(0), 10, 70, 320, 200, 0, 0, 0)
    LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")
    StickyWindow(0,1)
    direction = 1
    playerX = 1
    playerY = 1
    ms.i = CreateSprite(#PB_Any, 10, 10)
    StartDrawing(SpriteOutput(ms))
    Circle(5,5,5, $FF00FF)
    StopDrawing()
    ; Start with released input
    ReleaseMouse(#True)
    InputReleased = 1
   
    Repeat
      Repeat
        ; Always process all the events to flush the queue at every frame
        Event = WindowEvent()
       
        Select Event
          Case #PB_Event_CloseWindow
            Quit = 1
       
          Case #PB_Event_Gadget
           
            ; Do the normal application management here
            Gadget = EventGadget()
       
            Select Gadget
              Case 1
                InputReleased = 0
                ReleaseMouse(#False)
                SetGadgetText(4, "Press 'F1' to ungrab keyboard and mouse")
   
              Case 2, 3
                SetGadgetText(4, "Button "+Str(Gadget)+" pressed.")
            EndSelect
       
        EndSelect
       
      Until Event = 0 ; Quit the event loop only when no more events are available
     
      ExamineKeyboard()
     
      If InputReleased = 0
   
        ExamineMouse()
   
        ; do the sprite & screen management at every frame
        If KeyboardPushed(#PB_Key_Up)    And playerY > 0   : playerY -3 : EndIf
        If KeyboardPushed(#PB_Key_Down)  And playerY < 280 : playerY +3 : EndIf
        If KeyboardPushed(#PB_Key_Left)  And playerX > 0   : playerX -3 : EndIf
        If KeyboardPushed(#PB_Key_Right) And playerX < 300 : playerX +3 : EndIf
   
        If (MouseDeltaX() + MouseX()) < 0 Or (MouseDeltaX() + MouseX()) > ScreenHeight() Or (MouseDeltaY() + MouseY()) < 0 Or (MouseDeltaY()+MouseY()) > ScreenHeight()
          ReleaseMouse(#True)
          InputReleased = 1
          SetGadgetText(4, "Mouse and keyboard released");
        EndIf
      EndIf
     
      ; Clear the screen and draw our sprites
      ClearScreen(RGB(0,0,0))
      ClipSprite(0, 0, 0, x, x/8)
      DisplaySprite(0, x, 100)
      DisplaySprite(0, x, x)
      DisplaySprite(0, 300-x, x)
      DisplaySprite(0, playerX, playerY)
   
      x + direction
      If x > 300 : direction = -1 : EndIf   ; moving back to the left with negative value
      If x < 0   : direction =  1 : EndIf   ; moving to the right with positive value
      DisplaySprite(ms, MouseX(), MouseY())
      FlipBuffers()       ; Inverse the buffers (the back become the front (visible)... and we can do the rendering on the back
   
    Until  Quit Or KeyboardPushed(#PB_Key_Escape)
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
  EndIf
EndIf

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with mouse in games
PostPosted: Sun Jan 19, 2020 1:37 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6258
Location: Wales, UK
.... it's not a problem at all with the OpenGL Gadget (no code required, it works as "just another gadget").

So if enough PB'ers requested, perhaps Fred would create a Screen Gadget?

You could of course define your game in OpenGL instead........

Will Ogre ever be good enough or has the modern Vulcan platform already overtaken it?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with mouse in games
PostPosted: Sun Jan 19, 2020 1:51 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 870
Location: Denmark
IdeasVacuum wrote:
.... it's not a problem at all with the OpenGL Gadget (no code required, it works as "just another gadget").

So if enough PB'ers requested, perhaps Fred would create a Screen Gadget?

You could of course define your game in OpenGL instead........

Will Ogre ever be good enough or has the modern Vulcan platform already overtaken it?


Personally, the Ogre3D implementation has done a pretty good job and I really like it.
Granted, an updated version would be a very nice touch, but it can do a lot as it is.
For some reason I really don't like OpenGL and I find it too much of a hazzle/tedious to work with.
Maybe one day, my opinion about opengl will change but it hasn't so far.. :?

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with mouse in games
PostPosted: Thu Feb 13, 2020 11:20 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 732
Mby also check out this mouse module:
https://www.purebasic.fr/german/viewtopic.php?p=344843#p344843


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye