Re: Drawing in a view from a controller
Re: Drawing in a view from a controller
- Subject: Re: Drawing in a view from a controller
- From: Robert Borsuk <email@hidden>
- Date: Tue, 4 Nov 2003 12:28:34 -0500
Shawn,
Thanks for the reply. Yep, I understand drawRect and the subclassing
of NSView. Got it. I'm really seeing what I can do with the Cocoa
drawing enviroment outside of the drawRect stuff. In the nib I put a
view on a window and a button. Make a controller. Link the button to
an action (used to draw something to the view).
The action draws to the view using lockFocus. BUT when the view needs
to be redrawn (window resized) IS there a way to tell the view that it
has something in it? Maybe some kind of save / restore view contents.
Yes, I also know about drawing to an image and then in the drawRect
method blitting that image into the view. Yep, works good. I'm still
curious about this view thing though. It wasn't but two weeks ago that
someone asked IIRC the same style of question. I'm kind of looking for
that answer.
Thanks ahead of time.
Rob
On Nov 4, 2003, at 11:43 AM, Shawn Erickson wrote:
On Nov 4, 2003, at 6:03 AM, Robert Borsuk wrote:
Hi,
I know this question has been asked before but I've spent several
hours trying to find the answer in archives and I can't seem to
locate it. Okay, here's the question.
If I draw into a view from my controller using lockFocus how do I get
the view to stay (to know that it was drawn into)? I'm not drawing
using drawRect (non-subclassed NSView)(is that a word?).
I would appreciate if someone could even point me to archive that had
this question before.
You really should not be attempting to do things this way for a few
reasons (if I understand what you are saying). 1) A controller should
not be _directly_ involved in drawing, leave that to your views. 2)
You should be drawing in the drawRect pathway since when it is called
the drawing environment is setup correctly for you (clipping, etc.).
Doing things outside of that can result in strange behavior if done
wrong.
You can draw into NSImage by locking focus on the image and doing your
drawing then blit that image as needed in a drawRect.
Hard to best answer your question given what you have said so far...
what is the view you are drawing in, what are you trying to do, is
this window/panel loaded from a nib, etc.?
It should be as simple as defining a custom view in your nib and
making a simple NSView subclass that implement the drawing code needed
in drawRect.
-Shawn
Rob Borsuk
email: email@hidden
Colourfull Creations
Web:
http://www.colourfull.com
_______________________________________________
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.