Re: Converting point struct from superview to subview (SOLVED)
Re: Converting point struct from superview to subview (SOLVED)
- Subject: Re: Converting point struct from superview to subview (SOLVED)
- From: Ian was here <email@hidden>
- Date: Fri, 24 Jun 2005 13:25:23 -0700 (PDT)
Thanks guys for clearing that up for me. I really
appreciate it. I found it easiest to use the following
code within my NSTextView subclass.
NOTE: theEvent is passed in to this method from
mouseDown:
NSPoint prevP = [[self superview]
convertPoint:[theEvent locationInWindow]
fromView:nil]; // Convert window coordinates to slide
editor view coordinates.
NSPoint p = [self convertPoint:prevP fromView:[self
superview]]; // Convert slide editor view
coordinates to text view coordinates.
p.y = [self bounds].size.height - p.y; // The text
editor coordinates seem to be flipped, so flip the
mouse coordinates too.
It works! Yeah!!!
--- Fritz Anderson <email@hidden> wrote:
> On 24 Jun 2005, at 10:37 AM, Ian was here wrote:
>
> > I have an NSTextView positioned within an NSView.
> I am
> > trying to get the mouse coordinates within the
> > NSTextView. I'm using the following code in the
> > NSTextView subclass:
> >
> > NSPoint p = [self convertPoint:[NSEvent
> > mouseLocation] fromView:[self superview]]; //
> Get
> > mouse coordinates within the NSTextView.
>
> +[NSEvent mouseLocation] returns the mouse position
> in screen
> coordinates, not in the coordinates of your view's
> superview.
> Assuming you're doing this from within a mouseDown:
> handler, and
> therefore have access to an instance of an event,
> use [anEvent
> locationInWindow] to get the location, and pass that
> point, and nil,
> to convertPoint:fromView:. A nil view parameter in
> convertPoint:fromView: converts the point from
> window coordinates.
>
> -- F
>
>
____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden