Avoiding bouncing up when resizing
Avoiding bouncing up when resizing
- Subject: Avoiding bouncing up when resizing
- From: Michèle Garoche <email@hidden>
- Date: Fri, 1 Feb 2002 08:28:36 +0100
Hello,
I'm trying to resize a movie (e.g could be film, image, QTVR or sound)
into an NSMovieView and its window according to whatever magnification.
The view and its window are defined in IB. Margins are 20 pixels.
When the movie is loaded, it is drawn in its view with magnification 1.
Then the user can resize it, but the resizing is made proportional to
the size of the movie at magnification 1 and the top left corner must be
the same as before resizing.
How can I avoid bouncing up when resizing (is offscreen drawing possible
in Cocoa and how)? I've tried setAspectRatio, but I cannot have the view
well centered with 20 pixels margin in the window.
To do this, I use two methods:
- (void) resizeMovieViewAndWindow: (float) magnification
{
...
code for computing the size of the view at whatever magnification
and the new top left point of the window
...
// Set the window's content size to computed size
[movieWindow setContentSize: movieViewFutureSize];
// Set the top left point of the window after resizing
[movieWindow setFrameOrigin: topLeftPoint];
}
- (NSSize) windowWillResize: (NSWindow *) sender toSize: (NSSize)
proposedFrameSize
{
// Initialize the magnification to 1.0
float newMagnification = 1.0;
// Retrieve the size of the view at magnification 1
NSSize normalFrameSize = [movieView sizeForMagnification:
newMagnification];
// Check if the normal frame size width is not nil
if (!(normalFrameSize.width == 0.0 || normalFrameSize.height == 0.0))
{
// Computes the ratio between proposedFrameSize and
movieViewNormalSize widths
// and heights. Take the minimum
newMagnification = fmin(proposedFrameSize.width /
normalFrameSize.width,
proposedFrameSize.height / normalFrameSize.height);
}
// No resizing
else
{
NSBeep();
}
// Resizes the movie according to magnification
[self resizeMovieViewAndWindow: newMagnification];
return [sender frame].size;
}
Any help would be much appreciated,
Michhle