diff --git a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj index ee00dd906..df9f19b8b 100755 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj @@ -113,6 +113,9 @@ 93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */; }; A704172E20F7E74800A82227 /* controller_type.h in Headers */ = {isa = PBXBuildFile; fileRef = A704172D20F7E74800A82227 /* controller_type.h */; }; A704172F20F7E76000A82227 /* SDL_gamecontroller.c in Sources */ = {isa = PBXBuildFile; fileRef = AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */; }; + A7C19D29212E552C00DF2152 /* SDL_displayevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = A7C19D27212E552B00DF2152 /* SDL_displayevents_c.h */; }; + A7C19D2A212E552C00DF2152 /* SDL_displayevents.c in Sources */ = {isa = PBXBuildFile; fileRef = A7C19D28212E552B00DF2152 /* SDL_displayevents.c */; }; + A7C19D2B212E552C00DF2152 /* SDL_displayevents.c in Sources */ = {isa = PBXBuildFile; fileRef = A7C19D28212E552B00DF2152 /* SDL_displayevents.c */; }; A7F629241FE06523002F9CC9 /* SDL_uikitmetalview.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D7516F81EE1C28A00820EEA /* SDL_uikitmetalview.m */; }; AA0AD06216647BBB00CE5896 /* SDL_gamecontroller.c in Sources */ = {isa = PBXBuildFile; fileRef = AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */; }; AA0AD06516647BD400CE5896 /* SDL_gamecontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */; }; @@ -454,6 +457,8 @@ 93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitviewcontroller.h; sourceTree = ""; }; 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitviewcontroller.m; sourceTree = ""; }; A704172D20F7E74800A82227 /* controller_type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = controller_type.h; sourceTree = ""; }; + A7C19D27212E552B00DF2152 /* SDL_displayevents_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_displayevents_c.h; sourceTree = ""; }; + A7C19D28212E552B00DF2152 /* SDL_displayevents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_displayevents.c; sourceTree = ""; }; AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gamecontroller.c; sourceTree = ""; }; AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gamecontroller.h; sourceTree = ""; }; AA0F8494178D5F1A00823F9D /* SDL_systls.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_systls.c; sourceTree = ""; }; @@ -1109,6 +1114,8 @@ FD99B9920DD52EDC00FB1D6B /* scancodes_xfree86.h */, 0420496F11E6F03D007E7EC9 /* SDL_clipboardevents.c */, 0420496E11E6F03D007E7EC9 /* SDL_clipboardevents_c.h */, + A7C19D27212E552B00DF2152 /* SDL_displayevents_c.h */, + A7C19D28212E552B00DF2152 /* SDL_displayevents.c */, AA704DD5162AA90A0076D1C1 /* SDL_dropevents.c */, AA704DD4162AA90A0076D1C1 /* SDL_dropevents_c.h */, FD99B9930DD52EDC00FB1D6B /* SDL_events.c */, @@ -1326,6 +1333,7 @@ F30D9CA7212CD0BF0047DF2E /* SDL_coremotionsensor.h in Headers */, AA7558AF1595D55500BBD41B /* SDL_main.h in Headers */, AA7558B01595D55500BBD41B /* SDL_mouse.h in Headers */, + A7C19D29212E552C00DF2152 /* SDL_displayevents_c.h in Headers */, AA7558B11595D55500BBD41B /* SDL_mutex.h in Headers */, AA7558B21595D55500BBD41B /* SDL_name.h in Headers */, AA7558B31595D55500BBD41B /* SDL_opengl.h in Headers */, @@ -1557,6 +1565,7 @@ FAB598731BB5C31600BE72C5 /* SDL_iconv.c in Sources */, FAB598741BB5C31600BE72C5 /* SDL_malloc.c in Sources */, FAB598751BB5C31600BE72C5 /* SDL_qsort.c in Sources */, + A7C19D2B212E552C00DF2152 /* SDL_displayevents.c in Sources */, FAB598761BB5C31600BE72C5 /* SDL_stdlib.c in Sources */, FAB598771BB5C31600BE72C5 /* SDL_string.c in Sources */, FAB598781BB5C31600BE72C5 /* SDL_syscond.c in Sources */, @@ -1677,6 +1686,7 @@ FD689F1F0E26E5D900F90B21 /* SDL_uikitopengles.m in Sources */, FD689F210E26E5D900F90B21 /* SDL_uikitvideo.m in Sources */, FD689F230E26E5D900F90B21 /* SDL_uikitview.m in Sources */, + A7C19D2A212E552C00DF2152 /* SDL_displayevents.c in Sources */, FD689F250E26E5D900F90B21 /* SDL_uikitwindow.m in Sources */, FD689F270E26E5D900F90B21 /* SDL_uikitopenglview.m in Sources */, FD689FCE0E26E9D400F90B21 /* SDL_uikitappdelegate.m in Sources */, diff --git a/include/SDL_events.h b/include/SDL_events.h index 4cf1878ac..af22eb646 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -85,6 +85,9 @@ typedef enum Called on Android in onResume() */ + /* Display events */ + SDL_DISPLAYEVENT = 0x150, /**< Display state change */ + /* Window events */ SDL_WINDOWEVENT = 0x200, /**< Window state change */ SDL_SYSWMEVENT, /**< System specific event */ @@ -171,6 +174,21 @@ typedef struct SDL_CommonEvent Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ } SDL_CommonEvent; +/** + * \brief Display state change event data (event.display.*) + */ +typedef struct SDL_DisplayEvent +{ + Uint32 type; /**< ::SDL_DISPLAYEVENT */ + Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */ + Uint32 display; /**< The associated display index */ + Uint8 event; /**< ::SDL_DisplayEventID */ + Uint8 padding1; + Uint8 padding2; + Uint8 padding3; + Sint32 data1; /**< event dependent data */ +} SDL_DisplayEvent; + /** * \brief Window state change event data (event.window.*) */ @@ -540,6 +558,7 @@ typedef union SDL_Event { Uint32 type; /**< Event type, shared with all events */ SDL_CommonEvent common; /**< Common event data */ + SDL_DisplayEvent display; /**< Window event data */ SDL_WindowEvent window; /**< Window event data */ SDL_KeyboardEvent key; /**< Keyboard event data */ SDL_TextEditingEvent edit; /**< Text editing event data */ diff --git a/include/SDL_sensor.h b/include/SDL_sensor.h index a093056d5..5fd17519d 100644 --- a/include/SDL_sensor.h +++ b/include/SDL_sensor.h @@ -68,6 +68,51 @@ typedef enum SDL_SENSOR_GYRO, /**< Gyroscope */ } SDL_SensorType; +/** + * Accelerometer sensor + * + * The accelerometer returns the current acceleration in SI meters per + * second squared. This includes gravity, so a device at rest will have + * an acceleration of SDL_STANDARD_GRAVITY straight down. + * + * values[0]: Acceleration on the x axis + * values[1]: Acceleration on the y axis + * values[2]: Acceleration on the z axis + * + * For phones held in portrait mode, the axes are defined as follows: + * -X ... +X : left ... right + * -Y ... +Y : bottom ... top + * -Z ... +Z : farther ... closer + * + * The axis data is not changed when the phone is rotated. + * + * \sa SDL_GetDisplayOrientation() + */ +#define SDL_STANDARD_GRAVITY 9.80665f + +/** + * Gyroscope sensor + * + * The gyroscope returns the current rate of rotation in radians per second. + * The rotation is positive in the counter-clockwise direction. That is, + * an observer looking from a positive location on one of the axes would + * see positive rotation on that axis when it appeared to be rotating + * counter-clockwise. + * + * values[0]: Angular speed around the x axis + * values[1]: Angular speed around the y axis + * values[2]: Angular speed around the z axis + * + * For phones held in portrait mode, the axes are defined as follows: + * -X ... +X : left ... right + * -Y ... +Y : bottom ... top + * -Z ... +Z : farther ... closer + * + * The axis data is not changed when the phone is rotated. + * + * \sa SDL_GetDisplayOrientation() + */ + /* Function prototypes */ /** diff --git a/include/SDL_video.h b/include/SDL_video.h index 83f49faae..41ca07013 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -169,6 +169,24 @@ typedef enum SDL_WINDOWEVENT_HIT_TEST /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL. */ } SDL_WindowEventID; +/** + * \brief Event subtype for display events + */ +typedef enum +{ + SDL_DISPLAYEVENT_NONE, /**< Never used */ + SDL_DISPLAYEVENT_ORIENTATION, /**< Display orientation has changed to data1 */ +} SDL_DisplayEventID; + +typedef enum +{ + SDL_ORIENTATION_UNKNOWN, /**< The display orientation can't be determined */ + SDL_ORIENTATION_LANDSCAPE, /**< The display is in landscape mode, with the right side up, relative to portrait mode */ + SDL_ORIENTATION_LANDSCAPE_FLIPPED, /**< The display is in landscape mode, with the left side up, relative to portrait mode */ + SDL_ORIENTATION_PORTRAIT, /**< The display is in portrait mode */ + SDL_ORIENTATION_PORTRAIT_FLIPPED, /**< The display is in portrait mode, upside down */ +} SDL_DisplayOrientation; + /** * \brief An opaque handle to an OpenGL context. */ @@ -316,18 +334,6 @@ extern DECLSPEC const char * SDLCALL SDL_GetDisplayName(int displayIndex); */ extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect); -/** - * \brief Get the dots/pixels-per-inch for a display - * - * \note Diagonal, horizontal and vertical DPI can all be optionally - * returned if the parameter is non-NULL. - * - * \return 0 on success, or -1 if no DPI information is available or the index is out of range. - * - * \sa SDL_GetNumVideoDisplays() - */ -extern DECLSPEC int SDLCALL SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi); - /** * \brief Get the usable desktop area represented by a display, with the * primary display located at 0,0 @@ -347,6 +353,27 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayDPI(int displayIndex, float * ddpi, fl */ extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect); +/** + * \brief Get the dots/pixels-per-inch for a display + * + * \note Diagonal, horizontal and vertical DPI can all be optionally + * returned if the parameter is non-NULL. + * + * \return 0 on success, or -1 if no DPI information is available or the index is out of range. + * + * \sa SDL_GetNumVideoDisplays() + */ +extern DECLSPEC int SDLCALL SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi); + +/** + * \brief Get the orientation of a display + * + * \return The orientation of the display, or SDL_ORIENTATION_UNKNOWN if it isn't available. + * + * \sa SDL_GetNumVideoDisplays() + */ +extern DECLSPEC SDL_DisplayOrientation SDLCALL SDL_GetDisplayOrientation(int displayIndex); + /** * \brief Returns the number of available display modes. * diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index a58fe90fa..b1f029f37 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -695,3 +695,4 @@ #define SDL_SensorClose SDL_SensorClose_REAL #define SDL_SensorUpdate SDL_SensorUpdate_REAL #define SDL_IsTablet SDL_IsTablet_REAL +#define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 1bbc22810..6619f882a 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -737,3 +737,4 @@ SDL_DYNAPI_PROC(int,SDL_SensorGetData,(SDL_Sensor *a, float *b, int c),(a,b,c),r SDL_DYNAPI_PROC(void,SDL_SensorClose,(SDL_Sensor *a),(a),) SDL_DYNAPI_PROC(void,SDL_SensorUpdate,(void),(),) SDL_DYNAPI_PROC(SDL_bool,SDL_IsTablet,(void),(),return) +SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return) diff --git a/src/events/SDL_displayevents.c b/src/events/SDL_displayevents.c new file mode 100644 index 000000000..ba48541e0 --- /dev/null +++ b/src/events/SDL_displayevents.c @@ -0,0 +1,61 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../SDL_internal.h" + +/* Display event handling code for SDL */ + +#include "SDL_events.h" +#include "SDL_events_c.h" +#include "../video/SDL_sysvideo.h" + + +int +SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1) +{ + int posted; + + if (!display) { + return 0; + } + switch (displayevent) { + case SDL_DISPLAYEVENT_ORIENTATION: + if (data1 == SDL_ORIENTATION_UNKNOWN || data1 == display->orientation) { + return 0; + } + display->orientation = (SDL_DisplayOrientation)data1; + break; + } + + /* Post the event, if desired */ + posted = 0; + if (SDL_GetEventState(SDL_DISPLAYEVENT) == SDL_ENABLE) { + SDL_Event event; + event.type = SDL_DISPLAYEVENT; + event.display.event = displayevent; + event.display.display = SDL_GetIndexOfDisplay(display); + event.display.data1 = data1; + posted = (SDL_PushEvent(&event) > 0); + } + + return (posted); +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_displayevents_c.h b/src/events/SDL_displayevents_c.h new file mode 100644 index 000000000..72f8636b4 --- /dev/null +++ b/src/events/SDL_displayevents_c.h @@ -0,0 +1,32 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../SDL_internal.h" + +#ifndef SDL_displayevents_c_h_ +#define SDL_displayevents_c_h_ + +typedef struct SDL_VideoDisplay SDL_VideoDisplay; + +extern int SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1); + +#endif /* SDL_displayevents_c_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h index b1bd277e7..0f6b5bf4c 100644 --- a/src/events/SDL_events_c.h +++ b/src/events/SDL_events_c.h @@ -24,6 +24,7 @@ #include "SDL_events.h" #include "SDL_thread.h" #include "SDL_clipboardevents_c.h" +#include "SDL_displayevents_c.h" #include "SDL_dropevents_c.h" #include "SDL_gesture_c.h" #include "SDL_keyboard_c.h" diff --git a/src/sensor/coremotion/SDL_coremotionsensor.m b/src/sensor/coremotion/SDL_coremotionsensor.m index b384dbafc..526cce874 100644 --- a/src/sensor/coremotion/SDL_coremotionsensor.m +++ b/src/sensor/coremotion/SDL_coremotionsensor.m @@ -32,8 +32,6 @@ #include "../SDL_syssensor.h" #include "../SDL_sensor_c.h" -#define STANDARD_GRAVITY 9.80665f - typedef struct { SDL_SensorType type; @@ -160,9 +158,9 @@ SDL_COREMOTION_SensorUpdate(SDL_Sensor *sensor) if (accelerometerData) { CMAcceleration acceleration = accelerometerData.acceleration; float data[3]; - data[0] = acceleration.x * STANDARD_GRAVITY; - data[1] = acceleration.y * STANDARD_GRAVITY; - data[2] = acceleration.z * STANDARD_GRAVITY; + data[0] = acceleration.x * SDL_STANDARD_GRAVITY; + data[1] = acceleration.y * SDL_STANDARD_GRAVITY; + data[2] = acceleration.z * SDL_STANDARD_GRAVITY; if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) { SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data)); SDL_memcpy(sensor->hwdata->data, data, sizeof(data)); diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index a51274fe8..81dd39eb1 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -1048,6 +1048,22 @@ SDLTest_CommonInit(SDLTest_CommonState * state) return SDL_TRUE; } +static const char * +DisplayOrientationName(int orientation) +{ + switch (orientation) + { +#define CASE(X) case SDL_ORIENTATION_##X: return #X + CASE(UNKNOWN); + CASE(LANDSCAPE); + CASE(LANDSCAPE_FLIPPED); + CASE(PORTRAIT); + CASE(PORTRAIT_FLIPPED); +#undef CASE +default: return "???"; + } +} + static const char * ControllerAxisName(const SDL_GameControllerAxis axis) { @@ -1102,6 +1118,17 @@ SDLTest_PrintEvent(SDL_Event * event) } switch (event->type) { + case SDL_DISPLAYEVENT: + switch (event->display.event) { + case SDL_DISPLAYEVENT_ORIENTATION: + SDL_Log("SDL EVENT: Display %d changed orientation to %s", event->display.display, DisplayOrientationName(event->display.data1)); + break; + default: + SDL_Log("SDL EVENT: Display %d got unknown event 0x%4.4x", + event->display.display, event->display.event); + break; + } + break; case SDL_WINDOWEVENT: switch (event->window.event) { case SDL_WINDOWEVENT_SHOWN: diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 19e1682d1..25862ca1b 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -119,8 +119,8 @@ struct SDL_Window !((W)->flags & SDL_WINDOW_MINIMIZED)) /* - * Define the SDL display structure This corresponds to physical monitors - * attached to the system. + * Define the SDL display structure. + * This corresponds to physical monitors attached to the system. */ struct SDL_VideoDisplay { @@ -130,6 +130,7 @@ struct SDL_VideoDisplay SDL_DisplayMode *display_modes; SDL_DisplayMode desktop_mode; SDL_DisplayMode current_mode; + SDL_DisplayOrientation orientation; SDL_Window *fullscreen_window; @@ -180,16 +181,16 @@ struct SDL_VideoDevice */ int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); - /* - * Get the dots/pixels-per-inch of a display - */ - int (*GetDisplayDPI) (_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi); - /* * Get the usable bounds of a display (bounds minus menubar or whatever) */ int (*GetDisplayUsableBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); + /* + * Get the dots/pixels-per-inch of a display + */ + int (*GetDisplayDPI) (_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi); + /* * Get a list of the available display modes for a display. */ @@ -426,6 +427,8 @@ extern SDL_VideoDevice *SDL_GetVideoDevice(void); extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode); extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display); extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode); +extern int SDL_GetIndexOfDisplay(SDL_VideoDisplay *display); +extern SDL_VideoDisplay *SDL_GetDisplay(int displayIndex); extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window); extern void *SDL_GetDisplayDriverData( int displayIndex ); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 0f44a9c3b..ef661bf1e 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -641,7 +641,7 @@ SDL_GetNumVideoDisplays(void) return _this->num_displays; } -static int +int SDL_GetIndexOfDisplay(SDL_VideoDisplay *display) { int displayIndex; @@ -739,6 +739,17 @@ SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi) return -1; } +SDL_DisplayOrientation +SDL_GetDisplayOrientation(int displayIndex) +{ + SDL_VideoDisplay *display; + + CHECK_DISPLAY_INDEX(displayIndex, SDL_ORIENTATION_UNKNOWN); + + display = &_this->displays[displayIndex]; + return display->orientation; +} + SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) { @@ -1009,6 +1020,14 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * return 0; } +SDL_VideoDisplay * +SDL_GetDisplay(int displayIndex) +{ + CHECK_DISPLAY_INDEX(displayIndex, NULL); + + return &_this->displays[displayIndex]; +} + int SDL_GetWindowDisplayIndex(SDL_Window * window) { diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m index a942dfde0..3b1d101b1 100644 --- a/src/video/uikit/SDL_uikitappdelegate.m +++ b/src/video/uikit/SDL_uikitappdelegate.m @@ -451,6 +451,7 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh) if (_this && _this->num_displays > 0) { SDL_DisplayMode *desktopmode = &_this->displays[0].desktop_mode; SDL_DisplayMode *currentmode = &_this->displays[0].current_mode; + SDL_DisplayOrientation orientation = SDL_ORIENTATION_UNKNOWN; /* The desktop display mode should be kept in sync with the screen * orientation so that updating a window's fullscreen state to @@ -468,6 +469,26 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh) currentmode->w = currentmode->h; currentmode->h = height; } + + switch (application.statusBarOrientation) { + case UIInterfaceOrientationPortrait: + orientation = SDL_ORIENTATION_PORTRAIT; + break; + case UIInterfaceOrientationPortraitUpsideDown: + orientation = SDL_ORIENTATION_PORTRAIT_FLIPPED; + break; + case UIInterfaceOrientationLandscapeLeft: + /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */ + orientation = SDL_ORIENTATION_LANDSCAPE_FLIPPED; + break; + case UIInterfaceOrientationLandscapeRight: + /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */ + orientation = SDL_ORIENTATION_LANDSCAPE; + break; + default: + break; + } + SDL_SendDisplayEvent(&_this->displays[0], SDL_DISPLAYEVENT_ORIENTATION, orientation); } } #endif