Page 1 of 1

NSMouseInRect

Posted: Wed Dec 04, 2019 7:35 am
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()

Re: NSMouseInRect

Posted: Wed Dec 04, 2019 8:24 am
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.

Re: NSMouseInRect

Posted: Wed Dec 04, 2019 5:52 pm
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.

Re: NSMouseInRect

Posted: Wed Dec 04, 2019 6:13 pm
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.