Browse Source

Simplifies going fullscreen a lot!

master
Joshua Moerman 10 years ago
parent
commit
c24ec04646
  1. 12
      BoxCar2D.xcodeproj/project.pbxproj
  2. 2
      GLEssentials/Car.cpp
  3. 12
      GLEssentials/OSX/FullscreenWindow.h
  4. 41
      GLEssentials/OSX/FullscreenWindow.m
  5. 2
      GLEssentials/OSX/MainMenu.xib
  6. 16
      GLEssentials/OSX/WindowController.h
  7. 108
      GLEssentials/OSX/WindowController.m

12
BoxCar2D.xcodeproj/project.pbxproj

@ -24,9 +24,7 @@
4280D43318E8321100E4CDFB /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4280D41A18E8311400E4CDFB /* AppDelegate.m */; };
4280D43418E8321100E4CDFB /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4280D42018E8311400E4CDFB /* ViewController.m */; };
4280D43818E839C100E4CDFB /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4280D43718E839C100E4CDFB /* Images.xcassets */; };
4295A2CA18CB4E5100A58D8F /* FullscreenWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 4295A2C318CB4E5100A58D8F /* FullscreenWindow.m */; };
4295A2CB18CB4E5100A58D8F /* GLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4295A2C518CB4E5100A58D8F /* GLView.m */; };
4295A2CC18CB4E5100A58D8F /* WindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4295A2C718CB4E5100A58D8F /* WindowController.m */; };
4295A2E018CB68A400A58D8F /* Game.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4295A2DF18CB68A400A58D8F /* Game.mm */; };
4295A2EB18CBB0F700A58D8F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4295A2EA18CBB0F700A58D8F /* main.m */; };
4295A2F318CBB22800A58D8F /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4295A2F218CBB22800A58D8F /* MainMenu.xib */; };
@ -61,12 +59,8 @@
4280D41F18E8311400E4CDFB /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ViewController.h; path = GLEssentials/iOS/ViewController.h; sourceTree = SOURCE_ROOT; };
4280D42018E8311400E4CDFB /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ViewController.m; path = GLEssentials/iOS/ViewController.m; sourceTree = SOURCE_ROOT; };
4280D43718E839C100E4CDFB /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = GLEssentials/Images.xcassets; sourceTree = "<group>"; };
4295A2C218CB4E5100A58D8F /* FullscreenWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FullscreenWindow.h; path = GLEssentials/OSX/FullscreenWindow.h; sourceTree = "<group>"; };
4295A2C318CB4E5100A58D8F /* FullscreenWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FullscreenWindow.m; path = GLEssentials/OSX/FullscreenWindow.m; sourceTree = "<group>"; };
4295A2C418CB4E5100A58D8F /* GLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GLView.h; path = GLEssentials/OSX/GLView.h; sourceTree = "<group>"; };
4295A2C518CB4E5100A58D8F /* GLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GLView.m; path = GLEssentials/OSX/GLView.m; sourceTree = "<group>"; };
4295A2C618CB4E5100A58D8F /* WindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WindowController.h; path = GLEssentials/OSX/WindowController.h; sourceTree = "<group>"; };
4295A2C718CB4E5100A58D8F /* WindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WindowController.m; path = GLEssentials/OSX/WindowController.m; sourceTree = "<group>"; };
4295A2DE18CB68A400A58D8F /* Game.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Game.h; path = GLEssentials/Game.h; sourceTree = "<group>"; };
4295A2DF18CB68A400A58D8F /* Game.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = Game.mm; path = GLEssentials/Game.mm; sourceTree = "<group>"; };
4295A2EA18CBB0F700A58D8F /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = GLEssentials/OSX/main.m; sourceTree = "<group>"; };
@ -183,12 +177,8 @@
4295A2F018CBB1D200A58D8F /* BoxCar2D-Info.plist */,
4295A2EA18CBB0F700A58D8F /* main.m */,
4295A2F218CBB22800A58D8F /* MainMenu.xib */,
4295A2C218CB4E5100A58D8F /* FullscreenWindow.h */,
4295A2C318CB4E5100A58D8F /* FullscreenWindow.m */,
4295A2C418CB4E5100A58D8F /* GLView.h */,
4295A2C518CB4E5100A58D8F /* GLView.m */,
4295A2C618CB4E5100A58D8F /* WindowController.h */,
4295A2C718CB4E5100A58D8F /* WindowController.m */,
);
name = OSX;
sourceTree = "<group>";
@ -373,10 +363,8 @@
files = (
42409A2218EAD10900B43925 /* Car.cpp in Sources */,
4295A2EB18CBB0F700A58D8F /* main.m in Sources */,
4295A2CA18CB4E5100A58D8F /* FullscreenWindow.m in Sources */,
4295A2CB18CB4E5100A58D8F /* GLView.m in Sources */,
42409A2418EAD10900B43925 /* Drawer.cpp in Sources */,
4295A2CC18CB4E5100A58D8F /* WindowController.m in Sources */,
42409A2618EAD10900B43925 /* Path.cpp in Sources */,
4295A2E018CB68A400A58D8F /* Game.mm in Sources */,
);

2
GLEssentials/Car.cpp

@ -155,7 +155,6 @@ struct CarBuilder {
//stickJoint.enableLimit = true;
stickJoint.enableMotor = true;
stickJoint.maxMotorTorque = 1000;
stickJoint.motorSpeed = get_rand(-1, 2);
}
b2Body * createWheel(WheelGenome const & g){
@ -197,6 +196,7 @@ struct CarBuilder {
stickJoint.lowerAngle = startAngle - sg.limit;
stickJoint.upperAngle = startAngle + sg.limit;
stickJoint.referenceAngle = startAngle;
stickJoint.motorSpeed = get_rand(-1, 2);
world.CreateJoint(&stickJoint);
}

12
GLEssentials/OSX/FullscreenWindow.h

@ -1,12 +0,0 @@
//
//
// OSX GLEssentials
//
// Copied from the Apple GLEssentials
//
//
@import Cocoa;
@interface FullscreenWindow : NSWindow
@end

41
GLEssentials/OSX/FullscreenWindow.m

@ -1,41 +0,0 @@
//
//
// OSX GLEssentials
//
// Copied from the Apple GLEssentials
//
//
#import "FullscreenWindow.h"
@implementation FullscreenWindow
- (id)init {
// Create a screen-sized window on the display you want to take over
// Initialize the window making it size of the screen and borderless
NSRect screenRect = [[NSScreen mainScreen] frame];
if(self = [super initWithContentRect:screenRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES]){
self.level = NSMainMenuWindowLevel + 1; // Set the window level to be above the menu bar to cover everything else
self.opaque = YES; // Set opaque
self.hidesOnDeactivate = YES; // Hide this when user switches to another window (or app)
}
return self;
}
- (BOOL)canBecomeKeyWindow {
// Return yes so that this borderless window can receive input
return YES;
}
- (void)keyDown:(NSEvent *)event {
// Implement keyDown since controller will not get [ESC] key event which
// the controller uses to kill fullscreen
[self.windowController keyDown:event];
}
@end

2
GLEssentials/OSX/MainMenu.xib

@ -79,6 +79,7 @@
</menu>
<window title="GLEssentials" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="371">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowCollectionBehavior key="collectionBehavior" fullScreenPrimary="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="200" y="200" width="320" height="480"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1178"/>
@ -91,7 +92,6 @@
<customObject id="M8b-ga-iOS" userLabel="Window Controller" customClass="WindowController" colorLabel="IBBuiltInLabel-Blue">
<connections>
<outlet property="view" destination="372" id="hMc-Rf-8LH"/>
<outlet property="window" destination="371" id="z3B-S9-PsV"/>
</connections>
</customObject>
</objects>

16
GLEssentials/OSX/WindowController.h

@ -1,16 +0,0 @@
//
//
// OSX GLEssentials
//
// Copied from the Apple GLEssentials
//
//
@import Cocoa;
@class GLView;
@interface WindowController : NSWindowController {
IBOutlet GLView *view;
}
@end

108
GLEssentials/OSX/WindowController.m

@ -1,108 +0,0 @@
//
//
// OSX GLEssentials
//
// Copied from the Apple GLEssentials
//
//
#import "WindowController.h"
#import "FullscreenWindow.h"
#import "GLView.h"
@interface WindowController () {
FullscreenWindow *fullscreenWindow; // Fullscreen window
NSWindow* standardWindow; // Non-Fullscreen window (also the initial window)
}
@end
@implementation WindowController
- (id)initWithWindow:(NSWindow *) window{
if (self = [super initWithWindow:window]){
fullscreenWindow = nil;
}
return self;
}
- (void)goFullscreen{
if(fullscreenWindow){
return;
}
// Allocate a new fullscreen window
fullscreenWindow = [[FullscreenWindow alloc] init];
// Resize the view to screensize
view.frame = fullscreenWindow.frame;
// Set the view in the fullscreen window
fullscreenWindow.contentView = view;
// keep a referene to the old window
standardWindow = self.window;
// Hide non-fullscreen window so it doesn't show up when switching out
// of this app (i.e. with CMD-TAB)
[standardWindow orderOut:self];
// Set controller to the fullscreen window so that all input will go to
// this controller (self)
self.window = fullscreenWindow;
// Show the window and make it the key window for input
[fullscreenWindow makeKeyAndOrderFront:self];
}
- (void)goWindow{
if(!fullscreenWindow){
return;
}
// Resize the view to the window size
view.frame = standardWindow.frame;
// Set controller to the standard window so that all input will go to
// this controller (self)
self.window = standardWindow;
// Set the content of the orginal window to the view
self.window.contentView = view;
// Show the window and make it the key window for input
[[self window] makeKeyAndOrderFront:self];
// release fullscreenWindow
fullscreenWindow = nil;
}
- (void)keyDown:(NSEvent *)event{
unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0];
switch (c){
// Handle [ESC] key
case 27:
if(fullscreenWindow){
[self goWindow];
}
return;
// Have f key toggle fullscreen
case 'f':
if(fullscreenWindow){
[self goWindow];
} else {
[self goFullscreen];
}
return;
}
// Allow other character to be handled (or not and beep)
[super keyDown:event];
}
@end