• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Obtaining the NSGraphicsContext for custom NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obtaining the NSGraphicsContext for custom NSView


  • Subject: Re: Obtaining the NSGraphicsContext for custom NSView
  • From: Serge Meynard <email@hidden>
  • Date: Mon, 14 Mar 2005 14:12:45 -0500

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];
}

Try locking the focus on your view before you draw, since you're not inside a drawRect: method:


{
	// Graphic will always be drawn at y = 8 of the custom view.
	NSPoint mouseLoc = NSMakePoint(xCoord, 8.0f);

	[self lockFocus];
	[playHead dissolveToPoint:mouseLoc fraction:1.0f];
	[self unlockFocus];

	[self setNeedsDisplay:YES];
}

Or better yet, use the mouseDown method to set up a local variable, and do the drawing of the playhead inside the drawRect: method. It's easier to figure out display problems when all the drawing code is in the same place.

_______________________________________________
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


References: 
 >Obtaining the NSGraphicsContext for custom NSView (From: Damien Sorresso <email@hidden>)
 >Re: Obtaining the NSGraphicsContext for custom NSView (From: Chris Eplett <email@hidden>)
 >Re: Obtaining the NSGraphicsContext for custom NSView (From: Damien Sorresso <email@hidden>)

  • Prev by Date: Re: Does CFNotification center == NSNotification Center?
  • Next by Date: Re: multidimensional arrays
  • Previous by thread: Re: Obtaining the NSGraphicsContext for custom NSView
  • Next by thread: Re: Obtaining the NSGraphicsContext for custom NSView
  • Index(es):
    • Date
    • Thread