Added SDL_GetDisplayOrientation() to get the display orientation, and added a new event SDL_DISPLAYEVENT to notify the application when the orientation changes.

Documented the values returned by the accelerometer and gyroscope sensors
This commit is contained in:
Sam Lantinga
2018-08-22 21:48:28 -07:00
parent f1bc1c1274
commit f225af0c1e
14 changed files with 290 additions and 25 deletions

View File

@@ -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 );

View File

@@ -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)
{

View File

@@ -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