Re: Drawing graphics into a view in AppleScript Studio
Re: Drawing graphics into a view in AppleScript Studio
- Subject: Re: Drawing graphics into a view in AppleScript Studio
- From: Public Look <email@hidden>
- Date: Wed, 28 Jan 2004 23:52:35 -0500
I quick look at the NSView documentation is very helpful.
isOpaque
- (BOOL)isOpaque
Overridden by subclasses to return YES if the receiver is opaque, NO
otherwise. A view object is opaque if it completely covers its frame
rectangle when drawing itself. NSView, being an abstract class,
performs no drawing at all and so returns NO.
See Also: opaqueAncestor, displayRectIgnoringOpacity:,
displayIfNeededIgnoringOpacity, displayIfNeededInRectIgnoringOpacity:
I don't know why AppleScriptStudio would think it has to redraw the
entire window contents, but by telling the window that instances of
your NSView subclass are opaque, you can probably convince it not to
bother drawing the window background behind your opaque view. You
should also use QuartzDebug.app to find out what parts of the window
are being drawn when.
Finally, if you are really drawing every rectangle that
-getRectsBeingDrawn:count: tells you needs to be redrawn, you would not
see the window background under any circumstance (barring a bug n this
relatively new feature). I advice is that you take another look at
your drawing code because it is probably not right.
On Jan 28, 2004, at 11:13 PM, Jeffrey Mattox wrote:
>
Kerry:
>
>
That was helpful. But should clarify the problem. When I use your
>
advice and make the effort to avoid unnecessarily redrawing my graphic
>
items, I find that they all disappear because ASS is redrawing the
>
window background (before my drawRect: is called), forcing me to
>
redraw everything. This happens even when there is no obvious need to
>
redraw the window; for example, if I just click on a button.
>
>
What I need to do is figure out how to prevent ASS from redrawing the
>
window.
>
>
I've experimented with setting/clearing properties of my window. I'm
>
hoping that somebody knows a shortcut to using trial and error (which,
>
unfortunately is SOP when programming in AppleScript!).
>
>
Jeff
>
>
>
>
At 5:32 PM -0700 1/28/04, Kerry Hazelgren wrote:
>
> Jeff,
>
>
>
> On Jan 28, 2004, at 4:59 PM, Jeffrey Mattox wrote:
>
>
>
>> At 12:29 AM -0700 1/17/04, Kerry Hazelgren wrote:
>
>>> AppleScript Studio is really just Xcode with support for
>
>>> AppleScript thrown in, so why not use the standard Xcode/IB process
>
>>> for creating, overriding, and drawing into a view?
>
>>
>
>> I have figured out how to subclass NSView and use Cocoa to draw
>
>> graphics inside a window that is set up by AppleScript Studio. So,
>
>> now I can draw into my view and it stays there.
>
>>
>
>> But, I don't want to redraw everything each time my drawRect: is
>
>> called because much of it has not changed (too slow). However, if I
>
>> don't redraw everything, my prior strokes are overwritten before my
>
>> drawRect: is invoked. Something is clobbering my view and replacing
>
>> my prior strokes with the standard window background.
>
>
>
> Indeed, it is best NOT to redraw everything every time that -drawRect
>
> is called. To optimize things, your -drawRect method can check to
>
> see what areas inside the view need to be drawn, and then draw those.
>
> Take a look at the header for NSView.h, and look at
>
> -getRectsBeingDrawn:count: and -needsToDrawRect. You can view the
>
> documentation for them by option+double-clicking on the name of the
>
> method.
>
>
>
> These two methods will help you to determine what areas (rects) in
>
> you view need to be drawn for a given call to your -drawRect method.
>
>
>
>>
>
>> I have no commands in my drawRect: that refer to any other views or
>
>> windows, and I'm just drawing hundreds of lines and circles.
>
>
>
>
>
> For a bit of explanation, the process of drawing in a view starts
>
> when that view is invalidated, in whole (by calling
>
> -setNeedsDisplay:) or in part (by calling -setNeedsDisplayInRect:).
>
> In Cocoa, you don't explicitly erase views, as was the case in
>
> Carbon. The system then attempts to redraw those views. It starts
>
> with the hindmost view, sending a -drawRect message to that view. It
>
> should only redraw the portions that both (1) have been invalidated,
>
> and (2) are visible. This continues until the frontmost view has
>
> been redrawn, after which nothing happens until another view is
>
> invalidated.
>
>
>
>> How do I prevent the window background from clobbering my view
>
>> before my drawRect: is invoked?
>
>
>
> If you are seeing the window background in your view in places where
>
> your drawing should be, it means that your -drawRect method is not
>
> drawing in all of the places that it should. This makes sense if you
>
> consider that the content view of the window was redrawn, and then
>
> your view was redrawn, but didn't draw everything, leaving portions
>
> of the window background still visible.
>
>
>
>>
>
>> Jeff
>
>
>
> Hope this helps,
>
>
>
> Kerry Hazelgren
>
_______________________________________________
>
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.
_______________________________________________
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.