Re: window resize problem (NSMinX(windowFrame), NSMaxY(windowFrame)
Re: window resize problem (NSMinX(windowFrame), NSMaxY(windowFrame)
- Subject: Re: window resize problem (NSMinX(windowFrame), NSMaxY(windowFrame)
- From: Yann Bizeul <email@hidden>
- Date: Tue, 15 Jun 2004 08:13:24 +0200
If your problem persist, please post a log with your exact code (as you
did), and an NSLog of NSStringFromRect([window frame]) before and after
the resize
>
- (void)changeTransparency:(NSTimer *)timer
>
{
>
float alpha = [[self window] alphaValue];
>
BOOL reschedule = NO;
>
>
alpha += windowAlphaCurrentIncrement;
Just one thing about this, perhaps I'm wrong, but with this method, you
won't get the same resize time on all machines your application will
run on. According to graphics card performance, quartz active or not,
etc, your fade could be very slow, or just invisible because too fast !
You should watch the time at each iteration, and check which alpha
value to set up according to the time left before the end.
Here is the code I use, as a catgeory of NSWindow, in BuddyPop :
@implementation NSWindow (windowFading)
-(void)closeFade:(float)fadeTime {
NSTimeInterval start;
NSTimeInterval stop;
NSTimeInterval delta = 0;
start = [ NSDate timeIntervalSinceReferenceDate ];
while (delta < fadeTime)
{
stop = [ NSDate timeIntervalSinceReferenceDate ];
delta = stop - start;
[ self setAlphaValue: 1 - (delta/fadeTime) ];
}
[ self close ];
}
-(void)openFade:(float)fadeTime {
NSTimeInterval start;
NSTimeInterval stop;
NSTimeInterval delta = 0;
start = [ NSDate timeIntervalSinceReferenceDate ];
[ self setAlphaValue: 0 ];
[ self makeKeyAndOrderFront: self ];
while (delta < fadeTime)
{
stop = [ NSDate timeIntervalSinceReferenceDate ];
delta = stop - start;
[ self setAlphaValue: (delta/fadeTime) ];
}
[ self setAlphaValue: 1 ];
}
@end
>
>
// Reschedule timer if we haven't reached desired value
>
if (windowAlphaCurrentIncrement > 0)
>
{
>
if (alpha < windowAlphaMax)
>
reschedule = YES;
>
else
>
alpha = windowAlphaMax;
>
}
>
else
>
{
>
if (alpha > windowAlphaMin)
>
reschedule = YES;
>
else
>
alpha = windowAlphaMin;
>
}
>
>
if (reschedule)
>
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
>
target:self selector:@selector(changeTransparency:) userInfo:nil
>
repeats:NO];
>
>
[[self window] setAlphaValue:alpha];
>
}
>
>
- (void)resizeTheWindowLarge:(id)sender;
>
{
>
NSRect windowFrame;
>
NSRect newWindowFrame;
>
>
windowFrame = [self frame];
>
newWindowFrame = NSMakeRect(NSMinX(windowFrame), NSMaxY(windowFrame),
>
300, 85);
>
NSLog(@"Supposed to resize");
>
>
[[self window] setFrame:newWindowFrame display:YES animate:YES];
>
}
>
>
- (void)resizeTheWindowSmall:(id)sender;
>
{
>
NSRect windowFrame;
>
NSRect newWindowFrame;
>
>
windowFrame = [self frame];
>
newWindowFrame = NSMakeRect(NSMinX(windowFrame), NSMaxY(windowFrame),
>
170, 85);
>
NSLog(@"Supposed to resize");
>
>
[[self window] setFrame:newWindowFrame display:YES animate:YES];
>
}
>
>
- (void)mouseEntered:(NSEvent *)event {
>
NSLog(@"Mouse Entered");
>
//bring alpha back to 1
>
windowAlphaCurrentIncrement = windowAlphaIncrement;
>
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
>
target:self selector:@selector(changeTransparency:) userInfo:nil
>
repeats:NO];
>
//resize window to large view
>
[self resizeTheWindowLarge:nil];
>
>
>
>
}
>
>
>
- (void)mouseExited:(NSEvent *)event {
>
NSLog(@"Mouse Exited");
>
windowAlphaCurrentIncrement = -windowAlphaIncrement;
>
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
>
target:self selector:@selector(changeTransparency:) userInfo:nil
>
repeats:NO];
>
[self resizeTheWindowSmall:nil];
>
}
>
//end of mouse entered or exited window code
>
>
[demime 0.98b removed an attachment of type
>
application/pkcs7-signature which had a name of smime.p7s]
>
_______________________________________________
>
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.
>
>
>
--
Yann Bizeul - yann at tynsoe.org
http://projects.tynsoe.org/
_______________________________________________
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.