Permalink
Browse files

[ios/atv2/tvout] - move m_window from app to xbmccontroller on ios (s…

…ame as with atv2 before). Use screenmanager for handling screen/resolution changes
  • Loading branch information...
1 parent 7c1c44b commit 8996429d59e6f887d8ee3142eb562f7b4e44cff7 @Memphiz committed Apr 8, 2012
@@ -21,13 +21,16 @@
#import <Foundation/Foundation.h>
#import <BackRow/BackRow.h>
-#import "XBMCEAGLView.h"
+#import "IOSEAGLView.h"
+#import "IOSSCreenManager.h"
+#include "XBMC_keysym.h"
@interface XBMCController : BRController
{
int padding[16]; // credit is due here to SapphireCompatibilityClasses!!
int m_screensaverTimeout;
+
BRController *m_controller;
}
// message from which our instance is obtained
@@ -40,10 +43,18 @@
- (void) setFramebuffer;
- (bool) presentFramebuffer;
- (CGSize) getScreenSize;
+- (void) sendKey: (XBMCKey) key;
- (void) disableSystemSleep;
- (void) enableSystemSleep;
- (void) disableScreenSaver;
- (void) enableScreenSaver;
+- (void) pauseAnimation;
+- (void) resumeAnimation;
+- (void) startAnimation;
+- (void) stopAnimation;
+- (bool) changeScreen: (unsigned int)screenIdx withMode:(UIScreenMode *)mode;
+- (void) activateScreen: (UIScreen *)screen;
+
@end
@@ -25,14 +25,17 @@
#import "WinEventsIOS.h"
#import "XBMC_events.h"
#include "utils/log.h"
+#include "osx/DarwinUtils.h"
+#include "threads/Event.h"
+#include "Application.h"
#undef BOOL
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <BackRow/BackRow.h>
#import "XBMCController.h"
-#import "XBMCEAGLView.h"
+#import "IOSEAGLView.h"
#import "XBMCDebugHelpers.h"
//start repeating after 0.5s
@@ -170,12 +173,12 @@ -(int)sleepTimeout;
// notification messages
extern NSString* kBRScreenSaverActivated;
extern NSString* kBRScreenSaverDismissed;
-
//--------------------------------------------------------------
//--------------------------------------------------------------
@interface XBMCController (PrivateMethods)
-XBMCEAGLView *m_glView;
NSTimer *m_keyTimer;
+IOSEAGLView *m_glView;
+
int m_screensaverTimeout;
int m_systemsleepTimeout;
@@ -188,6 +191,7 @@ - (void) setUserEvent:(int) id withHoldTime:(unsigned int) holdTime;
//
//
@implementation XBMCController
+
/*
+ (XBMCController*) sharedInstance
{
@@ -244,6 +248,11 @@ - (CGSize) getScreenSize
return screensize;
}
+- (void) sendKey: (XBMCKey) key
+{
+ //empty because its not used here. Only implemented for getting rid
+ //of "may not respond to selector" compile warnings in IOSExternalTouchController
+}
- (id) init
@@ -262,11 +271,9 @@ - (id) init
selector: @selector(observeDefaultCenterStuff:)
name: nil
object: nil];
-
- CGRect interfaceFrame = [BRWindow interfaceFrame];
- NSLog(@"XBMC: interfaceFrame: %f, %f, %f, %f", interfaceFrame.origin.x, interfaceFrame.origin.y, interfaceFrame.size.width, interfaceFrame.size.height);
- //init glview with interfaceframe (might be more the resolution - ios scales for us)
- m_glView = [[XBMCEAGLView alloc] initWithFrame:interfaceFrame];
+
+ m_glView = [[IOSEAGLView alloc] initWithFrame:[BRWindow interfaceFrame] withScreen:[UIScreen mainScreen]];
+ [[IOSScreenManager sharedInstance] setView:m_glView];
g_xbmcController = self;
@@ -279,6 +286,7 @@ - (void)dealloc
[m_glView stopAnimation];
[m_glView release];
+
NSNotificationCenter *center;
// take us off the default center for our app
center = [NSNotificationCenter defaultCenter];
@@ -1021,5 +1029,53 @@ - (XBMC_Event) translateCocoaToXBMCEvent: (unichar) c
return newEvent;
}
+//--------------------------------------------------------------
+- (void)pauseAnimation
+{
+ XBMC_Event newEvent;
+ memset(&newEvent, 0, sizeof(XBMC_Event));
+
+ newEvent.appcommand.type = XBMC_APPCOMMAND;
+ newEvent.appcommand.action = ACTION_PLAYER_PLAYPAUSE;
+ CWinEventsIOS::MessagePush(&newEvent);
+
+ /* Give player time to pause */
+ Sleep(2000);
+ //NSLog(@"%s", __PRETTY_FUNCTION__);
+
+ [m_glView pauseAnimation];
+
+}
+//--------------------------------------------------------------
+- (void)resumeAnimation
+{
+ XBMC_Event newEvent;
+ memset(&newEvent, 0, sizeof(XBMC_Event));
+
+ newEvent.appcommand.type = XBMC_APPCOMMAND;
+ newEvent.appcommand.action = ACTION_PLAYER_PLAY;
+ CWinEventsIOS::MessagePush(&newEvent);
+
+ [m_glView resumeAnimation];
+}
+//--------------------------------------------------------------
+- (void)startAnimation
+{
+ [m_glView startAnimation];
+}
+//--------------------------------------------------------------
+- (void)stopAnimation
+{
+ [m_glView stopAnimation];
+}
+//--------------------------------------------------------------
+- (bool) changeScreen: (unsigned int)screenIdx withMode:(UIScreenMode *)mode
+{
+ return [[IOSScreenManager sharedInstance] changeScreen: screenIdx withMode: mode];
+}
+//--------------------------------------------------------------
+- (void) activateScreen: (UIScreen *)screen
+{
+}
@end
@@ -24,4 +24,3 @@
@interface XBMCApplicationDelegate : NSObject <UIApplicationDelegate> {
}
@end
-
@@ -23,10 +23,10 @@
#import "XBMCApplication.h"
#import "XBMCController.h"
+#import "IOSScreenManager.h"
@implementation XBMCApplicationDelegate
XBMCController *m_xbmcController;
-UIWindow *m_window;
- (void)applicationWillResignActive:(UIApplication *)application
{
@@ -53,33 +53,53 @@ - (void)applicationWillEnterForeground:(UIApplication *)application
[m_xbmcController resumeAnimation];
}
-- (void)applicationDidFinishLaunching:(UIApplication *)application
+- (void)screenDidConnect:(NSNotification *)aNotification
{
- [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
-
- m_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ [IOSScreenManager updateResolutions];
+}
- /* Turn off autoresizing */
- m_window.autoresizingMask = 0;
- m_window.autoresizesSubviews = NO;
+- (void)screenDidDisconnect:(NSNotification *)aNotification
+{
+ [IOSScreenManager updateResolutions];
+ //switch back to mainscreen when external screen is removed
+ [[IOSScreenManager sharedInstance] screenDisconnect];
+}
- m_xbmcController = [[XBMCController alloc] initWithFrame: [m_window bounds]];
- m_xbmcController.wantsFullScreenLayout = YES;
-
- //m_window.rootViewController = m_xbmcController;
-
- [m_window addSubview: m_xbmcController.view];
- [m_window makeKeyAndVisible];
+- (void)registerScreenNotifications:(BOOL)bRegister
+{
+ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
+ if( bRegister )
+ {
+ //register to screen notifications
+ [nc addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];
+ [nc addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];
+ }
+ else
+ {
+ //deregister from screen notifications
+ [nc removeObserver:self name:UIScreenDidConnectNotification object:nil];
+ [nc removeObserver:self name:UIScreenDidDisconnectNotification object:nil];
+ }
+}
+
+- (void)applicationDidFinishLaunching:(UIApplication *)application
+{
+ [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
+ UIScreen *currentScreen = [UIScreen mainScreen];
+
+ m_xbmcController = [[XBMCController alloc] initWithFrame: [currentScreen bounds] withScreen:currentScreen];
+ m_xbmcController.wantsFullScreenLayout = YES;
[m_xbmcController startAnimation];
+ [self registerScreenNotifications:YES];
}
- (void)dealloc
{
+ [self registerScreenNotifications:NO];
[m_xbmcController stopAnimation];
[m_xbmcController release];
- [m_window release];
-
+
[super dealloc];
}
@end
@@ -26,7 +26,6 @@
#import "XBMC_events.h"
#include "XBMC_keysym.h"
-
@interface XBMCController : UIViewController
{
int m_screensaverTimeout;
@@ -38,7 +37,8 @@
CGFloat currentPinchScale;
CGFloat screenScale;
bool touchBeginSignaled;
-
+ int m_screenIdx;
+
UIInterfaceOrientation orientation;
XBMC_Event lastEvent;
@@ -49,6 +49,7 @@
@property CGFloat currentPinchScale;
@property CGFloat screenScale;
@property bool touchBeginSignaled;
+@property int m_screenIdx;
@property CGSize screensize;
@property XBMC_Event lastEvent;
@@ -66,11 +67,15 @@
- (bool) presentFramebuffer;
- (CGSize) getScreenSize;
- (UIInterfaceOrientation) getOrientation;
-- (void)createGestureRecognizers;
+- (void) createGestureRecognizers;
+
- (void) disableSystemSleep;
- (void) enableSystemSleep;
- (void) disableScreenSaver;
- (void) enableScreenSaver;
+- (bool) changeScreen: (unsigned int)screenIdx withMode:(UIScreenMode *)mode;
+- (void) activateScreen: (UIScreen *)screen;
+- (id) initWithFrame:(CGRect)frame withScreen:(UIScreen *)screen;
@end
extern XBMCController *g_xbmcController;
Oops, something went wrong.

0 comments on commit 8996429

Please sign in to comment.