2013-02-07 08:58:36 -05:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2013-2014 - Jason Fetters
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
2013-02-07 08:58:36 -05:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-09-20 17:31:03 -04:00
|
|
|
#import <Availability.h>
|
2013-07-06 18:24:25 -04:00
|
|
|
#import "RetroArch_Apple.h"
|
2013-11-22 15:30:02 +01:00
|
|
|
#include "../../general.h"
|
2013-07-06 23:54:47 -04:00
|
|
|
|
2014-10-03 21:04:59 +02:00
|
|
|
/* Define compatibility symbols and categories. */
|
|
|
|
|
2014-11-18 18:11:01 +01:00
|
|
|
#if defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_4_0)
|
2013-12-01 19:31:00 +01:00
|
|
|
#include <AVFoundation/AVCaptureSession.h>
|
|
|
|
#include <AVFoundation/AVCaptureDevice.h>
|
|
|
|
#include <AVFoundation/AVCaptureOutput.h>
|
|
|
|
#include <AVFoundation/AVCaptureInput.h>
|
|
|
|
#include <AVFoundation/AVMediaFormat.h>
|
2014-11-18 18:04:17 +01:00
|
|
|
#ifdef HAVE_OPENGLES
|
2013-12-01 19:31:00 +01:00
|
|
|
#include <CoreVideo/CVOpenGLESTextureCache.h>
|
2014-11-18 18:04:17 +01:00
|
|
|
#else
|
|
|
|
#include <CoreVideo/CVOpenGLTexture.h>
|
|
|
|
#endif
|
2014-01-06 16:27:30 +01:00
|
|
|
#endif
|
|
|
|
|
2014-11-18 18:04:17 +01:00
|
|
|
#if defined(OSX)
|
2014-10-03 21:04:59 +02:00
|
|
|
|
|
|
|
/* RAGameView is a container on iOS;
|
|
|
|
* on OSX these are both the same object
|
|
|
|
*/
|
|
|
|
#define g_view g_instance
|
2013-09-13 16:22:04 -04:00
|
|
|
|
2014-11-18 18:04:17 +01:00
|
|
|
#elif defined(IOS)
|
2013-09-13 16:22:04 -04:00
|
|
|
|
2013-11-22 15:30:02 +01:00
|
|
|
#include <GLKit/GLKit.h>
|
2014-05-03 19:12:00 +02:00
|
|
|
#include "../iOS/views.h"
|
2014-05-03 19:14:19 +02:00
|
|
|
#define ALMOST_INVISIBLE (.021f)
|
|
|
|
static GLKView *g_view;
|
|
|
|
static UIView *g_pause_indicator_view;
|
2013-07-06 23:54:47 -04:00
|
|
|
#endif
|
|
|
|
|
2013-09-13 16:22:04 -04:00
|
|
|
static RAGameView* g_instance;
|
2013-07-06 23:54:47 -04:00
|
|
|
|
2014-10-03 21:57:53 +02:00
|
|
|
#include "apple_gfx_context.c.inl"
|
|
|
|
|
2013-02-13 18:18:55 -05:00
|
|
|
@implementation RAGameView
|
2013-03-05 00:14:26 -05:00
|
|
|
+ (RAGameView*)get
|
|
|
|
{
|
|
|
|
if (!g_instance)
|
|
|
|
g_instance = [RAGameView new];
|
|
|
|
|
|
|
|
return g_instance;
|
2013-02-07 12:05:46 -05:00
|
|
|
}
|
|
|
|
|
2013-07-06 23:54:47 -04:00
|
|
|
- (id)init
|
|
|
|
{
|
2013-08-15 19:28:51 -04:00
|
|
|
self = [super init];
|
2014-10-03 21:00:54 +02:00
|
|
|
|
|
|
|
#if defined(OSX)
|
2013-12-14 20:35:47 -05:00
|
|
|
[self setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
2014-10-03 21:00:54 +02:00
|
|
|
#elif defined(IOS)
|
|
|
|
/* iOS Pause menu and lifecycle. */
|
|
|
|
UINib *xib = (UINib*)[UINib nibWithNibName:BOXSTRING("PauseIndicatorView") bundle:nil];
|
|
|
|
g_pause_indicator_view = [[xib instantiateWithOwner:[RetroArch_iOS get] options:nil] lastObject];
|
|
|
|
|
|
|
|
g_view = [GLKView new];
|
|
|
|
g_view.multipleTouchEnabled = YES;
|
|
|
|
g_view.enableSetNeedsDisplay = NO;
|
|
|
|
[g_view addSubview:g_pause_indicator_view];
|
|
|
|
|
|
|
|
self.view = g_view;
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showPauseIndicator) name:UIApplicationWillEnterForegroundNotification object:nil];
|
|
|
|
#endif
|
|
|
|
|
2013-07-06 23:54:47 -04:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-10-03 21:00:54 +02:00
|
|
|
#ifdef OSX
|
|
|
|
|
2014-10-03 21:47:46 +02:00
|
|
|
static void apple_gfx_ctx_update(void);
|
|
|
|
|
2013-08-15 19:28:51 -04:00
|
|
|
- (void)setFrame:(NSRect)frameRect
|
|
|
|
{
|
|
|
|
[super setFrame:frameRect];
|
|
|
|
|
2014-10-03 21:47:46 +02:00
|
|
|
apple_gfx_ctx_update();
|
2013-08-15 19:28:51 -04:00
|
|
|
}
|
|
|
|
|
2014-10-03 21:04:59 +02:00
|
|
|
/* Stop the annoying sound when pressing a key. */
|
2013-07-07 16:01:58 -04:00
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2013-08-11 00:20:15 -04:00
|
|
|
- (BOOL)isFlipped
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2013-07-07 16:01:58 -04:00
|
|
|
- (void)keyDown:(NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-01 17:06:44 +01:00
|
|
|
#elif defined(IOS)
|
2013-12-31 12:52:24 -05:00
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
{
|
2014-10-03 21:04:59 +02:00
|
|
|
/* Pause Menus. */
|
2013-12-31 12:52:24 -05:00
|
|
|
[self showPauseIndicator];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showPauseIndicator
|
|
|
|
{
|
|
|
|
g_pause_indicator_view.alpha = 1.0f;
|
|
|
|
[NSObject cancelPreviousPerformRequestsWithTarget:g_instance];
|
|
|
|
[g_instance performSelector:@selector(hidePauseButton) withObject:g_instance afterDelay:3.0f];
|
|
|
|
}
|
|
|
|
|
2013-03-05 00:14:26 -05:00
|
|
|
- (void)viewWillLayoutSubviews
|
|
|
|
{
|
|
|
|
UIInterfaceOrientation orientation = self.interfaceOrientation;
|
|
|
|
CGRect screenSize = [[UIScreen mainScreen] bounds];
|
2014-07-09 13:20:12 +02:00
|
|
|
float width = ((int)orientation < 3) ? CGRectGetWidth(screenSize) : CGRectGetHeight(screenSize);
|
|
|
|
float height = ((int)orientation < 3) ? CGRectGetHeight(screenSize) : CGRectGetWidth(screenSize);
|
|
|
|
float tenpctw = width / 10.0f;
|
|
|
|
float tenpcth = height / 10.0f;
|
2013-03-05 00:14:26 -05:00
|
|
|
|
2013-03-20 20:54:38 -04:00
|
|
|
g_pause_indicator_view.frame = CGRectMake(tenpctw * 4.0f, 0.0f, tenpctw * 2.0f, tenpcth);
|
2013-05-27 13:04:00 -04:00
|
|
|
[g_pause_indicator_view viewWithTag:1].frame = CGRectMake(0, 0, tenpctw * 2.0f, tenpcth);
|
2013-03-05 00:14:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)hidePauseButton
|
|
|
|
{
|
|
|
|
[UIView animateWithDuration:0.2
|
2013-06-21 23:39:01 -04:00
|
|
|
animations:^{ g_pause_indicator_view.alpha = ALMOST_INVISIBLE; }
|
|
|
|
completion:^(BOOL finished) { }
|
|
|
|
];
|
2013-03-05 00:14:26 -05:00
|
|
|
}
|
|
|
|
|
2014-10-03 21:04:59 +02:00
|
|
|
/* NOTE: This version runs on iOS6+. */
|
2013-12-20 19:20:01 -05:00
|
|
|
- (NSUInteger)supportedInterfaceOrientations
|
|
|
|
{
|
|
|
|
return apple_frontend_settings.orientation_flags;
|
|
|
|
}
|
|
|
|
|
2014-10-03 21:04:59 +02:00
|
|
|
/* NOTE: This version runs on iOS2-iOS5, but not iOS6+. */
|
2013-12-20 19:20:01 -05:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
|
|
|
{
|
|
|
|
switch (interfaceOrientation)
|
|
|
|
{
|
|
|
|
case UIInterfaceOrientationPortrait:
|
|
|
|
return (apple_frontend_settings.orientation_flags & UIInterfaceOrientationMaskPortrait);
|
|
|
|
case UIInterfaceOrientationPortraitUpsideDown:
|
|
|
|
return (apple_frontend_settings.orientation_flags & UIInterfaceOrientationMaskPortraitUpsideDown);
|
|
|
|
case UIInterfaceOrientationLandscapeLeft:
|
|
|
|
return (apple_frontend_settings.orientation_flags & UIInterfaceOrientationMaskLandscapeLeft);
|
|
|
|
case UIInterfaceOrientationLandscapeRight:
|
|
|
|
return (apple_frontend_settings.orientation_flags & UIInterfaceOrientationMaskLandscapeRight);
|
2014-09-20 17:31:03 -04:00
|
|
|
|
2014-11-09 17:38:26 +01:00
|
|
|
default:
|
2014-09-20 17:31:03 -04:00
|
|
|
return (apple_frontend_settings.orientation_flags & UIInterfaceOrientationMaskAll);
|
2013-12-20 19:20:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2013-07-06 23:54:47 -04:00
|
|
|
#endif
|
2013-04-03 11:48:24 -04:00
|
|
|
|
2014-11-18 18:11:01 +01:00
|
|
|
#if defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_4_0)
|
2014-11-18 18:04:17 +01:00
|
|
|
#include "contentview_camera_ios.m.inl"
|
2014-01-06 16:27:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCATION
|
2014-07-09 13:27:30 +02:00
|
|
|
#include "contentview_location.m.inl"
|
2014-01-06 16:27:30 +01:00
|
|
|
#endif
|
2013-12-25 05:04:18 +01:00
|
|
|
|
2013-03-05 00:14:26 -05:00
|
|
|
@end
|
|
|
|
|
2014-11-18 18:11:01 +01:00
|
|
|
#if defined(MAC_OS_X_VERSION_10_7) || defined(__IPHONE_4_0)
|
2014-07-09 12:56:29 +02:00
|
|
|
#include "apple_camera_ios.c.inl"
|
2013-07-07 23:17:38 +02:00
|
|
|
#endif
|
2013-12-19 02:39:06 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_LOCATION
|
2014-07-09 12:56:29 +02:00
|
|
|
#include "apple_location.c.inl"
|
2013-12-19 03:37:26 +01:00
|
|
|
#endif
|