NSMouseInRect

Mac OSX specific forum
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

NSMouseInRect

Post by Rinzwind »

Definition: BOOL NSMouseInRect(NSPoint aPoint, NSRect aRect, BOOL flipped);

Is the following a correct ImportC?
NSMouseInRect(x.CGFloat,y.CGFloat, rx.CGFloat, ry.CGFloat, rw.CGFloat, rh.CGFloat, flipped)

Because it doesn't seem to work..

Code: Select all

ImportC ""
CGEventCreate(e)
CGEventGetLocation(e)
NSMouseInRect(x.CGFloat,y.CGFloat, rx.CGFloat, ry.CGFloat, rw.CGFloat, rh.CGFloat, flipped)
EndImport

Procedure GetScreenWithMouse()
  Protected i, mouseLoc.CGPoint
  Protected ev = CGEventCreate(0)
  CGEventGetLocation(ev)
  !movsd [p.v_mouseLoc], xmm0
  !movsd [p.v_mouseLoc + 8], xmm1
  Protected nssa = CocoaMessage(0, 0, "NSScreen screens")
  Protected c = CocoaMessage(0, nssa, "count")
  Protected frame.CGRect
  While i < c
    Protected nss = CocoaMessage(0, nssa, "objectAtIndex:", i)
    CocoaMessage(@frame, nss, "frame")
    Debug "" + frame\origin\x + "," + frame\origin\y + ":" + frame\size\width + "," + frame\size\height
    If NSMouseInRect(mouseLoc\x, mouseLoc\y, frame\origin\x, frame\origin\y, frame\size\width, frame\size\height, #YES)  ; or #NO
      Debug "Found"
    EndIf
    i + 1
  Wend
EndProcedure

GetScreenWithMouse()
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: NSMouseInRect

Post by wilbert »

Rinzwind wrote:Is the following a correct ImportC?
NSMouseInRect(x.CGFloat,y.CGFloat, rx.CGFloat, ry.CGFloat, rw.CGFloat, rh.CGFloat, flipped)
No. This way the rectangle is passed through registers xmm2 - xmm5 while it needs to be passed by stack memory.

You have a few options...
- make the import work by adding dummy variables to make the rectangle end up on the stack.
- use something like libffi or my VCall module to make the call.
- see if you can use the mouse:inRect: method from the NSView class.
- write a procedure yourself which does the same.
Windows (x64)
Raspberry Pi OS (Arm64)
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: NSMouseInRect

Post by Rinzwind »

This lack of structure passing and returning in pb is sure a pita on macos...

In this case one implementation can be found in gnustep... So there we go.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: NSMouseInRect

Post by wilbert »

Rinzwind wrote:This lack of structure passing and returning in pb is sure a pita on macos...
Indeed it is.

Fortunately NSMouseInRect is easy to implement yourself.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply