Fixed view resizing with Cocoa (close #207)

This commit is contained in:
Marco Antognini 2012-04-19 19:50:13 +02:00
parent eebaa27d17
commit 3e8961d05f
3 changed files with 62 additions and 45 deletions

View File

@ -71,6 +71,8 @@
// Set the (OGL) view to the view as its "content" view.
[m_view addSubview:m_oglView];
[m_oglView setAutoresizingMask:[m_view autoresizingMask]];
}
return self;
@ -105,27 +107,6 @@
}
////////////////////////////////////////////////////////
-(void)changeTitle:(NSString *)title
{
sf::err() << "Cannot change the title of the SFML area when SFML is integrated in a NSView." << std::endl;
}
////////////////////////////////////////////////////////
-(void)enableKeyRepeat
{
[m_oglView enableKeyRepeat];
}
////////////////////////////////////////////////////////
-(void)disableKeyRepeat
{
[m_oglView disableKeyRepeat];
}
////////////////////////////////////////////////////////
-(void)hideMouseCursor
{
@ -140,31 +121,11 @@
}
////////////////////////////////////////////////////////
-(void)hideWindow
{
[m_view setHidden:YES];
}
////////////////////////////////////////////////////////
-(void)showWindow
{
[m_view setHidden:NO];
}
////////////////////////////////////////////////////////
-(void)closeWindow
{
sf::err() << "Cannot close SFML area when SFML is integrated in a NSView." << std::endl;
[self setRequesterTo:0];
}
////////////////////////////////////////////////////////
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y
{
// TODO remove this ? use ogl view selector instead ?
if (m_requester == 0) return;
// Create a SFML event.
@ -203,6 +164,7 @@
return [m_view convertPoint:NSMakePoint(0, 0) toView:nil]; // nil means window
}
////////////////////////////////////////////////////////.
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y
{
@ -213,18 +175,65 @@
////////////////////////////////////////////////////////////
-(NSSize)size
{
return [m_view frame].size;
// TODO scaleUnitSquareToSize: ?
return [m_oglView frame].size;
}
////////////////////////////////////////////////////////
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
{
// TODO scaleUnitSquareToSize: ?
NSRect frame = NSMakeRect([m_view frame].origin.x,
[m_view frame].origin.y,
width,
height);
[m_view setFrame:frame];
[m_oglView setFrame:frame];
}
////////////////////////////////////////////////////////
-(void)changeTitle:(NSString *)title
{
sf::err() << "Cannot change the title of the SFML area when SFML is integrated in a NSView." << std::endl;
}
////////////////////////////////////////////////////////
-(void)hideWindow
{
[m_view setHidden:YES];
}
////////////////////////////////////////////////////////
-(void)showWindow
{
[m_view setHidden:NO];
}
////////////////////////////////////////////////////////
-(void)closeWindow
{
sf::err() << "Cannot close SFML area when SFML is integrated in a NSView." << std::endl;
}
////////////////////////////////////////////////////////
-(void)enableKeyRepeat
{
[m_oglView enableKeyRepeat];
}
////////////////////////////////////////////////////////
-(void)disableKeyRepeat
{
[m_oglView disableKeyRepeat];
}

View File

@ -317,6 +317,7 @@
////////////////////////////////////////////////////////
-(NSSize)size
{
// TODO scaleUnitSquareToSize: ?
return [m_oglView frame].size;
}
@ -324,6 +325,8 @@
////////////////////////////////////////////////////////
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
{
// TODO scaleUnitSquareToSize: ?
// Add titlebar height.
NSRect frame = NSMakeRect([m_window frame].origin.x,
[m_window frame].origin.y,

View File

@ -41,6 +41,11 @@ namespace sf {
/// This protocol defines the interface of the delegate of
/// the window implementation.
///
/// We don't create an interface here because Obj-C doesn't allow
/// multiple inheritance (SFViewController and SFWindowController
/// don't have the same parent classes). Unfortunately this means
/// we have to duplicate some code.
///
/// Everything is done via a class that implement this protocol.
/// There are two of these classes :
///
@ -56,7 +61,7 @@ namespace sf {
///
/// keyDown, keyUp, textEntered
///
/// Note : Joystick are not bound to a view or window
/// Note : Joysticks are not bound to a view or window
/// thus they're not managed by a class implementing this protocol.
///
////////////////////////////////////////////////////////////