Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merged with latest SDL2 sources
  • Loading branch information
DavidLudwig committed Sep 1, 2012
2 parents 9894b5b + 58b0ae5 commit 2b4c041
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.iOS
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_syswm.h
Expand Up @@ -92,6 +92,7 @@ typedef struct _NSWindow NSWindow;
#include <UIKit/UIKit.h>
#else
typedef struct _UIWindow UIWindow;
typedef struct _UIViewController UIViewController;
#endif
#endif

Expand Down Expand Up @@ -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 */
Expand Down
17 changes: 16 additions & 1 deletion src/video/uikit/SDL_uikitevents.m
Expand Up @@ -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);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -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];
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 2b4c041

Please sign in to comment.