iPhone screen orientation hint (patch included)
Tim Angus <tim <at> ngus.net>
2011-06-01 15:02:14 GMT
For a title I'm developing, the default behaviour of allowing either
both portrait orientations or both landscape orientatins doesn't really
work to the point where it makes the game unplayable. Setting
SDL_WINDOW_RESIZABLE and enabling all rotations makes the problem worse.
Really what I want to do is restrict which orientations are allowable.
I've banged together a patch (attached) to do this using the hint API.
In my particular case I want portrait only:
SDL_SetHint( "SDL_HINT_ORIENTATIONS", "Portrait" );
The second parameter is a space delimited list of the orientations
required. If you wanted all orientations then you would call:
SDL_SetHint( "SDL_HINT_ORIENTATIONS", "Portrait PortraitUpsideDown
LandscapeLeft LandscapeRight" );
I think this is a fairly important bit of functionality to have, so it
would be nice to see it committed at some point. Does anybody have any
comments/objections/suggestions? If not I'll punt it into bugzilla...
diff -r cd2167525827 src/video/uikit/SDL_uikitwindow.m
--- a/src/video/uikit/SDL_uikitwindow.m Fri Apr 22 09:06:29 2011 -0700
+++ b/src/video/uikit/SDL_uikitwindow.m Wed Jun 01 15:49:05 2011 +0100
<at> <at> -24,6 +24,7 <at> <at>
#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"
<at> <at> -48,6 +49,37 <at> <at>
}
- (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: <at> " "]];
+
+ switch (orient) {
+ case UIInterfaceOrientationLandscapeLeft:
+ rotate = [orientations containsObject: <at> "LandscapeLeft"];
+ break;
+
+ case UIInterfaceOrientationLandscapeRight:
+ rotate = [orientations containsObject: <at> "LandscapeRight"];
+ break;
+
+ case UIInterfaceOrientationPortrait:
+ rotate = [orientations containsObject: <at> "Portrait"];
+ break;
+
+ case UIInterfaceOrientationPortraitUpsideDown:
+ rotate = [orientations containsObject: <at> "PortraitUpsideDown"];
+ break;
+
+ default: break;
+ }
+
+ return rotate;
+ }
+
if (self->window->flags & SDL_WINDOW_RESIZABLE) {
return YES; // any orientation is okay.
}
_______________________________________________
SDL mailing list
SDL <at> lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org