From b668a54e176574aa65944c032271c74d35060f58 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 10 Dec 2007 20:36:34 +0000 Subject: [PATCH] From Eric Wing, "For osgviewerCocoa, a very simple change to allow toggling between fullscreen mode and back between views. (To activate, double click on the view to toggle.) It demonstrates/uses the new one-liner fullscreen method introduced in Leopard. Code will still compile and run in pre-Leopard (thanks to Obj-C dynamic/late binding), but code path is treated as a no-op in those cases." --- examples/osgviewerCocoa/ViewerCocoa.h | 1 + examples/osgviewerCocoa/ViewerCocoa.mm | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/examples/osgviewerCocoa/ViewerCocoa.h b/examples/osgviewerCocoa/ViewerCocoa.h index 46e508e46..a0022f224 100644 --- a/examples/osgviewerCocoa/ViewerCocoa.h +++ b/examples/osgviewerCocoa/ViewerCocoa.h @@ -186,6 +186,7 @@ namespace osgViewer // Examples of providing an action to connect to. - (IBAction) resetPosition:(id)the_sender; - (IBAction) takeBackgroundColorFrom:(id)the_sender; +- (IBAction) toggleFullScreen:(id)the_sender; @end diff --git a/examples/osgviewerCocoa/ViewerCocoa.mm b/examples/osgviewerCocoa/ViewerCocoa.mm index aab9c2685..41bf7b474 100644 --- a/examples/osgviewerCocoa/ViewerCocoa.mm +++ b/examples/osgviewerCocoa/ViewerCocoa.mm @@ -674,6 +674,11 @@ A -respondsToSelector: check has been used to provide compatibility with previou else { theViewer->getEventQueue()->mouseDoubleButtonPress(converted_point.x, converted_point.y, 1); + + + // Let's toggle fullscreen for show + [self toggleFullScreen:nil]; + } [self setNeedsDisplay:YES]; } @@ -1388,6 +1393,27 @@ A -respondsToSelector: check has been used to provide compatibility with previou [self setNeedsDisplay:YES]; } +- (IBAction) toggleFullScreen:(id)the_sender +{ + // I'm lazy and rather use the new 10.5 Cocoa Fullscreen API. + // For now, no legacy support for fullscreen. + // One of the cool things about Obj-C is dynamic/late binding. + // We can compile and run this code on versions prior to 10.5. + // At run-time, we check to see if these methods actually exist + // and if they do, we message them. If not, we avoid them. + if([self respondsToSelector:@selector(isInFullScreenMode)]) + { + if([self isInFullScreenMode]) + { + [self exitFullScreenModeWithOptions:nil]; + } + else + { + [self enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; + } + } +} + //////////////////////////////////////////////////////////////////////// /////////////////////////// End IBAction examples ///////////////////// ////////////////////////////////////////////////////////////////////////