mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-03 00:18:28 +00:00
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:
@@ -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
|
||||
|
@@ -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)
|
||||
|
61
src/events/SDL_displayevents.c
Normal file
61
src/events/SDL_displayevents.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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: */
|
32
src/events/SDL_displayevents_c.h
Normal file
32
src/events/SDL_displayevents_c.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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: */
|
@@ -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"
|
||||
|
@@ -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));
|
||||
|
@@ -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:
|
||||
|
@@ -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 );
|
||||
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user