Fixed line endings on WinRT source code

This commit is contained in:
Sam Lantinga 2014-03-09 11:06:11 -07:00
parent 61ae0c1b50
commit 05c23063bb
35 changed files with 11262 additions and 11262 deletions

View File

@ -166,9 +166,9 @@ typedef unsigned int uintptr_t;
#define SDL_VIDEO_DRIVER_WINRT 1 #define SDL_VIDEO_DRIVER_WINRT 1
#define SDL_VIDEO_DRIVER_DUMMY 1 #define SDL_VIDEO_DRIVER_DUMMY 1
/* Enable OpenGL ES 2.0 (via a modified ANGLE library) */ /* Enable OpenGL ES 2.0 (via a modified ANGLE library) */
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP /* TODO, WinRT: try adding OpenGL ES 2 support for Windows Phone 8 */ #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP /* TODO, WinRT: try adding OpenGL ES 2 support for Windows Phone 8 */
#define SDL_VIDEO_OPENGL_ES2 1 #define SDL_VIDEO_OPENGL_ES2 1
#define SDL_VIDEO_OPENGL_EGL 1 #define SDL_VIDEO_OPENGL_EGL 1
#endif #endif

View File

@ -393,8 +393,8 @@ typedef enum {
#if __WINRT__ #if __WINRT__
#include <Unknwn.h> #include <Unknwn.h>
typedef IUnknown * EGLNativeWindowType; typedef IUnknown * EGLNativeWindowType;
typedef int EGLNativeDisplayType; typedef int EGLNativeDisplayType;
typedef HBITMAP EGLNativePixmapType; typedef HBITMAP EGLNativePixmapType;
#else #else
typedef HDC EGLNativeDisplayType; typedef HDC EGLNativeDisplayType;

View File

@ -140,7 +140,7 @@ extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
* \ret 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more * \ret 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more
* information on the failure. * information on the failure.
*/ */
extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel); extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel);
#endif /* __WINRT__ */ #endif /* __WINRT__ */

View File

@ -1,168 +1,168 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
/** /**
* \file SDL_platform.h * \file SDL_platform.h
* *
* Try to get a standard set of platform defines. * Try to get a standard set of platform defines.
*/ */
#ifndef _SDL_platform_h #ifndef _SDL_platform_h
#define _SDL_platform_h #define _SDL_platform_h
#if defined(_AIX) #if defined(_AIX)
#undef __AIX__ #undef __AIX__
#define __AIX__ 1 #define __AIX__ 1
#endif #endif
#if defined(__HAIKU__) #if defined(__HAIKU__)
#undef __HAIKU__ #undef __HAIKU__
#define __HAIKU__ 1 #define __HAIKU__ 1
#endif #endif
#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__) #if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
#undef __BSDI__ #undef __BSDI__
#define __BSDI__ 1 #define __BSDI__ 1
#endif #endif
#if defined(_arch_dreamcast) #if defined(_arch_dreamcast)
#undef __DREAMCAST__ #undef __DREAMCAST__
#define __DREAMCAST__ 1 #define __DREAMCAST__ 1
#endif #endif
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
#undef __FREEBSD__ #undef __FREEBSD__
#define __FREEBSD__ 1 #define __FREEBSD__ 1
#endif #endif
#if defined(hpux) || defined(__hpux) || defined(__hpux__) #if defined(hpux) || defined(__hpux) || defined(__hpux__)
#undef __HPUX__ #undef __HPUX__
#define __HPUX__ 1 #define __HPUX__ 1
#endif #endif
#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE) #if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
#undef __IRIX__ #undef __IRIX__
#define __IRIX__ 1 #define __IRIX__ 1
#endif #endif
#if defined(linux) || defined(__linux) || defined(__linux__) #if defined(linux) || defined(__linux) || defined(__linux__)
#undef __LINUX__ #undef __LINUX__
#define __LINUX__ 1 #define __LINUX__ 1
#endif #endif
#if defined(ANDROID) #if defined(ANDROID)
#undef __ANDROID__ #undef __ANDROID__
#undef __LINUX__ /* do we need to do this? */ #undef __LINUX__ /* do we need to do this? */
#define __ANDROID__ 1 #define __ANDROID__ 1
#endif #endif
#if defined(__APPLE__) #if defined(__APPLE__)
/* lets us know what version of Mac OS X we're compiling on */ /* lets us know what version of Mac OS X we're compiling on */
#include "AvailabilityMacros.h" #include "AvailabilityMacros.h"
#include "TargetConditionals.h" #include "TargetConditionals.h"
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
/* if compiling for iPhone */ /* if compiling for iPhone */
#undef __IPHONEOS__ #undef __IPHONEOS__
#define __IPHONEOS__ 1 #define __IPHONEOS__ 1
#undef __MACOSX__ #undef __MACOSX__
#else #else
/* if not compiling for iPhone */ /* if not compiling for iPhone */
#undef __MACOSX__ #undef __MACOSX__
#define __MACOSX__ 1 #define __MACOSX__ 1
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
# error SDL for Mac OS X only supports deploying on 10.5 and above. # error SDL for Mac OS X only supports deploying on 10.5 and above.
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */ #endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
# error SDL for Mac OS X must be built with a 10.6 SDK or above. # error SDL for Mac OS X must be built with a 10.6 SDK or above.
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */ #endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */
#endif /* TARGET_OS_IPHONE */ #endif /* TARGET_OS_IPHONE */
#endif /* defined(__APPLE__) */ #endif /* defined(__APPLE__) */
#if defined(__NetBSD__) #if defined(__NetBSD__)
#undef __NETBSD__ #undef __NETBSD__
#define __NETBSD__ 1 #define __NETBSD__ 1
#endif #endif
#if defined(__OpenBSD__) #if defined(__OpenBSD__)
#undef __OPENBSD__ #undef __OPENBSD__
#define __OPENBSD__ 1 #define __OPENBSD__ 1
#endif #endif
#if defined(__OS2__) #if defined(__OS2__)
#undef __OS2__ #undef __OS2__
#define __OS2__ 1 #define __OS2__ 1
#endif #endif
#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE) #if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
#undef __OSF__ #undef __OSF__
#define __OSF__ 1 #define __OSF__ 1
#endif #endif
#if defined(__QNXNTO__) #if defined(__QNXNTO__)
#undef __QNXNTO__ #undef __QNXNTO__
#define __QNXNTO__ 1 #define __QNXNTO__ 1
#endif #endif
#if defined(riscos) || defined(__riscos) || defined(__riscos__) #if defined(riscos) || defined(__riscos) || defined(__riscos__)
#undef __RISCOS__ #undef __RISCOS__
#define __RISCOS__ 1 #define __RISCOS__ 1
#endif #endif
#if defined(__SVR4) #if defined(__SVR4)
#undef __SOLARIS__ #undef __SOLARIS__
#define __SOLARIS__ 1 #define __SOLARIS__ 1
#endif #endif
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
/* Try to find out if we're compiling for WinRT or non-WinRT */ /* Try to find out if we're compiling for WinRT or non-WinRT */
#if defined(_MSC_VER) && (_MSC_VER >= 1700) /* _MSC_VER==1700 for MSVC 2012 */ #if defined(_MSC_VER) && (_MSC_VER >= 1700) /* _MSC_VER==1700 for MSVC 2012 */
#include <winapifamily.h> #include <winapifamily.h>
#endif /* _MSC_VER >= 1700 */ #endif /* _MSC_VER >= 1700 */
/* Default to classic, Win32/Win64/Desktop compilation either if: /* Default to classic, Win32/Win64/Desktop compilation either if:
1. the version of Windows is explicity set to a 'Desktop' (non-Metro) app 1. the version of Windows is explicity set to a 'Desktop' (non-Metro) app
2. the version of Windows cannot be determined via winapifamily.h 2. the version of Windows cannot be determined via winapifamily.h
If neither is true, then see if we're compiling for WinRT. If neither is true, then see if we're compiling for WinRT.
*/ */
#if ! defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if ! defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#undef __WINDOWS__ #undef __WINDOWS__
#define __WINDOWS__ 1 #define __WINDOWS__ 1
/* See if we're compiling for WinRT: */ /* See if we're compiling for WinRT: */
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#undef __WINRT__ #undef __WINRT__
#define __WINRT__ 1 #define __WINRT__ 1
#endif /* ! defined(WINAPI_FAMILY_PARTITION) */ #endif /* ! defined(WINAPI_FAMILY_PARTITION) */
#endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */ #endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
#undef __WIN32__ #undef __WIN32__
#define __WIN32__ 1 #define __WIN32__ 1
#endif #endif
#if defined(__PSP__) #if defined(__PSP__)
#undef __PSP__ #undef __PSP__
#define __PSP__ 1 #define __PSP__ 1
#endif #endif
#include "begin_code.h" #include "begin_code.h"
/* Set up for C function definitions, even when using C++ */ /* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** /**
* \brief Gets the name of the platform. * \brief Gets the name of the platform.
*/ */
extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void); extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#include "close_code.h" #include "close_code.h"
#endif /* _SDL_platform_h */ #endif /* _SDL_platform_h */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,185 +1,185 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
/** /**
* \file SDL_system.h * \file SDL_system.h
* *
* Include file for platform specific SDL API functions * Include file for platform specific SDL API functions
*/ */
#ifndef _SDL_system_h #ifndef _SDL_system_h
#define _SDL_system_h #define _SDL_system_h
#include "SDL_stdinc.h" #include "SDL_stdinc.h"
#include "SDL_keyboard.h" #include "SDL_keyboard.h"
#include "SDL_render.h" #include "SDL_render.h"
#include "SDL_video.h" #include "SDL_video.h"
#include "begin_code.h" #include "begin_code.h"
/* Set up for C function definitions, even when using C++ */ /* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* Platform specific functions for Windows */ /* Platform specific functions for Windows */
#ifdef __WIN32__ #ifdef __WIN32__
/* Returns the D3D9 adapter index that matches the specified display index. /* Returns the D3D9 adapter index that matches the specified display index.
This adapter index can be passed to IDirect3D9::CreateDevice and controls This adapter index can be passed to IDirect3D9::CreateDevice and controls
on which monitor a full screen application will appear. on which monitor a full screen application will appear.
*/ */
extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex ); extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
/* Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer. /* Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
Once you are done using the device, you should release it to avoid a resource leak. Once you are done using the device, you should release it to avoid a resource leak.
*/ */
typedef struct IDirect3DDevice9 IDirect3DDevice9; typedef struct IDirect3DDevice9 IDirect3DDevice9;
extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer); extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
#endif /* __WIN32__ */ #endif /* __WIN32__ */
/* Platform specific functions for iOS */ /* Platform specific functions for iOS */
#if defined(__IPHONEOS__) && __IPHONEOS__ #if defined(__IPHONEOS__) && __IPHONEOS__
extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam); extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled); extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
#endif /* __IPHONEOS__ */ #endif /* __IPHONEOS__ */
/* Platform specific functions for Android */ /* Platform specific functions for Android */
#if defined(__ANDROID__) && __ANDROID__ #if defined(__ANDROID__) && __ANDROID__
/* Get the JNI environment for the current thread /* Get the JNI environment for the current thread
This returns JNIEnv*, but the prototype is void* so we don't need jni.h This returns JNIEnv*, but the prototype is void* so we don't need jni.h
*/ */
extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv(); extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
/* Get the SDL Activity object for the application /* Get the SDL Activity object for the application
This returns jobject, but the prototype is void* so we don't need jni.h This returns jobject, but the prototype is void* so we don't need jni.h
The jobject returned by SDL_AndroidGetActivity is a local reference. The jobject returned by SDL_AndroidGetActivity is a local reference.
It is the caller's responsibility to properly release it It is the caller's responsibility to properly release it
(using env->Push/PopLocalFrame or manually with env->DeleteLocalRef) (using env->Push/PopLocalFrame or manually with env->DeleteLocalRef)
*/ */
extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(); extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();
/* See the official Android developer guide for more information: /* See the official Android developer guide for more information:
http://developer.android.com/guide/topics/data/data-storage.html http://developer.android.com/guide/topics/data/data-storage.html
*/ */
#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01 #define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02 #define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
/* Get the path used for internal storage for this application. /* Get the path used for internal storage for this application.
This path is unique to your application and cannot be written to This path is unique to your application and cannot be written to
by other applications. by other applications.
*/ */
extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath(); extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();
/* Get the current state of external storage, a bitmask of these values: /* Get the current state of external storage, a bitmask of these values:
SDL_ANDROID_EXTERNAL_STORAGE_READ SDL_ANDROID_EXTERNAL_STORAGE_READ
SDL_ANDROID_EXTERNAL_STORAGE_WRITE SDL_ANDROID_EXTERNAL_STORAGE_WRITE
If external storage is currently unavailable, this will return 0. If external storage is currently unavailable, this will return 0.
*/ */
extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState(); extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState();
/* Get the path used for external storage for this application. /* Get the path used for external storage for this application.
This path is unique to your application, but is public and can be This path is unique to your application, but is public and can be
written to by other applications. written to by other applications.
*/ */
extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(); extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath();
#endif /* __ANDROID__ */ #endif /* __ANDROID__ */
/* Platform specific functions for WinRT */ /* Platform specific functions for WinRT */
#if defined(__WINRT__) && __WINRT__ #if defined(__WINRT__) && __WINRT__
/** /**
* \brief WinRT / Windows Phone path types * \brief WinRT / Windows Phone path types
*/ */
typedef enum typedef enum
{ {
/** \brief The installed app's root directory. /** \brief The installed app's root directory.
Files here are likely to be read-only. */ Files here are likely to be read-only. */
SDL_WINRT_PATH_INSTALLED_LOCATION, SDL_WINRT_PATH_INSTALLED_LOCATION,
/** \brief The app's local data store. Files may be written here */ /** \brief The app's local data store. Files may be written here */
SDL_WINRT_PATH_LOCAL_FOLDER, SDL_WINRT_PATH_LOCAL_FOLDER,
/** \brief The app's roaming data store. Unsupported on Windows Phone. /** \brief The app's roaming data store. Unsupported on Windows Phone.
Files written here may be copied to other machines via a network Files written here may be copied to other machines via a network
connection. connection.
*/ */
SDL_WINRT_PATH_ROAMING_FOLDER, SDL_WINRT_PATH_ROAMING_FOLDER,
/** \brief The app's temporary data store. Unsupported on Windows Phone. /** \brief The app's temporary data store. Unsupported on Windows Phone.
Files written here may be deleted at any time. */ Files written here may be deleted at any time. */
SDL_WINRT_PATH_TEMP_FOLDER SDL_WINRT_PATH_TEMP_FOLDER
} SDL_WinRT_Path; } SDL_WinRT_Path;
/** /**
* \brief Retrieves a WinRT defined path on the local file system * \brief Retrieves a WinRT defined path on the local file system
* *
* \note Documentation on most app-specific path types on WinRT * \note Documentation on most app-specific path types on WinRT
* can be found on MSDN, at the URL: * can be found on MSDN, at the URL:
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
* *
* \param pathType The type of path to retrieve. * \param pathType The type of path to retrieve.
* \ret A UCS-2 string (16-bit, wide-char) containing the path, or NULL * \ret A UCS-2 string (16-bit, wide-char) containing the path, or NULL
* if the path is not available for any reason. Not all paths are * if the path is not available for any reason. Not all paths are
* available on all versions of Windows. This is especially true on * available on all versions of Windows. This is especially true on
* Windows Phone. Check the documentation for the given * Windows Phone. Check the documentation for the given
* SDL_WinRT_Path for more information on which path types are * SDL_WinRT_Path for more information on which path types are
* supported where. * supported where.
*/ */
extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType); extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
/** /**
* \brief Retrieves a WinRT defined path on the local file system * \brief Retrieves a WinRT defined path on the local file system
* *
* \note Documentation on most app-specific path types on WinRT * \note Documentation on most app-specific path types on WinRT
* can be found on MSDN, at the URL: * can be found on MSDN, at the URL:
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
* *
* \param pathType The type of path to retrieve. * \param pathType The type of path to retrieve.
* \ret A UTF-8 string (8-bit, multi-byte) containing the path, or NULL * \ret A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
* if the path is not available for any reason. Not all paths are * if the path is not available for any reason. Not all paths are
* available on all versions of Windows. This is especially true on * available on all versions of Windows. This is especially true on
* Windows Phone. Check the documentation for the given * Windows Phone. Check the documentation for the given
* SDL_WinRT_Path for more information on which path types are * SDL_WinRT_Path for more information on which path types are
* supported where. * supported where.
*/ */
extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType); extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
#endif /* __WINRT__ */ #endif /* __WINRT__ */
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#include "close_code.h" #include "close_code.h"
#endif /* _SDL_system_h */ #endif /* _SDL_system_h */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,140 +1,140 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
/** /**
* \file begin_code.h * \file begin_code.h
* *
* This file sets things up for C dynamic library function definitions, * This file sets things up for C dynamic library function definitions,
* static inlined functions, and structures aligned at 4-byte alignment. * static inlined functions, and structures aligned at 4-byte alignment.
* If you don't like ugly C preprocessor code, don't look at this file. :) * If you don't like ugly C preprocessor code, don't look at this file. :)
*/ */
/* This shouldn't be nested -- included it around code only. */ /* This shouldn't be nested -- included it around code only. */
#ifdef _begin_code_h #ifdef _begin_code_h
#error Nested inclusion of begin_code.h #error Nested inclusion of begin_code.h
#endif #endif
#define _begin_code_h #define _begin_code_h
#ifndef SDL_DEPRECATED #ifndef SDL_DEPRECATED
# if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */ # if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
# define SDL_DEPRECATED __attribute__((deprecated)) # define SDL_DEPRECATED __attribute__((deprecated))
# else # else
# define SDL_DEPRECATED # define SDL_DEPRECATED
# endif # endif
#endif #endif
/* Some compilers use a special export keyword */ /* Some compilers use a special export keyword */
#ifndef DECLSPEC #ifndef DECLSPEC
# if defined(__WIN32__) || defined(__WINRT__) # if defined(__WIN32__) || defined(__WINRT__)
# ifdef __BORLANDC__ # ifdef __BORLANDC__
# ifdef BUILD_SDL # ifdef BUILD_SDL
# define DECLSPEC # define DECLSPEC
# else # else
# define DECLSPEC __declspec(dllimport) # define DECLSPEC __declspec(dllimport)
# endif # endif
# else # else
# define DECLSPEC __declspec(dllexport) # define DECLSPEC __declspec(dllexport)
# endif # endif
# else # else
# if defined(__GNUC__) && __GNUC__ >= 4 # if defined(__GNUC__) && __GNUC__ >= 4
# define DECLSPEC __attribute__ ((visibility("default"))) # define DECLSPEC __attribute__ ((visibility("default")))
# elif defined(__GNUC__) && __GNUC__ >= 2 # elif defined(__GNUC__) && __GNUC__ >= 2
# define DECLSPEC __declspec(dllexport) # define DECLSPEC __declspec(dllexport)
# else # else
# define DECLSPEC # define DECLSPEC
# endif # endif
# endif # endif
#endif #endif
/* By default SDL uses the C calling convention */ /* By default SDL uses the C calling convention */
#ifndef SDLCALL #ifndef SDLCALL
#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__) #if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
#define SDLCALL __cdecl #define SDLCALL __cdecl
#else #else
#define SDLCALL #define SDLCALL
#endif #endif
#endif /* SDLCALL */ #endif /* SDLCALL */
/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */ /* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
#ifdef __SYMBIAN32__ #ifdef __SYMBIAN32__
#undef DECLSPEC #undef DECLSPEC
#define DECLSPEC #define DECLSPEC
#endif /* __SYMBIAN32__ */ #endif /* __SYMBIAN32__ */
/* Force structure packing at 4 byte alignment. /* Force structure packing at 4 byte alignment.
This is necessary if the header is included in code which has structure This is necessary if the header is included in code which has structure
packing set to an alternate value, say for loading structures from disk. packing set to an alternate value, say for loading structures from disk.
The packing is reset to the previous value in close_code.h The packing is reset to the previous value in close_code.h
*/ */
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable: 4103) #pragma warning(disable: 4103)
#endif #endif
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma nopackwarning #pragma nopackwarning
#endif #endif
#ifdef _M_X64 #ifdef _M_X64
/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */ /* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
#pragma pack(push,8) #pragma pack(push,8)
#else #else
#pragma pack(push,4) #pragma pack(push,4)
#endif #endif
#endif /* Compiler needs structure packing set */ #endif /* Compiler needs structure packing set */
#ifndef SDL_INLINE #ifndef SDL_INLINE
#if defined(__GNUC__) #if defined(__GNUC__)
#define SDL_INLINE __inline__ #define SDL_INLINE __inline__
#elif defined(_MSC_VER) || defined(__BORLANDC__) || \ #elif defined(_MSC_VER) || defined(__BORLANDC__) || \
defined(__DMC__) || defined(__SC__) || \ defined(__DMC__) || defined(__SC__) || \
defined(__WATCOMC__) || defined(__LCC__) || \ defined(__WATCOMC__) || defined(__LCC__) || \
defined(__DECC) defined(__DECC)
#define SDL_INLINE __inline #define SDL_INLINE __inline
#ifndef __inline__ #ifndef __inline__
#define __inline__ __inline #define __inline__ __inline
#endif #endif
#else #else
#define SDL_INLINE inline #define SDL_INLINE inline
#ifndef __inline__ #ifndef __inline__
#define __inline__ inline #define __inline__ inline
#endif #endif
#endif #endif
#endif /* SDL_INLINE not defined */ #endif /* SDL_INLINE not defined */
#ifndef SDL_FORCE_INLINE #ifndef SDL_FORCE_INLINE
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define SDL_FORCE_INLINE __forceinline #define SDL_FORCE_INLINE __forceinline
#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) ) #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__ #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
#else #else
#define SDL_FORCE_INLINE static SDL_INLINE #define SDL_FORCE_INLINE static SDL_INLINE
#endif #endif
#endif /* SDL_FORCE_INLINE not defined */ #endif /* SDL_FORCE_INLINE not defined */
/* Apparently this is needed by several Windows compilers */ /* Apparently this is needed by several Windows compilers */
#if !defined(__MACH__) #if !defined(__MACH__)
#ifndef NULL #ifndef NULL
#ifdef __cplusplus #ifdef __cplusplus
#define NULL 0 #define NULL 0
#else #else
#define NULL ((void *)0) #define NULL ((void *)0)
#endif #endif
#endif /* NULL */ #endif /* NULL */
#endif /* ! Mac OS X - breaks precompiled headers */ #endif /* ! Mac OS X - breaks precompiled headers */

View File

@ -1,439 +1,439 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#if defined(__WIN32__) || defined(__WINRT__) #if defined(__WIN32__) || defined(__WINRT__)
#include "core/windows/SDL_windows.h" #include "core/windows/SDL_windows.h"
#endif #endif
/* Simple log messages in SDL */ /* Simple log messages in SDL */
#include "SDL_log.h" #include "SDL_log.h"
#if HAVE_STDIO_H #if HAVE_STDIO_H
#include <stdio.h> #include <stdio.h>
#endif #endif
#if defined(__ANDROID__) #if defined(__ANDROID__)
#include <android/log.h> #include <android/log.h>
#endif #endif
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL #define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN #define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO #define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE #define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
/* Forward definition of error function */ /* Forward definition of error function */
extern int SDL_SetError(const char *fmt, ...); extern int SDL_SetError(const char *fmt, ...);
typedef struct SDL_LogLevel typedef struct SDL_LogLevel
{ {
int category; int category;
SDL_LogPriority priority; SDL_LogPriority priority;
struct SDL_LogLevel *next; struct SDL_LogLevel *next;
} SDL_LogLevel; } SDL_LogLevel;
/* The default log output function */ /* The default log output function */
static void SDL_LogOutput(void *userdata, static void SDL_LogOutput(void *userdata,
int category, SDL_LogPriority priority, int category, SDL_LogPriority priority,
const char *message); const char *message);
static SDL_LogLevel *SDL_loglevels; static SDL_LogLevel *SDL_loglevels;
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY; static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY; static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY; static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY; static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput; static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
static void *SDL_log_userdata = NULL; static void *SDL_log_userdata = NULL;
static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = { static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
NULL, NULL,
"VERBOSE", "VERBOSE",
"DEBUG", "DEBUG",
"INFO", "INFO",
"WARN", "WARN",
"ERROR", "ERROR",
"CRITICAL" "CRITICAL"
}; };
#ifdef __ANDROID__ #ifdef __ANDROID__
static const char *SDL_category_prefixes[SDL_LOG_CATEGORY_RESERVED1] = { static const char *SDL_category_prefixes[SDL_LOG_CATEGORY_RESERVED1] = {
"APP", "APP",
"ERROR", "ERROR",
"SYSTEM", "SYSTEM",
"AUDIO", "AUDIO",
"VIDEO", "VIDEO",
"RENDER", "RENDER",
"INPUT" "INPUT"
}; };
static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = { static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
ANDROID_LOG_UNKNOWN, ANDROID_LOG_UNKNOWN,
ANDROID_LOG_VERBOSE, ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG, ANDROID_LOG_DEBUG,
ANDROID_LOG_INFO, ANDROID_LOG_INFO,
ANDROID_LOG_WARN, ANDROID_LOG_WARN,
ANDROID_LOG_ERROR, ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL ANDROID_LOG_FATAL
}; };
#endif /* __ANDROID__ */ #endif /* __ANDROID__ */
void void
SDL_LogSetAllPriority(SDL_LogPriority priority) SDL_LogSetAllPriority(SDL_LogPriority priority)
{ {
SDL_LogLevel *entry; SDL_LogLevel *entry;
for (entry = SDL_loglevels; entry; entry = entry->next) { for (entry = SDL_loglevels; entry; entry = entry->next) {
entry->priority = priority; entry->priority = priority;
} }
SDL_default_priority = priority; SDL_default_priority = priority;
SDL_assert_priority = priority; SDL_assert_priority = priority;
SDL_application_priority = priority; SDL_application_priority = priority;
} }
void void
SDL_LogSetPriority(int category, SDL_LogPriority priority) SDL_LogSetPriority(int category, SDL_LogPriority priority)
{ {
SDL_LogLevel *entry; SDL_LogLevel *entry;
for (entry = SDL_loglevels; entry; entry = entry->next) { for (entry = SDL_loglevels; entry; entry = entry->next) {
if (entry->category == category) { if (entry->category == category) {
entry->priority = priority; entry->priority = priority;
return; return;
} }
} }
/* Create a new entry */ /* Create a new entry */
entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry)); entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
if (entry) { if (entry) {
entry->category = category; entry->category = category;
entry->priority = priority; entry->priority = priority;
entry->next = SDL_loglevels; entry->next = SDL_loglevels;
SDL_loglevels = entry; SDL_loglevels = entry;
} }
} }
SDL_LogPriority SDL_LogPriority
SDL_LogGetPriority(int category) SDL_LogGetPriority(int category)
{ {
SDL_LogLevel *entry; SDL_LogLevel *entry;
for (entry = SDL_loglevels; entry; entry = entry->next) { for (entry = SDL_loglevels; entry; entry = entry->next) {
if (entry->category == category) { if (entry->category == category) {
return entry->priority; return entry->priority;
} }
} }
if (category == SDL_LOG_CATEGORY_TEST) { if (category == SDL_LOG_CATEGORY_TEST) {
return SDL_test_priority; return SDL_test_priority;
} else if (category == SDL_LOG_CATEGORY_APPLICATION) { } else if (category == SDL_LOG_CATEGORY_APPLICATION) {
return SDL_application_priority; return SDL_application_priority;
} else if (category == SDL_LOG_CATEGORY_ASSERT) { } else if (category == SDL_LOG_CATEGORY_ASSERT) {
return SDL_assert_priority; return SDL_assert_priority;
} else { } else {
return SDL_default_priority; return SDL_default_priority;
} }
} }
void void
SDL_LogResetPriorities(void) SDL_LogResetPriorities(void)
{ {
SDL_LogLevel *entry; SDL_LogLevel *entry;
while (SDL_loglevels) { while (SDL_loglevels) {
entry = SDL_loglevels; entry = SDL_loglevels;
SDL_loglevels = entry->next; SDL_loglevels = entry->next;
SDL_free(entry); SDL_free(entry);
} }
SDL_default_priority = DEFAULT_PRIORITY; SDL_default_priority = DEFAULT_PRIORITY;
SDL_assert_priority = DEFAULT_ASSERT_PRIORITY; SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
SDL_application_priority = DEFAULT_APPLICATION_PRIORITY; SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
SDL_test_priority = DEFAULT_TEST_PRIORITY; SDL_test_priority = DEFAULT_TEST_PRIORITY;
} }
void void
SDL_Log(const char *fmt, ...) SDL_Log(const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap);
va_end(ap); va_end(ap);
} }
void void
SDL_LogVerbose(int category, const char *fmt, ...) SDL_LogVerbose(int category, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap); SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap);
va_end(ap); va_end(ap);
} }
void void
SDL_LogDebug(int category, const char *fmt, ...) SDL_LogDebug(int category, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
SDL_LogMessageV(category, SDL_LOG_PRIORITY_DEBUG, fmt, ap); SDL_LogMessageV(category, SDL_LOG_PRIORITY_DEBUG, fmt, ap);
va_end(ap); va_end(ap);
} }
void void
SDL_LogInfo(int category, const char *fmt, ...) SDL_LogInfo(int category, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap); SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap);
va_end(ap); va_end(ap);
} }
void void
SDL_LogWarn(int category, const char *fmt, ...) SDL_LogWarn(int category, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap); SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap);
va_end(ap); va_end(ap);
} }
void void
SDL_LogError(int category, const char *fmt, ...) SDL_LogError(int category, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap); SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap);
va_end(ap); va_end(ap);
} }
void void
SDL_LogCritical(int category, const char *fmt, ...) SDL_LogCritical(int category, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap); SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap);
va_end(ap); va_end(ap);
} }
void void
SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...) SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
SDL_LogMessageV(category, priority, fmt, ap); SDL_LogMessageV(category, priority, fmt, ap);
va_end(ap); va_end(ap);
} }
#ifdef __ANDROID__ #ifdef __ANDROID__
static const char * static const char *
GetCategoryPrefix(int category) GetCategoryPrefix(int category)
{ {
if (category < SDL_LOG_CATEGORY_RESERVED1) { if (category < SDL_LOG_CATEGORY_RESERVED1) {
return SDL_category_prefixes[category]; return SDL_category_prefixes[category];
} }
if (category < SDL_LOG_CATEGORY_CUSTOM) { if (category < SDL_LOG_CATEGORY_CUSTOM) {
return "RESERVED"; return "RESERVED";
} }
return "CUSTOM"; return "CUSTOM";
} }
#endif /* __ANDROID__ */ #endif /* __ANDROID__ */
void void
SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap) SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
{ {
char *message; char *message;
size_t len; size_t len;
/* Nothing to do if we don't have an output function */ /* Nothing to do if we don't have an output function */
if (!SDL_log_function) { if (!SDL_log_function) {
return; return;
} }
/* Make sure we don't exceed array bounds */ /* Make sure we don't exceed array bounds */
if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) { if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
return; return;
} }
/* See if we want to do anything with this message */ /* See if we want to do anything with this message */
if (priority < SDL_LogGetPriority(category)) { if (priority < SDL_LogGetPriority(category)) {
return; return;
} }
message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
if (!message) { if (!message) {
return; return;
} }
SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap); SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
/* Chop off final endline. */ /* Chop off final endline. */
len = SDL_strlen(message); len = SDL_strlen(message);
if ((len > 0) && (message[len-1] == '\n')) { if ((len > 0) && (message[len-1] == '\n')) {
message[--len] = '\0'; message[--len] = '\0';
if ((len > 0) && (message[len-1] == '\r')) { /* catch "\r\n", too. */ if ((len > 0) && (message[len-1] == '\r')) { /* catch "\r\n", too. */
message[--len] = '\0'; message[--len] = '\0';
} }
} }
SDL_log_function(SDL_log_userdata, category, priority, message); SDL_log_function(SDL_log_userdata, category, priority, message);
SDL_stack_free(message); SDL_stack_free(message);
} }
#if defined(__WIN32__) #if defined(__WIN32__)
/* Flag tracking the attachment of the console: 0=unattached, 1=attached, -1=error */ /* Flag tracking the attachment of the console: 0=unattached, 1=attached, -1=error */
static int consoleAttached = 0; static int consoleAttached = 0;
/* Handle to stderr output of console. */ /* Handle to stderr output of console. */
static HANDLE stderrHandle = NULL; static HANDLE stderrHandle = NULL;
#endif #endif
static void static void
SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
const char *message) const char *message)
{ {
#if defined(__WIN32__) || defined(__WINRT__) #if defined(__WIN32__) || defined(__WINRT__)
/* Way too many allocations here, urgh */ /* Way too many allocations here, urgh */
/* Note: One can't call SDL_SetError here, since that function itself logs. */ /* Note: One can't call SDL_SetError here, since that function itself logs. */
{ {
char *output; char *output;
size_t length; size_t length;
LPTSTR tstr; LPTSTR tstr;
#ifndef __WINRT__ #ifndef __WINRT__
BOOL attachResult; BOOL attachResult;
DWORD attachError; DWORD attachError;
unsigned long charsWritten; unsigned long charsWritten;
/* Maybe attach console and get stderr handle */ /* Maybe attach console and get stderr handle */
if (consoleAttached == 0) { if (consoleAttached == 0) {
attachResult = AttachConsole(ATTACH_PARENT_PROCESS); attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
if (!attachResult) { if (!attachResult) {
attachError = GetLastError(); attachError = GetLastError();
if (attachError == ERROR_INVALID_HANDLE) { if (attachError == ERROR_INVALID_HANDLE) {
OutputDebugString(TEXT("Parent process has no console\r\n")); OutputDebugString(TEXT("Parent process has no console\r\n"));
consoleAttached = -1; consoleAttached = -1;
} else if (attachError == ERROR_GEN_FAILURE) { } else if (attachError == ERROR_GEN_FAILURE) {
OutputDebugString(TEXT("Could not attach to console of parent process\r\n")); OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
consoleAttached = -1; consoleAttached = -1;
} else if (attachError == ERROR_ACCESS_DENIED) { } else if (attachError == ERROR_ACCESS_DENIED) {
/* Already attached */ /* Already attached */
consoleAttached = 1; consoleAttached = 1;
} else { } else {
OutputDebugString(TEXT("Error attaching console\r\n")); OutputDebugString(TEXT("Error attaching console\r\n"));
consoleAttached = -1; consoleAttached = -1;
} }
} else { } else {
/* Newly attached */ /* Newly attached */
consoleAttached = 1; consoleAttached = 1;
} }
if (consoleAttached == 1) { if (consoleAttached == 1) {
stderrHandle = GetStdHandle(STD_ERROR_HANDLE); stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
} }
} }
#endif /* ifndef __WINRT__ */ #endif /* ifndef __WINRT__ */
length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1; length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1;
output = SDL_stack_alloc(char, length); output = SDL_stack_alloc(char, length);
SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message); SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
tstr = WIN_UTF8ToString(output); tstr = WIN_UTF8ToString(output);
/* Output to debugger */ /* Output to debugger */
OutputDebugString(tstr); OutputDebugString(tstr);
#ifndef __WINRT__ #ifndef __WINRT__
/* Screen output to stderr, if console was attached. */ /* Screen output to stderr, if console was attached. */
if (consoleAttached == 1) { if (consoleAttached == 1) {
if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) { if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
OutputDebugString(TEXT("Error calling WriteConsole\r\n")); OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
} }
if (charsWritten == ERROR_NOT_ENOUGH_MEMORY) { if (charsWritten == ERROR_NOT_ENOUGH_MEMORY) {
OutputDebugString(TEXT("Insufficient heap memory to write message\r\n")); OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
} }
} }
#endif /* ifndef __WINRT__ */ #endif /* ifndef __WINRT__ */
SDL_free(tstr); SDL_free(tstr);
SDL_stack_free(output); SDL_stack_free(output);
} }
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
{ {
char tag[32]; char tag[32];
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category)); SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
__android_log_write(SDL_android_priority[priority], tag, message); __android_log_write(SDL_android_priority[priority], tag, message);
} }
#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA) #elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA)
/* Technically we don't need SDL_VIDEO_DRIVER_COCOA, but that's where this function is defined for now. /* Technically we don't need SDL_VIDEO_DRIVER_COCOA, but that's where this function is defined for now.
*/ */
extern void SDL_NSLog(const char *text); extern void SDL_NSLog(const char *text);
{ {
char *text; char *text;
text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
if (text) { if (text) {
SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message); SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message);
SDL_NSLog(text); SDL_NSLog(text);
SDL_stack_free(text); SDL_stack_free(text);
return; return;
} }
} }
#elif defined(__PSP__) #elif defined(__PSP__)
{ {
FILE* pFile; FILE* pFile;
pFile = fopen ("SDL_Log.txt", "a"); pFile = fopen ("SDL_Log.txt", "a");
fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message); fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
fclose (pFile); fclose (pFile);
} }
#endif #endif
#if HAVE_STDIO_H #if HAVE_STDIO_H
fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message); fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
#endif #endif
} }
void void
SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata) SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
{ {
if (callback) { if (callback) {
*callback = SDL_log_function; *callback = SDL_log_function;
} }
if (userdata) { if (userdata) {
*userdata = SDL_log_userdata; *userdata = SDL_log_userdata;
} }
} }
void void
SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata) SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
{ {
SDL_log_function = callback; SDL_log_function = callback;
SDL_log_userdata = userdata; SDL_log_userdata = userdata;
} }
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,126 +1,126 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#if defined(__WIN32__) || defined(__WINRT__) #if defined(__WIN32__) || defined(__WINRT__)
#include "../core/windows/SDL_windows.h" #include "../core/windows/SDL_windows.h"
#endif #endif
#include "SDL_atomic.h" #include "SDL_atomic.h"
#include "SDL_mutex.h" #include "SDL_mutex.h"
#include "SDL_timer.h" #include "SDL_timer.h"
/* This function is where all the magic happens... */ /* This function is where all the magic happens... */
SDL_bool SDL_bool
SDL_AtomicTryLock(SDL_SpinLock *lock) SDL_AtomicTryLock(SDL_SpinLock *lock)
{ {
#if SDL_ATOMIC_DISABLED #if SDL_ATOMIC_DISABLED
/* Terrible terrible damage */ /* Terrible terrible damage */
static SDL_mutex *_spinlock_mutex; static SDL_mutex *_spinlock_mutex;
if (!_spinlock_mutex) { if (!_spinlock_mutex) {
/* Race condition on first lock... */ /* Race condition on first lock... */
_spinlock_mutex = SDL_CreateMutex(); _spinlock_mutex = SDL_CreateMutex();
} }
SDL_LockMutex(_spinlock_mutex); SDL_LockMutex(_spinlock_mutex);
if (*lock == 0) { if (*lock == 0) {
*lock = 1; *lock = 1;
SDL_UnlockMutex(_spinlock_mutex); SDL_UnlockMutex(_spinlock_mutex);
return SDL_TRUE; return SDL_TRUE;
} else { } else {
SDL_UnlockMutex(_spinlock_mutex); SDL_UnlockMutex(_spinlock_mutex);
return SDL_FALSE; return SDL_FALSE;
} }
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
return (InterlockedExchange((long*)lock, 1) == 0); return (InterlockedExchange((long*)lock, 1) == 0);
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
return (__sync_lock_test_and_set(lock, 1) == 0); return (__sync_lock_test_and_set(lock, 1) == 0);
#elif defined(__GNUC__) && defined(__arm__) && \ #elif defined(__GNUC__) && defined(__arm__) && \
(defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \ (defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \ defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
defined(__ARM_ARCH_5TEJ__)) defined(__ARM_ARCH_5TEJ__))
int result; int result;
__asm__ __volatile__ ( __asm__ __volatile__ (
"swp %0, %1, [%2]\n" "swp %0, %1, [%2]\n"
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory"); : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
return (result == 0); return (result == 0);
#elif defined(__GNUC__) && defined(__arm__) #elif defined(__GNUC__) && defined(__arm__)
int result; int result;
__asm__ __volatile__ ( __asm__ __volatile__ (
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]" "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory"); : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
return (result == 0); return (result == 0);
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
int result; int result;
__asm__ __volatile__( __asm__ __volatile__(
"lock ; xchgl %0, (%1)\n" "lock ; xchgl %0, (%1)\n"
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory"); : "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
return (result == 0); return (result == 0);
#elif defined(__MACOSX__) || defined(__IPHONEOS__) #elif defined(__MACOSX__) || defined(__IPHONEOS__)
/* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */ /* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
return OSAtomicCompareAndSwap32Barrier(0, 1, lock); return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
#elif HAVE_PTHREAD_SPINLOCK #elif HAVE_PTHREAD_SPINLOCK
/* pthread instructions */ /* pthread instructions */
return (pthread_spin_trylock(lock) == 0); return (pthread_spin_trylock(lock) == 0);
#else #else
#error Please implement for your platform. #error Please implement for your platform.
return SDL_FALSE; return SDL_FALSE;
#endif #endif
} }
void void
SDL_AtomicLock(SDL_SpinLock *lock) SDL_AtomicLock(SDL_SpinLock *lock)
{ {
/* FIXME: Should we have an eventual timeout? */ /* FIXME: Should we have an eventual timeout? */
while (!SDL_AtomicTryLock(lock)) { while (!SDL_AtomicTryLock(lock)) {
SDL_Delay(0); SDL_Delay(0);
} }
} }
void void
SDL_AtomicUnlock(SDL_SpinLock *lock) SDL_AtomicUnlock(SDL_SpinLock *lock)
{ {
#if defined(_MSC_VER) #if defined(_MSC_VER)
_ReadWriteBarrier(); _ReadWriteBarrier();
*lock = 0; *lock = 0;
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
__sync_lock_release(lock); __sync_lock_release(lock);
#elif HAVE_PTHREAD_SPINLOCK #elif HAVE_PTHREAD_SPINLOCK
pthread_spin_unlock(lock); pthread_spin_unlock(lock);
#else #else
*lock = 0; *lock = 0;
#endif #endif
} }
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@ -1,69 +1,69 @@
#include <xaudio2.h> #include <xaudio2.h>
#include "SDL_xaudio2_winrthelpers.h" #include "SDL_xaudio2_winrthelpers.h"
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
using Windows::Devices::Enumeration::DeviceClass; using Windows::Devices::Enumeration::DeviceClass;
using Windows::Devices::Enumeration::DeviceInformation; using Windows::Devices::Enumeration::DeviceInformation;
using Windows::Devices::Enumeration::DeviceInformationCollection; using Windows::Devices::Enumeration::DeviceInformationCollection;
#endif #endif
extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount) extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
{ {
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
// There doesn't seem to be any audio device enumeration on Windows Phone. // There doesn't seem to be any audio device enumeration on Windows Phone.
// In lieu of this, just treat things as if there is one and only one // In lieu of this, just treat things as if there is one and only one
// audio device. // audio device.
*devcount = 1; *devcount = 1;
return S_OK; return S_OK;
#else #else
// TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background // TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender); auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
while (operation->Status != Windows::Foundation::AsyncStatus::Completed) while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
{ {
} }
DeviceInformationCollection^ devices = operation->GetResults(); DeviceInformationCollection^ devices = operation->GetResults();
*devcount = devices->Size; *devcount = devices->Size;
return S_OK; return S_OK;
#endif #endif
} }
extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details) extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
{ {
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
// Windows Phone doesn't seem to have the same device enumeration APIs that // Windows Phone doesn't seem to have the same device enumeration APIs that
// Windows 8/RT has, or it doesn't have them at all. In lieu of this, // Windows 8/RT has, or it doesn't have them at all. In lieu of this,
// just treat things as if there is one, and only one, default device. // just treat things as if there is one, and only one, default device.
if (index != 0) if (index != 0)
{ {
return XAUDIO2_E_INVALID_CALL; return XAUDIO2_E_INVALID_CALL;
} }
if (details) if (details)
{ {
wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE); wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE);
wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE); wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE);
} }
return S_OK; return S_OK;
#else #else
auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender); auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
while (operation->Status != Windows::Foundation::AsyncStatus::Completed) while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
{ {
} }
DeviceInformationCollection^ devices = operation->GetResults(); DeviceInformationCollection^ devices = operation->GetResults();
if (index >= devices->Size) if (index >= devices->Size)
{ {
return XAUDIO2_E_INVALID_CALL; return XAUDIO2_E_INVALID_CALL;
} }
DeviceInformation^ d = devices->GetAt(index); DeviceInformation^ d = devices->GetAt(index);
if (details) if (details)
{ {
wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE); wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE); wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
} }
return S_OK; return S_OK;
#endif #endif
} }

View File

@ -1,52 +1,52 @@
#pragma once #pragma once
// //
// Re-implementation of methods removed from XAudio2 (in WinRT): // Re-implementation of methods removed from XAudio2 (in WinRT):
// //
typedef struct XAUDIO2_DEVICE_DETAILS typedef struct XAUDIO2_DEVICE_DETAILS
{ {
WCHAR DeviceID[256]; WCHAR DeviceID[256];
WCHAR DisplayName[256]; WCHAR DisplayName[256];
/* Other fields exist in the pre-Windows 8 version of this struct, however /* Other fields exist in the pre-Windows 8 version of this struct, however
they weren't used by SDL, so they weren't added. they weren't used by SDL, so they weren't added.
*/ */
} XAUDIO2_DEVICE_DETAILS; } XAUDIO2_DEVICE_DETAILS;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
HRESULT IXAudio2_GetDeviceCount(IXAudio2 * unused, UINT32 * devcount); HRESULT IXAudio2_GetDeviceCount(IXAudio2 * unused, UINT32 * devcount);
HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details); HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
// //
// C-style macros to call XAudio2's methods in C++: // C-style macros to call XAudio2's methods in C++:
// //
#ifdef __cplusplus #ifdef __cplusplus
/* /*
#define IXAudio2_CreateMasteringVoice(A, B, C, D, E, F, G) (A)->CreateMasteringVoice((B), (C), (D), (E), (F), (G)) #define IXAudio2_CreateMasteringVoice(A, B, C, D, E, F, G) (A)->CreateMasteringVoice((B), (C), (D), (E), (F), (G))
#define IXAudio2_CreateSourceVoice(A, B, C, D, E, F, G, H) (A)->CreateSourceVoice((B), (C), (D), (E), (F), (G), (H)) #define IXAudio2_CreateSourceVoice(A, B, C, D, E, F, G, H) (A)->CreateSourceVoice((B), (C), (D), (E), (F), (G), (H))
#define IXAudio2_QueryInterface(A, B, C) (A)->QueryInterface((B), (C)) #define IXAudio2_QueryInterface(A, B, C) (A)->QueryInterface((B), (C))
#define IXAudio2_Release(A) (A)->Release() #define IXAudio2_Release(A) (A)->Release()
#define IXAudio2_StartEngine(A) (A)->StartEngine() #define IXAudio2_StartEngine(A) (A)->StartEngine()
#define IXAudio2_StopEngine(A) (A)->StopEngine() #define IXAudio2_StopEngine(A) (A)->StopEngine()
#define IXAudio2MasteringVoice_DestroyVoice(A) (A)->DestroyVoice() #define IXAudio2MasteringVoice_DestroyVoice(A) (A)->DestroyVoice()
#define IXAudio2SourceVoice_DestroyVoice(A) (A)->DestroyVoice() #define IXAudio2SourceVoice_DestroyVoice(A) (A)->DestroyVoice()
#define IXAudio2SourceVoice_Discontinuity(A) (A)->Discontinuity() #define IXAudio2SourceVoice_Discontinuity(A) (A)->Discontinuity()
#define IXAudio2SourceVoice_FlushSourceBuffers(A) (A)->FlushSourceBuffers() #define IXAudio2SourceVoice_FlushSourceBuffers(A) (A)->FlushSourceBuffers()
#define IXAudio2SourceVoice_GetState(A, B) (A)->GetState((B)) #define IXAudio2SourceVoice_GetState(A, B) (A)->GetState((B))
#define IXAudio2SourceVoice_Start(A, B, C) (A)->Start((B), (C)) #define IXAudio2SourceVoice_Start(A, B, C) (A)->Start((B), (C))
#define IXAudio2SourceVoice_Stop(A, B, C) (A)->Stop((B), (C)) #define IXAudio2SourceVoice_Stop(A, B, C) (A)->Stop((B), (C))
#define IXAudio2SourceVoice_SubmitSourceBuffer(A, B, C) (A)->SubmitSourceBuffer((B), (C)) #define IXAudio2SourceVoice_SubmitSourceBuffer(A, B, C) (A)->SubmitSourceBuffer((B), (C))
*/ */
#endif // ifdef __cplusplus #endif // ifdef __cplusplus

View File

@ -1,16 +1,16 @@
#include <SDL_system.h> #include <SDL_system.h>
#include "SDL_winrtapp_direct3d.h" #include "SDL_winrtapp_direct3d.h"
#include "SDL_winrtapp_xaml.h" #include "SDL_winrtapp_xaml.h"
int (*WINRT_SDLAppEntryPoint)(int, char **) = NULL; int (*WINRT_SDLAppEntryPoint)(int, char **) = NULL;
extern "C" DECLSPEC int extern "C" DECLSPEC int
SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel) SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel)
{ {
if (xamlBackgroundPanel) { if (xamlBackgroundPanel) {
return SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel); return SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel);
} else { } else {
return SDL_WinRTInitNonXAMLApp(mainFunction); return SDL_WinRTInitNonXAMLApp(mainFunction);
} }
} }

View File

@ -19,13 +19,13 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#ifndef _SDL_winrtapp_common_h #ifndef _SDL_winrtapp_common_h
#define _SDL_winrtapp_common_h #define _SDL_winrtapp_common_h
/* A pointer to the app's C-style main() function (which is a different /* A pointer to the app's C-style main() function (which is a different
function than the WinRT app's actual entry point). function than the WinRT app's actual entry point).
*/ */
extern int (*WINRT_SDLAppEntryPoint)(int, char **); extern int (*WINRT_SDLAppEntryPoint)(int, char **);
#endif // ifndef _SDL_winrtapp_common_h #endif // ifndef _SDL_winrtapp_common_h

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +1,58 @@
#pragma once #pragma once
#include <Windows.h> #include <Windows.h>
extern int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **)); extern int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **));
ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
{ {
public: public:
SDL_WinRTApp(); SDL_WinRTApp();
// IFrameworkView Methods. // IFrameworkView Methods.
virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
virtual void Load(Platform::String^ entryPoint); virtual void Load(Platform::String^ entryPoint);
virtual void Run(); virtual void Run();
virtual void Uninitialize(); virtual void Uninitialize();
internal: internal:
// SDL-specific methods // SDL-specific methods
void PumpEvents(); void PumpEvents();
protected: protected:
// Event Handlers. // Event Handlers.
#if WINAPI_FAMILY == WINAPI_FAMILY_APP // for Windows 8/8.1/RT apps... (and not Phone apps) #if WINAPI_FAMILY == WINAPI_FAMILY_APP // for Windows 8/8.1/RT apps... (and not Phone apps)
void OnSettingsPaneCommandsRequested( void OnSettingsPaneCommandsRequested(
Windows::UI::ApplicationSettings::SettingsPane ^p, Windows::UI::ApplicationSettings::SettingsPane ^p,
Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args); Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args);
#endif // if WINAPI_FAMILY == WINAPI_FAMILY_APP #endif // if WINAPI_FAMILY == WINAPI_FAMILY_APP
void OnOrientationChanged(Platform::Object^ sender); void OnOrientationChanged(Platform::Object^ sender);
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
void OnLogicalDpiChanged(Platform::Object^ sender); void OnLogicalDpiChanged(Platform::Object^ sender);
void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args); void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
void OnResuming(Platform::Object^ sender, Platform::Object^ args); void OnResuming(Platform::Object^ sender, Platform::Object^ args);
void OnExiting(Platform::Object^ sender, Platform::Object^ args); void OnExiting(Platform::Object^ sender, Platform::Object^ args);
void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args); void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args);
void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args); void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
#endif #endif
private: private:
bool m_windowClosed; bool m_windowClosed;
bool m_windowVisible; bool m_windowVisible;
}; };
extern SDL_WinRTApp ^ SDL_WinRTGlobalApp; extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;

File diff suppressed because it is too large Load Diff

View File

@ -1,154 +1,154 @@
/* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp /* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp
TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#ifdef __WINRT__ #ifdef __WINRT__
extern "C" { extern "C" {
#include "SDL_filesystem.h" #include "SDL_filesystem.h"
#include "SDL_error.h" #include "SDL_error.h"
#include "SDL_stdinc.h" #include "SDL_stdinc.h"
#include "SDL_system.h" #include "SDL_system.h"
#include "../../core/windows/SDL_windows.h" #include "../../core/windows/SDL_windows.h"
} }
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
using namespace std; using namespace std;
using namespace Windows::Storage; using namespace Windows::Storage;
extern "C" const wchar_t * extern "C" const wchar_t *
SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType) SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
{ {
switch (pathType) { switch (pathType) {
case SDL_WINRT_PATH_INSTALLED_LOCATION: case SDL_WINRT_PATH_INSTALLED_LOCATION:
{ {
static wstring path; static wstring path;
if (path.empty()) { if (path.empty()) {
path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data(); path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
} }
return path.c_str(); return path.c_str();
} }
case SDL_WINRT_PATH_LOCAL_FOLDER: case SDL_WINRT_PATH_LOCAL_FOLDER:
{ {
static wstring path; static wstring path;
if (path.empty()) { if (path.empty()) {
path = ApplicationData::Current->LocalFolder->Path->Data(); path = ApplicationData::Current->LocalFolder->Path->Data();
} }
return path.c_str(); return path.c_str();
} }
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
case SDL_WINRT_PATH_ROAMING_FOLDER: case SDL_WINRT_PATH_ROAMING_FOLDER:
{ {
static wstring path; static wstring path;
if (path.empty()) { if (path.empty()) {
path = ApplicationData::Current->RoamingFolder->Path->Data(); path = ApplicationData::Current->RoamingFolder->Path->Data();
} }
return path.c_str(); return path.c_str();
} }
case SDL_WINRT_PATH_TEMP_FOLDER: case SDL_WINRT_PATH_TEMP_FOLDER:
{ {
static wstring path; static wstring path;
if (path.empty()) { if (path.empty()) {
path = ApplicationData::Current->TemporaryFolder->Path->Data(); path = ApplicationData::Current->TemporaryFolder->Path->Data();
} }
return path.c_str(); return path.c_str();
} }
#endif #endif
default: default:
break; break;
} }
SDL_Unsupported(); SDL_Unsupported();
return NULL; return NULL;
} }
extern "C" const char * extern "C" const char *
SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType) SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
{ {
typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap; typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
static UTF8PathMap utf8Paths; static UTF8PathMap utf8Paths;
UTF8PathMap::iterator searchResult = utf8Paths.find(pathType); UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
if (searchResult != utf8Paths.end()) { if (searchResult != utf8Paths.end()) {
return searchResult->second.c_str(); return searchResult->second.c_str();
} }
const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType); const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
if (!ucs2Path) { if (!ucs2Path) {
return NULL; return NULL;
} }
char * utf8Path = WIN_StringToUTF8(ucs2Path); char * utf8Path = WIN_StringToUTF8(ucs2Path);
utf8Paths[pathType] = utf8Path; utf8Paths[pathType] = utf8Path;
SDL_free(utf8Path); SDL_free(utf8Path);
return utf8Paths[pathType].c_str(); return utf8Paths[pathType].c_str();
} }
extern "C" char * extern "C" char *
SDL_GetBasePath(void) SDL_GetBasePath(void)
{ {
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION); const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
size_t destPathLen; size_t destPathLen;
char * destPath = NULL; char * destPath = NULL;
if (!srcPath) { if (!srcPath) {
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError()); SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
return NULL; return NULL;
} }
destPathLen = SDL_strlen(srcPath) + 2; destPathLen = SDL_strlen(srcPath) + 2;
destPath = (char *) SDL_malloc(destPathLen); destPath = (char *) SDL_malloc(destPathLen);
if (!destPath) { if (!destPath) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
SDL_snprintf(destPath, destPathLen, "%s\\", srcPath); SDL_snprintf(destPath, destPathLen, "%s\\", srcPath);
return destPath; return destPath;
} }
extern "C" char * extern "C" char *
SDL_GetPrefPath(const char *org, const char *app) SDL_GetPrefPath(const char *org, const char *app)
{ {
/* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and /* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and
* earlier is not available on WinRT or Windows Phone. WinRT provides * earlier is not available on WinRT or Windows Phone. WinRT provides
* a similar API, but SHGetFolderPath can't be called, at least not * a similar API, but SHGetFolderPath can't be called, at least not
* without violating Microsoft's app-store requirements. * without violating Microsoft's app-store requirements.
*/ */
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
/* A 'Roaming' folder is not available in Windows Phone 8, however a 'Local' folder is. */ /* A 'Roaming' folder is not available in Windows Phone 8, however a 'Local' folder is. */
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_LOCAL_FOLDER); const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_LOCAL_FOLDER);
#else #else
/* A 'Roaming' folder is available on Windows 8 and 8.1. Use that. */ /* A 'Roaming' folder is available on Windows 8 and 8.1. Use that. */
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER); const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER);
#endif #endif
size_t destPathLen; size_t destPathLen;
char * destPath = NULL; char * destPath = NULL;
if (!srcPath) { if (!srcPath) {
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError()); SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
return NULL; return NULL;
} }
destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4; destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4;
destPath = (char *) SDL_malloc(destPathLen); destPath = (char *) SDL_malloc(destPathLen);
if (!destPath) { if (!destPath) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app); SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app);
return destPath; return destPath;
} }
#endif /* __WINRT__ */ #endif /* __WINRT__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,56 +1,56 @@
#include <SDL_main.h> #include <SDL_main.h>
#include <wrl.h> #include <wrl.h>
/* At least one file in any SDL/WinRT app appears to require compilation /* At least one file in any SDL/WinRT app appears to require compilation
with C++/CX, otherwise a Windows Metadata file won't get created, and with C++/CX, otherwise a Windows Metadata file won't get created, and
an APPX0702 build error can appear shortly after linking. an APPX0702 build error can appear shortly after linking.
The following set of preprocessor code forces this file to be compiled The following set of preprocessor code forces this file to be compiled
as C++/CX, which appears to cause Visual C++ 2012's build tools to as C++/CX, which appears to cause Visual C++ 2012's build tools to
create this .winmd file, and will help allow builds of SDL/WinRT apps create this .winmd file, and will help allow builds of SDL/WinRT apps
to proceed without error. to proceed without error.
If other files in an app's project enable C++/CX compilation, then it might If other files in an app's project enable C++/CX compilation, then it might
be possible for SDL_winrt_main_NonXAML.cpp to be compiled without /ZW, be possible for SDL_winrt_main_NonXAML.cpp to be compiled without /ZW,
for Visual C++'s build tools to create a winmd file, and for the app to for Visual C++'s build tools to create a winmd file, and for the app to
build without APPX0702 errors. In this case, if build without APPX0702 errors. In this case, if
SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then
the #error (to force C++/CX compilation) will be disabled. the #error (to force C++/CX compilation) will be disabled.
Please note that /ZW can be specified on a file-by-file basis. To do this, Please note that /ZW can be specified on a file-by-file basis. To do this,
right click on the file in Visual C++, click Properties, then change the right click on the file in Visual C++, click Properties, then change the
setting through the dialog that comes up. setting through the dialog that comes up.
*/ */
#ifndef SDL_WINRT_METADATA_FILE_AVAILABLE #ifndef SDL_WINRT_METADATA_FILE_AVAILABLE
#ifndef __cplusplus_winrt #ifndef __cplusplus_winrt
#error SDL_winrt_main_NonXAML.cpp must be compiled with /ZW, otherwise build errors due to missing .winmd files can occur. #error SDL_winrt_main_NonXAML.cpp must be compiled with /ZW, otherwise build errors due to missing .winmd files can occur.
#endif #endif
#endif #endif
/* Prevent MSVC++ from warning about threading models when defining our /* Prevent MSVC++ from warning about threading models when defining our
custom WinMain. The threading model will instead be set via a direct custom WinMain. The threading model will instead be set via a direct
call to Windows::Foundation::Initialize (rather than via an attributed call to Windows::Foundation::Initialize (rather than via an attributed
function). function).
To note, this warning (C4447) does not seem to come up unless this file To note, this warning (C4447) does not seem to come up unless this file
is compiled with C++/CX enabled (via the /ZW compiler flag). is compiled with C++/CX enabled (via the /ZW compiler flag).
*/ */
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable:4447) #pragma warning(disable:4447)
#endif #endif
/* Make sure the function to initialize the Windows Runtime gets linked in. */ /* Make sure the function to initialize the Windows Runtime gets linked in. */
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma comment(lib, "runtimeobject.lib") #pragma comment(lib, "runtimeobject.lib")
#endif #endif
int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{ {
if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) { if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) {
return 1; return 1;
} }
SDL_WinRTRunApp(SDL_main, NULL); SDL_WinRTRunApp(SDL_main, NULL);
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -151,17 +151,17 @@ SDL_SYS_DetachThread(SDL_Thread * thread)
} }
extern "C" extern "C"
SDL_TLSData * SDL_TLSData *
SDL_SYS_GetTLSData() SDL_SYS_GetTLSData()
{ {
return SDL_Generic_GetTLSData(); return SDL_Generic_GetTLSData();
} }
extern "C" extern "C"
int int
SDL_SYS_SetTLSData(SDL_TLSData *data) SDL_SYS_SetTLSData(SDL_TLSData *data)
{ {
return SDL_Generic_SetTLSData(data); return SDL_Generic_SetTLSData(data);
} }
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -170,17 +170,17 @@ SDL_GetPerformanceFrequency(void)
return frequency.QuadPart; return frequency.QuadPart;
} }
#ifdef __WINRT__ #ifdef __WINRT__
static void static void
Sleep(DWORD timeout) Sleep(DWORD timeout)
{ {
static HANDLE mutex = 0; static HANDLE mutex = 0;
if ( ! mutex ) if ( ! mutex )
{ {
mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS); mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
} }
WaitForSingleObjectEx(mutex, timeout, FALSE); WaitForSingleObjectEx(mutex, timeout, FALSE);
} }
#endif #endif
void void

View File

@ -1,401 +1,401 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#ifndef _SDL_sysvideo_h #ifndef _SDL_sysvideo_h
#define _SDL_sysvideo_h #define _SDL_sysvideo_h
#include "SDL_messagebox.h" #include "SDL_messagebox.h"
#include "SDL_shape.h" #include "SDL_shape.h"
#include "SDL_thread.h" #include "SDL_thread.h"
/* The SDL video driver */ /* The SDL video driver */
typedef struct SDL_WindowShaper SDL_WindowShaper; typedef struct SDL_WindowShaper SDL_WindowShaper;
typedef struct SDL_ShapeDriver SDL_ShapeDriver; typedef struct SDL_ShapeDriver SDL_ShapeDriver;
typedef struct SDL_VideoDisplay SDL_VideoDisplay; typedef struct SDL_VideoDisplay SDL_VideoDisplay;
typedef struct SDL_VideoDevice SDL_VideoDevice; typedef struct SDL_VideoDevice SDL_VideoDevice;
/* Define the SDL window-shaper structure */ /* Define the SDL window-shaper structure */
struct SDL_WindowShaper struct SDL_WindowShaper
{ {
/* The window associated with the shaper */ /* The window associated with the shaper */
SDL_Window *window; SDL_Window *window;
/* The user's specified coordinates for the window, for once we give it a shape. */ /* The user's specified coordinates for the window, for once we give it a shape. */
Uint32 userx,usery; Uint32 userx,usery;
/* The parameters for shape calculation. */ /* The parameters for shape calculation. */
SDL_WindowShapeMode mode; SDL_WindowShapeMode mode;
/* Has this window been assigned a shape? */ /* Has this window been assigned a shape? */
SDL_bool hasshape; SDL_bool hasshape;
void *driverdata; void *driverdata;
}; };
/* Define the SDL shape driver structure */ /* Define the SDL shape driver structure */
struct SDL_ShapeDriver struct SDL_ShapeDriver
{ {
SDL_WindowShaper *(*CreateShaper)(SDL_Window * window); SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode); int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
int (*ResizeWindowShape)(SDL_Window *window); int (*ResizeWindowShape)(SDL_Window *window);
}; };
typedef struct SDL_WindowUserData typedef struct SDL_WindowUserData
{ {
char *name; char *name;
void *data; void *data;
struct SDL_WindowUserData *next; struct SDL_WindowUserData *next;
} SDL_WindowUserData; } SDL_WindowUserData;
/* Define the SDL window structure, corresponding to toplevel windows */ /* Define the SDL window structure, corresponding to toplevel windows */
struct SDL_Window struct SDL_Window
{ {
const void *magic; const void *magic;
Uint32 id; Uint32 id;
char *title; char *title;
SDL_Surface *icon; SDL_Surface *icon;
int x, y; int x, y;
int w, h; int w, h;
int min_w, min_h; int min_w, min_h;
int max_w, max_h; int max_w, max_h;
Uint32 flags; Uint32 flags;
/* Stored position and size for windowed mode */ /* Stored position and size for windowed mode */
SDL_Rect windowed; SDL_Rect windowed;
SDL_DisplayMode fullscreen_mode; SDL_DisplayMode fullscreen_mode;
float brightness; float brightness;
Uint16 *gamma; Uint16 *gamma;
Uint16 *saved_gamma; /* (just offset into gamma) */ Uint16 *saved_gamma; /* (just offset into gamma) */
SDL_Surface *surface; SDL_Surface *surface;
SDL_bool surface_valid; SDL_bool surface_valid;
SDL_WindowShaper *shaper; SDL_WindowShaper *shaper;
SDL_WindowUserData *data; SDL_WindowUserData *data;
void *driverdata; void *driverdata;
SDL_Window *prev; SDL_Window *prev;
SDL_Window *next; SDL_Window *next;
}; };
#define FULLSCREEN_VISIBLE(W) \ #define FULLSCREEN_VISIBLE(W) \
(((W)->flags & SDL_WINDOW_FULLSCREEN) && \ (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
((W)->flags & SDL_WINDOW_SHOWN) && \ ((W)->flags & SDL_WINDOW_SHOWN) && \
!((W)->flags & SDL_WINDOW_MINIMIZED)) !((W)->flags & SDL_WINDOW_MINIMIZED))
/* /*
* Define the SDL display structure This corresponds to physical monitors * Define the SDL display structure This corresponds to physical monitors
* attached to the system. * attached to the system.
*/ */
struct SDL_VideoDisplay struct SDL_VideoDisplay
{ {
char *name; char *name;
int max_display_modes; int max_display_modes;
int num_display_modes; int num_display_modes;
SDL_DisplayMode *display_modes; SDL_DisplayMode *display_modes;
SDL_DisplayMode desktop_mode; SDL_DisplayMode desktop_mode;
SDL_DisplayMode current_mode; SDL_DisplayMode current_mode;
SDL_Window *fullscreen_window; SDL_Window *fullscreen_window;
SDL_VideoDevice *device; SDL_VideoDevice *device;
void *driverdata; void *driverdata;
}; };
/* Forward declaration */ /* Forward declaration */
struct SDL_SysWMinfo; struct SDL_SysWMinfo;
/* Define the SDL video driver structure */ /* Define the SDL video driver structure */
#define _THIS SDL_VideoDevice *_this #define _THIS SDL_VideoDevice *_this
struct SDL_VideoDevice struct SDL_VideoDevice
{ {
/* * * */ /* * * */
/* The name of this video driver */ /* The name of this video driver */
const char *name; const char *name;
/* * * */ /* * * */
/* Initialization/Query functions */ /* Initialization/Query functions */
/* /*
* Initialize the native video subsystem, filling in the list of * Initialize the native video subsystem, filling in the list of
* displays for this driver, returning 0 or -1 if there's an error. * displays for this driver, returning 0 or -1 if there's an error.
*/ */
int (*VideoInit) (_THIS); int (*VideoInit) (_THIS);
/* /*
* Reverse the effects VideoInit() -- called if VideoInit() fails or * Reverse the effects VideoInit() -- called if VideoInit() fails or
* if the application is shutting down the video subsystem. * if the application is shutting down the video subsystem.
*/ */
void (*VideoQuit) (_THIS); void (*VideoQuit) (_THIS);
/* * * */ /* * * */
/* /*
* Display functions * Display functions
*/ */
/* /*
* Get the bounds of a display * Get the bounds of a display
*/ */
int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
/* /*
* Get a list of the available display modes for a display. * Get a list of the available display modes for a display.
*/ */
void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display); void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
/* /*
* Setting the display mode is independent of creating windows, so * Setting the display mode is independent of creating windows, so
* when the display mode is changed, all existing windows should have * when the display mode is changed, all existing windows should have
* their data updated accordingly, including the display surfaces * their data updated accordingly, including the display surfaces
* associated with them. * associated with them.
*/ */
int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
/* * * */ /* * * */
/* /*
* Window functions * Window functions
*/ */
int (*CreateWindow) (_THIS, SDL_Window * window); int (*CreateWindow) (_THIS, SDL_Window * window);
int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data); int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
void (*SetWindowTitle) (_THIS, SDL_Window * window); void (*SetWindowTitle) (_THIS, SDL_Window * window);
void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon); void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
void (*SetWindowPosition) (_THIS, SDL_Window * window); void (*SetWindowPosition) (_THIS, SDL_Window * window);
void (*SetWindowSize) (_THIS, SDL_Window * window); void (*SetWindowSize) (_THIS, SDL_Window * window);
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window); void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
void (*SetWindowMaximumSize) (_THIS, SDL_Window * window); void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
void (*ShowWindow) (_THIS, SDL_Window * window); void (*ShowWindow) (_THIS, SDL_Window * window);
void (*HideWindow) (_THIS, SDL_Window * window); void (*HideWindow) (_THIS, SDL_Window * window);
void (*RaiseWindow) (_THIS, SDL_Window * window); void (*RaiseWindow) (_THIS, SDL_Window * window);
void (*MaximizeWindow) (_THIS, SDL_Window * window); void (*MaximizeWindow) (_THIS, SDL_Window * window);
void (*MinimizeWindow) (_THIS, SDL_Window * window); void (*MinimizeWindow) (_THIS, SDL_Window * window);
void (*RestoreWindow) (_THIS, SDL_Window * window); void (*RestoreWindow) (_THIS, SDL_Window * window);
void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered); void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen); void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp); int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp); int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed); void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
void (*DestroyWindow) (_THIS, SDL_Window * window); void (*DestroyWindow) (_THIS, SDL_Window * window);
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch); int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects); int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window); void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
void (*OnWindowEnter) (_THIS, SDL_Window * window); void (*OnWindowEnter) (_THIS, SDL_Window * window);
/* * * */ /* * * */
/* /*
* Shaped-window functions * Shaped-window functions
*/ */
SDL_ShapeDriver shape_driver; SDL_ShapeDriver shape_driver;
/* Get some platform dependent window information */ /* Get some platform dependent window information */
SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window, SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
struct SDL_SysWMinfo * info); struct SDL_SysWMinfo * info);
/* * * */ /* * * */
/* /*
* OpenGL support * OpenGL support
*/ */
int (*GL_LoadLibrary) (_THIS, const char *path); int (*GL_LoadLibrary) (_THIS, const char *path);
void *(*GL_GetProcAddress) (_THIS, const char *proc); void *(*GL_GetProcAddress) (_THIS, const char *proc);
void (*GL_UnloadLibrary) (_THIS); void (*GL_UnloadLibrary) (_THIS);
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window); SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context); int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h); void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
int (*GL_SetSwapInterval) (_THIS, int interval); int (*GL_SetSwapInterval) (_THIS, int interval);
int (*GL_GetSwapInterval) (_THIS); int (*GL_GetSwapInterval) (_THIS);
void (*GL_SwapWindow) (_THIS, SDL_Window * window); void (*GL_SwapWindow) (_THIS, SDL_Window * window);
void (*GL_DeleteContext) (_THIS, SDL_GLContext context); void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
/* * * */ /* * * */
/* /*
* Event manager functions * Event manager functions
*/ */
void (*PumpEvents) (_THIS); void (*PumpEvents) (_THIS);
/* Suspend the screensaver */ /* Suspend the screensaver */
void (*SuspendScreenSaver) (_THIS); void (*SuspendScreenSaver) (_THIS);
/* Text input */ /* Text input */
void (*StartTextInput) (_THIS); void (*StartTextInput) (_THIS);
void (*StopTextInput) (_THIS); void (*StopTextInput) (_THIS);
void (*SetTextInputRect) (_THIS, SDL_Rect *rect); void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
/* Screen keyboard */ /* Screen keyboard */
SDL_bool (*HasScreenKeyboardSupport) (_THIS); SDL_bool (*HasScreenKeyboardSupport) (_THIS);
void (*ShowScreenKeyboard) (_THIS, SDL_Window *window); void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
void (*HideScreenKeyboard) (_THIS, SDL_Window *window); void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window); SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
/* Clipboard */ /* Clipboard */
int (*SetClipboardText) (_THIS, const char *text); int (*SetClipboardText) (_THIS, const char *text);
char * (*GetClipboardText) (_THIS); char * (*GetClipboardText) (_THIS);
SDL_bool (*HasClipboardText) (_THIS); SDL_bool (*HasClipboardText) (_THIS);
/* MessageBox */ /* MessageBox */
int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid); int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
/* * * */ /* * * */
/* Data common to all drivers */ /* Data common to all drivers */
SDL_bool suspend_screensaver; SDL_bool suspend_screensaver;
int num_displays; int num_displays;
SDL_VideoDisplay *displays; SDL_VideoDisplay *displays;
SDL_Window *windows; SDL_Window *windows;
Uint8 window_magic; Uint8 window_magic;
Uint32 next_object_id; Uint32 next_object_id;
char * clipboard_text; char * clipboard_text;
/* * * */ /* * * */
/* Data used by the GL drivers */ /* Data used by the GL drivers */
struct struct
{ {
int red_size; int red_size;
int green_size; int green_size;
int blue_size; int blue_size;
int alpha_size; int alpha_size;
int depth_size; int depth_size;
int buffer_size; int buffer_size;
int stencil_size; int stencil_size;
int double_buffer; int double_buffer;
int accum_red_size; int accum_red_size;
int accum_green_size; int accum_green_size;
int accum_blue_size; int accum_blue_size;
int accum_alpha_size; int accum_alpha_size;
int stereo; int stereo;
int multisamplebuffers; int multisamplebuffers;
int multisamplesamples; int multisamplesamples;
int accelerated; int accelerated;
int major_version; int major_version;
int minor_version; int minor_version;
int flags; int flags;
int profile_mask; int profile_mask;
int share_with_current_context; int share_with_current_context;
int framebuffer_srgb_capable; int framebuffer_srgb_capable;
int retained_backing; int retained_backing;
int driver_loaded; int driver_loaded;
char driver_path[256]; char driver_path[256];
void *dll_handle; void *dll_handle;
} gl_config; } gl_config;
/* * * */ /* * * */
/* Cache current GL context; don't call the OS when it hasn't changed. */ /* Cache current GL context; don't call the OS when it hasn't changed. */
/* We have the global pointers here so Cocoa continues to work the way /* We have the global pointers here so Cocoa continues to work the way
it always has, and the thread-local storage for the general case. it always has, and the thread-local storage for the general case.
*/ */
SDL_Window *current_glwin; SDL_Window *current_glwin;
SDL_GLContext current_glctx; SDL_GLContext current_glctx;
SDL_TLSID current_glwin_tls; SDL_TLSID current_glwin_tls;
SDL_TLSID current_glctx_tls; SDL_TLSID current_glctx_tls;
/* * * */ /* * * */
/* Data private to this driver */ /* Data private to this driver */
void *driverdata; void *driverdata;
struct SDL_GLDriverData *gl_data; struct SDL_GLDriverData *gl_data;
#if SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_OPENGL_EGL
struct SDL_EGL_VideoData *egl_data; struct SDL_EGL_VideoData *egl_data;
#endif #endif
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
struct SDL_PrivateGLESData *gles_data; struct SDL_PrivateGLESData *gles_data;
#endif #endif
/* * * */ /* * * */
/* The function used to dispose of this structure */ /* The function used to dispose of this structure */
void (*free) (_THIS); void (*free) (_THIS);
}; };
typedef struct VideoBootStrap typedef struct VideoBootStrap
{ {
const char *name; const char *name;
const char *desc; const char *desc;
int (*available) (void); int (*available) (void);
SDL_VideoDevice *(*create) (int devindex); SDL_VideoDevice *(*create) (int devindex);
} VideoBootStrap; } VideoBootStrap;
#if SDL_VIDEO_DRIVER_COCOA #if SDL_VIDEO_DRIVER_COCOA
extern VideoBootStrap COCOA_bootstrap; extern VideoBootStrap COCOA_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_X11 #if SDL_VIDEO_DRIVER_X11
extern VideoBootStrap X11_bootstrap; extern VideoBootStrap X11_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_DIRECTFB #if SDL_VIDEO_DRIVER_DIRECTFB
extern VideoBootStrap DirectFB_bootstrap; extern VideoBootStrap DirectFB_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_WINDOWS #if SDL_VIDEO_DRIVER_WINDOWS
extern VideoBootStrap WINDOWS_bootstrap; extern VideoBootStrap WINDOWS_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_WINRT #if SDL_VIDEO_DRIVER_WINRT
extern VideoBootStrap WINRT_bootstrap; extern VideoBootStrap WINRT_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_HAIKU #if SDL_VIDEO_DRIVER_HAIKU
extern VideoBootStrap HAIKU_bootstrap; extern VideoBootStrap HAIKU_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_PANDORA #if SDL_VIDEO_DRIVER_PANDORA
extern VideoBootStrap PND_bootstrap; extern VideoBootStrap PND_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_UIKIT #if SDL_VIDEO_DRIVER_UIKIT
extern VideoBootStrap UIKIT_bootstrap; extern VideoBootStrap UIKIT_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_ANDROID #if SDL_VIDEO_DRIVER_ANDROID
extern VideoBootStrap Android_bootstrap; extern VideoBootStrap Android_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_PSP #if SDL_VIDEO_DRIVER_PSP
extern VideoBootStrap PSP_bootstrap; extern VideoBootStrap PSP_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_RPI #if SDL_VIDEO_DRIVER_RPI
extern VideoBootStrap RPI_bootstrap; extern VideoBootStrap RPI_bootstrap;
#endif #endif
#if SDL_VIDEO_DRIVER_DUMMY #if SDL_VIDEO_DRIVER_DUMMY
extern VideoBootStrap DUMMY_bootstrap; extern VideoBootStrap DUMMY_bootstrap;
#endif #endif
extern SDL_VideoDevice *SDL_GetVideoDevice(void); extern SDL_VideoDevice *SDL_GetVideoDevice(void);
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode); extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display); extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode); extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window); extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
extern void *SDL_GetDisplayDriverData( int displayIndex ); extern void *SDL_GetDisplayDriverData( int displayIndex );
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
extern void SDL_OnWindowShown(SDL_Window * window); extern void SDL_OnWindowShown(SDL_Window * window);
extern void SDL_OnWindowHidden(SDL_Window * window); extern void SDL_OnWindowHidden(SDL_Window * window);
extern void SDL_OnWindowResized(SDL_Window * window); extern void SDL_OnWindowResized(SDL_Window * window);
extern void SDL_OnWindowMinimized(SDL_Window * window); extern void SDL_OnWindowMinimized(SDL_Window * window);
extern void SDL_OnWindowRestored(SDL_Window * window); extern void SDL_OnWindowRestored(SDL_Window * window);
extern void SDL_OnWindowEnter(SDL_Window * window); extern void SDL_OnWindowEnter(SDL_Window * window);
extern void SDL_OnWindowLeave(SDL_Window * window); extern void SDL_OnWindowLeave(SDL_Window * window);
extern void SDL_OnWindowFocusGained(SDL_Window * window); extern void SDL_OnWindowFocusGained(SDL_Window * window);
extern void SDL_OnWindowFocusLost(SDL_Window * window); extern void SDL_OnWindowFocusLost(SDL_Window * window);
extern void SDL_UpdateWindowGrab(SDL_Window * window); extern void SDL_UpdateWindowGrab(SDL_Window * window);
extern SDL_Window * SDL_GetFocusWindow(void); extern SDL_Window * SDL_GetFocusWindow(void);
extern SDL_bool SDL_ShouldAllowTopmost(void); extern SDL_bool SDL_ShouldAllowTopmost(void);
#endif /* _SDL_sysvideo_h */ #endif /* _SDL_sysvideo_h */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

File diff suppressed because it is too large Load Diff

View File

@ -22,15 +22,15 @@
#if SDL_VIDEO_DRIVER_WINRT #if SDL_VIDEO_DRIVER_WINRT
/* /*
* Windows includes: * Windows includes:
*/ */
#include <Windows.h> #include <Windows.h>
using namespace Windows::UI::Core; using namespace Windows::UI::Core;
using Windows::UI::Core::CoreCursor; using Windows::UI::Core::CoreCursor;
/* /*
* SDL includes: * SDL includes:
*/ */
#include "SDL_winrtevents_c.h" #include "SDL_winrtevents_c.h"
#include "../../core/winrt/SDL_winrtapp_common.h" #include "../../core/winrt/SDL_winrtapp_common.h"
@ -63,89 +63,89 @@ WINRT_PumpEvents(_THIS)
/* XAML Thread management */ /* XAML Thread management */
enum SDL_XAMLAppThreadState enum SDL_XAMLAppThreadState
{ {
ThreadState_NotLaunched = 0, ThreadState_NotLaunched = 0,
ThreadState_Running, ThreadState_Running,
ThreadState_Yielding ThreadState_Yielding
}; };
static SDL_XAMLAppThreadState _threadState = ThreadState_NotLaunched; static SDL_XAMLAppThreadState _threadState = ThreadState_NotLaunched;
static SDL_Thread * _XAMLThread = nullptr; static SDL_Thread * _XAMLThread = nullptr;
static SDL_mutex * _mutex = nullptr; static SDL_mutex * _mutex = nullptr;
static SDL_cond * _cond = nullptr; static SDL_cond * _cond = nullptr;
static void static void
WINRT_YieldXAMLThread() WINRT_YieldXAMLThread()
{ {
SDL_LockMutex(_mutex); SDL_LockMutex(_mutex);
SDL_assert(_threadState == ThreadState_Running); SDL_assert(_threadState == ThreadState_Running);
_threadState = ThreadState_Yielding; _threadState = ThreadState_Yielding;
SDL_UnlockMutex(_mutex); SDL_UnlockMutex(_mutex);
SDL_CondSignal(_cond); SDL_CondSignal(_cond);
SDL_LockMutex(_mutex); SDL_LockMutex(_mutex);
while (_threadState != ThreadState_Running) { while (_threadState != ThreadState_Running) {
SDL_CondWait(_cond, _mutex); SDL_CondWait(_cond, _mutex);
} }
SDL_UnlockMutex(_mutex); SDL_UnlockMutex(_mutex);
} }
static int static int
WINRT_XAMLThreadMain(void * userdata) WINRT_XAMLThreadMain(void * userdata)
{ {
// TODO, WinRT: pass the C-style main() a reasonably realistic // TODO, WinRT: pass the C-style main() a reasonably realistic
// representation of command line arguments. // representation of command line arguments.
int argc = 0; int argc = 0;
char **argv = NULL; char **argv = NULL;
return WINRT_SDLAppEntryPoint(argc, argv); return WINRT_SDLAppEntryPoint(argc, argv);
} }
void void
WINRT_CycleXAMLThread() WINRT_CycleXAMLThread()
{ {
switch (_threadState) { switch (_threadState) {
case ThreadState_NotLaunched: case ThreadState_NotLaunched:
{ {
_cond = SDL_CreateCond(); _cond = SDL_CreateCond();
_mutex = SDL_CreateMutex(); _mutex = SDL_CreateMutex();
_threadState = ThreadState_Running; _threadState = ThreadState_Running;
_XAMLThread = SDL_CreateThread(WINRT_XAMLThreadMain, "SDL/XAML App Thread", nullptr); _XAMLThread = SDL_CreateThread(WINRT_XAMLThreadMain, "SDL/XAML App Thread", nullptr);
SDL_LockMutex(_mutex); SDL_LockMutex(_mutex);
while (_threadState != ThreadState_Yielding) { while (_threadState != ThreadState_Yielding) {
SDL_CondWait(_cond, _mutex); SDL_CondWait(_cond, _mutex);
} }
SDL_UnlockMutex(_mutex); SDL_UnlockMutex(_mutex);
break; break;
} }
case ThreadState_Running: case ThreadState_Running:
{ {
SDL_assert(false); SDL_assert(false);
break; break;
} }
case ThreadState_Yielding: case ThreadState_Yielding:
{ {
SDL_LockMutex(_mutex); SDL_LockMutex(_mutex);
SDL_assert(_threadState == ThreadState_Yielding); SDL_assert(_threadState == ThreadState_Yielding);
_threadState = ThreadState_Running; _threadState = ThreadState_Running;
SDL_UnlockMutex(_mutex); SDL_UnlockMutex(_mutex);
SDL_CondSignal(_cond); SDL_CondSignal(_cond);
SDL_LockMutex(_mutex); SDL_LockMutex(_mutex);
while (_threadState != ThreadState_Yielding) { while (_threadState != ThreadState_Yielding) {
SDL_CondWait(_cond, _mutex); SDL_CondWait(_cond, _mutex);
} }
SDL_UnlockMutex(_mutex); SDL_UnlockMutex(_mutex);
} }
} }
} }
#endif /* SDL_VIDEO_DRIVER_WINRT */ #endif /* SDL_VIDEO_DRIVER_WINRT */

View File

@ -46,9 +46,9 @@ extern void WINRT_PumpEvents(_THIS);
#ifdef __cplusplus_winrt #ifdef __cplusplus_winrt
/* Pointers (Mice, Touch, etc.) */ /* Pointers (Mice, Touch, etc.) */
typedef enum { typedef enum {
NormalizeZeroToOne, NormalizeZeroToOne,
TransformToSDLWindowSize TransformToSDLWindowSize
} WINRT_CursorNormalizationType; } WINRT_CursorNormalizationType;
extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window, extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window,
Windows::Foundation::Point rawPosition, Windows::Foundation::Point rawPosition,

View File

@ -1,301 +1,301 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#if SDL_VIDEO_DRIVER_WINRT #if SDL_VIDEO_DRIVER_WINRT
/* Standard C++11 includes */ /* Standard C++11 includes */
#include <unordered_map> #include <unordered_map>
/* Windows-specific includes */ /* Windows-specific includes */
#include <Windows.h> #include <Windows.h>
#include <agile.h> #include <agile.h>
/* SDL-specific includes */ /* SDL-specific includes */
#include <SDL.h> #include <SDL.h>
#include "SDL_winrtevents_c.h" #include "SDL_winrtevents_c.h"
extern "C" { extern "C" {
#include "../../events/scancodes_windows.h" #include "../../events/scancodes_windows.h"
#include "../../events/SDL_keyboard_c.h" #include "../../events/SDL_keyboard_c.h"
} }
static SDL_Scancode WinRT_Official_Keycodes[] = { static SDL_Scancode WinRT_Official_Keycodes[] = {
SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0 SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1 SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2 SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3 SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4 SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5 SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6 SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
SDL_SCANCODE_UNKNOWN, // -- 7 SDL_SCANCODE_UNKNOWN, // -- 7
SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8 SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9 SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
SDL_SCANCODE_UNKNOWN, // -- 10 SDL_SCANCODE_UNKNOWN, // -- 10
SDL_SCANCODE_UNKNOWN, // -- 11 SDL_SCANCODE_UNKNOWN, // -- 11
SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12 SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13 SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
SDL_SCANCODE_UNKNOWN, // -- 14 SDL_SCANCODE_UNKNOWN, // -- 14
SDL_SCANCODE_UNKNOWN, // -- 15 SDL_SCANCODE_UNKNOWN, // -- 15
SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16 SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17 SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18 SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19 SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20 SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21 SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
SDL_SCANCODE_UNKNOWN, // -- 22 SDL_SCANCODE_UNKNOWN, // -- 22
SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23 SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24 SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25 SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
SDL_SCANCODE_UNKNOWN, // -- 26 SDL_SCANCODE_UNKNOWN, // -- 26
SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27 SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28 SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29 SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30 SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31 (maybe SDL_SCANCODE_MODE ?) SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31 (maybe SDL_SCANCODE_MODE ?)
SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32 SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33 SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34 SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
SDL_SCANCODE_END, // VirtualKey.End -- 35 SDL_SCANCODE_END, // VirtualKey.End -- 35
SDL_SCANCODE_HOME, // VirtualKey.Home -- 36 SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37 SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
SDL_SCANCODE_UP, // VirtualKey.Up -- 38 SDL_SCANCODE_UP, // VirtualKey.Up -- 38
SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39 SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40 SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41 SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42 (maybe SDL_SCANCODE_PRINTSCREEN ?) SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42 (maybe SDL_SCANCODE_PRINTSCREEN ?)
SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43 SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44 SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45 SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46 SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
SDL_SCANCODE_HELP, // VirtualKey.Help -- 47 SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
SDL_SCANCODE_0, // VirtualKey.Number0 -- 48 SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
SDL_SCANCODE_1, // VirtualKey.Number1 -- 49 SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
SDL_SCANCODE_2, // VirtualKey.Number2 -- 50 SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
SDL_SCANCODE_3, // VirtualKey.Number3 -- 51 SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
SDL_SCANCODE_4, // VirtualKey.Number4 -- 52 SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
SDL_SCANCODE_5, // VirtualKey.Number5 -- 53 SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
SDL_SCANCODE_6, // VirtualKey.Number6 -- 54 SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
SDL_SCANCODE_7, // VirtualKey.Number7 -- 55 SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
SDL_SCANCODE_8, // VirtualKey.Number8 -- 56 SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
SDL_SCANCODE_9, // VirtualKey.Number9 -- 57 SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
SDL_SCANCODE_UNKNOWN, // -- 58 SDL_SCANCODE_UNKNOWN, // -- 58
SDL_SCANCODE_UNKNOWN, // -- 59 SDL_SCANCODE_UNKNOWN, // -- 59
SDL_SCANCODE_UNKNOWN, // -- 60 SDL_SCANCODE_UNKNOWN, // -- 60
SDL_SCANCODE_UNKNOWN, // -- 61 SDL_SCANCODE_UNKNOWN, // -- 61
SDL_SCANCODE_UNKNOWN, // -- 62 SDL_SCANCODE_UNKNOWN, // -- 62
SDL_SCANCODE_UNKNOWN, // -- 63 SDL_SCANCODE_UNKNOWN, // -- 63
SDL_SCANCODE_UNKNOWN, // -- 64 SDL_SCANCODE_UNKNOWN, // -- 64
SDL_SCANCODE_A, // VirtualKey.A -- 65 SDL_SCANCODE_A, // VirtualKey.A -- 65
SDL_SCANCODE_B, // VirtualKey.B -- 66 SDL_SCANCODE_B, // VirtualKey.B -- 66
SDL_SCANCODE_C, // VirtualKey.C -- 67 SDL_SCANCODE_C, // VirtualKey.C -- 67
SDL_SCANCODE_D, // VirtualKey.D -- 68 SDL_SCANCODE_D, // VirtualKey.D -- 68
SDL_SCANCODE_E, // VirtualKey.E -- 69 SDL_SCANCODE_E, // VirtualKey.E -- 69
SDL_SCANCODE_F, // VirtualKey.F -- 70 SDL_SCANCODE_F, // VirtualKey.F -- 70
SDL_SCANCODE_G, // VirtualKey.G -- 71 SDL_SCANCODE_G, // VirtualKey.G -- 71
SDL_SCANCODE_H, // VirtualKey.H -- 72 SDL_SCANCODE_H, // VirtualKey.H -- 72
SDL_SCANCODE_I, // VirtualKey.I -- 73 SDL_SCANCODE_I, // VirtualKey.I -- 73
SDL_SCANCODE_J, // VirtualKey.J -- 74 SDL_SCANCODE_J, // VirtualKey.J -- 74
SDL_SCANCODE_K, // VirtualKey.K -- 75 SDL_SCANCODE_K, // VirtualKey.K -- 75
SDL_SCANCODE_L, // VirtualKey.L -- 76 SDL_SCANCODE_L, // VirtualKey.L -- 76
SDL_SCANCODE_M, // VirtualKey.M -- 77 SDL_SCANCODE_M, // VirtualKey.M -- 77
SDL_SCANCODE_N, // VirtualKey.N -- 78 SDL_SCANCODE_N, // VirtualKey.N -- 78
SDL_SCANCODE_O, // VirtualKey.O -- 79 SDL_SCANCODE_O, // VirtualKey.O -- 79
SDL_SCANCODE_P, // VirtualKey.P -- 80 SDL_SCANCODE_P, // VirtualKey.P -- 80
SDL_SCANCODE_Q, // VirtualKey.Q -- 81 SDL_SCANCODE_Q, // VirtualKey.Q -- 81
SDL_SCANCODE_R, // VirtualKey.R -- 82 SDL_SCANCODE_R, // VirtualKey.R -- 82
SDL_SCANCODE_S, // VirtualKey.S -- 83 SDL_SCANCODE_S, // VirtualKey.S -- 83
SDL_SCANCODE_T, // VirtualKey.T -- 84 SDL_SCANCODE_T, // VirtualKey.T -- 84
SDL_SCANCODE_U, // VirtualKey.U -- 85 SDL_SCANCODE_U, // VirtualKey.U -- 85
SDL_SCANCODE_V, // VirtualKey.V -- 86 SDL_SCANCODE_V, // VirtualKey.V -- 86
SDL_SCANCODE_W, // VirtualKey.W -- 87 SDL_SCANCODE_W, // VirtualKey.W -- 87
SDL_SCANCODE_X, // VirtualKey.X -- 88 SDL_SCANCODE_X, // VirtualKey.X -- 88
SDL_SCANCODE_Y, // VirtualKey.Y -- 89 SDL_SCANCODE_Y, // VirtualKey.Y -- 89
SDL_SCANCODE_Z, // VirtualKey.Z -- 90 SDL_SCANCODE_Z, // VirtualKey.Z -- 90
SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?) SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftWindows -- 91 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?)
SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?) SDL_SCANCODE_UNKNOWN, // VirtualKey.RightWindows -- 92 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?)
SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93 SDL_SCANCODE_APPLICATION, // VirtualKey.Application -- 93
SDL_SCANCODE_UNKNOWN, // -- 94 SDL_SCANCODE_UNKNOWN, // -- 94
SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95 SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96 SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97 SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98 SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99 SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100 SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101 SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102 SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103 SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104 SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105 SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106 SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107 SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108 SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109 SDL_SCANCODE_KP_MINUS, // VirtualKey.Subtract -- 109
SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110 (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?) SDL_SCANCODE_UNKNOWN, // VirtualKey.Decimal -- 110 (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?)
SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111 SDL_SCANCODE_KP_DIVIDE, // VirtualKey.Divide -- 111
SDL_SCANCODE_F1, // VirtualKey.F1 -- 112 SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
SDL_SCANCODE_F2, // VirtualKey.F2 -- 113 SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
SDL_SCANCODE_F3, // VirtualKey.F3 -- 114 SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
SDL_SCANCODE_F4, // VirtualKey.F4 -- 115 SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
SDL_SCANCODE_F5, // VirtualKey.F5 -- 116 SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
SDL_SCANCODE_F6, // VirtualKey.F6 -- 117 SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
SDL_SCANCODE_F7, // VirtualKey.F7 -- 118 SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
SDL_SCANCODE_F8, // VirtualKey.F8 -- 119 SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
SDL_SCANCODE_F9, // VirtualKey.F9 -- 120 SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
SDL_SCANCODE_F10, // VirtualKey.F10 -- 121 SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
SDL_SCANCODE_F11, // VirtualKey.F11 -- 122 SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
SDL_SCANCODE_F12, // VirtualKey.F12 -- 123 SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
SDL_SCANCODE_F13, // VirtualKey.F13 -- 124 SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
SDL_SCANCODE_F14, // VirtualKey.F14 -- 125 SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
SDL_SCANCODE_F15, // VirtualKey.F15 -- 126 SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
SDL_SCANCODE_F16, // VirtualKey.F16 -- 127 SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
SDL_SCANCODE_F17, // VirtualKey.F17 -- 128 SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
SDL_SCANCODE_F18, // VirtualKey.F18 -- 129 SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
SDL_SCANCODE_F19, // VirtualKey.F19 -- 130 SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
SDL_SCANCODE_F20, // VirtualKey.F20 -- 131 SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
SDL_SCANCODE_F21, // VirtualKey.F21 -- 132 SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
SDL_SCANCODE_F22, // VirtualKey.F22 -- 133 SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
SDL_SCANCODE_F23, // VirtualKey.F23 -- 134 SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
SDL_SCANCODE_F24, // VirtualKey.F24 -- 135 SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
SDL_SCANCODE_UNKNOWN, // -- 136 SDL_SCANCODE_UNKNOWN, // -- 136
SDL_SCANCODE_UNKNOWN, // -- 137 SDL_SCANCODE_UNKNOWN, // -- 137
SDL_SCANCODE_UNKNOWN, // -- 138 SDL_SCANCODE_UNKNOWN, // -- 138
SDL_SCANCODE_UNKNOWN, // -- 139 SDL_SCANCODE_UNKNOWN, // -- 139
SDL_SCANCODE_UNKNOWN, // -- 140 SDL_SCANCODE_UNKNOWN, // -- 140
SDL_SCANCODE_UNKNOWN, // -- 141 SDL_SCANCODE_UNKNOWN, // -- 141
SDL_SCANCODE_UNKNOWN, // -- 142 SDL_SCANCODE_UNKNOWN, // -- 142
SDL_SCANCODE_UNKNOWN, // -- 143 SDL_SCANCODE_UNKNOWN, // -- 143
SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144 SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145 SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
SDL_SCANCODE_UNKNOWN, // -- 146 SDL_SCANCODE_UNKNOWN, // -- 146
SDL_SCANCODE_UNKNOWN, // -- 147 SDL_SCANCODE_UNKNOWN, // -- 147
SDL_SCANCODE_UNKNOWN, // -- 148 SDL_SCANCODE_UNKNOWN, // -- 148
SDL_SCANCODE_UNKNOWN, // -- 149 SDL_SCANCODE_UNKNOWN, // -- 149
SDL_SCANCODE_UNKNOWN, // -- 150 SDL_SCANCODE_UNKNOWN, // -- 150
SDL_SCANCODE_UNKNOWN, // -- 151 SDL_SCANCODE_UNKNOWN, // -- 151
SDL_SCANCODE_UNKNOWN, // -- 152 SDL_SCANCODE_UNKNOWN, // -- 152
SDL_SCANCODE_UNKNOWN, // -- 153 SDL_SCANCODE_UNKNOWN, // -- 153
SDL_SCANCODE_UNKNOWN, // -- 154 SDL_SCANCODE_UNKNOWN, // -- 154
SDL_SCANCODE_UNKNOWN, // -- 155 SDL_SCANCODE_UNKNOWN, // -- 155
SDL_SCANCODE_UNKNOWN, // -- 156 SDL_SCANCODE_UNKNOWN, // -- 156
SDL_SCANCODE_UNKNOWN, // -- 157 SDL_SCANCODE_UNKNOWN, // -- 157
SDL_SCANCODE_UNKNOWN, // -- 158 SDL_SCANCODE_UNKNOWN, // -- 158
SDL_SCANCODE_UNKNOWN, // -- 159 SDL_SCANCODE_UNKNOWN, // -- 159
SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160 SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161 SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162 SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163 SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164 SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165 SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
}; };
static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes; static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
static SDL_Scancode static SDL_Scancode
TranslateKeycode(int keycode) TranslateKeycode(int keycode)
{ {
if (WinRT_Unofficial_Keycodes.empty()) { if (WinRT_Unofficial_Keycodes.empty()) {
/* Set up a table of undocumented (by Microsoft), WinRT-specific, /* Set up a table of undocumented (by Microsoft), WinRT-specific,
key codes: */ key codes: */
// TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible // TODO, WinRT: move content declarations of WinRT_Unofficial_Keycodes into a C++11 initializer list, when possible
WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE; WinRT_Unofficial_Keycodes[220] = SDL_SCANCODE_GRAVE;
WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH; WinRT_Unofficial_Keycodes[222] = SDL_SCANCODE_BACKSLASH;
} }
/* Try to get a documented, WinRT, 'VirtualKey' first (as documented at /* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ). http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
If that fails, fall back to a Win32 virtual key. If that fails, fall back to a Win32 virtual key.
*/ */
// TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
//SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode); //SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN; SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) { if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
scancode = WinRT_Official_Keycodes[keycode]; scancode = WinRT_Official_Keycodes[keycode];
} }
if (scancode == SDL_SCANCODE_UNKNOWN) { if (scancode == SDL_SCANCODE_UNKNOWN) {
if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) { if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
scancode = WinRT_Unofficial_Keycodes[keycode]; scancode = WinRT_Unofficial_Keycodes[keycode];
} }
} }
if (scancode == SDL_SCANCODE_UNKNOWN) { if (scancode == SDL_SCANCODE_UNKNOWN) {
if (keycode < SDL_arraysize(windows_scancode_table)) { if (keycode < SDL_arraysize(windows_scancode_table)) {
scancode = windows_scancode_table[keycode]; scancode = windows_scancode_table[keycode];
} }
} }
if (scancode == SDL_SCANCODE_UNKNOWN) { if (scancode == SDL_SCANCODE_UNKNOWN) {
SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode); SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
} }
return scancode; return scancode;
} }
void void
WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args) WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
{ {
SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey); SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
#if 0 #if 0
SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode); SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n", SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
(args->Handled ? "1" : "0"), (args->Handled ? "1" : "0"),
(args->KeyStatus.IsExtendedKey ? "1" : "0"), (args->KeyStatus.IsExtendedKey ? "1" : "0"),
(args->KeyStatus.IsKeyReleased ? "1" : "0"), (args->KeyStatus.IsKeyReleased ? "1" : "0"),
(args->KeyStatus.IsMenuKeyDown ? "1" : "0"), (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
args->KeyStatus.RepeatCount, args->KeyStatus.RepeatCount,
args->KeyStatus.ScanCode, args->KeyStatus.ScanCode,
(args->KeyStatus.WasKeyDown ? "1" : "0"), (args->KeyStatus.WasKeyDown ? "1" : "0"),
args->VirtualKey, args->VirtualKey,
sdlScancode, sdlScancode,
SDL_GetScancodeName(sdlScancode), SDL_GetScancodeName(sdlScancode),
keycode, keycode,
SDL_GetKeyName(keycode)); SDL_GetKeyName(keycode));
//args->Handled = true; //args->Handled = true;
//VirtualKey vkey = args->VirtualKey; //VirtualKey vkey = args->VirtualKey;
#endif #endif
SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode); SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
} }
void void
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args) WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
{ {
SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey); SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
#if 0 #if 0
SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode); SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n", SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, repeat count=%d, native scan code=%d, was down?=%s, vkey=%d, sdl scan code=%d (%s), sdl key code=%d (%s)\n",
(args->Handled ? "1" : "0"), (args->Handled ? "1" : "0"),
(args->KeyStatus.IsExtendedKey ? "1" : "0"), (args->KeyStatus.IsExtendedKey ? "1" : "0"),
(args->KeyStatus.IsKeyReleased ? "1" : "0"), (args->KeyStatus.IsKeyReleased ? "1" : "0"),
(args->KeyStatus.IsMenuKeyDown ? "1" : "0"), (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
args->KeyStatus.RepeatCount, args->KeyStatus.RepeatCount,
args->KeyStatus.ScanCode, args->KeyStatus.ScanCode,
(args->KeyStatus.WasKeyDown ? "1" : "0"), (args->KeyStatus.WasKeyDown ? "1" : "0"),
args->VirtualKey, args->VirtualKey,
sdlScancode, sdlScancode,
SDL_GetScancodeName(sdlScancode), SDL_GetScancodeName(sdlScancode),
keycode, keycode,
SDL_GetKeyName(keycode)); SDL_GetKeyName(keycode));
//args->Handled = true; //args->Handled = true;
#endif #endif
SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode); SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
} }
#endif // SDL_VIDEO_DRIVER_WINRT #endif // SDL_VIDEO_DRIVER_WINRT

View File

@ -1,166 +1,166 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#if SDL_VIDEO_DRIVER_WINRT #if SDL_VIDEO_DRIVER_WINRT
/* /*
* Windows includes: * Windows includes:
*/ */
#include <Windows.h> #include <Windows.h>
using namespace Windows::UI::Core; using namespace Windows::UI::Core;
using Windows::UI::Core::CoreCursor; using Windows::UI::Core::CoreCursor;
/* /*
* SDL includes: * SDL includes:
*/ */
extern "C" { extern "C" {
#include "SDL_assert.h" #include "SDL_assert.h"
#include "../../events/SDL_mouse_c.h" #include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_touch_c.h" #include "../../events/SDL_touch_c.h"
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#include "SDL_events.h" #include "SDL_events.h"
#include "SDL_log.h" #include "SDL_log.h"
} }
#include "../../core/winrt/SDL_winrtapp_direct3d.h" #include "../../core/winrt/SDL_winrtapp_direct3d.h"
#include "SDL_winrtvideo_cpp.h" #include "SDL_winrtvideo_cpp.h"
#include "SDL_winrtmouse_c.h" #include "SDL_winrtmouse_c.h"
extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE; extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE;
static SDL_Cursor * static SDL_Cursor *
WINRT_CreateSystemCursor(SDL_SystemCursor id) WINRT_CreateSystemCursor(SDL_SystemCursor id)
{ {
SDL_Cursor *cursor; SDL_Cursor *cursor;
CoreCursorType cursorType = CoreCursorType::Arrow; CoreCursorType cursorType = CoreCursorType::Arrow;
switch(id) switch(id)
{ {
default: default:
SDL_assert(0); SDL_assert(0);
return NULL; return NULL;
case SDL_SYSTEM_CURSOR_ARROW: cursorType = CoreCursorType::Arrow; break; case SDL_SYSTEM_CURSOR_ARROW: cursorType = CoreCursorType::Arrow; break;
case SDL_SYSTEM_CURSOR_IBEAM: cursorType = CoreCursorType::IBeam; break; case SDL_SYSTEM_CURSOR_IBEAM: cursorType = CoreCursorType::IBeam; break;
case SDL_SYSTEM_CURSOR_WAIT: cursorType = CoreCursorType::Wait; break; case SDL_SYSTEM_CURSOR_WAIT: cursorType = CoreCursorType::Wait; break;
case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break; case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break; case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
case SDL_SYSTEM_CURSOR_SIZENWSE: cursorType = CoreCursorType::SizeNorthwestSoutheast; break; case SDL_SYSTEM_CURSOR_SIZENWSE: cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
case SDL_SYSTEM_CURSOR_SIZENESW: cursorType = CoreCursorType::SizeNortheastSouthwest; break; case SDL_SYSTEM_CURSOR_SIZENESW: cursorType = CoreCursorType::SizeNortheastSouthwest; break;
case SDL_SYSTEM_CURSOR_SIZEWE: cursorType = CoreCursorType::SizeWestEast; break; case SDL_SYSTEM_CURSOR_SIZEWE: cursorType = CoreCursorType::SizeWestEast; break;
case SDL_SYSTEM_CURSOR_SIZENS: cursorType = CoreCursorType::SizeNorthSouth; break; case SDL_SYSTEM_CURSOR_SIZENS: cursorType = CoreCursorType::SizeNorthSouth; break;
case SDL_SYSTEM_CURSOR_SIZEALL: cursorType = CoreCursorType::SizeAll; break; case SDL_SYSTEM_CURSOR_SIZEALL: cursorType = CoreCursorType::SizeAll; break;
case SDL_SYSTEM_CURSOR_NO: cursorType = CoreCursorType::UniversalNo; break; case SDL_SYSTEM_CURSOR_NO: cursorType = CoreCursorType::UniversalNo; break;
case SDL_SYSTEM_CURSOR_HAND: cursorType = CoreCursorType::Hand; break; case SDL_SYSTEM_CURSOR_HAND: cursorType = CoreCursorType::Hand; break;
} }
cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor)); cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
if (cursor) { if (cursor) {
/* Create a pointer to a COM reference to a cursor. The extra /* Create a pointer to a COM reference to a cursor. The extra
pointer is used (on top of the COM reference) to allow the cursor pointer is used (on top of the COM reference) to allow the cursor
to be referenced by the SDL_cursor's driverdata field, which is to be referenced by the SDL_cursor's driverdata field, which is
a void pointer. a void pointer.
*/ */
CoreCursor ^* theCursor = new CoreCursor^(nullptr); CoreCursor ^* theCursor = new CoreCursor^(nullptr);
*theCursor = ref new CoreCursor(cursorType, 0); *theCursor = ref new CoreCursor(cursorType, 0);
cursor->driverdata = (void *) theCursor; cursor->driverdata = (void *) theCursor;
} else { } else {
SDL_OutOfMemory(); SDL_OutOfMemory();
} }
return cursor; return cursor;
} }
static SDL_Cursor * static SDL_Cursor *
WINRT_CreateDefaultCursor() WINRT_CreateDefaultCursor()
{ {
return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
} }
static void static void
WINRT_FreeCursor(SDL_Cursor * cursor) WINRT_FreeCursor(SDL_Cursor * cursor)
{ {
if (cursor->driverdata) { if (cursor->driverdata) {
CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata; CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
*theCursor = nullptr; // Release the COM reference to the CoreCursor *theCursor = nullptr; // Release the COM reference to the CoreCursor
delete theCursor; // Delete the pointer to the COM reference delete theCursor; // Delete the pointer to the COM reference
} }
SDL_free(cursor); SDL_free(cursor);
} }
static int static int
WINRT_ShowCursor(SDL_Cursor * cursor) WINRT_ShowCursor(SDL_Cursor * cursor)
{ {
// TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled. // TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled.
if ( ! CoreWindow::GetForCurrentThread()) { if ( ! CoreWindow::GetForCurrentThread()) {
return 0; return 0;
} }
if (cursor) { if (cursor) {
CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata; CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor; CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
} else { } else {
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
} }
return 0; return 0;
} }
static int static int
WINRT_SetRelativeMouseMode(SDL_bool enabled) WINRT_SetRelativeMouseMode(SDL_bool enabled)
{ {
WINRT_UsingRelativeMouseMode = enabled; WINRT_UsingRelativeMouseMode = enabled;
return 0; return 0;
} }
void void
WINRT_InitMouse(_THIS) WINRT_InitMouse(_THIS)
{ {
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
/* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for /* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for
the following features, AFAIK: the following features, AFAIK:
- custom cursors (multiple system cursors are, however, available) - custom cursors (multiple system cursors are, however, available)
- programmatically moveable cursors - programmatically moveable cursors
*/ */
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
//mouse->CreateCursor = WINRT_CreateCursor; //mouse->CreateCursor = WINRT_CreateCursor;
mouse->CreateSystemCursor = WINRT_CreateSystemCursor; mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
mouse->ShowCursor = WINRT_ShowCursor; mouse->ShowCursor = WINRT_ShowCursor;
mouse->FreeCursor = WINRT_FreeCursor; mouse->FreeCursor = WINRT_FreeCursor;
//mouse->WarpMouse = WINRT_WarpMouse; //mouse->WarpMouse = WINRT_WarpMouse;
mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode; mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
SDL_SetDefaultCursor(WINRT_CreateDefaultCursor()); SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
#endif #endif
} }
void void
WINRT_QuitMouse(_THIS) WINRT_QuitMouse(_THIS)
{ {
} }
#endif /* SDL_VIDEO_DRIVER_WINRT */ #endif /* SDL_VIDEO_DRIVER_WINRT */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,50 +1,50 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
// TODO: WinRT, make this file compile via C code // TODO: WinRT, make this file compile via C code
#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
/* EGL implementation of SDL OpenGL support */ /* EGL implementation of SDL OpenGL support */
#include "SDL_winrtvideo_cpp.h" #include "SDL_winrtvideo_cpp.h"
extern "C" { extern "C" {
#include "SDL_winrtopengles.h" #include "SDL_winrtopengles.h"
} }
#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((NativeDisplayType) -3) #define EGL_D3D11_ONLY_DISPLAY_ANGLE ((NativeDisplayType) -3)
extern "C" int extern "C" int
WINRT_GLES_LoadLibrary(_THIS, const char *path) { WINRT_GLES_LoadLibrary(_THIS, const char *path) {
return SDL_EGL_LoadLibrary(_this, path, EGL_D3D11_ONLY_DISPLAY_ANGLE); return SDL_EGL_LoadLibrary(_this, path, EGL_D3D11_ONLY_DISPLAY_ANGLE);
} }
extern "C" { extern "C" {
SDL_EGL_CreateContext_impl(WINRT) SDL_EGL_CreateContext_impl(WINRT)
SDL_EGL_SwapWindow_impl(WINRT) SDL_EGL_SwapWindow_impl(WINRT)
SDL_EGL_MakeCurrent_impl(WINRT) SDL_EGL_MakeCurrent_impl(WINRT)
} }
#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */ #endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,48 +1,48 @@
/* /*
Simple DirectMedia Layer Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated but is not required. appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#ifndef _SDL_winrtopengles_h #ifndef _SDL_winrtopengles_h
#define _SDL_winrtopengles_h #define _SDL_winrtopengles_h
#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL #if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#include "../SDL_egl_c.h" #include "../SDL_egl_c.h"
/* OpenGLES functions */ /* OpenGLES functions */
#define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute #define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute
#define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress #define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress
#define WINRT_GLES_UnloadLibrary SDL_EGL_UnloadLibrary #define WINRT_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
#define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval #define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
#define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval #define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext #define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext
extern int WINRT_GLES_LoadLibrary(_THIS, const char *path); extern int WINRT_GLES_LoadLibrary(_THIS, const char *path);
extern SDL_GLContext WINRT_GLES_CreateContext(_THIS, SDL_Window * window); extern SDL_GLContext WINRT_GLES_CreateContext(_THIS, SDL_Window * window);
extern void WINRT_GLES_SwapWindow(_THIS, SDL_Window * window); extern void WINRT_GLES_SwapWindow(_THIS, SDL_Window * window);
extern int WINRT_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); extern int WINRT_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */ #endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
#endif /* _SDL_winrtopengles_h */ #endif /* _SDL_winrtopengles_h */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -17,7 +17,7 @@
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#if SDL_VIDEO_DRIVER_WINRT #if SDL_VIDEO_DRIVER_WINRT
@ -32,363 +32,363 @@
extern "C" { extern "C" {
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#include "../../events/SDL_mouse_c.h" #include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_touch_c.h" #include "../../events/SDL_touch_c.h"
} }
/* File-specific globals: */ /* File-specific globals: */
static SDL_TouchID WINRT_TouchID = 1; static SDL_TouchID WINRT_TouchID = 1;
static unsigned int WINRT_LeftFingerDown = 0; static unsigned int WINRT_LeftFingerDown = 0;
void void
WINRT_InitTouch(_THIS) WINRT_InitTouch(_THIS)
{ {
SDL_AddTouch(WINRT_TouchID, ""); SDL_AddTouch(WINRT_TouchID, "");
}
//
// Applies necessary geometric transformations to raw cursor positions:
//
Windows::Foundation::Point
WINRT_TransformCursorPosition(SDL_Window * window,
Windows::Foundation::Point rawPosition,
WINRT_CursorNormalizationType normalization)
{
using namespace Windows::UI::Core;
using namespace Windows::Graphics::Display;
if (!window) {
return rawPosition;
}
SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
if (windowData->coreWindow == nullptr) {
// For some reason, the window isn't associated with a CoreWindow.
// This might end up being the case as XAML support is extended.
// For now, if there's no CoreWindow attached to the SDL_Window,
// don't do any transforms.
// TODO, WinRT: make sure touch input coordinate ranges are correct when using XAML support
return rawPosition;
}
// The CoreWindow can only be accessed on certain thread(s).
SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
Windows::Foundation::Point outputPosition;
// Compute coordinates normalized from 0..1.
// If the coordinates need to be sized to the SDL window,
// we'll do that after.
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
#else
switch (DisplayProperties::CurrentOrientation)
{
case DisplayOrientations::Portrait:
outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
break;
case DisplayOrientations::PortraitFlipped:
outputPosition.X = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
outputPosition.Y = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height);
break;
case DisplayOrientations::Landscape:
outputPosition.X = rawPosition.Y / nativeWindow->Bounds.Height;
outputPosition.Y = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
break;
case DisplayOrientations::LandscapeFlipped:
outputPosition.X = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height);
outputPosition.Y = rawPosition.X / nativeWindow->Bounds.Width;
break;
default:
break;
}
#endif
if (normalization == TransformToSDLWindowSize) {
outputPosition.X *= ((float32) window->w);
outputPosition.Y *= ((float32) window->h);
}
return outputPosition;
}
static inline int
_lround(float arg)
{
if (arg >= 0.0f) {
return (int)floor(arg + 0.5f);
} else {
return (int)ceil(arg - 0.5f);
}
}
Uint8
WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
{
using namespace Windows::UI::Input;
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
return SDL_BUTTON_LEFT;
#else
switch (pt->Properties->PointerUpdateKind)
{
case PointerUpdateKind::LeftButtonPressed:
case PointerUpdateKind::LeftButtonReleased:
return SDL_BUTTON_LEFT;
case PointerUpdateKind::RightButtonPressed:
case PointerUpdateKind::RightButtonReleased:
return SDL_BUTTON_RIGHT;
case PointerUpdateKind::MiddleButtonPressed:
case PointerUpdateKind::MiddleButtonReleased:
return SDL_BUTTON_MIDDLE;
case PointerUpdateKind::XButton1Pressed:
case PointerUpdateKind::XButton1Released:
return SDL_BUTTON_X1;
case PointerUpdateKind::XButton2Pressed:
case PointerUpdateKind::XButton2Released:
return SDL_BUTTON_X2;
default:
break;
}
#endif
return 0;
}
//const char *
//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
//{
// using namespace Windows::UI::Input;
//
// switch (kind)
// {
// case PointerUpdateKind::Other:
// return "Other";
// case PointerUpdateKind::LeftButtonPressed:
// return "LeftButtonPressed";
// case PointerUpdateKind::LeftButtonReleased:
// return "LeftButtonReleased";
// case PointerUpdateKind::RightButtonPressed:
// return "RightButtonPressed";
// case PointerUpdateKind::RightButtonReleased:
// return "RightButtonReleased";
// case PointerUpdateKind::MiddleButtonPressed:
// return "MiddleButtonPressed";
// case PointerUpdateKind::MiddleButtonReleased:
// return "MiddleButtonReleased";
// case PointerUpdateKind::XButton1Pressed:
// return "XButton1Pressed";
// case PointerUpdateKind::XButton1Released:
// return "XButton1Released";
// case PointerUpdateKind::XButton2Pressed:
// return "XButton2Pressed";
// case PointerUpdateKind::XButton2Released:
// return "XButton2Released";
// }
//
// return "";
//}
static bool
WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
{
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
return true;
#else
using namespace Windows::Devices::Input;
switch (pointerPoint->PointerDevice->PointerDeviceType) {
case PointerDeviceType::Touch:
case PointerDeviceType::Pen:
return true;
default:
return false;
}
#endif
}
void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window) {
return;
}
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
if ( ! WINRT_IsTouchEvent(pointerPoint)) {
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
} else {
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize);
if (!WINRT_LeftFingerDown) {
if (button) {
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
}
WINRT_LeftFingerDown = pointerPoint->PointerId;
}
SDL_SendTouch(
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
SDL_TRUE,
normalizedPoint.X,
normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
} }
void
WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window || WINRT_UsingRelativeMouseMode) {
return;
}
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize);
if ( ! WINRT_IsTouchEvent(pointerPoint)) {
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
} else if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
}
SDL_SendTouchMotion(
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
normalizedPoint.X,
normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
}
void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window) {
return;
}
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
if (!WINRT_IsTouchEvent(pointerPoint)) {
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
} else {
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
if (button) {
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
}
WINRT_LeftFingerDown = 0;
}
SDL_SendTouch(
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
SDL_FALSE,
normalizedPoint.X,
normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
}
void
WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window) {
return;
}
// FIXME: This may need to accumulate deltas up to WHEEL_DELTA
short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
SDL_SendMouseWheel(window, 0, 0, motion);
}
void //
WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args) // Applies necessary geometric transformations to raw cursor positions:
{ //
if (!window || !WINRT_UsingRelativeMouseMode) { Windows::Foundation::Point
return; WINRT_TransformCursorPosition(SDL_Window * window,
} Windows::Foundation::Point rawPosition,
WINRT_CursorNormalizationType normalization)
// DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows {
// Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs' using namespace Windows::UI::Core;
// MouseDelta field often reports very large values. More information using namespace Windows::Graphics::Display;
// on this can be found at the following pages on MSDN:
// - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8 if (!window) {
// - https://connect.microsoft.com/VisualStudio/Feedback/details/756515 return rawPosition;
// }
// The values do not appear to be as large when running on some systems,
// most notably a Surface RT. Furthermore, the values returned by SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
// CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved if (windowData->coreWindow == nullptr) {
// method, do not ever appear to be large, even when MouseEventArgs' // For some reason, the window isn't associated with a CoreWindow.
// MouseDelta is reporting to the contrary. // This might end up being the case as XAML support is extended.
// // For now, if there's no CoreWindow attached to the SDL_Window,
// On systems with the large-values behavior, it appears that the values // don't do any transforms.
// get reported as if the screen's size is 65536 units in both the X and Y
// dimensions. This can be viewed by using Windows' now-private, "Raw Input" // TODO, WinRT: make sure touch input coordinate ranges are correct when using XAML support
// APIs. (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.) return rawPosition;
// }
// MSDN's documentation on MouseEventArgs' MouseDelta field (at
// http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ), // The CoreWindow can only be accessed on certain thread(s).
// does not seem to indicate (to me) that its values should be so large. It SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
// says that its values should be a "change in screen location". I could
// be misinterpreting this, however a post on MSDN from a Microsoft engineer (see: CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
// http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ), Windows::Foundation::Point outputPosition;
// indicates that these values are in DIPs, which is the same unit used
// by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint // Compute coordinates normalized from 0..1.
// property. See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx // If the coordinates need to be sized to the SDL window,
// for details.) // we'll do that after.
// #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
// To note, PointerMoved events are sent a 'RawPosition' value (via the outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
// CurrentPoint property in MouseEventArgs), however these do not seem outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
// to exhibit the same large-value behavior. #else
// switch (DisplayProperties::CurrentOrientation)
// The values passed via PointerMoved events can't always be used for relative {
// mouse motion, unfortunately. Its values are bound to the cursor's position, case DisplayOrientations::Portrait:
// which stops when it hits one of the screen's edges. This can be a problem in outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
// first person shooters, whereby it is normal for mouse motion to travel far outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
// along any one axis for a period of time. MouseMoved events do not have the break;
// screen-bounding limitation, and can be used regardless of where the system's case DisplayOrientations::PortraitFlipped:
// cursor is. outputPosition.X = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
// outputPosition.Y = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height);
// One possible workaround would be to programmatically set the cursor's break;
// position to the screen's center (when SDL's relative mouse mode is enabled), case DisplayOrientations::Landscape:
// however WinRT does not yet seem to have the ability to set the cursor's outputPosition.X = rawPosition.Y / nativeWindow->Bounds.Height;
// position via a public API. Win32 did this via an API call, SetCursorPos, outputPosition.Y = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
// however WinRT makes this function be private. Apps that use it won't get break;
// approved for distribution in the Windows Store. I've yet to be able to find case DisplayOrientations::LandscapeFlipped:
// a suitable, store-friendly counterpart for WinRT. outputPosition.X = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height);
// outputPosition.Y = rawPosition.X / nativeWindow->Bounds.Width;
// There may be some room for a workaround whereby OnPointerMoved's values break;
// are compared to the values from OnMouseMoved in order to detect default:
// when this bug is active. A suitable transformation could then be made to break;
// OnMouseMoved's values. For now, however, the system-reported values are sent }
// to SDL with minimal transformation: from native screen coordinates (in DIPs) #endif
// to SDL window coordinates.
// if (normalization == TransformToSDLWindowSize) {
const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y); outputPosition.X *= ((float32) window->w);
const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs, TransformToSDLWindowSize); outputPosition.Y *= ((float32) window->h);
SDL_SendMouseMotion( }
window,
0, return outputPosition;
1, }
_lround(mouseDeltaInSDLWindowCoords.X),
_lround(mouseDeltaInSDLWindowCoords.Y)); static inline int
_lround(float arg)
{
if (arg >= 0.0f) {
return (int)floor(arg + 0.5f);
} else {
return (int)ceil(arg - 0.5f);
}
}
Uint8
WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
{
using namespace Windows::UI::Input;
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
return SDL_BUTTON_LEFT;
#else
switch (pt->Properties->PointerUpdateKind)
{
case PointerUpdateKind::LeftButtonPressed:
case PointerUpdateKind::LeftButtonReleased:
return SDL_BUTTON_LEFT;
case PointerUpdateKind::RightButtonPressed:
case PointerUpdateKind::RightButtonReleased:
return SDL_BUTTON_RIGHT;
case PointerUpdateKind::MiddleButtonPressed:
case PointerUpdateKind::MiddleButtonReleased:
return SDL_BUTTON_MIDDLE;
case PointerUpdateKind::XButton1Pressed:
case PointerUpdateKind::XButton1Released:
return SDL_BUTTON_X1;
case PointerUpdateKind::XButton2Pressed:
case PointerUpdateKind::XButton2Released:
return SDL_BUTTON_X2;
default:
break;
}
#endif
return 0;
}
//const char *
//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
//{
// using namespace Windows::UI::Input;
//
// switch (kind)
// {
// case PointerUpdateKind::Other:
// return "Other";
// case PointerUpdateKind::LeftButtonPressed:
// return "LeftButtonPressed";
// case PointerUpdateKind::LeftButtonReleased:
// return "LeftButtonReleased";
// case PointerUpdateKind::RightButtonPressed:
// return "RightButtonPressed";
// case PointerUpdateKind::RightButtonReleased:
// return "RightButtonReleased";
// case PointerUpdateKind::MiddleButtonPressed:
// return "MiddleButtonPressed";
// case PointerUpdateKind::MiddleButtonReleased:
// return "MiddleButtonReleased";
// case PointerUpdateKind::XButton1Pressed:
// return "XButton1Pressed";
// case PointerUpdateKind::XButton1Released:
// return "XButton1Released";
// case PointerUpdateKind::XButton2Pressed:
// return "XButton2Pressed";
// case PointerUpdateKind::XButton2Released:
// return "XButton2Released";
// }
//
// return "";
//}
static bool
WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
{
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
return true;
#else
using namespace Windows::Devices::Input;
switch (pointerPoint->PointerDevice->PointerDeviceType) {
case PointerDeviceType::Touch:
case PointerDeviceType::Pen:
return true;
default:
return false;
}
#endif
}
void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window) {
return;
}
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
if ( ! WINRT_IsTouchEvent(pointerPoint)) {
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
} else {
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize);
if (!WINRT_LeftFingerDown) {
if (button) {
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
}
WINRT_LeftFingerDown = pointerPoint->PointerId;
}
SDL_SendTouch(
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
SDL_TRUE,
normalizedPoint.X,
normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
}
void
WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window || WINRT_UsingRelativeMouseMode) {
return;
}
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize);
if ( ! WINRT_IsTouchEvent(pointerPoint)) {
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
} else if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
}
SDL_SendTouchMotion(
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
normalizedPoint.X,
normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
}
void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window) {
return;
}
Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
if (!WINRT_IsTouchEvent(pointerPoint)) {
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
} else {
Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
if (button) {
SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
}
WINRT_LeftFingerDown = 0;
}
SDL_SendTouch(
WINRT_TouchID,
(SDL_FingerID) pointerPoint->PointerId,
SDL_FALSE,
normalizedPoint.X,
normalizedPoint.Y,
pointerPoint->Properties->Pressure);
}
}
void
WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
{
if (!window) {
return;
}
// FIXME: This may need to accumulate deltas up to WHEEL_DELTA
short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
SDL_SendMouseWheel(window, 0, 0, motion);
}
void
WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args)
{
if (!window || !WINRT_UsingRelativeMouseMode) {
return;
}
// DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
// Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
// MouseDelta field often reports very large values. More information
// on this can be found at the following pages on MSDN:
// - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
// - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
//
// The values do not appear to be as large when running on some systems,
// most notably a Surface RT. Furthermore, the values returned by
// CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
// method, do not ever appear to be large, even when MouseEventArgs'
// MouseDelta is reporting to the contrary.
//
// On systems with the large-values behavior, it appears that the values
// get reported as if the screen's size is 65536 units in both the X and Y
// dimensions. This can be viewed by using Windows' now-private, "Raw Input"
// APIs. (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
//
// MSDN's documentation on MouseEventArgs' MouseDelta field (at
// http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
// does not seem to indicate (to me) that its values should be so large. It
// says that its values should be a "change in screen location". I could
// be misinterpreting this, however a post on MSDN from a Microsoft engineer (see:
// http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
// indicates that these values are in DIPs, which is the same unit used
// by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
// property. See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
// for details.)
//
// To note, PointerMoved events are sent a 'RawPosition' value (via the
// CurrentPoint property in MouseEventArgs), however these do not seem
// to exhibit the same large-value behavior.
//
// The values passed via PointerMoved events can't always be used for relative
// mouse motion, unfortunately. Its values are bound to the cursor's position,
// which stops when it hits one of the screen's edges. This can be a problem in
// first person shooters, whereby it is normal for mouse motion to travel far
// along any one axis for a period of time. MouseMoved events do not have the
// screen-bounding limitation, and can be used regardless of where the system's
// cursor is.
//
// One possible workaround would be to programmatically set the cursor's
// position to the screen's center (when SDL's relative mouse mode is enabled),
// however WinRT does not yet seem to have the ability to set the cursor's
// position via a public API. Win32 did this via an API call, SetCursorPos,
// however WinRT makes this function be private. Apps that use it won't get
// approved for distribution in the Windows Store. I've yet to be able to find
// a suitable, store-friendly counterpart for WinRT.
//
// There may be some room for a workaround whereby OnPointerMoved's values
// are compared to the values from OnMouseMoved in order to detect
// when this bug is active. A suitable transformation could then be made to
// OnMouseMoved's values. For now, however, the system-reported values are sent
// to SDL with minimal transformation: from native screen coordinates (in DIPs)
// to SDL window coordinates.
//
const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs, TransformToSDLWindowSize);
SDL_SendMouseMotion(
window,
0,
1,
_lround(mouseDeltaInSDLWindowCoords.X),
_lround(mouseDeltaInSDLWindowCoords.Y));
} }
#endif // SDL_VIDEO_DRIVER_WINRT #endif // SDL_VIDEO_DRIVER_WINRT

View File

@ -113,14 +113,14 @@ WINRT_CreateDevice(int devindex)
device->PumpEvents = WINRT_PumpEvents; device->PumpEvents = WINRT_PumpEvents;
device->GetWindowWMInfo = WINRT_GetWindowWMInfo; device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
#ifdef SDL_VIDEO_OPENGL_EGL #ifdef SDL_VIDEO_OPENGL_EGL
device->GL_LoadLibrary = WINRT_GLES_LoadLibrary; device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
device->GL_GetProcAddress = WINRT_GLES_GetProcAddress; device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary; device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
device->GL_CreateContext = WINRT_GLES_CreateContext; device->GL_CreateContext = WINRT_GLES_CreateContext;
device->GL_MakeCurrent = WINRT_GLES_MakeCurrent; device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval; device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval; device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
device->GL_SwapWindow = WINRT_GLES_SwapWindow; device->GL_SwapWindow = WINRT_GLES_SwapWindow;
device->GL_DeleteContext = WINRT_GLES_DeleteContext; device->GL_DeleteContext = WINRT_GLES_DeleteContext;
#endif #endif
device->free = WINRT_DeleteDevice; device->free = WINRT_DeleteDevice;
@ -351,7 +351,7 @@ WINRT_CreateWindow(_THIS, SDL_Window * window)
/* For now, treat WinRT apps as if they always have focus. /* For now, treat WinRT apps as if they always have focus.
TODO, WinRT: try tracking keyboard and mouse focus state with respect to snapped apps TODO, WinRT: try tracking keyboard and mouse focus state with respect to snapped apps
*/ */
SDL_SetMouseFocus(window); SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window); SDL_SetKeyboardFocus(window);
/* Make sure the WinRT app's IFramworkView can post events on /* Make sure the WinRT app's IFramworkView can post events on

View File

@ -44,36 +44,36 @@ extern SDL_Window * WINRT_GlobalSDLWindow;
/* The global, WinRT, video device. */ /* The global, WinRT, video device. */
extern SDL_VideoDevice * WINRT_GlobalSDLVideoDevice; extern SDL_VideoDevice * WINRT_GlobalSDLVideoDevice;
/* Creates a display mode for Plain Direct3D (non-XAML) apps, using the lone, native window's settings. /* Creates a display mode for Plain Direct3D (non-XAML) apps, using the lone, native window's settings.
Pass in an allocated SDL_DisplayMode field to store the data in. Pass in an allocated SDL_DisplayMode field to store the data in.
This function will return 0 on success, -1 on failure. This function will return 0 on success, -1 on failure.
If this function succeeds, be sure to call SDL_free on the If this function succeeds, be sure to call SDL_free on the
SDL_DisplayMode's driverdata field. SDL_DisplayMode's driverdata field.
*/ */
extern int WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode); extern int WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode);
/* Duplicates a display mode, copying over driverdata as necessary */ /* Duplicates a display mode, copying over driverdata as necessary */
extern int WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src); extern int WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src);
/* Display mode internals */ /* Display mode internals */
typedef struct typedef struct
{ {
Windows::Graphics::Display::DisplayOrientations currentOrientation; Windows::Graphics::Display::DisplayOrientations currentOrientation;
} SDL_DisplayModeData; } SDL_DisplayModeData;
#ifdef __cplusplus_winrt #ifdef __cplusplus_winrt
/* Internal window data */ /* Internal window data */
struct SDL_WindowData struct SDL_WindowData
{ {
SDL_Window *sdlWindow; SDL_Window *sdlWindow;
Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow; Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
#ifdef SDL_VIDEO_OPENGL_EGL #ifdef SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface; EGLSurface egl_surface;
#endif #endif
}; };
#endif // ifdef __cplusplus_winrt #endif // ifdef __cplusplus_winrt

View File

@ -1,144 +1,144 @@
/* /*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely. freely.
*/ */
/* Program to load a wave file and loop playing it using SDL sound */ /* Program to load a wave file and loop playing it using SDL sound */
/* loopwaves.c is much more robust in handling WAVE files -- /* loopwaves.c is much more robust in handling WAVE files --
This is only for simple WAVEs This is only for simple WAVEs
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#if HAVE_SIGNAL_H #if HAVE_SIGNAL_H
#include <signal.h> #include <signal.h>
#endif #endif
#include "SDL.h" #include "SDL.h"
#include "SDL_audio.h" #include "SDL_audio.h"
struct struct
{ {
SDL_AudioSpec spec; SDL_AudioSpec spec;
Uint8 *sound; /* Pointer to wave data */ Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */ Uint32 soundlen; /* Length of wave data */
int soundpos; /* Current play position */ int soundpos; /* Current play position */
} wave; } wave;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void static void
quit(int rc) quit(int rc)
{ {
SDL_Quit(); SDL_Quit();
exit(rc); exit(rc);
} }
void SDLCALL void SDLCALL
fillerup(void *unused, Uint8 * stream, int len) fillerup(void *unused, Uint8 * stream, int len)
{ {
Uint8 *waveptr; Uint8 *waveptr;
int waveleft; int waveleft;
/* Set up the pointers */ /* Set up the pointers */
waveptr = wave.sound + wave.soundpos; waveptr = wave.sound + wave.soundpos;
waveleft = wave.soundlen - wave.soundpos; waveleft = wave.soundlen - wave.soundpos;
/* Go! */ /* Go! */
while (waveleft <= len) { while (waveleft <= len) {
SDL_memcpy(stream, waveptr, waveleft); SDL_memcpy(stream, waveptr, waveleft);
stream += waveleft; stream += waveleft;
len -= waveleft; len -= waveleft;
waveptr = wave.sound; waveptr = wave.sound;
waveleft = wave.soundlen; waveleft = wave.soundlen;
wave.soundpos = 0; wave.soundpos = 0;
} }
SDL_memcpy(stream, waveptr, len); SDL_memcpy(stream, waveptr, len);
wave.soundpos += len; wave.soundpos += len;
} }
static int done = 0; static int done = 0;
void void
poked(int sig) poked(int sig)
{ {
done = 1; done = 1;
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int i; int i;
char filename[4096]; char filename[4096];
/* Enable standard application logging */ /* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) { if (SDL_Init(SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
if (argc >= 1) { if (argc >= 1) {
SDL_strlcpy(filename, argv[1], sizeof(filename)); SDL_strlcpy(filename, argv[1], sizeof(filename));
} else { } else {
SDL_strlcpy(filename, "sample.wav", sizeof(filename)); SDL_strlcpy(filename, "sample.wav", sizeof(filename));
} }
/* Load the wave file into memory */ /* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) { if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1], SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
quit(1); quit(1);
} }
wave.spec.callback = fillerup; wave.spec.callback = fillerup;
#if HAVE_SIGNAL_H #if HAVE_SIGNAL_H
/* Set the signals */ /* Set the signals */
#ifdef SIGHUP #ifdef SIGHUP
signal(SIGHUP, poked); signal(SIGHUP, poked);
#endif #endif
signal(SIGINT, poked); signal(SIGINT, poked);
#ifdef SIGQUIT #ifdef SIGQUIT
signal(SIGQUIT, poked); signal(SIGQUIT, poked);
#endif #endif
signal(SIGTERM, poked); signal(SIGTERM, poked);
#endif /* HAVE_SIGNAL_H */ #endif /* HAVE_SIGNAL_H */
/* Show the list of available drivers */ /* Show the list of available drivers */
SDL_Log("Available audio drivers:"); SDL_Log("Available audio drivers:");
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) { for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
SDL_Log("%i: %s", i, SDL_GetAudioDriver(i)); SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
} }
/* Initialize fillerup() variables */ /* Initialize fillerup() variables */
if (SDL_OpenAudio(&wave.spec, NULL) < 0) { if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
SDL_FreeWAV(wave.sound); SDL_FreeWAV(wave.sound);
quit(2); quit(2);
} }
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
/* Let the audio run */ /* Let the audio run */
SDL_PauseAudio(0); SDL_PauseAudio(0);
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
SDL_Delay(1000); SDL_Delay(1000);
/* Clean up on signal */ /* Clean up on signal */
SDL_CloseAudio(); SDL_CloseAudio();
SDL_FreeWAV(wave.sound); SDL_FreeWAV(wave.sound);
SDL_Quit(); SDL_Quit();
return (0); return (0);
} }
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -1,99 +1,99 @@
/* /*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely. freely.
*/ */
/* Simple test of the SDL threading code */ /* Simple test of the SDL threading code */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_thread.h" #include "SDL_thread.h"
static SDL_TLSID tls; static SDL_TLSID tls;
static int alive = 0; static int alive = 0;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void static void
quit(int rc) quit(int rc)
{ {
SDL_Quit(); SDL_Quit();
exit(rc); exit(rc);
} }
int SDLCALL int SDLCALL
ThreadFunc(void *data) ThreadFunc(void *data)
{ {
SDL_TLSSet(tls, "baby thread", NULL); SDL_TLSSet(tls, "baby thread", NULL);
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n", SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls)); (char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
while (alive) { while (alive) {
SDL_Log("Thread '%s' is alive!\n", (char *) data); SDL_Log("Thread '%s' is alive!\n", (char *) data);
SDL_Delay(1 * 1000); SDL_Delay(1 * 1000);
} }
SDL_Log("Thread '%s' exiting!\n", (char *) data); SDL_Log("Thread '%s' exiting!\n", (char *) data);
return (0); return (0);
} }
static void static void
killed(int sig) killed(int sig)
{ {
SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n"); SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
SDL_Delay(5 * 1000); SDL_Delay(5 * 1000);
alive = 0; alive = 0;
quit(0); quit(0);
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
SDL_Thread *thread; SDL_Thread *thread;
/* Enable standard application logging */ /* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(0) < 0) { if (SDL_Init(0) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
tls = SDL_TLSCreate(); tls = SDL_TLSCreate();
SDL_assert(tls); SDL_assert(tls);
SDL_TLSSet(tls, "main thread", NULL); SDL_TLSSet(tls, "main thread", NULL);
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls)); SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1; alive = 1;
thread = SDL_CreateThread(ThreadFunc, "One", "#1"); thread = SDL_CreateThread(ThreadFunc, "One", "#1");
if (thread == NULL) { if (thread == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1); quit(1);
} }
SDL_Delay(5 * 1000); SDL_Delay(5 * 1000);
SDL_Log("Waiting for thread #1\n"); SDL_Log("Waiting for thread #1\n");
alive = 0; alive = 0;
SDL_WaitThread(thread, NULL); SDL_WaitThread(thread, NULL);
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls)); SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1; alive = 1;
signal(SIGTERM, killed); signal(SIGTERM, killed);
thread = SDL_CreateThread(ThreadFunc, "Two", "#2"); thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
if (thread == NULL) { if (thread == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1); quit(1);
} }
raise(SIGTERM); raise(SIGTERM);
SDL_Quit(); /* Never reached */ SDL_Quit(); /* Never reached */
return (0); /* Never reached */ return (0); /* Never reached */
} }