• 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: Drawing into custom view from another object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing into custom view from another object


  • Subject: Re: Drawing into custom view from another object
  • From: "John C. Randolph" <email@hidden>
  • Date: Wed, 21 Aug 2002 16:08:41 -0700

On Wednesday, August 21, 2002, at 03:46 PM, Nikita Zhuk wrote:

Hi there,

I have a custom view (a subclass of NSView, named "theView"), and I would like that another object would be able to draw NSBezierPaths into that view. This another object (let's call it "theShip") is a subclass of NSObject, so calling mePath = [NSBezierPath bezierPathWithRect:myRect]; and [mePath fill]; doesn't do a thing, of course (as it would in subclass of NSView). In a NSView subclass I would draw a simple blue rect like this:

[[NSColor blueColor] set];
myRect = NSMakeRect(x,y,20,20);
meBpath = [[NSBezierPath bezierPathWithRect:myRect] retain];
[meBpath fill];

So the question is, how can I draw things from theShip's function into theView? This is probably a pretty basic question, but I didn't find any helpful messages from mailing list archive.

You need to call the code above while the view in question has the drawing focus. You can either do this:

[myView lockFocus];
[theShip draw];
[myView unlockFocus];

or just call [theShip draw] from within myView's -drawRect: method. (This is preferred, BTW.)

-jcr


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.

References: 
 >Drawing into custom view from another object (From: Nikita Zhuk <email@hidden>)

  • Prev by Date: Newbie *me = [[Newbie alloc] initWithProblem:customViewDrawing];
  • Next by Date: Re: Newbie *me = [[Newbie alloc] initWithProblem:customViewDrawing];
  • Previous by thread: Drawing into custom view from another object
  • Next by thread: Re: years:months:days:hours:minutes:seconds:sinceDate: really slow!
  • Index(es):
    • Date
    • Thread