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

Commit

Permalink
* SDL_IOS_ORIENTATIONS hint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Angus committed Jun 10, 2011
1 parent 1049c3b commit e1b5a1e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/SDL_hints.h
Expand Up @@ -118,6 +118,17 @@ extern "C" {
* By default SDL does not sync screen surface updates with vertical refresh.
*/
#define SDL_HINT_RENDER_VSYNC "SDL_RENDER_VSYNC"

/**
* \brief A variable controlling which orientations are allowed on iOS.
*
* In some circumstances it is necessary to be able to explicitly control
* which UI orientations are allowed.
*
* This variable is a space delimited list of the following values:
* "LandscapeLeft", "LandscapeRight", "Portrait" "PortraitUpsideDown"
*/
#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"


/**
Expand Down
32 changes: 32 additions & 0 deletions src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -24,6 +24,7 @@
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_assert.h"
#include "SDL_hints.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Expand All @@ -48,6 +49,37 @@ - (id)initWithSDLWindow:(SDL_Window *)_window {
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
const char *orientationsCString;
if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
BOOL rotate = NO;
NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
encoding:NSUTF8StringEncoding];
NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@" "]];

switch (orient) {
case UIInterfaceOrientationLandscapeLeft:
rotate = [orientations containsObject:@"LandscapeLeft"];
break;

case UIInterfaceOrientationLandscapeRight:
rotate = [orientations containsObject:@"LandscapeRight"];
break;

case UIInterfaceOrientationPortrait:
rotate = [orientations containsObject:@"Portrait"];
break;

case UIInterfaceOrientationPortraitUpsideDown:
rotate = [orientations containsObject:@"PortraitUpsideDown"];
break;

default: break;
}

return rotate;
}

if (self->window->flags & SDL_WINDOW_RESIZABLE) {
return YES; // any orientation is okay.
}
Expand Down

0 comments on commit e1b5a1e

Please sign in to comment.