Re: Obtaining the NSGraphicsContext for custom NSView
Re: Obtaining the NSGraphicsContext for custom NSView
- Subject: Re: Obtaining the NSGraphicsContext for custom NSView
- From: Damien Sorresso <email@hidden>
- Date: Mon, 14 Mar 2005 11:43:56 -0600
I've already got the appropriate coordinates for my view. The problem
is that the method to draw the graphic takes those coordinates and
applies them to the main window instead of the view, that is (I think)
it's drawing in the window's context, not the view's, because if I
hard-code the coordinates to draw at the appropriate coordinates (using
the window's coordinate system), the graphic is drawn under the custom
view and is not visible.
Here's the code I'm using.
- (void)drawPlayHeadAtX:(float)xCoord
Y:(float)yCoord
{
// Graphic will always be drawn at y = 8 of the custom view.
NSPoint mouseLoc = NSMakePoint(xCoord, 8.0f);
NSLog (@"mouseLoc: %f, %f", mouseLoc.x, mouseLoc.y);
[playHead dissolveToPoint:mouseLoc
fraction:1.0f];
[self setNeedsDisplay:YES];
}
- (void)mouseDown:(NSEvent *)event
{
BOOL isInside;
NSPoint mouseLoc;
NSSize sliderSize;
NSRect sliderRect;
mouseLoc = [self convertPoint:[event locationInWindow] fromView:nil];
sliderSize.width = [self bounds].size.width -
(kGLQTLCDSliderLeftPadding + kGLQTLCDSliderRightPadding) + 1.0f;
sliderSize.height = kGLQTLCDSliderHeight;
sliderRect.size = sliderSize;
sliderRect.origin = NSMakePoint(kGLQTLCDSliderLeftPadding - 1.0f,
kGLQTLCDSliderHeight);
isInside = [self mouse:mouseLoc inRect:sliderRect];
//NSLog (@"isInside: %d", isInside);
if( isInside ) {
// The y-coord parameter is just for testing.
[self drawPlayHeadAtX:mouseLoc.x
Y:mouseLoc.y];
}
}
isInside is being set correctly, so I know that mouseDown: is using the
right coordinate system, but mouseDown: is using the wrong context.
I've tried doing a saving and restoring the graphics context before
drawing, but it doesn't seem to have any effect.
-- Damien Sorresso
Macintosh Developer
Computer Infrastructure Support Services
Illinois State University
email@hidden
309.438.5777
On Mar 14, 2005, at 8:50 AM, Chris Eplett wrote:
the locationInWindow of the NSEvent sent to mouseDown is always in the
windows coordinate system. To convert to your view's local
coordinates, do this in your view's mouseDown method:
- (void)mouseDown:(NSEvent*)event
{
NSPoint localPoint = [self convertPoint:[event locationInWindow]
fromView:nil];
}
the "nil" fromView indicates that the coordinates should be converted
from the window's coord system.
Hope this helps!
-
Chris Eplett
palmOne, Inc.
Senior Software Engineer
email@hidden
On Mar 14, 2005, at 9:42 AM, Damien Sorresso wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
I've got a custom NSView inside a window that acts as first responder
for mouse clicks. I've got it set up right now so that whenever the
user clicks inside the view, an image is drawn at the mouse
coordinates by calling a method. The image draws, but relative to the
containing window, not the view. So it's using the window's
coordinate system.
How can I obtain the view's coordinate system explicitly?
-- Damien Sorresso
Macintosh Developer
Computer Infrastructure Support Services
Illinois State University
email@hidden
309.438.5777
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFCNaK4M4NYyqeoGX8RAmzeAJ9JyJZ5yi2rqqBdMSYyBr6Q+AGD/ACgnNLT
g7OBoxtFP3+Dx/T7U4NPcfg=
=LTdu
-----END PGP SIGNATURE-----
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
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