Re: Weird behavior of mouse location when performing a drag
Re: Weird behavior of mouse location when performing a drag
- Subject: Re: Weird behavior of mouse location when performing a drag
- From: Rob Keniger <email@hidden>
- Date: Tue, 9 Dec 2008 08:26:19 +1000
On 09/12/2008, at 3:56 AM, Gustavo Pizano wrote:
Well Im performing a drag-ndrop between views of the same app, I
implemented the - (NSDragOperation)draggingUpdated:(id <
NSDraggingInfo >)sender method, because I need to know the location
of the mouse so I can place the image in the correct position of the
view. But weirdly after converting the point to the currentview
there was a gap of about 145ox in x coordinate and 45 px in the y
coord, those values are not even close to where the view resides in
the window. So what I did to fix the problem was the following.
- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
{
NSPoint converted = [NSEvent mouseLocation];
actualDragPoint = [self convertPoint:converted fromView:nil];
actualDragPoint.x = actualDragPoint.x - 144 ;
actualDragPoint.y = actualDragPoint.y -76;
return NSDragOperationMove;
}
it fixed the problem, but Im wondering why is this happening?
[NSEvent mouseLocation] returns the location of the mouse in screen
coordinates and you are treating it as if it is in Window coordinates.
You want the following:
- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
{
NSPoint locationOnScreen = [NSEvent mouseLocation];
actualDragPoint = [self convertPointFromBase: locationOnScreen];
return NSDragOperationMove;
}
--
Rob Keniger
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden