• 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
Drawing in a NSView out side of drawRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing in a NSView out side of drawRect


  • Subject: Drawing in a NSView out side of drawRect
  • From: "David Alter" <email@hidden>
  • Date: Fri, 19 Dec 2008 16:20:00 -0800

I want to draw in a NSView but not when drawRect is called. To do this I
understand that I need to call lockFocus before drawing and unlockFocus
after. The drawing appears to happen but it is not until I deactivate the
window do I see my results. How can I get it to refresh once I have done my
drawing?
To test this out I have sub classed NSView and overloaded mouseDown. I added
the following code.

- (void)mouseDown:(NSEvent *)theEvent ;

{

    NSPoint loc = [[self window] mouseLocationOutsideOfEventStream];

    loc = [self convertPoint:loc fromView:[[self window] contentView]];

     CGContextRef myContext =
(CGContextRef)[[NSGraphicsContext currentContext]graphicsPort];

    [self lockFocus];

    CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);

    CGContextFillRect (myContext, CGRectMake (loc.x, loc.y, 10, 10 ));

    [self unlockFocus];

}

This will draw a box for each mouse click, but not until I deactivate my
window.

thanks for the help
-dave
_______________________________________________

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

  • Follow-Ups:
    • Re: Drawing in a NSView out side of drawRect
      • From: "Michael Ash" <email@hidden>
    • Re: Drawing in a NSView out side of drawRect
      • From: Graham Cox <email@hidden>
    • Re: Drawing in a NSView out side of drawRect
      • From: Ricky Sharp <email@hidden>
  • Prev by Date: Re: [Q] How will the Pasteboard manager be changed?
  • Next by Date: Re: Listening for changes
  • Previous by thread: Re: Newbie Question: implementing a stack
  • Next by thread: Re: Drawing in a NSView out side of drawRect
  • Index(es):
    • Date
    • Thread