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: "Louis C. Sacha" <email@hidden>
- Date: Mon, 14 Jun 2004 19:22:07 -0700
Hello...
You probably don't want to use any of the NSMin/Max NSRect functions
to do this.
Since you aren't changing the height of the window at all, just doing
the following should work:
// making the window bigger
newWindowFrame = NSMakeRect(windowFrame.origin.x, windowFrame.origin.y,
300, 85);
[[self window] setFrame:newWindowFrame display:YES animate:YES];
and
// making the window smaller
newWindowFrame = NSMakeRect(windowFrame.origin.x, windowFrame.origin.y,
175, 85);
[[self window] setFrame:newWindowFrame display:YES animate:YES];
If you later decide to make the height of the window change, you will
need to do some math to get the correct new origin for the window
frame.
As Yann mentioned , the window frame origin is at the bottom left
corner. The point you want to stay constant when the window resizes
is probably the upper left corner. If the height changes, then the
origin needs to be adjusted so that the position of the upper left
corner remains constant.
- (void)resizeWindow:(NSWindow *)someWindow toSize:(NSSize)newSize
/* resizes a window to the provided size, keeping the position of the
window's upper left corner constant */
{
NSRect oldFrame = [someWindow frame];
NSRect newFrame;
newFrame.origin.x = oldFrame.origin.x;
newFrame.origin.y = oldFrame.origin.y + oldFrame.size.height
- newSize.height;
newFrame.size.width = newSize.width;
newFrame.size.height = newSize.height;
[someWindow setFrame:newFrame display:TRUE animate:TRUE];
}
Hope that helps,
Louis
PS: It might just be something that you only did when you posted the
code to the list, but your windowAlphaCurrentIncrement variable
should not be a static variable (shared by all instances of this
class), since it is used to hold part of the state of a particular
instance, and will cause problems if there are more than one instance
of of this class in existence at any time. It should be an instance
variable instead.
Hi,
I still have not been able to get this to work right. Maybe to shed
some more light for you, I am basically using Apple's
RoundTransparentWindow example
(http://developer.apple.com/samplecode/RoundTransparentWindow/
RoundTransparentWindow.html) modified. I changed the two images, it now
uses just one (rectangular colored image).
What I added to the example:
Added code:
-when the mouse enters the window the alpha setting of the window is
set to 1.0
-when the mouse exits the window the alpha setting of the window is set
to 0.2
What I have working now, is the setting of the alpha setting on
mouseentered and mouseexited. What I want to get working is when the
mouse enters the window, the window will resize to 300 x 85. Then when
the mouse exits, i want the window to resize back to 170 x 85. I dont
want the window to move around though. I want it to stay in the same
place. With what I have working now, the window resizes properly, but
it moves to the bottom(about 2 inches up) left side of the screen. I
dont believe the newWindowFrame = NSMakeRect(NSMinX(windowFrame),
NSMaxY(windowFrame), 170, 85); code is working properly, using
(NSMinX(windowFrame), NSMaxY(windowFrame) the resize should keep the
window in the same position, but it is not.
Can someone please shed some light on this for me?
Thanks,
-rhon
SOME CODE
------------------
//mouse entered exited window code below
- (void)viewDidMoveToWindow {
[self addTrackingRect:[self frame] owner:self userData:nil
assumeInside:YES];
[super viewDidMoveToWindow];
}
static float windowAlphaIncrement = 0.15;
static float windowAlphaCurrentIncrement;
static float windowAlphaMin = 0.2;
static float windowAlphaMax = 1.0;
static float windowAlphaFadeRate = 1.0 / 15.0;
- (void)changeTransparency:(NSTimer *)timer
{
float alpha = [[self window] alphaValue];
BOOL reschedule = NO;
alpha += windowAlphaCurrentIncrement;
// 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.
_______________________________________________
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.