Re: Coordinate Systems
Re: Coordinate Systems
- Subject: Re: Coordinate Systems
- From: Ando Sonenblick <email@hidden>
- Date: Sat, 12 Oct 2002 09:09:22 -0700
Tom, just in case it helps, here is some of my code. I'm doing something
similar - but wanting to call characterIndexForPoint at idle time (I have a
timer firing). Here are my mouse location related routines:
- (void) timerFired: (NSTimer *)timer
{
NSPoint currentLocation,
screenLocation;
screenLocation = [NSEvent mouseLocation];
currentLocation = [[binaryTextFieldOutlet window]
convertScreenToBase:screenLocation];
// currentLocation = [binaryTextFieldOutlet convertPoint:currentLocation
fromView:[binaryTextFieldOutlet superview]];
if (NSEqualPoints(currentLocation, lastLocation) == YES)
return;
lastLocation = currentLocation;
[binaryTextFieldOutlet mouseDidMoveAtWindowLocation:currentLocation
atScreenLocation:screenLocation];
}
/// in my text field subclass
- (void) mouseDidMoveAtWindowLocation: (NSPoint)windowLocation
atScreenLocation:(NSPoint)screenLocation
{
if ([self hitTest:windowLocation] == self)
mouseIsWithin = YES;
else
mouseIsWithin = NO;
[self idle:screenLocation];
}
- (void) idle:(NSPoint)screenLocation
{
NSMutableString *string;
string = [NSMutableString string];
if (mouseIsWithin == YES)
{
// I do the characterForPoint stuff here...
// and set string accordingly..
}
else
{
// I clear the string here
}
[controllerOutlet displayBinaryInformation: string];
}
>
Hi,
>
>
I am trying to improve my understanding of locationInWindow and
>
characterIndexForPoint. What I am attempting to do is get the index of
>
a character in a NSTextView underneath a mouse click. I using the
>
NSEvent method locationInWindow to get the mouse click location.
>
>
>
-------
>
locationInWindow
>
>
- (NSPoint)locationInWindow
>
>
Returns the receiver's location in the base coordinate system of the
>
associated window.
>
-------
>
>
This method returns the location of the mouse click in the "base"
>
system. From my tests this seems to be based on the lower left corner
>
of the window the NSTextView is contained it. It is screen position
>
independent.
>
>
Once I have the point of the mouse click, I am trying to determine
>
which character was clicked on by using the method
>
characterIndexForPoint with the string associated with the
>
NSTextStorage of my NSTextView. ([myTextStorage string]).
>
>
-------
>
characterIndexForPoint:
>
>
- (unsigned int)characterIndexForPoint:(NSPoint)thePoint
>
>
Returns the index of the character whose frame rectangle includes
>
thePoint. The returned index measures from the start of the receiver's
>
text storage. thePoint is in the screen coordinate system.
>
-------
>
>
Here's the question... it seems characterIndexForPoint requires a
>
"screen" coordinate and locationInWindow returns a "window centric
>
coordinate", so, do I need to convert my "window centric coordinate" to
>
a "screen" coordinate for this method to work for me?
>
>
Anybody know why this method requires a screen coordinate and not a
>
window coordinate?
>
>
Tom Gray
>
-------------
>
email@hidden
>
or
>
email@hidden
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.