2010-07-22 16:13:55 +00:00
|
|
|
//
|
|
|
|
// GameWindow.m
|
|
|
|
// XNI
|
|
|
|
//
|
|
|
|
// Created by Matej Jan on 20.7.10.
|
|
|
|
// Copyright 2010 Retronator. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "GameWindow.h"
|
2010-11-02 09:29:19 +00:00
|
|
|
#import "GameWindow+Internal.h"
|
2010-07-22 16:13:55 +00:00
|
|
|
|
|
|
|
#import "Retronator.Xni.Framework.h"
|
2010-10-19 13:31:39 +00:00
|
|
|
#import "GameViewController.h"
|
|
|
|
#import "GameView.h"
|
2010-07-22 16:13:55 +00:00
|
|
|
|
2010-11-02 09:29:19 +00:00
|
|
|
@interface GameWindow()
|
|
|
|
|
|
|
|
- (Rectangle*) calculateClientBounds;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2010-07-22 16:13:55 +00:00
|
|
|
@implementation GameWindow
|
|
|
|
|
|
|
|
- (id) init {
|
|
|
|
if (self = [super init]) {
|
|
|
|
currentOrientation = DisplayOrientationDefault;
|
|
|
|
clientSizeChanged = [[Event alloc] init];
|
|
|
|
orientationChanged = [[Event alloc] init];
|
2010-11-02 09:29:19 +00:00
|
|
|
|
|
|
|
clientBounds = [[Rectangle rectangleWithCGRect:[[UIScreen mainScreen] bounds]] retain];
|
2010-07-22 16:13:55 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PROPERTIES
|
|
|
|
|
|
|
|
@synthesize clientBounds;
|
|
|
|
@synthesize currentOrientation;
|
|
|
|
|
|
|
|
@synthesize clientSizeChanged;
|
|
|
|
@synthesize orientationChanged;
|
|
|
|
|
2010-12-08 04:57:47 +00:00
|
|
|
- (GameViewController *) gameViewController {
|
|
|
|
return gameViewController;
|
|
|
|
}
|
|
|
|
|
2010-07-22 16:13:55 +00:00
|
|
|
- (id) handle {
|
2010-07-27 18:23:25 +00:00
|
|
|
return (id)gameViewController.view.layer;
|
2010-07-22 16:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
|
|
|
- (void) beginScreenDeviceChangeWithFullscreen:(BOOL)willBeFullscreen {
|
|
|
|
gameViewController.wantsFullScreenLayout = willBeFullscreen;
|
|
|
|
[[UIApplication sharedApplication] setStatusBarHidden:willBeFullscreen];
|
|
|
|
gameViewController.view.frame = [UIScreen mainScreen].applicationFrame;
|
2010-12-08 04:57:47 +00:00
|
|
|
[clientBounds release];
|
2010-11-02 09:29:19 +00:00
|
|
|
clientBounds = [[self calculateClientBounds] retain];
|
2010-07-22 16:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) endScreenDeviceChange {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-02 09:29:19 +00:00
|
|
|
- (void) initialize {
|
|
|
|
// Create UI window.
|
|
|
|
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
|
|
|
|
|
|
|
// Create game view controller.
|
|
|
|
gameViewController = [[GameViewController alloc] initWithGameWindow:self];
|
|
|
|
[((GameView*)gameViewController.view).viewSizeChanged
|
|
|
|
subscribeDelegate:[Delegate delegateWithTarget:self Method:@selector(gameViewSizeChanged)]];
|
|
|
|
|
|
|
|
// Add the game view to the window.
|
|
|
|
[window addSubview: gameViewController.view];
|
|
|
|
|
|
|
|
// Present the window.
|
|
|
|
[window makeKeyAndVisible];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSupportedOrientations:(DisplayOrientation)orientations {
|
|
|
|
gameViewController.supportedOrientations = orientations;
|
|
|
|
}
|
|
|
|
|
2010-07-22 16:13:55 +00:00
|
|
|
- (void) gameViewSizeChanged {
|
2010-11-02 09:29:19 +00:00
|
|
|
Rectangle *newClientBounds = [self calculateClientBounds];
|
2010-07-22 16:13:55 +00:00
|
|
|
if (![newClientBounds equals:clientBounds]) {
|
|
|
|
[clientBounds release];
|
|
|
|
clientBounds = [newClientBounds retain];
|
|
|
|
[clientSizeChanged raiseWithSender:self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-02 09:29:19 +00:00
|
|
|
- (Rectangle*) calculateClientBounds {
|
|
|
|
Rectangle *bounds = [Rectangle rectangleWithCGRect:gameViewController.view.bounds];
|
|
|
|
float scale = [UIScreen mainScreen].scale;
|
|
|
|
bounds.width *= scale;
|
|
|
|
bounds.height *= scale;
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
2010-07-22 16:13:55 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[clientBounds release];
|
|
|
|
[gameViewController release];
|
|
|
|
[window release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|