Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programmatic resize flicker



I wrote some JNI that seems to work well. I wanted to animated resizing, but the flicker drove me crazy. After a lot of digging, I wrote the following. It requires you to do a bit of belly dancing, but works on both Tiger and Leopard. It relies on the _StartLiveResize and _EndLiveResize methods that are defined in the NSWindow class. The challenges are:

1. you need to call _StartLiveResize and _EndLiveResize on the AppKit thread
2. you need to call your Java code on the EDT
3. you have to code it up slightly different on 10.4 and 10.5


I have a subclass of JFrame, where code is:

public void setBoundsNoFlicker(int x, int y, int width, int height) {
if (Platform.isMacOSX(10, 5)) {
setBoundsNoFlicker_10_5(x, y, width, height);
} else if (Platform.isMacOSX(10, 4)) {
setBoundsNoFlicker_10_4(x, y, width, height);
} else { // Don't have an implementation for Windows or earlier/later MacOS X
super.setBounds(x, y, width, height);
}
}


private void setBoundsNoFlicker_10_5(int x, int y, int width, int height) {
NSWindowJNI.library().StartLiveResize(nswindow); // will call on AppKit thread
super.setBounds(x, y, width, height);
NSWindowJNI.library().EndLiveResize(nswindow); // will call on AppKit thread
}


private void setBoundsNoFlicker_10_4(int x, int y, int width, int height) {
NSWindowJNI.library().SetMacBoundsNoFlicker10point4 (nswindow, x, y, width, height); // will call on AppKit thread
super.setBounds(x, y, width, height);
}


And then my C code looks like:

void StartLiveResize(NSWindow *window)
{
    StAutoreleasePool pool;
    [window _startLiveResize];
}
	
void EndLiveResize(NSWindow *window)
{
    StAutoreleasePool pool;
    [window _endLiveResize];
}

void SetMacBoundsNoFlicker10point4(NSWindow *window, int x, int y, int width, int height)
{
StAutoreleasePool pool;
NSRect frame = [window frame];

[window _startLiveResize];
[window setFrame:NSMakeRect(frame.origin.x, frame.origin.y + (frame.size.height - height), width, height) display:YES];
[window _endLiveResize];
}


NOTE: I have glue code that ensures that those C methods are run on the AppKit thread using performSelectorOnMainThread: passing YES on the waitUntilDone:

At some point I'll have time to post my entire library but hopefully that snippet will help.

-- John



On Sep 23, 2008, at 7:43 PM, Ken Orr wrote:

Is there any way to programmatically resize a Window via setSize without causing a horrendous looking flicker? Its impossible to create a custom window resize widget that reacts to mouseDragged events with the current state of affairs. If there is *any* way to do this, even with platform specific casting, I'm willing to do it. I'm hoping one of the Apple guys chimes in!

By the way, I know this issue has been brought up here, as far back as this message: http://lists.apple.com/archives/Java-dev/2006/Mar/ msg00179.html

-Ken


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Programmatic resize flicker (From: Ken Orr <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.