From 9c07503350bb3356d173f552740765997526f510 Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Mon, 28 Mar 2011 14:53:28 +0200 Subject: [PATCH] Add support for external window handling (NSView + NSWindow) (bis) --- src/SFML/Window/CMakeLists.txt | 2 ++ src/SFML/Window/OSX/SFContext.mm | 3 ++- src/SFML/Window/OSX/SFWindowController.mm | 6 +++--- src/SFML/Window/OSX/WindowImplCocoa.mm | 18 +++++++++++------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index 9e942344b..2b02eb9d3 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -68,6 +68,8 @@ else() # MACOSX ${SRCROOT}/OSX/SFWindow.m ${SRCROOT}/OSX/SFWindowController.h ${SRCROOT}/OSX/SFWindowController.mm + ${SRCROOT}/OSX/SFViewController.h + ${SRCROOT}/OSX/SFViewController.mm ${SRCROOT}/OSX/VideoModeImpl.cpp ${SRCROOT}/OSX/WindowImplCocoa.hpp ${SRCROOT}/OSX/WindowImplCocoa.mm diff --git a/src/SFML/Window/OSX/SFContext.mm b/src/SFML/Window/OSX/SFContext.mm index 2479dd97b..e46687454 100644 --- a/src/SFML/Window/OSX/SFContext.mm +++ b/src/SFML/Window/OSX/SFContext.mm @@ -55,7 +55,7 @@ SFContext::SFContext(SFContext* shared) myPool = [[NSAutoreleasePool alloc] init]; // Create the context - CreateContext(shared, 0, ContextSettings(0, 0, 0)); + CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings(0, 0, 0)); // Activate the context SetActive(true); @@ -83,6 +83,7 @@ SFContext::SFContext(SFContext* shared, const WindowImpl* owner, //////////////////////////////////////////////////////////// SFContext::~SFContext() { + [myContext clearDrawable]; [myContext release]; [myPool drain]; // [A] diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm index dd6b81834..4aa87332b 100644 --- a/src/SFML/Window/OSX/SFWindowController.mm +++ b/src/SFML/Window/OSX/SFWindowController.mm @@ -88,14 +88,14 @@ sf::Err() << "Could not create an instance of NSOpenGLView " - << "in (SFWindowController -initWithMode:andStyle:)." + << "in (SFWindowController -initWithWindow:)." << std::endl; return self; } // Set the view to the window as its content view. - [myWindow setContentView:myOGLView]; + [[myWindow contentView] addSubview:myOGLView]; } return self; @@ -434,7 +434,7 @@ * for more information. */ sf::Err() - << "Cannot fetch event from a worker thread. (OS X limitation)" + << "Cannot fetch event from a worker thread. (OS X restriction)" << std::endl; return; diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index 86180c08b..61cfbb468 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -30,8 +30,7 @@ #include #import -//#import -#warning SFViewController not yet implemented. +#import #import namespace sf @@ -45,9 +44,6 @@ namespace priv //////////////////////////////////////////////////////////// WindowImplCocoa::WindowImplCocoa(WindowHandle handle) { - sf::Err() << "Not yet fully supported." << std::endl; -#warning WindowImplCocoa(WindowHandle handle) not yet fully implemented - SetUpPoolAndApplication(); // Treat the handle as it real type @@ -56,13 +52,21 @@ WindowImplCocoa::WindowImplCocoa(WindowHandle handle) // We have a window. myDelegate = [[SFWindowController alloc] initWithWindow:nsHandle]; + + // Don't forget to update our parent (that is, WindowImpl) size : + myWidth = [[nsHandle contentView] frame].size.width; + myHeight = [[nsHandle contentView] frame].size.height; - } /*else if ([nsHandle isKindOfClass:[NSView class]]) { + } else if ([nsHandle isKindOfClass:[NSView class]]) { // We have a view. myDelegate = [[SFViewController alloc] initWithView:nsHandle]; - } */ else { + // Don't forget to update our parent (that is, WindowImpl) size : + myWidth = [nsHandle frame].size.width; + myHeight = [nsHandle frame].size.height; + + } else { sf::Err() << "Cannot import this Window Handle because it is neither "