advertisement

Article:
  Movies and Menus
Subject:   Resizing the window
Date:   2002-01-31 19:33:28
From:   michele
Here are two methods to resize the window and the movie at whatever magnification.


If someone could help me drawing it offscreen with Cocoa, it would be nicer to look at.


- (void) resizeMovieViewAndWindow: (float) magnification
{
NSSize movieViewFutureSize;
NSPoint topLeftPoint;
NSRect newFrame;



// Get the window and the frame view
NSWindow *movieWindow = [movieView window];
NSRect frameMovieView = [movieView frame];


// Get the movie size
NSSize movieViewNormalSize = [movieView sizeForMagnification: 1.0];
[movieView setNeedsDisplay: NO];


// Check if width is nil - for mp3s for example
// not sure for height if standard controller present: mini 16 pixels
// anyway does no harm to test it
if (movieViewNormalSize.width == 0.0 || movieViewNormalSize.height == 0.0)
{
// Set the width to length of controller, height to height of controller
movieViewFutureSize.width = frameMovieView.size.width;
movieViewFutureSize.height = 16;
}


// width is not nil
else
{
// Get the size of the view at magnification magnification
movieViewFutureSize = [movieView sizeForMagnification: magnification];


// Check if the size of the future view is less than the size of the min view as set in IB
if (movieViewFutureSize.width < [movieWindow minSize].width ||
movieViewFutureSize.height < [movieWindow minSize].height)
{
// Change the magnification to the max of magnification with minSize width
// and minSize height
magnification = fmax([movieWindow minSize].width / movieViewNormalSize.width,
[movieWindow minSize].height / movieViewNormalSize.height);
}


// Check if the size of the future view is more than the size of the max view as set in IB
if (movieViewFutureSize.width > [movieWindow maxSize].width ||
movieViewFutureSize.height > [movieWindow maxSize].height)
{
// Change the magnification to the min of magnification with maxSize width
// and maxSize height
magnification = fmin([movieWindow maxSize].width / movieViewNormalSize.width,
[movieWindow maxSize].height / movieViewNormalSize.height);
}


// Change the future size accordingly
movieViewFutureSize = [movieView sizeForMagnification: magnification];


// Resize the view's frame
[movieView resizeWithMagnification: magnification];
}


// Compute the window's frame according to movie view size
// and borders size
movieViewFutureSize.width += 2 * frameMovieView.origin.x;
movieViewFutureSize.height += 2 * frameMovieView.origin.y;


// Get the top left point of the window before resizing
// 22 is the height of the main menu bar
topLeftPoint = NSMakePoint([movieWindow frame].origin.x,
[movieWindow frame].origin.y -
movieViewFutureSize.height +
[movieWindow frame].size.height -
22);


newFrame = NSMakeRect(topLeftPoint.x, topLeftPoint.y, movieViewFutureSize.width, movieViewFutureSize.height);
// Set the window's content size to computed size
[movieWindow setContentSize: movieViewFutureSize];
//[movieWindow setFrame: newFrame display: NO];


// 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;
}


1 to 1 of 1
  1. Resizing the window
    2005-01-17 12:10:26  nottings [View]

1 to 1 of 1