ReleaseMouse()

Mac OSX specific forum
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

ReleaseMouse()

Post by J. Baker »

Anyone know how to release a mouse on a window screen? What worked on Windows doesn't seem to on Mac.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: ReleaseMouse()

Post by J. Baker »

Here's some code if anyone wants to help solve this.

Code: Select all

#WinWidth = 640
#WinHeight = 480

InitSprite()
InitSprite3D()
InitKeyboard()
InitMouse()

OpenWindow(0, 0, 0,#WinWidth, #WinHeight, "Release Mouse", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #WinWidth, #WinHeight, 0, 0, 0)

    CreateSprite(1, 117, 16)
     StartDrawing(SpriteOutput(1))
      DrawingMode(#PB_2DDrawing_Default)
       DrawText(4, 0, "Press ESC to quit.")
      StopDrawing()
       
    Quit = #False
    MR = 0
    
Repeat
      
    ExamineMouse()
    ExamineKeyboard()
  
    Repeat
      Event = WindowEvent()
      If Event = #PB_Event_CloseWindow
        Quit = #True
      EndIf
    Until Event = 0
  
    FlipBuffers()
     ClearScreen(0)
    SetFrameRate(60)
     
        If WindowMouseX(0) > 0 And WindowMouseY(0) > 0 And WindowMouseX(0) < 640 -1 And WindowMouseY(0) < 480 -1
          If MR = 0
            ReleaseMouse(0)
            MouseLocate(WindowWidth(0) / 2, WindowHeight(0) / 2)
           MR = 1
          EndIf
        ElseIf MouseX() = 0 Or MouseY() = 0 Or MouseX() = 640 -1 Or MouseY() = 480 -1
          If MR = 1
            ReleaseMouse(1)
            MR = 0
          EndIf
        EndIf
        
     DisplaySprite(1, MouseX(), MouseY())
      
Until Quit Or KeyboardPushed(#PB_Key_Escape)

End   
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: ReleaseMouse()

Post by jesperbrannmark »

Why you want to use examinemouse?
Why not use windowmousex(#window) ?
If you use windowmouse you can set a eventhandle on the window and then override, something like:

Code: Select all

Global override.l

ProcedureC EventHandler(*NextEventHandler, Event, UserData)
  Select GetEventClass(Event)
    Case #kEventClassMouse
      Select GetEventKind_(Event)
        Case #kEventMouseDown
          override=#WM_LBUTTONDOWN 
        Case #kEventMouseUp
          override=#WM_LBUTTONUP
        Case #kEventMouseMoved
          override=#WM_MOUSEMOVE 
        Case #kEventMouseDragged
          override=#WM_MOUSEMOVE 
      EndSelect
  EndSelect
  If *NextEventHandler
    CallNextEventHandler_(*NextEventHandler, Event)
  EndIf
EndProcedure
;openwindow etc goes here, then install eventhandler:
EventHandlerUPP = NewEventHandlerUPP_(@EventHandler())
EventCount = 4
Dim EventTypes.EventTypeSpec(EventCount - 1)
EventTypes(0)\EventClass = #kEventClassMouse
EventTypes(0)\EventKind = #kEventMouseDown
eventTypes(1)\eventClass = #kEventClassMouse
eventtypes(1)\eventKind = #kEventMouseMoved
eventTypes(2)\eventClass = #kEventClassMouse
eventtypes(2)\eventKind = #kEventMouseUp
eventTypes(3)\eventClass = #kEventClassMouse
eventtypes(3)\eventKind = #kEventMouseDragged
InstallEventHandler_(GetWindowEventTarget_(WindowID(#window)), EventHandlerUPP, EventCount, @EventTypes(), UserData, @EventHandlerRef)
;here do all window related tuff
Or if you dont repend on hardware acceleration I would use canvasgadget where you have #PB_EventType_LeftButtonDown and #PB_EventType_LeftButtonUp as events

Jesper
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: ReleaseMouse()

Post by J. Baker »

Thanks but WindowMouse doesn't work in a game screen. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply