Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merged with latest SDL2 sources

  • Loading branch information
DavidLudwig committed Sep 1, 2012
2 parents 9894b5b + 58b0ae5 commit 2b4c04162315f4fd818b1b60686d011a8ee6eda4
Showing with 38 additions and 3 deletions.
  1. +3 −2 README.iOS
  2. +2 −0 include/SDL_syswm.h
  3. +16 −1 src/video/uikit/SDL_uikitevents.m
  4. +12 −0 src/video/uikit/SDL_uikitview.m
  5. +5 −0 src/video/uikit/SDL_uikitwindow.m
@@ -51,8 +51,9 @@ Here is a more manual method:
1. Create a new iPhone view based application.
2. Build the SDL static libraries (libSDL.a and libSDLSimulator.a) for iPhone and include them in your project. XCode will ignore the library that is not currently of the correct architecture, hence your app will work both on iPhone and in the iPhone Simulator.
3. Include the SDL header files in your project.
4. Remove the ApplicationDelegate.h and ApplicationDelegate.m files -- SDL for iPhone provides its own UIApplicationDelegate. Remove MainWindow.xib -- SDL for iPhone produces its user interface programmatically.
5. Delete the contents of main.m and program your app as a regular SDL program instead. You may replace main.m with your own main.c, but you must tell XCode not to use the project prefix file, as it includes Objective-C code.
4. Remove the AppDelegate.h and AppDelegate.m files -- SDL for iPhone provides its own UIApplicationDelegate. Remove ViewController.h, ViewController.m, and ViewController.xib -- SDL for iPhone produces its user interface programmatically.
5. Make sure your project links to the following, iOS-provided frameworks: OpenGLES.framework, AudioToolbox.framework, and QuartzCore.framework
6. Delete the contents of main.m and program your app as a regular SDL program instead. You may replace main.m with your own main.c, but you must tell XCode not to use the project prefix file, as it includes Objective-C code.

==============================================================================
Notes -- Accelerometer as Joystick
@@ -92,6 +92,7 @@ typedef struct _NSWindow NSWindow;
#include <UIKit/UIKit.h>
#else
typedef struct _UIWindow UIWindow;
typedef struct _UIViewController UIViewController;
#endif
#endif

@@ -195,6 +196,7 @@ struct SDL_SysWMinfo
struct
{
UIWindow *window; /* The UIKit window */
UIViewController *viewcontroller; /* The UIKit view controller */
} uikit;
#endif
/* Can't have an empty union */
@@ -57,10 +57,25 @@ So what we do is that in the UIApplicationDelegate class (SDLUIApplicationDelega
*/
if (setjmp(*jump_env()) == 0) {
/* if we're setting the jump, rather than jumping back */

/* Let the run loop run for a short amount of time: long enough for
touch events to get processed (which is important to get certain
elements of Game Center's GKLeaderboardViewController to respond
to touch input), but not long enough to introduce a significant
delay in the rest of the app.
*/
const CFTimeInterval seconds = 0.000002;

/* Pump most event types. */
SInt32 result;
do {
result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);
result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, seconds, TRUE);
} while (result == kCFRunLoopRunHandledSource);

/* Make sure UIScrollView objects scroll properly. */
do {
result = CFRunLoopRunInMode((CFStringRef)UITrackingRunLoopMode, seconds, TRUE);
} while(result == kCFRunLoopRunHandledSource);
}
}

@@ -94,6 +94,12 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

if (touch) {
CGPoint locationInView = [touch locationInView: self];

/* Make sure UIView points are converted to screen pixels: */
if ([self respondsToSelector:@selector(contentScaleFactor)]) {
locationInView.x *= self.contentScaleFactor;
locationInView.y *= self.contentScaleFactor;
}

/* send moved event */
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
@@ -184,6 +190,12 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

if (touch) {
CGPoint locationInView = [touch locationInView: self];

/* Make sure UIView points are converted to screen pixels: */
if ([self respondsToSelector:@selector(contentScaleFactor)]) {
locationInView.x *= self.contentScaleFactor;
locationInView.y *= self.contentScaleFactor;
}

/* send moved event */
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
@@ -199,6 +199,9 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
if (external) {
[uiwindow setScreen:data->uiscreen];
}

// Make sure the native window gets displayed.
[uiwindow makeKeyAndVisible];

if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
[uiwindow release];
@@ -282,10 +285,12 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo
UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
{
UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
UIViewController *uiviewcontroller = ((SDL_WindowData *) window->driverdata)->viewcontroller;

if (info->version.major <= SDL_MAJOR_VERSION) {
info->subsystem = SDL_SYSWM_UIKIT;
info->info.uikit.window = uiwindow;
info->info.uikit.viewcontroller = uiviewcontroller;
return SDL_TRUE;
} else {
SDL_SetError("Application not compiled with SDL %d.%d\n",

0 comments on commit 2b4c041

Please sign in to comment.