Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / December 2006



Tip: Looking for answers? Try searching our database.

Second problem: animating while resizing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel Griscom - 22 Dec 2006 18:13 GMT
I've got an application (SeisMac) which uses a thread to animate
continuously. The animation continues while the window is being
dragged (good) but if you resize the window the animation continues
only while the window is actually changing shape (bad).

This is shown by the same demo for my previous problem, at
<http://www.suitable.com/temp/NSVIewTest.zip>. The window contains an
NSView subclass called PrintView (framed in green). Inside PrintView
are four instances of AnimateView, which show moving animations (blue
lines) clipped to their bounds (red rectangles). Each AnimateView has
an NSThread which regularly increments the rotation and calls [self
setNeedsDisplay:YES].

Try it: the animation continues while the window is dragged, and
while the window is actively being resized. But, if the user stops
moving the window size dragger then the animation stops updating.

The thread runs continuously, and regularly calls setNeedsDisplay in
all circumstances, but if the user clicks and holds on the window
resize dragger then drawRect stops being called.

How can I get drawRect to be called when requested?

Thanks,
Dan

Signature

Daniel Griscom               Suitable Systems
griscom@suitable.com         1 Centre Street
www.suitable.com             Wakefield, MA  01880
(781) 665-0053

Patrick Machielse - 22 Dec 2006 20:02 GMT
> Try it: the animation continues while the window is dragged, and
> while the window is actively being resized. But, if the user stops
[quoted text clipped - 3 lines]
> all circumstances, but if the user clicks and holds on the window
> resize dragger then drawRect stops being called.

Your code uses -[setNeedsDisplay:] (which should be called on the main
thread). This 'asks' the ui thread to repaint the view when it gets
around to it. Obviously, it has better things to do when a resizing...

You can use -[display] to make this request less volontary:

[self performSelectorOnMainThread:@selector(display) withObject:nil
waitUntilDone:YES];

This will tell the ui to draw your view _now_, and wait for it. Since
this is less optimal, you may want to do so only when you're not
resizing:

SEL paintSEL = [self inLiveResize] ? @selector(display) :
@selector(refresh);
[self performSelectorOnMainThread:paintSEL withObject:nil
waitUntilDone:YES];

(where 'refresh' simply calls setNeedsDisplay)

patrick
Daniel Griscom - 22 Dec 2006 23:52 GMT
Excellent. Just what I needed.

Thanks,
Dan

Signature

Daniel Griscom               Suitable Systems
griscom@suitable.com         1 Centre Street
www.suitable.com             Wakefield, MA  01880
(781) 665-0053

Patrick Machielse - 23 Dec 2006 00:25 GMT
> Excellent. Just what I needed.

Three notes:

(1) I don't know _exactly_ what's keeping the UI thread when you
drag-resize a window. It may have something to do with 'runloop modes'.

(2) If you don't care about resizes, you could also refresh your view
periodically using an NSTimer. It's more light weight, and you avoid
threading issues.

(3) It's illustrative to use the Quartz Debug Frame Meter (command-f) to
monitor the behavior of your app. Notice how the frame rate ~ quadruples
when you resize the window.

patrick
John C. Randolph - 24 Dec 2006 14:51 GMT
> (1) I don't know _exactly_ what's keeping the UI thread when you
> drag-resize a window.

It's a bad habit of the AppKit when tracking the mouse.  Window
resizing, moving sliders, etc.  The code grabs the event loop, and
doesn't return until mouse up.  It's a major nuisance when you want to
subclass many common controls.

-jcr
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.