mirror of https://github.com/encounter/SDL.git
Fixed line endings on WinRT source code
This commit is contained in:
parent
61ae0c1b50
commit
05c23063bb
|
@ -166,9 +166,9 @@ typedef unsigned int uintptr_t;
|
|||
#define SDL_VIDEO_DRIVER_WINRT 1
|
||||
#define SDL_VIDEO_DRIVER_DUMMY 1
|
||||
|
||||
/* 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 */
|
||||
#define SDL_VIDEO_OPENGL_ES2 1
|
||||
/* 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 */
|
||||
#define SDL_VIDEO_OPENGL_ES2 1
|
||||
#define SDL_VIDEO_OPENGL_EGL 1
|
||||
#endif
|
||||
|
||||
|
|
|
@ -393,8 +393,8 @@ typedef enum {
|
|||
|
||||
#if __WINRT__
|
||||
#include <Unknwn.h>
|
||||
typedef IUnknown * EGLNativeWindowType;
|
||||
typedef int EGLNativeDisplayType;
|
||||
typedef IUnknown * EGLNativeWindowType;
|
||||
typedef int EGLNativeDisplayType;
|
||||
typedef HBITMAP EGLNativePixmapType;
|
||||
#else
|
||||
typedef HDC EGLNativeDisplayType;
|
||||
|
|
|
@ -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
|
||||
* 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__ */
|
||||
|
||||
|
|
|
@ -1,168 +1,168 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_platform.h
|
||||
*
|
||||
* Try to get a standard set of platform defines.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_platform_h
|
||||
#define _SDL_platform_h
|
||||
|
||||
#if defined(_AIX)
|
||||
#undef __AIX__
|
||||
#define __AIX__ 1
|
||||
#endif
|
||||
#if defined(__HAIKU__)
|
||||
#undef __HAIKU__
|
||||
#define __HAIKU__ 1
|
||||
#endif
|
||||
#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
|
||||
#undef __BSDI__
|
||||
#define __BSDI__ 1
|
||||
#endif
|
||||
#if defined(_arch_dreamcast)
|
||||
#undef __DREAMCAST__
|
||||
#define __DREAMCAST__ 1
|
||||
#endif
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
||||
#undef __FREEBSD__
|
||||
#define __FREEBSD__ 1
|
||||
#endif
|
||||
#if defined(hpux) || defined(__hpux) || defined(__hpux__)
|
||||
#undef __HPUX__
|
||||
#define __HPUX__ 1
|
||||
#endif
|
||||
#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
|
||||
#undef __IRIX__
|
||||
#define __IRIX__ 1
|
||||
#endif
|
||||
#if defined(linux) || defined(__linux) || defined(__linux__)
|
||||
#undef __LINUX__
|
||||
#define __LINUX__ 1
|
||||
#endif
|
||||
#if defined(ANDROID)
|
||||
#undef __ANDROID__
|
||||
#undef __LINUX__ /* do we need to do this? */
|
||||
#define __ANDROID__ 1
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
/* lets us know what version of Mac OS X we're compiling on */
|
||||
#include "AvailabilityMacros.h"
|
||||
#include "TargetConditionals.h"
|
||||
#if TARGET_OS_IPHONE
|
||||
/* if compiling for iPhone */
|
||||
#undef __IPHONEOS__
|
||||
#define __IPHONEOS__ 1
|
||||
#undef __MACOSX__
|
||||
#else
|
||||
/* if not compiling for iPhone */
|
||||
#undef __MACOSX__
|
||||
#define __MACOSX__ 1
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
|
||||
# error SDL for Mac OS X only supports deploying on 10.5 and above.
|
||||
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||
# 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 /* TARGET_OS_IPHONE */
|
||||
#endif /* defined(__APPLE__) */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#undef __NETBSD__
|
||||
#define __NETBSD__ 1
|
||||
#endif
|
||||
#if defined(__OpenBSD__)
|
||||
#undef __OPENBSD__
|
||||
#define __OPENBSD__ 1
|
||||
#endif
|
||||
#if defined(__OS2__)
|
||||
#undef __OS2__
|
||||
#define __OS2__ 1
|
||||
#endif
|
||||
#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
|
||||
#undef __OSF__
|
||||
#define __OSF__ 1
|
||||
#endif
|
||||
#if defined(__QNXNTO__)
|
||||
#undef __QNXNTO__
|
||||
#define __QNXNTO__ 1
|
||||
#endif
|
||||
#if defined(riscos) || defined(__riscos) || defined(__riscos__)
|
||||
#undef __RISCOS__
|
||||
#define __RISCOS__ 1
|
||||
#endif
|
||||
#if defined(__SVR4)
|
||||
#undef __SOLARIS__
|
||||
#define __SOLARIS__ 1
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
|
||||
/* 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 */
|
||||
#include <winapifamily.h>
|
||||
#endif /* _MSC_VER >= 1700 */
|
||||
/* Default to classic, Win32/Win64/Desktop compilation either if:
|
||||
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
|
||||
If neither is true, then see if we're compiling for WinRT.
|
||||
*/
|
||||
#if ! defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
#undef __WINDOWS__
|
||||
#define __WINDOWS__ 1
|
||||
/* See if we're compiling for WinRT: */
|
||||
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
||||
#undef __WINRT__
|
||||
#define __WINRT__ 1
|
||||
#endif /* ! defined(WINAPI_FAMILY_PARTITION) */
|
||||
#endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
#undef __WIN32__
|
||||
#define __WIN32__ 1
|
||||
#endif
|
||||
#if defined(__PSP__)
|
||||
#undef __PSP__
|
||||
#define __PSP__ 1
|
||||
#endif
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Gets the name of the platform.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_platform_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_platform.h
|
||||
*
|
||||
* Try to get a standard set of platform defines.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_platform_h
|
||||
#define _SDL_platform_h
|
||||
|
||||
#if defined(_AIX)
|
||||
#undef __AIX__
|
||||
#define __AIX__ 1
|
||||
#endif
|
||||
#if defined(__HAIKU__)
|
||||
#undef __HAIKU__
|
||||
#define __HAIKU__ 1
|
||||
#endif
|
||||
#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
|
||||
#undef __BSDI__
|
||||
#define __BSDI__ 1
|
||||
#endif
|
||||
#if defined(_arch_dreamcast)
|
||||
#undef __DREAMCAST__
|
||||
#define __DREAMCAST__ 1
|
||||
#endif
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
||||
#undef __FREEBSD__
|
||||
#define __FREEBSD__ 1
|
||||
#endif
|
||||
#if defined(hpux) || defined(__hpux) || defined(__hpux__)
|
||||
#undef __HPUX__
|
||||
#define __HPUX__ 1
|
||||
#endif
|
||||
#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
|
||||
#undef __IRIX__
|
||||
#define __IRIX__ 1
|
||||
#endif
|
||||
#if defined(linux) || defined(__linux) || defined(__linux__)
|
||||
#undef __LINUX__
|
||||
#define __LINUX__ 1
|
||||
#endif
|
||||
#if defined(ANDROID)
|
||||
#undef __ANDROID__
|
||||
#undef __LINUX__ /* do we need to do this? */
|
||||
#define __ANDROID__ 1
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
/* lets us know what version of Mac OS X we're compiling on */
|
||||
#include "AvailabilityMacros.h"
|
||||
#include "TargetConditionals.h"
|
||||
#if TARGET_OS_IPHONE
|
||||
/* if compiling for iPhone */
|
||||
#undef __IPHONEOS__
|
||||
#define __IPHONEOS__ 1
|
||||
#undef __MACOSX__
|
||||
#else
|
||||
/* if not compiling for iPhone */
|
||||
#undef __MACOSX__
|
||||
#define __MACOSX__ 1
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
|
||||
# error SDL for Mac OS X only supports deploying on 10.5 and above.
|
||||
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||
# 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 /* TARGET_OS_IPHONE */
|
||||
#endif /* defined(__APPLE__) */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#undef __NETBSD__
|
||||
#define __NETBSD__ 1
|
||||
#endif
|
||||
#if defined(__OpenBSD__)
|
||||
#undef __OPENBSD__
|
||||
#define __OPENBSD__ 1
|
||||
#endif
|
||||
#if defined(__OS2__)
|
||||
#undef __OS2__
|
||||
#define __OS2__ 1
|
||||
#endif
|
||||
#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
|
||||
#undef __OSF__
|
||||
#define __OSF__ 1
|
||||
#endif
|
||||
#if defined(__QNXNTO__)
|
||||
#undef __QNXNTO__
|
||||
#define __QNXNTO__ 1
|
||||
#endif
|
||||
#if defined(riscos) || defined(__riscos) || defined(__riscos__)
|
||||
#undef __RISCOS__
|
||||
#define __RISCOS__ 1
|
||||
#endif
|
||||
#if defined(__SVR4)
|
||||
#undef __SOLARIS__
|
||||
#define __SOLARIS__ 1
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
|
||||
/* 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 */
|
||||
#include <winapifamily.h>
|
||||
#endif /* _MSC_VER >= 1700 */
|
||||
/* Default to classic, Win32/Win64/Desktop compilation either if:
|
||||
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
|
||||
If neither is true, then see if we're compiling for WinRT.
|
||||
*/
|
||||
#if ! defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
#undef __WINDOWS__
|
||||
#define __WINDOWS__ 1
|
||||
/* See if we're compiling for WinRT: */
|
||||
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
||||
#undef __WINRT__
|
||||
#define __WINRT__ 1
|
||||
#endif /* ! defined(WINAPI_FAMILY_PARTITION) */
|
||||
#endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
#undef __WIN32__
|
||||
#define __WIN32__ 1
|
||||
#endif
|
||||
#if defined(__PSP__)
|
||||
#undef __PSP__
|
||||
#define __PSP__ 1
|
||||
#endif
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Gets the name of the platform.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_platform_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,185 +1,185 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_system.h
|
||||
*
|
||||
* Include file for platform specific SDL API functions
|
||||
*/
|
||||
|
||||
#ifndef _SDL_system_h
|
||||
#define _SDL_system_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_keyboard.h"
|
||||
#include "SDL_render.h"
|
||||
#include "SDL_video.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Platform specific functions for Windows */
|
||||
#ifdef __WIN32__
|
||||
|
||||
/* Returns the D3D9 adapter index that matches the specified display index.
|
||||
This adapter index can be passed to IDirect3D9::CreateDevice and controls
|
||||
on which monitor a full screen application will appear.
|
||||
*/
|
||||
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.
|
||||
Once you are done using the device, you should release it to avoid a resource leak.
|
||||
*/
|
||||
typedef struct IDirect3DDevice9 IDirect3DDevice9;
|
||||
extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
|
||||
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
|
||||
/* Platform specific functions for iOS */
|
||||
#if defined(__IPHONEOS__) && __IPHONEOS__
|
||||
|
||||
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);
|
||||
|
||||
#endif /* __IPHONEOS__ */
|
||||
|
||||
|
||||
/* Platform specific functions for Android */
|
||||
#if defined(__ANDROID__) && __ANDROID__
|
||||
|
||||
/* Get the JNI environment for the current thread
|
||||
This returns JNIEnv*, but the prototype is void* so we don't need jni.h
|
||||
*/
|
||||
extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
|
||||
|
||||
/* Get the SDL Activity object for the application
|
||||
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.
|
||||
It is the caller's responsibility to properly release it
|
||||
(using env->Push/PopLocalFrame or manually with env->DeleteLocalRef)
|
||||
*/
|
||||
extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();
|
||||
|
||||
/* See the official Android developer guide for more information:
|
||||
http://developer.android.com/guide/topics/data/data-storage.html
|
||||
*/
|
||||
#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
|
||||
#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
|
||||
|
||||
/* Get the path used for internal storage for this application.
|
||||
This path is unique to your application and cannot be written to
|
||||
by other applications.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();
|
||||
|
||||
/* Get the current state of external storage, a bitmask of these values:
|
||||
SDL_ANDROID_EXTERNAL_STORAGE_READ
|
||||
SDL_ANDROID_EXTERNAL_STORAGE_WRITE
|
||||
If external storage is currently unavailable, this will return 0.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState();
|
||||
|
||||
/* Get the path used for external storage for this application.
|
||||
This path is unique to your application, but is public and can be
|
||||
written to by other applications.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath();
|
||||
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
/* Platform specific functions for WinRT */
|
||||
#if defined(__WINRT__) && __WINRT__
|
||||
|
||||
/**
|
||||
* \brief WinRT / Windows Phone path types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** \brief The installed app's root directory.
|
||||
Files here are likely to be read-only. */
|
||||
SDL_WINRT_PATH_INSTALLED_LOCATION,
|
||||
|
||||
/** \brief The app's local data store. Files may be written here */
|
||||
SDL_WINRT_PATH_LOCAL_FOLDER,
|
||||
|
||||
/** \brief The app's roaming data store. Unsupported on Windows Phone.
|
||||
Files written here may be copied to other machines via a network
|
||||
connection.
|
||||
*/
|
||||
SDL_WINRT_PATH_ROAMING_FOLDER,
|
||||
|
||||
/** \brief The app's temporary data store. Unsupported on Windows Phone.
|
||||
Files written here may be deleted at any time. */
|
||||
SDL_WINRT_PATH_TEMP_FOLDER
|
||||
} SDL_WinRT_Path;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Retrieves a WinRT defined path on the local file system
|
||||
*
|
||||
* \note Documentation on most app-specific path types on WinRT
|
||||
* can be found on MSDN, at the URL:
|
||||
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
|
||||
*
|
||||
* \param pathType The type of path to retrieve.
|
||||
* \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
|
||||
* available on all versions of Windows. This is especially true on
|
||||
* Windows Phone. Check the documentation for the given
|
||||
* SDL_WinRT_Path for more information on which path types are
|
||||
* supported where.
|
||||
*/
|
||||
extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
|
||||
|
||||
/**
|
||||
* \brief Retrieves a WinRT defined path on the local file system
|
||||
*
|
||||
* \note Documentation on most app-specific path types on WinRT
|
||||
* can be found on MSDN, at the URL:
|
||||
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
|
||||
*
|
||||
* \param pathType The type of path to retrieve.
|
||||
* \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
|
||||
* available on all versions of Windows. This is especially true on
|
||||
* Windows Phone. Check the documentation for the given
|
||||
* SDL_WinRT_Path for more information on which path types are
|
||||
* supported where.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
|
||||
|
||||
#endif /* __WINRT__ */
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_system_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file SDL_system.h
|
||||
*
|
||||
* Include file for platform specific SDL API functions
|
||||
*/
|
||||
|
||||
#ifndef _SDL_system_h
|
||||
#define _SDL_system_h
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_keyboard.h"
|
||||
#include "SDL_render.h"
|
||||
#include "SDL_video.h"
|
||||
|
||||
#include "begin_code.h"
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Platform specific functions for Windows */
|
||||
#ifdef __WIN32__
|
||||
|
||||
/* Returns the D3D9 adapter index that matches the specified display index.
|
||||
This adapter index can be passed to IDirect3D9::CreateDevice and controls
|
||||
on which monitor a full screen application will appear.
|
||||
*/
|
||||
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.
|
||||
Once you are done using the device, you should release it to avoid a resource leak.
|
||||
*/
|
||||
typedef struct IDirect3DDevice9 IDirect3DDevice9;
|
||||
extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
|
||||
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
|
||||
/* Platform specific functions for iOS */
|
||||
#if defined(__IPHONEOS__) && __IPHONEOS__
|
||||
|
||||
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);
|
||||
|
||||
#endif /* __IPHONEOS__ */
|
||||
|
||||
|
||||
/* Platform specific functions for Android */
|
||||
#if defined(__ANDROID__) && __ANDROID__
|
||||
|
||||
/* Get the JNI environment for the current thread
|
||||
This returns JNIEnv*, but the prototype is void* so we don't need jni.h
|
||||
*/
|
||||
extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
|
||||
|
||||
/* Get the SDL Activity object for the application
|
||||
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.
|
||||
It is the caller's responsibility to properly release it
|
||||
(using env->Push/PopLocalFrame or manually with env->DeleteLocalRef)
|
||||
*/
|
||||
extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();
|
||||
|
||||
/* See the official Android developer guide for more information:
|
||||
http://developer.android.com/guide/topics/data/data-storage.html
|
||||
*/
|
||||
#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
|
||||
#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
|
||||
|
||||
/* Get the path used for internal storage for this application.
|
||||
This path is unique to your application and cannot be written to
|
||||
by other applications.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();
|
||||
|
||||
/* Get the current state of external storage, a bitmask of these values:
|
||||
SDL_ANDROID_EXTERNAL_STORAGE_READ
|
||||
SDL_ANDROID_EXTERNAL_STORAGE_WRITE
|
||||
If external storage is currently unavailable, this will return 0.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState();
|
||||
|
||||
/* Get the path used for external storage for this application.
|
||||
This path is unique to your application, but is public and can be
|
||||
written to by other applications.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath();
|
||||
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
/* Platform specific functions for WinRT */
|
||||
#if defined(__WINRT__) && __WINRT__
|
||||
|
||||
/**
|
||||
* \brief WinRT / Windows Phone path types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** \brief The installed app's root directory.
|
||||
Files here are likely to be read-only. */
|
||||
SDL_WINRT_PATH_INSTALLED_LOCATION,
|
||||
|
||||
/** \brief The app's local data store. Files may be written here */
|
||||
SDL_WINRT_PATH_LOCAL_FOLDER,
|
||||
|
||||
/** \brief The app's roaming data store. Unsupported on Windows Phone.
|
||||
Files written here may be copied to other machines via a network
|
||||
connection.
|
||||
*/
|
||||
SDL_WINRT_PATH_ROAMING_FOLDER,
|
||||
|
||||
/** \brief The app's temporary data store. Unsupported on Windows Phone.
|
||||
Files written here may be deleted at any time. */
|
||||
SDL_WINRT_PATH_TEMP_FOLDER
|
||||
} SDL_WinRT_Path;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Retrieves a WinRT defined path on the local file system
|
||||
*
|
||||
* \note Documentation on most app-specific path types on WinRT
|
||||
* can be found on MSDN, at the URL:
|
||||
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
|
||||
*
|
||||
* \param pathType The type of path to retrieve.
|
||||
* \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
|
||||
* available on all versions of Windows. This is especially true on
|
||||
* Windows Phone. Check the documentation for the given
|
||||
* SDL_WinRT_Path for more information on which path types are
|
||||
* supported where.
|
||||
*/
|
||||
extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
|
||||
|
||||
/**
|
||||
* \brief Retrieves a WinRT defined path on the local file system
|
||||
*
|
||||
* \note Documentation on most app-specific path types on WinRT
|
||||
* can be found on MSDN, at the URL:
|
||||
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
|
||||
*
|
||||
* \param pathType The type of path to retrieve.
|
||||
* \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
|
||||
* available on all versions of Windows. This is especially true on
|
||||
* Windows Phone. Check the documentation for the given
|
||||
* SDL_WinRT_Path for more information on which path types are
|
||||
* supported where.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
|
||||
|
||||
#endif /* __WINRT__ */
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include "close_code.h"
|
||||
|
||||
#endif /* _SDL_system_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,140 +1,140 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file begin_code.h
|
||||
*
|
||||
* This file sets things up for C dynamic library function definitions,
|
||||
* 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. :)
|
||||
*/
|
||||
|
||||
/* This shouldn't be nested -- included it around code only. */
|
||||
#ifdef _begin_code_h
|
||||
#error Nested inclusion of begin_code.h
|
||||
#endif
|
||||
#define _begin_code_h
|
||||
|
||||
#ifndef SDL_DEPRECATED
|
||||
# if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
|
||||
# define SDL_DEPRECATED __attribute__((deprecated))
|
||||
# else
|
||||
# define SDL_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some compilers use a special export keyword */
|
||||
#ifndef DECLSPEC
|
||||
# if defined(__WIN32__) || defined(__WINRT__)
|
||||
# ifdef __BORLANDC__
|
||||
# ifdef BUILD_SDL
|
||||
# define DECLSPEC
|
||||
# else
|
||||
# define DECLSPEC __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# endif
|
||||
# else
|
||||
# if defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define DECLSPEC __attribute__ ((visibility("default")))
|
||||
# elif defined(__GNUC__) && __GNUC__ >= 2
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# else
|
||||
# define DECLSPEC
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* By default SDL uses the C calling convention */
|
||||
#ifndef SDLCALL
|
||||
#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
|
||||
#define SDLCALL __cdecl
|
||||
#else
|
||||
#define SDLCALL
|
||||
#endif
|
||||
#endif /* SDLCALL */
|
||||
|
||||
/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
|
||||
#ifdef __SYMBIAN32__
|
||||
#undef DECLSPEC
|
||||
#define DECLSPEC
|
||||
#endif /* __SYMBIAN32__ */
|
||||
|
||||
/* Force structure packing at 4 byte alignment.
|
||||
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.
|
||||
The packing is reset to the previous value in close_code.h
|
||||
*/
|
||||
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4103)
|
||||
#endif
|
||||
#ifdef __BORLANDC__
|
||||
#pragma nopackwarning
|
||||
#endif
|
||||
#ifdef _M_X64
|
||||
/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
|
||||
#pragma pack(push,8)
|
||||
#else
|
||||
#pragma pack(push,4)
|
||||
#endif
|
||||
#endif /* Compiler needs structure packing set */
|
||||
|
||||
#ifndef SDL_INLINE
|
||||
#if defined(__GNUC__)
|
||||
#define SDL_INLINE __inline__
|
||||
#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
|
||||
defined(__DMC__) || defined(__SC__) || \
|
||||
defined(__WATCOMC__) || defined(__LCC__) || \
|
||||
defined(__DECC)
|
||||
#define SDL_INLINE __inline
|
||||
#ifndef __inline__
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
#else
|
||||
#define SDL_INLINE inline
|
||||
#ifndef __inline__
|
||||
#define __inline__ inline
|
||||
#endif
|
||||
#endif
|
||||
#endif /* SDL_INLINE not defined */
|
||||
|
||||
#ifndef SDL_FORCE_INLINE
|
||||
#if defined(_MSC_VER)
|
||||
#define SDL_FORCE_INLINE __forceinline
|
||||
#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
|
||||
#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
|
||||
#else
|
||||
#define SDL_FORCE_INLINE static SDL_INLINE
|
||||
#endif
|
||||
#endif /* SDL_FORCE_INLINE not defined */
|
||||
|
||||
/* Apparently this is needed by several Windows compilers */
|
||||
#if !defined(__MACH__)
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
#endif /* NULL */
|
||||
#endif /* ! Mac OS X - breaks precompiled headers */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file begin_code.h
|
||||
*
|
||||
* This file sets things up for C dynamic library function definitions,
|
||||
* 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. :)
|
||||
*/
|
||||
|
||||
/* This shouldn't be nested -- included it around code only. */
|
||||
#ifdef _begin_code_h
|
||||
#error Nested inclusion of begin_code.h
|
||||
#endif
|
||||
#define _begin_code_h
|
||||
|
||||
#ifndef SDL_DEPRECATED
|
||||
# if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
|
||||
# define SDL_DEPRECATED __attribute__((deprecated))
|
||||
# else
|
||||
# define SDL_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some compilers use a special export keyword */
|
||||
#ifndef DECLSPEC
|
||||
# if defined(__WIN32__) || defined(__WINRT__)
|
||||
# ifdef __BORLANDC__
|
||||
# ifdef BUILD_SDL
|
||||
# define DECLSPEC
|
||||
# else
|
||||
# define DECLSPEC __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# endif
|
||||
# else
|
||||
# if defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define DECLSPEC __attribute__ ((visibility("default")))
|
||||
# elif defined(__GNUC__) && __GNUC__ >= 2
|
||||
# define DECLSPEC __declspec(dllexport)
|
||||
# else
|
||||
# define DECLSPEC
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* By default SDL uses the C calling convention */
|
||||
#ifndef SDLCALL
|
||||
#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
|
||||
#define SDLCALL __cdecl
|
||||
#else
|
||||
#define SDLCALL
|
||||
#endif
|
||||
#endif /* SDLCALL */
|
||||
|
||||
/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
|
||||
#ifdef __SYMBIAN32__
|
||||
#undef DECLSPEC
|
||||
#define DECLSPEC
|
||||
#endif /* __SYMBIAN32__ */
|
||||
|
||||
/* Force structure packing at 4 byte alignment.
|
||||
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.
|
||||
The packing is reset to the previous value in close_code.h
|
||||
*/
|
||||
#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4103)
|
||||
#endif
|
||||
#ifdef __BORLANDC__
|
||||
#pragma nopackwarning
|
||||
#endif
|
||||
#ifdef _M_X64
|
||||
/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
|
||||
#pragma pack(push,8)
|
||||
#else
|
||||
#pragma pack(push,4)
|
||||
#endif
|
||||
#endif /* Compiler needs structure packing set */
|
||||
|
||||
#ifndef SDL_INLINE
|
||||
#if defined(__GNUC__)
|
||||
#define SDL_INLINE __inline__
|
||||
#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
|
||||
defined(__DMC__) || defined(__SC__) || \
|
||||
defined(__WATCOMC__) || defined(__LCC__) || \
|
||||
defined(__DECC)
|
||||
#define SDL_INLINE __inline
|
||||
#ifndef __inline__
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
#else
|
||||
#define SDL_INLINE inline
|
||||
#ifndef __inline__
|
||||
#define __inline__ inline
|
||||
#endif
|
||||
#endif
|
||||
#endif /* SDL_INLINE not defined */
|
||||
|
||||
#ifndef SDL_FORCE_INLINE
|
||||
#if defined(_MSC_VER)
|
||||
#define SDL_FORCE_INLINE __forceinline
|
||||
#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
|
||||
#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
|
||||
#else
|
||||
#define SDL_FORCE_INLINE static SDL_INLINE
|
||||
#endif
|
||||
#endif /* SDL_FORCE_INLINE not defined */
|
||||
|
||||
/* Apparently this is needed by several Windows compilers */
|
||||
#if !defined(__MACH__)
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
#endif /* NULL */
|
||||
#endif /* ! Mac OS X - breaks precompiled headers */
|
||||
|
|
878
src/SDL_log.c
878
src/SDL_log.c
|
@ -1,439 +1,439 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if defined(__WIN32__) || defined(__WINRT__)
|
||||
#include "core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
/* Simple log messages in SDL */
|
||||
|
||||
#include "SDL_log.h"
|
||||
|
||||
#if HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
|
||||
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
|
||||
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
|
||||
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
|
||||
|
||||
/* Forward definition of error function */
|
||||
extern int SDL_SetError(const char *fmt, ...);
|
||||
|
||||
typedef struct SDL_LogLevel
|
||||
{
|
||||
int category;
|
||||
SDL_LogPriority priority;
|
||||
struct SDL_LogLevel *next;
|
||||
} SDL_LogLevel;
|
||||
|
||||
/* The default log output function */
|
||||
static void SDL_LogOutput(void *userdata,
|
||||
int category, SDL_LogPriority priority,
|
||||
const char *message);
|
||||
|
||||
static SDL_LogLevel *SDL_loglevels;
|
||||
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
|
||||
static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
|
||||
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
||||
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
|
||||
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
|
||||
static void *SDL_log_userdata = NULL;
|
||||
|
||||
static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
|
||||
NULL,
|
||||
"VERBOSE",
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARN",
|
||||
"ERROR",
|
||||
"CRITICAL"
|
||||
};
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static const char *SDL_category_prefixes[SDL_LOG_CATEGORY_RESERVED1] = {
|
||||
"APP",
|
||||
"ERROR",
|
||||
"SYSTEM",
|
||||
"AUDIO",
|
||||
"VIDEO",
|
||||
"RENDER",
|
||||
"INPUT"
|
||||
};
|
||||
|
||||
static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
|
||||
ANDROID_LOG_UNKNOWN,
|
||||
ANDROID_LOG_VERBOSE,
|
||||
ANDROID_LOG_DEBUG,
|
||||
ANDROID_LOG_INFO,
|
||||
ANDROID_LOG_WARN,
|
||||
ANDROID_LOG_ERROR,
|
||||
ANDROID_LOG_FATAL
|
||||
};
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
|
||||
void
|
||||
SDL_LogSetAllPriority(SDL_LogPriority priority)
|
||||
{
|
||||
SDL_LogLevel *entry;
|
||||
|
||||
for (entry = SDL_loglevels; entry; entry = entry->next) {
|
||||
entry->priority = priority;
|
||||
}
|
||||
SDL_default_priority = priority;
|
||||
SDL_assert_priority = priority;
|
||||
SDL_application_priority = priority;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogSetPriority(int category, SDL_LogPriority priority)
|
||||
{
|
||||
SDL_LogLevel *entry;
|
||||
|
||||
for (entry = SDL_loglevels; entry; entry = entry->next) {
|
||||
if (entry->category == category) {
|
||||
entry->priority = priority;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new entry */
|
||||
entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
|
||||
if (entry) {
|
||||
entry->category = category;
|
||||
entry->priority = priority;
|
||||
entry->next = SDL_loglevels;
|
||||
SDL_loglevels = entry;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_LogPriority
|
||||
SDL_LogGetPriority(int category)
|
||||
{
|
||||
SDL_LogLevel *entry;
|
||||
|
||||
for (entry = SDL_loglevels; entry; entry = entry->next) {
|
||||
if (entry->category == category) {
|
||||
return entry->priority;
|
||||
}
|
||||
}
|
||||
|
||||
if (category == SDL_LOG_CATEGORY_TEST) {
|
||||
return SDL_test_priority;
|
||||
} else if (category == SDL_LOG_CATEGORY_APPLICATION) {
|
||||
return SDL_application_priority;
|
||||
} else if (category == SDL_LOG_CATEGORY_ASSERT) {
|
||||
return SDL_assert_priority;
|
||||
} else {
|
||||
return SDL_default_priority;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogResetPriorities(void)
|
||||
{
|
||||
SDL_LogLevel *entry;
|
||||
|
||||
while (SDL_loglevels) {
|
||||
entry = SDL_loglevels;
|
||||
SDL_loglevels = entry->next;
|
||||
SDL_free(entry);
|
||||
}
|
||||
|
||||
SDL_default_priority = DEFAULT_PRIORITY;
|
||||
SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
|
||||
SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
||||
SDL_test_priority = DEFAULT_TEST_PRIORITY;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Log(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogVerbose(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogDebug(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_DEBUG, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogInfo(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogWarn(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogError(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogCritical(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, priority, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static const char *
|
||||
GetCategoryPrefix(int category)
|
||||
{
|
||||
if (category < SDL_LOG_CATEGORY_RESERVED1) {
|
||||
return SDL_category_prefixes[category];
|
||||
}
|
||||
if (category < SDL_LOG_CATEGORY_CUSTOM) {
|
||||
return "RESERVED";
|
||||
}
|
||||
return "CUSTOM";
|
||||
}
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
void
|
||||
SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
|
||||
{
|
||||
char *message;
|
||||
size_t len;
|
||||
|
||||
/* Nothing to do if we don't have an output function */
|
||||
if (!SDL_log_function) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure we don't exceed array bounds */
|
||||
if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* See if we want to do anything with this message */
|
||||
if (priority < SDL_LogGetPriority(category)) {
|
||||
return;
|
||||
}
|
||||
|
||||
message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
|
||||
|
||||
/* Chop off final endline. */
|
||||
len = SDL_strlen(message);
|
||||
if ((len > 0) && (message[len-1] == '\n')) {
|
||||
message[--len] = '\0';
|
||||
if ((len > 0) && (message[len-1] == '\r')) { /* catch "\r\n", too. */
|
||||
message[--len] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
SDL_log_function(SDL_log_userdata, category, priority, message);
|
||||
SDL_stack_free(message);
|
||||
}
|
||||
|
||||
#if defined(__WIN32__)
|
||||
/* Flag tracking the attachment of the console: 0=unattached, 1=attached, -1=error */
|
||||
static int consoleAttached = 0;
|
||||
|
||||
/* Handle to stderr output of console. */
|
||||
static HANDLE stderrHandle = NULL;
|
||||
#endif
|
||||
|
||||
static void
|
||||
SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
|
||||
const char *message)
|
||||
{
|
||||
#if defined(__WIN32__) || defined(__WINRT__)
|
||||
/* Way too many allocations here, urgh */
|
||||
/* Note: One can't call SDL_SetError here, since that function itself logs. */
|
||||
{
|
||||
char *output;
|
||||
size_t length;
|
||||
LPTSTR tstr;
|
||||
|
||||
#ifndef __WINRT__
|
||||
BOOL attachResult;
|
||||
DWORD attachError;
|
||||
unsigned long charsWritten;
|
||||
|
||||
/* Maybe attach console and get stderr handle */
|
||||
if (consoleAttached == 0) {
|
||||
attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
|
||||
if (!attachResult) {
|
||||
attachError = GetLastError();
|
||||
if (attachError == ERROR_INVALID_HANDLE) {
|
||||
OutputDebugString(TEXT("Parent process has no console\r\n"));
|
||||
consoleAttached = -1;
|
||||
} else if (attachError == ERROR_GEN_FAILURE) {
|
||||
OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
|
||||
consoleAttached = -1;
|
||||
} else if (attachError == ERROR_ACCESS_DENIED) {
|
||||
/* Already attached */
|
||||
consoleAttached = 1;
|
||||
} else {
|
||||
OutputDebugString(TEXT("Error attaching console\r\n"));
|
||||
consoleAttached = -1;
|
||||
}
|
||||
} else {
|
||||
/* Newly attached */
|
||||
consoleAttached = 1;
|
||||
}
|
||||
|
||||
if (consoleAttached == 1) {
|
||||
stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
|
||||
}
|
||||
}
|
||||
#endif /* ifndef __WINRT__ */
|
||||
|
||||
length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1;
|
||||
output = SDL_stack_alloc(char, length);
|
||||
SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
|
||||
tstr = WIN_UTF8ToString(output);
|
||||
|
||||
/* Output to debugger */
|
||||
OutputDebugString(tstr);
|
||||
|
||||
#ifndef __WINRT__
|
||||
/* Screen output to stderr, if console was attached. */
|
||||
if (consoleAttached == 1) {
|
||||
if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
|
||||
OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
|
||||
}
|
||||
if (charsWritten == ERROR_NOT_ENOUGH_MEMORY) {
|
||||
OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
|
||||
}
|
||||
}
|
||||
#endif /* ifndef __WINRT__ */
|
||||
|
||||
SDL_free(tstr);
|
||||
SDL_stack_free(output);
|
||||
}
|
||||
#elif defined(__ANDROID__)
|
||||
{
|
||||
char tag[32];
|
||||
|
||||
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
|
||||
__android_log_write(SDL_android_priority[priority], tag, message);
|
||||
}
|
||||
#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.
|
||||
*/
|
||||
extern void SDL_NSLog(const char *text);
|
||||
{
|
||||
char *text;
|
||||
|
||||
text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
|
||||
if (text) {
|
||||
SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message);
|
||||
SDL_NSLog(text);
|
||||
SDL_stack_free(text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#elif defined(__PSP__)
|
||||
{
|
||||
FILE* pFile;
|
||||
pFile = fopen ("SDL_Log.txt", "a");
|
||||
fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
||||
fclose (pFile);
|
||||
}
|
||||
#endif
|
||||
#if HAVE_STDIO_H
|
||||
fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
|
||||
{
|
||||
if (callback) {
|
||||
*callback = SDL_log_function;
|
||||
}
|
||||
if (userdata) {
|
||||
*userdata = SDL_log_userdata;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
|
||||
{
|
||||
SDL_log_function = callback;
|
||||
SDL_log_userdata = userdata;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if defined(__WIN32__) || defined(__WINRT__)
|
||||
#include "core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
/* Simple log messages in SDL */
|
||||
|
||||
#include "SDL_log.h"
|
||||
|
||||
#if HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
|
||||
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
|
||||
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
|
||||
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
|
||||
|
||||
/* Forward definition of error function */
|
||||
extern int SDL_SetError(const char *fmt, ...);
|
||||
|
||||
typedef struct SDL_LogLevel
|
||||
{
|
||||
int category;
|
||||
SDL_LogPriority priority;
|
||||
struct SDL_LogLevel *next;
|
||||
} SDL_LogLevel;
|
||||
|
||||
/* The default log output function */
|
||||
static void SDL_LogOutput(void *userdata,
|
||||
int category, SDL_LogPriority priority,
|
||||
const char *message);
|
||||
|
||||
static SDL_LogLevel *SDL_loglevels;
|
||||
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
|
||||
static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
|
||||
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
||||
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
|
||||
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
|
||||
static void *SDL_log_userdata = NULL;
|
||||
|
||||
static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
|
||||
NULL,
|
||||
"VERBOSE",
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARN",
|
||||
"ERROR",
|
||||
"CRITICAL"
|
||||
};
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static const char *SDL_category_prefixes[SDL_LOG_CATEGORY_RESERVED1] = {
|
||||
"APP",
|
||||
"ERROR",
|
||||
"SYSTEM",
|
||||
"AUDIO",
|
||||
"VIDEO",
|
||||
"RENDER",
|
||||
"INPUT"
|
||||
};
|
||||
|
||||
static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
|
||||
ANDROID_LOG_UNKNOWN,
|
||||
ANDROID_LOG_VERBOSE,
|
||||
ANDROID_LOG_DEBUG,
|
||||
ANDROID_LOG_INFO,
|
||||
ANDROID_LOG_WARN,
|
||||
ANDROID_LOG_ERROR,
|
||||
ANDROID_LOG_FATAL
|
||||
};
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
|
||||
void
|
||||
SDL_LogSetAllPriority(SDL_LogPriority priority)
|
||||
{
|
||||
SDL_LogLevel *entry;
|
||||
|
||||
for (entry = SDL_loglevels; entry; entry = entry->next) {
|
||||
entry->priority = priority;
|
||||
}
|
||||
SDL_default_priority = priority;
|
||||
SDL_assert_priority = priority;
|
||||
SDL_application_priority = priority;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogSetPriority(int category, SDL_LogPriority priority)
|
||||
{
|
||||
SDL_LogLevel *entry;
|
||||
|
||||
for (entry = SDL_loglevels; entry; entry = entry->next) {
|
||||
if (entry->category == category) {
|
||||
entry->priority = priority;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new entry */
|
||||
entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
|
||||
if (entry) {
|
||||
entry->category = category;
|
||||
entry->priority = priority;
|
||||
entry->next = SDL_loglevels;
|
||||
SDL_loglevels = entry;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_LogPriority
|
||||
SDL_LogGetPriority(int category)
|
||||
{
|
||||
SDL_LogLevel *entry;
|
||||
|
||||
for (entry = SDL_loglevels; entry; entry = entry->next) {
|
||||
if (entry->category == category) {
|
||||
return entry->priority;
|
||||
}
|
||||
}
|
||||
|
||||
if (category == SDL_LOG_CATEGORY_TEST) {
|
||||
return SDL_test_priority;
|
||||
} else if (category == SDL_LOG_CATEGORY_APPLICATION) {
|
||||
return SDL_application_priority;
|
||||
} else if (category == SDL_LOG_CATEGORY_ASSERT) {
|
||||
return SDL_assert_priority;
|
||||
} else {
|
||||
return SDL_default_priority;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogResetPriorities(void)
|
||||
{
|
||||
SDL_LogLevel *entry;
|
||||
|
||||
while (SDL_loglevels) {
|
||||
entry = SDL_loglevels;
|
||||
SDL_loglevels = entry->next;
|
||||
SDL_free(entry);
|
||||
}
|
||||
|
||||
SDL_default_priority = DEFAULT_PRIORITY;
|
||||
SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
|
||||
SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
||||
SDL_test_priority = DEFAULT_TEST_PRIORITY;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_Log(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogVerbose(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogDebug(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_DEBUG, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogInfo(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogWarn(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogError(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogCritical(int category, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_LogMessageV(category, priority, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static const char *
|
||||
GetCategoryPrefix(int category)
|
||||
{
|
||||
if (category < SDL_LOG_CATEGORY_RESERVED1) {
|
||||
return SDL_category_prefixes[category];
|
||||
}
|
||||
if (category < SDL_LOG_CATEGORY_CUSTOM) {
|
||||
return "RESERVED";
|
||||
}
|
||||
return "CUSTOM";
|
||||
}
|
||||
#endif /* __ANDROID__ */
|
||||
|
||||
void
|
||||
SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
|
||||
{
|
||||
char *message;
|
||||
size_t len;
|
||||
|
||||
/* Nothing to do if we don't have an output function */
|
||||
if (!SDL_log_function) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure we don't exceed array bounds */
|
||||
if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* See if we want to do anything with this message */
|
||||
if (priority < SDL_LogGetPriority(category)) {
|
||||
return;
|
||||
}
|
||||
|
||||
message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
|
||||
|
||||
/* Chop off final endline. */
|
||||
len = SDL_strlen(message);
|
||||
if ((len > 0) && (message[len-1] == '\n')) {
|
||||
message[--len] = '\0';
|
||||
if ((len > 0) && (message[len-1] == '\r')) { /* catch "\r\n", too. */
|
||||
message[--len] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
SDL_log_function(SDL_log_userdata, category, priority, message);
|
||||
SDL_stack_free(message);
|
||||
}
|
||||
|
||||
#if defined(__WIN32__)
|
||||
/* Flag tracking the attachment of the console: 0=unattached, 1=attached, -1=error */
|
||||
static int consoleAttached = 0;
|
||||
|
||||
/* Handle to stderr output of console. */
|
||||
static HANDLE stderrHandle = NULL;
|
||||
#endif
|
||||
|
||||
static void
|
||||
SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
|
||||
const char *message)
|
||||
{
|
||||
#if defined(__WIN32__) || defined(__WINRT__)
|
||||
/* Way too many allocations here, urgh */
|
||||
/* Note: One can't call SDL_SetError here, since that function itself logs. */
|
||||
{
|
||||
char *output;
|
||||
size_t length;
|
||||
LPTSTR tstr;
|
||||
|
||||
#ifndef __WINRT__
|
||||
BOOL attachResult;
|
||||
DWORD attachError;
|
||||
unsigned long charsWritten;
|
||||
|
||||
/* Maybe attach console and get stderr handle */
|
||||
if (consoleAttached == 0) {
|
||||
attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
|
||||
if (!attachResult) {
|
||||
attachError = GetLastError();
|
||||
if (attachError == ERROR_INVALID_HANDLE) {
|
||||
OutputDebugString(TEXT("Parent process has no console\r\n"));
|
||||
consoleAttached = -1;
|
||||
} else if (attachError == ERROR_GEN_FAILURE) {
|
||||
OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
|
||||
consoleAttached = -1;
|
||||
} else if (attachError == ERROR_ACCESS_DENIED) {
|
||||
/* Already attached */
|
||||
consoleAttached = 1;
|
||||
} else {
|
||||
OutputDebugString(TEXT("Error attaching console\r\n"));
|
||||
consoleAttached = -1;
|
||||
}
|
||||
} else {
|
||||
/* Newly attached */
|
||||
consoleAttached = 1;
|
||||
}
|
||||
|
||||
if (consoleAttached == 1) {
|
||||
stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
|
||||
}
|
||||
}
|
||||
#endif /* ifndef __WINRT__ */
|
||||
|
||||
length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1;
|
||||
output = SDL_stack_alloc(char, length);
|
||||
SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
|
||||
tstr = WIN_UTF8ToString(output);
|
||||
|
||||
/* Output to debugger */
|
||||
OutputDebugString(tstr);
|
||||
|
||||
#ifndef __WINRT__
|
||||
/* Screen output to stderr, if console was attached. */
|
||||
if (consoleAttached == 1) {
|
||||
if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
|
||||
OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
|
||||
}
|
||||
if (charsWritten == ERROR_NOT_ENOUGH_MEMORY) {
|
||||
OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
|
||||
}
|
||||
}
|
||||
#endif /* ifndef __WINRT__ */
|
||||
|
||||
SDL_free(tstr);
|
||||
SDL_stack_free(output);
|
||||
}
|
||||
#elif defined(__ANDROID__)
|
||||
{
|
||||
char tag[32];
|
||||
|
||||
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
|
||||
__android_log_write(SDL_android_priority[priority], tag, message);
|
||||
}
|
||||
#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.
|
||||
*/
|
||||
extern void SDL_NSLog(const char *text);
|
||||
{
|
||||
char *text;
|
||||
|
||||
text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
|
||||
if (text) {
|
||||
SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message);
|
||||
SDL_NSLog(text);
|
||||
SDL_stack_free(text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#elif defined(__PSP__)
|
||||
{
|
||||
FILE* pFile;
|
||||
pFile = fopen ("SDL_Log.txt", "a");
|
||||
fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
||||
fclose (pFile);
|
||||
}
|
||||
#endif
|
||||
#if HAVE_STDIO_H
|
||||
fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
|
||||
{
|
||||
if (callback) {
|
||||
*callback = SDL_log_function;
|
||||
}
|
||||
if (userdata) {
|
||||
*userdata = SDL_log_userdata;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
|
||||
{
|
||||
SDL_log_function = callback;
|
||||
SDL_log_userdata = userdata;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,126 +1,126 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if defined(__WIN32__) || defined(__WINRT__)
|
||||
#include "../core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
#include "SDL_atomic.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_timer.h"
|
||||
|
||||
|
||||
/* This function is where all the magic happens... */
|
||||
SDL_bool
|
||||
SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
{
|
||||
#if SDL_ATOMIC_DISABLED
|
||||
/* Terrible terrible damage */
|
||||
static SDL_mutex *_spinlock_mutex;
|
||||
|
||||
if (!_spinlock_mutex) {
|
||||
/* Race condition on first lock... */
|
||||
_spinlock_mutex = SDL_CreateMutex();
|
||||
}
|
||||
SDL_LockMutex(_spinlock_mutex);
|
||||
if (*lock == 0) {
|
||||
*lock = 1;
|
||||
SDL_UnlockMutex(_spinlock_mutex);
|
||||
return SDL_TRUE;
|
||||
} else {
|
||||
SDL_UnlockMutex(_spinlock_mutex);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
|
||||
return (InterlockedExchange((long*)lock, 1) == 0);
|
||||
|
||||
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
||||
return (__sync_lock_test_and_set(lock, 1) == 0);
|
||||
|
||||
#elif defined(__GNUC__) && defined(__arm__) && \
|
||||
(defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
|
||||
defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
|
||||
defined(__ARM_ARCH_5TEJ__))
|
||||
int result;
|
||||
__asm__ __volatile__ (
|
||||
"swp %0, %1, [%2]\n"
|
||||
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
|
||||
return (result == 0);
|
||||
|
||||
#elif defined(__GNUC__) && defined(__arm__)
|
||||
int result;
|
||||
__asm__ __volatile__ (
|
||||
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
|
||||
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
|
||||
return (result == 0);
|
||||
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
int result;
|
||||
__asm__ __volatile__(
|
||||
"lock ; xchgl %0, (%1)\n"
|
||||
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
|
||||
return (result == 0);
|
||||
|
||||
#elif defined(__MACOSX__) || defined(__IPHONEOS__)
|
||||
/* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
|
||||
return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
|
||||
|
||||
#elif HAVE_PTHREAD_SPINLOCK
|
||||
/* pthread instructions */
|
||||
return (pthread_spin_trylock(lock) == 0);
|
||||
|
||||
#else
|
||||
#error Please implement for your platform.
|
||||
return SDL_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
{
|
||||
/* FIXME: Should we have an eventual timeout? */
|
||||
while (!SDL_AtomicTryLock(lock)) {
|
||||
SDL_Delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
_ReadWriteBarrier();
|
||||
*lock = 0;
|
||||
|
||||
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
||||
__sync_lock_release(lock);
|
||||
|
||||
#elif HAVE_PTHREAD_SPINLOCK
|
||||
pthread_spin_unlock(lock);
|
||||
|
||||
#else
|
||||
*lock = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if defined(__WIN32__) || defined(__WINRT__)
|
||||
#include "../core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
#include "SDL_atomic.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_timer.h"
|
||||
|
||||
|
||||
/* This function is where all the magic happens... */
|
||||
SDL_bool
|
||||
SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
{
|
||||
#if SDL_ATOMIC_DISABLED
|
||||
/* Terrible terrible damage */
|
||||
static SDL_mutex *_spinlock_mutex;
|
||||
|
||||
if (!_spinlock_mutex) {
|
||||
/* Race condition on first lock... */
|
||||
_spinlock_mutex = SDL_CreateMutex();
|
||||
}
|
||||
SDL_LockMutex(_spinlock_mutex);
|
||||
if (*lock == 0) {
|
||||
*lock = 1;
|
||||
SDL_UnlockMutex(_spinlock_mutex);
|
||||
return SDL_TRUE;
|
||||
} else {
|
||||
SDL_UnlockMutex(_spinlock_mutex);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
|
||||
return (InterlockedExchange((long*)lock, 1) == 0);
|
||||
|
||||
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
||||
return (__sync_lock_test_and_set(lock, 1) == 0);
|
||||
|
||||
#elif defined(__GNUC__) && defined(__arm__) && \
|
||||
(defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
|
||||
defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
|
||||
defined(__ARM_ARCH_5TEJ__))
|
||||
int result;
|
||||
__asm__ __volatile__ (
|
||||
"swp %0, %1, [%2]\n"
|
||||
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
|
||||
return (result == 0);
|
||||
|
||||
#elif defined(__GNUC__) && defined(__arm__)
|
||||
int result;
|
||||
__asm__ __volatile__ (
|
||||
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
|
||||
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
|
||||
return (result == 0);
|
||||
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
int result;
|
||||
__asm__ __volatile__(
|
||||
"lock ; xchgl %0, (%1)\n"
|
||||
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
|
||||
return (result == 0);
|
||||
|
||||
#elif defined(__MACOSX__) || defined(__IPHONEOS__)
|
||||
/* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
|
||||
return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
|
||||
|
||||
#elif HAVE_PTHREAD_SPINLOCK
|
||||
/* pthread instructions */
|
||||
return (pthread_spin_trylock(lock) == 0);
|
||||
|
||||
#else
|
||||
#error Please implement for your platform.
|
||||
return SDL_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
{
|
||||
/* FIXME: Should we have an eventual timeout? */
|
||||
while (!SDL_AtomicTryLock(lock)) {
|
||||
SDL_Delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
_ReadWriteBarrier();
|
||||
*lock = 0;
|
||||
|
||||
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
||||
__sync_lock_release(lock);
|
||||
|
||||
#elif HAVE_PTHREAD_SPINLOCK
|
||||
pthread_spin_unlock(lock);
|
||||
|
||||
#else
|
||||
*lock = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,69 +1,69 @@
|
|||
|
||||
#include <xaudio2.h>
|
||||
#include "SDL_xaudio2_winrthelpers.h"
|
||||
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
using Windows::Devices::Enumeration::DeviceClass;
|
||||
using Windows::Devices::Enumeration::DeviceInformation;
|
||||
using Windows::Devices::Enumeration::DeviceInformationCollection;
|
||||
#endif
|
||||
|
||||
extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
|
||||
{
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
// 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
|
||||
// audio device.
|
||||
*devcount = 1;
|
||||
return S_OK;
|
||||
#else
|
||||
// TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
|
||||
auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
|
||||
while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceInformationCollection^ devices = operation->GetResults();
|
||||
*devcount = devices->Size;
|
||||
return S_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
|
||||
{
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
// 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,
|
||||
// just treat things as if there is one, and only one, default device.
|
||||
if (index != 0)
|
||||
{
|
||||
return XAUDIO2_E_INVALID_CALL;
|
||||
}
|
||||
|
||||
if (details)
|
||||
{
|
||||
wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE);
|
||||
wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE);
|
||||
}
|
||||
return S_OK;
|
||||
#else
|
||||
auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
|
||||
while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceInformationCollection^ devices = operation->GetResults();
|
||||
if (index >= devices->Size)
|
||||
{
|
||||
return XAUDIO2_E_INVALID_CALL;
|
||||
}
|
||||
|
||||
DeviceInformation^ d = devices->GetAt(index);
|
||||
if (details)
|
||||
{
|
||||
wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
|
||||
wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
|
||||
}
|
||||
return S_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <xaudio2.h>
|
||||
#include "SDL_xaudio2_winrthelpers.h"
|
||||
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
using Windows::Devices::Enumeration::DeviceClass;
|
||||
using Windows::Devices::Enumeration::DeviceInformation;
|
||||
using Windows::Devices::Enumeration::DeviceInformationCollection;
|
||||
#endif
|
||||
|
||||
extern "C" HRESULT __cdecl IXAudio2_GetDeviceCount(IXAudio2 * ixa2, UINT32 * devcount)
|
||||
{
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
// 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
|
||||
// audio device.
|
||||
*devcount = 1;
|
||||
return S_OK;
|
||||
#else
|
||||
// TODO, WinRT: make xaudio2 device enumeration only happen once, and in the background
|
||||
auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
|
||||
while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceInformationCollection^ devices = operation->GetResults();
|
||||
*devcount = devices->Size;
|
||||
return S_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details)
|
||||
{
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
// 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,
|
||||
// just treat things as if there is one, and only one, default device.
|
||||
if (index != 0)
|
||||
{
|
||||
return XAUDIO2_E_INVALID_CALL;
|
||||
}
|
||||
|
||||
if (details)
|
||||
{
|
||||
wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), L"default", _TRUNCATE);
|
||||
wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), L"default", _TRUNCATE);
|
||||
}
|
||||
return S_OK;
|
||||
#else
|
||||
auto operation = DeviceInformation::FindAllAsync(DeviceClass::AudioRender);
|
||||
while (operation->Status != Windows::Foundation::AsyncStatus::Completed)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceInformationCollection^ devices = operation->GetResults();
|
||||
if (index >= devices->Size)
|
||||
{
|
||||
return XAUDIO2_E_INVALID_CALL;
|
||||
}
|
||||
|
||||
DeviceInformation^ d = devices->GetAt(index);
|
||||
if (details)
|
||||
{
|
||||
wcsncpy_s(details->DeviceID, ARRAYSIZE(details->DeviceID), d->Id->Data(), _TRUNCATE);
|
||||
wcsncpy_s(details->DisplayName, ARRAYSIZE(details->DisplayName), d->Name->Data(), _TRUNCATE);
|
||||
}
|
||||
return S_OK;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Re-implementation of methods removed from XAudio2 (in WinRT):
|
||||
//
|
||||
|
||||
typedef struct XAUDIO2_DEVICE_DETAILS
|
||||
{
|
||||
WCHAR DeviceID[256];
|
||||
WCHAR DisplayName[256];
|
||||
/* Other fields exist in the pre-Windows 8 version of this struct, however
|
||||
they weren't used by SDL, so they weren't added.
|
||||
*/
|
||||
} XAUDIO2_DEVICE_DETAILS;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
HRESULT IXAudio2_GetDeviceCount(IXAudio2 * unused, UINT32 * devcount);
|
||||
HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// C-style macros to call XAudio2's methods in C++:
|
||||
//
|
||||
#ifdef __cplusplus
|
||||
/*
|
||||
#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_QueryInterface(A, B, C) (A)->QueryInterface((B), (C))
|
||||
#define IXAudio2_Release(A) (A)->Release()
|
||||
#define IXAudio2_StartEngine(A) (A)->StartEngine()
|
||||
#define IXAudio2_StopEngine(A) (A)->StopEngine()
|
||||
|
||||
#define IXAudio2MasteringVoice_DestroyVoice(A) (A)->DestroyVoice()
|
||||
|
||||
#define IXAudio2SourceVoice_DestroyVoice(A) (A)->DestroyVoice()
|
||||
#define IXAudio2SourceVoice_Discontinuity(A) (A)->Discontinuity()
|
||||
#define IXAudio2SourceVoice_FlushSourceBuffers(A) (A)->FlushSourceBuffers()
|
||||
#define IXAudio2SourceVoice_GetState(A, B) (A)->GetState((B))
|
||||
#define IXAudio2SourceVoice_Start(A, B, C) (A)->Start((B), (C))
|
||||
#define IXAudio2SourceVoice_Stop(A, B, C) (A)->Stop((B), (C))
|
||||
#define IXAudio2SourceVoice_SubmitSourceBuffer(A, B, C) (A)->SubmitSourceBuffer((B), (C))
|
||||
*/
|
||||
#endif // ifdef __cplusplus
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Re-implementation of methods removed from XAudio2 (in WinRT):
|
||||
//
|
||||
|
||||
typedef struct XAUDIO2_DEVICE_DETAILS
|
||||
{
|
||||
WCHAR DeviceID[256];
|
||||
WCHAR DisplayName[256];
|
||||
/* Other fields exist in the pre-Windows 8 version of this struct, however
|
||||
they weren't used by SDL, so they weren't added.
|
||||
*/
|
||||
} XAUDIO2_DEVICE_DETAILS;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
HRESULT IXAudio2_GetDeviceCount(IXAudio2 * unused, UINT32 * devcount);
|
||||
HRESULT IXAudio2_GetDeviceDetails(IXAudio2 * unused, UINT32 index, XAUDIO2_DEVICE_DETAILS * details);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// C-style macros to call XAudio2's methods in C++:
|
||||
//
|
||||
#ifdef __cplusplus
|
||||
/*
|
||||
#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_QueryInterface(A, B, C) (A)->QueryInterface((B), (C))
|
||||
#define IXAudio2_Release(A) (A)->Release()
|
||||
#define IXAudio2_StartEngine(A) (A)->StartEngine()
|
||||
#define IXAudio2_StopEngine(A) (A)->StopEngine()
|
||||
|
||||
#define IXAudio2MasteringVoice_DestroyVoice(A) (A)->DestroyVoice()
|
||||
|
||||
#define IXAudio2SourceVoice_DestroyVoice(A) (A)->DestroyVoice()
|
||||
#define IXAudio2SourceVoice_Discontinuity(A) (A)->Discontinuity()
|
||||
#define IXAudio2SourceVoice_FlushSourceBuffers(A) (A)->FlushSourceBuffers()
|
||||
#define IXAudio2SourceVoice_GetState(A, B) (A)->GetState((B))
|
||||
#define IXAudio2SourceVoice_Start(A, B, C) (A)->Start((B), (C))
|
||||
#define IXAudio2SourceVoice_Stop(A, B, C) (A)->Stop((B), (C))
|
||||
#define IXAudio2SourceVoice_SubmitSourceBuffer(A, B, C) (A)->SubmitSourceBuffer((B), (C))
|
||||
*/
|
||||
#endif // ifdef __cplusplus
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
|
||||
#include <SDL_system.h>
|
||||
#include "SDL_winrtapp_direct3d.h"
|
||||
#include "SDL_winrtapp_xaml.h"
|
||||
|
||||
int (*WINRT_SDLAppEntryPoint)(int, char **) = NULL;
|
||||
|
||||
|
||||
#include <SDL_system.h>
|
||||
#include "SDL_winrtapp_direct3d.h"
|
||||
#include "SDL_winrtapp_xaml.h"
|
||||
|
||||
int (*WINRT_SDLAppEntryPoint)(int, char **) = NULL;
|
||||
|
||||
extern "C" DECLSPEC int
|
||||
SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel)
|
||||
{
|
||||
if (xamlBackgroundPanel) {
|
||||
return SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel);
|
||||
} else {
|
||||
return SDL_WinRTInitNonXAMLApp(mainFunction);
|
||||
}
|
||||
}
|
||||
SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel)
|
||||
{
|
||||
if (xamlBackgroundPanel) {
|
||||
return SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel);
|
||||
} else {
|
||||
return SDL_WinRTInitNonXAMLApp(mainFunction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
|
||||
#ifndef _SDL_winrtapp_common_h
|
||||
#define _SDL_winrtapp_common_h
|
||||
|
||||
/* A pointer to the app's C-style main() function (which is a different
|
||||
function than the WinRT app's actual entry point).
|
||||
*/
|
||||
extern int (*WINRT_SDLAppEntryPoint)(int, char **);
|
||||
|
||||
#endif // ifndef _SDL_winrtapp_common_h
|
||||
#define _SDL_winrtapp_common_h
|
||||
|
||||
/* A pointer to the app's C-style main() function (which is a different
|
||||
function than the WinRT app's actual entry point).
|
||||
*/
|
||||
extern int (*WINRT_SDLAppEntryPoint)(int, char **);
|
||||
|
||||
#endif // ifndef _SDL_winrtapp_common_h
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,58 +1,58 @@
|
|||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
extern int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **));
|
||||
|
||||
ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
|
||||
{
|
||||
public:
|
||||
SDL_WinRTApp();
|
||||
|
||||
// IFrameworkView Methods.
|
||||
virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
|
||||
virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
|
||||
virtual void Load(Platform::String^ entryPoint);
|
||||
virtual void Run();
|
||||
virtual void Uninitialize();
|
||||
|
||||
internal:
|
||||
// SDL-specific methods
|
||||
void PumpEvents();
|
||||
|
||||
protected:
|
||||
// Event Handlers.
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_APP // for Windows 8/8.1/RT apps... (and not Phone apps)
|
||||
void OnSettingsPaneCommandsRequested(
|
||||
Windows::UI::ApplicationSettings::SettingsPane ^p,
|
||||
Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args);
|
||||
#endif // if WINAPI_FAMILY == WINAPI_FAMILY_APP
|
||||
|
||||
void OnOrientationChanged(Platform::Object^ sender);
|
||||
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
|
||||
void OnLogicalDpiChanged(Platform::Object^ sender);
|
||||
void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
|
||||
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
|
||||
void OnResuming(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 OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ 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 OnPointerWheelChanged(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 OnKeyDown(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
|
||||
void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool m_windowClosed;
|
||||
bool m_windowVisible;
|
||||
};
|
||||
|
||||
extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
extern int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **));
|
||||
|
||||
ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
|
||||
{
|
||||
public:
|
||||
SDL_WinRTApp();
|
||||
|
||||
// IFrameworkView Methods.
|
||||
virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
|
||||
virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
|
||||
virtual void Load(Platform::String^ entryPoint);
|
||||
virtual void Run();
|
||||
virtual void Uninitialize();
|
||||
|
||||
internal:
|
||||
// SDL-specific methods
|
||||
void PumpEvents();
|
||||
|
||||
protected:
|
||||
// Event Handlers.
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_APP // for Windows 8/8.1/RT apps... (and not Phone apps)
|
||||
void OnSettingsPaneCommandsRequested(
|
||||
Windows::UI::ApplicationSettings::SettingsPane ^p,
|
||||
Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args);
|
||||
#endif // if WINAPI_FAMILY == WINAPI_FAMILY_APP
|
||||
|
||||
void OnOrientationChanged(Platform::Object^ sender);
|
||||
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
|
||||
void OnLogicalDpiChanged(Platform::Object^ sender);
|
||||
void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
|
||||
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
|
||||
void OnResuming(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 OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ 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 OnPointerWheelChanged(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 OnKeyDown(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
|
||||
void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool m_windowClosed;
|
||||
bool m_windowVisible;
|
||||
};
|
||||
|
||||
extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
|
||||
|
|
1530
src/file/SDL_rwops.c
1530
src/file/SDL_rwops.c
File diff suppressed because it is too large
Load Diff
|
@ -1,154 +1,154 @@
|
|||
/* 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
|
||||
*/
|
||||
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef __WINRT__
|
||||
|
||||
extern "C" {
|
||||
#include "SDL_filesystem.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_system.h"
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
}
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
using namespace Windows::Storage;
|
||||
|
||||
extern "C" const wchar_t *
|
||||
SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
|
||||
{
|
||||
switch (pathType) {
|
||||
case SDL_WINRT_PATH_INSTALLED_LOCATION:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
case SDL_WINRT_PATH_LOCAL_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->LocalFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
case SDL_WINRT_PATH_ROAMING_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->RoamingFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
case SDL_WINRT_PATH_TEMP_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->TemporaryFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C" const char *
|
||||
SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
|
||||
{
|
||||
typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
|
||||
static UTF8PathMap utf8Paths;
|
||||
|
||||
UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
|
||||
if (searchResult != utf8Paths.end()) {
|
||||
return searchResult->second.c_str();
|
||||
}
|
||||
|
||||
const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
|
||||
if (!ucs2Path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char * utf8Path = WIN_StringToUTF8(ucs2Path);
|
||||
utf8Paths[pathType] = utf8Path;
|
||||
SDL_free(utf8Path);
|
||||
return utf8Paths[pathType].c_str();
|
||||
}
|
||||
|
||||
extern "C" char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
|
||||
size_t destPathLen;
|
||||
char * destPath = NULL;
|
||||
|
||||
if (!srcPath) {
|
||||
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
destPathLen = SDL_strlen(srcPath) + 2;
|
||||
destPath = (char *) SDL_malloc(destPathLen);
|
||||
if (!destPath) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(destPath, destPathLen, "%s\\", srcPath);
|
||||
return destPath;
|
||||
}
|
||||
|
||||
extern "C" char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
/* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and
|
||||
* earlier is not available on WinRT or Windows Phone. WinRT provides
|
||||
* a similar API, but SHGetFolderPath can't be called, at least not
|
||||
* without violating Microsoft's app-store requirements.
|
||||
*/
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
/* 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);
|
||||
#else
|
||||
/* A 'Roaming' folder is available on Windows 8 and 8.1. Use that. */
|
||||
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER);
|
||||
#endif
|
||||
|
||||
size_t destPathLen;
|
||||
char * destPath = NULL;
|
||||
|
||||
if (!srcPath) {
|
||||
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
destPath = (char *) SDL_malloc(destPathLen);
|
||||
if (!destPath) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app);
|
||||
return destPath;
|
||||
}
|
||||
|
||||
#endif /* __WINRT__ */
|
||||
/* 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
|
||||
*/
|
||||
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef __WINRT__
|
||||
|
||||
extern "C" {
|
||||
#include "SDL_filesystem.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_system.h"
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
}
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
using namespace Windows::Storage;
|
||||
|
||||
extern "C" const wchar_t *
|
||||
SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
|
||||
{
|
||||
switch (pathType) {
|
||||
case SDL_WINRT_PATH_INSTALLED_LOCATION:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
case SDL_WINRT_PATH_LOCAL_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->LocalFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
case SDL_WINRT_PATH_ROAMING_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->RoamingFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
case SDL_WINRT_PATH_TEMP_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->TemporaryFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C" const char *
|
||||
SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
|
||||
{
|
||||
typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
|
||||
static UTF8PathMap utf8Paths;
|
||||
|
||||
UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
|
||||
if (searchResult != utf8Paths.end()) {
|
||||
return searchResult->second.c_str();
|
||||
}
|
||||
|
||||
const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
|
||||
if (!ucs2Path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char * utf8Path = WIN_StringToUTF8(ucs2Path);
|
||||
utf8Paths[pathType] = utf8Path;
|
||||
SDL_free(utf8Path);
|
||||
return utf8Paths[pathType].c_str();
|
||||
}
|
||||
|
||||
extern "C" char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
|
||||
size_t destPathLen;
|
||||
char * destPath = NULL;
|
||||
|
||||
if (!srcPath) {
|
||||
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
destPathLen = SDL_strlen(srcPath) + 2;
|
||||
destPath = (char *) SDL_malloc(destPathLen);
|
||||
if (!destPath) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(destPath, destPathLen, "%s\\", srcPath);
|
||||
return destPath;
|
||||
}
|
||||
|
||||
extern "C" char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
/* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and
|
||||
* earlier is not available on WinRT or Windows Phone. WinRT provides
|
||||
* a similar API, but SHGetFolderPath can't be called, at least not
|
||||
* without violating Microsoft's app-store requirements.
|
||||
*/
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
/* 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);
|
||||
#else
|
||||
/* A 'Roaming' folder is available on Windows 8 and 8.1. Use that. */
|
||||
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER);
|
||||
#endif
|
||||
|
||||
size_t destPathLen;
|
||||
char * destPath = NULL;
|
||||
|
||||
if (!srcPath) {
|
||||
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
destPath = (char *) SDL_malloc(destPathLen);
|
||||
if (!destPath) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app);
|
||||
return destPath;
|
||||
}
|
||||
|
||||
#endif /* __WINRT__ */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,56 +1,56 @@
|
|||
|
||||
#include <SDL_main.h>
|
||||
#include <wrl.h>
|
||||
|
||||
/* 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
|
||||
an APPX0702 build error can appear shortly after linking.
|
||||
|
||||
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
|
||||
create this .winmd file, and will help allow builds of SDL/WinRT apps
|
||||
to proceed without error.
|
||||
|
||||
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,
|
||||
for Visual C++'s build tools to create a winmd file, and for the app to
|
||||
build without APPX0702 errors. In this case, if
|
||||
SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then
|
||||
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,
|
||||
right click on the file in Visual C++, click Properties, then change the
|
||||
setting through the dialog that comes up.
|
||||
*/
|
||||
#ifndef SDL_WINRT_METADATA_FILE_AVAILABLE
|
||||
#ifndef __cplusplus_winrt
|
||||
#error SDL_winrt_main_NonXAML.cpp must be compiled with /ZW, otherwise build errors due to missing .winmd files can occur.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Prevent MSVC++ from warning about threading models when defining our
|
||||
custom WinMain. The threading model will instead be set via a direct
|
||||
call to Windows::Foundation::Initialize (rather than via an attributed
|
||||
function).
|
||||
|
||||
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).
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4447)
|
||||
#endif
|
||||
|
||||
/* Make sure the function to initialize the Windows Runtime gets linked in. */
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "runtimeobject.lib")
|
||||
#endif
|
||||
|
||||
int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||
{
|
||||
if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_WinRTRunApp(SDL_main, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <SDL_main.h>
|
||||
#include <wrl.h>
|
||||
|
||||
/* 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
|
||||
an APPX0702 build error can appear shortly after linking.
|
||||
|
||||
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
|
||||
create this .winmd file, and will help allow builds of SDL/WinRT apps
|
||||
to proceed without error.
|
||||
|
||||
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,
|
||||
for Visual C++'s build tools to create a winmd file, and for the app to
|
||||
build without APPX0702 errors. In this case, if
|
||||
SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then
|
||||
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,
|
||||
right click on the file in Visual C++, click Properties, then change the
|
||||
setting through the dialog that comes up.
|
||||
*/
|
||||
#ifndef SDL_WINRT_METADATA_FILE_AVAILABLE
|
||||
#ifndef __cplusplus_winrt
|
||||
#error SDL_winrt_main_NonXAML.cpp must be compiled with /ZW, otherwise build errors due to missing .winmd files can occur.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Prevent MSVC++ from warning about threading models when defining our
|
||||
custom WinMain. The threading model will instead be set via a direct
|
||||
call to Windows::Foundation::Initialize (rather than via an attributed
|
||||
function).
|
||||
|
||||
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).
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4447)
|
||||
#endif
|
||||
|
||||
/* Make sure the function to initialize the Windows Runtime gets linked in. */
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "runtimeobject.lib")
|
||||
#endif
|
||||
|
||||
int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||
{
|
||||
if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_WinRTRunApp(SDL_main, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -151,17 +151,17 @@ SDL_SYS_DetachThread(SDL_Thread * thread)
|
|||
}
|
||||
|
||||
extern "C"
|
||||
SDL_TLSData *
|
||||
SDL_SYS_GetTLSData()
|
||||
{
|
||||
return SDL_Generic_GetTLSData();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
int
|
||||
SDL_SYS_SetTLSData(SDL_TLSData *data)
|
||||
{
|
||||
return SDL_Generic_SetTLSData(data);
|
||||
SDL_TLSData *
|
||||
SDL_SYS_GetTLSData()
|
||||
{
|
||||
return SDL_Generic_GetTLSData();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
int
|
||||
SDL_SYS_SetTLSData(SDL_TLSData *data)
|
||||
{
|
||||
return SDL_Generic_SetTLSData(data);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -170,17 +170,17 @@ SDL_GetPerformanceFrequency(void)
|
|||
return frequency.QuadPart;
|
||||
}
|
||||
|
||||
#ifdef __WINRT__
|
||||
static void
|
||||
Sleep(DWORD timeout)
|
||||
{
|
||||
static HANDLE mutex = 0;
|
||||
if ( ! mutex )
|
||||
{
|
||||
mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
|
||||
}
|
||||
WaitForSingleObjectEx(mutex, timeout, FALSE);
|
||||
}
|
||||
#ifdef __WINRT__
|
||||
static void
|
||||
Sleep(DWORD timeout)
|
||||
{
|
||||
static HANDLE mutex = 0;
|
||||
if ( ! mutex )
|
||||
{
|
||||
mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
|
||||
}
|
||||
WaitForSingleObjectEx(mutex, timeout, FALSE);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
|
|
|
@ -1,401 +1,401 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_sysvideo_h
|
||||
#define _SDL_sysvideo_h
|
||||
|
||||
#include "SDL_messagebox.h"
|
||||
#include "SDL_shape.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
/* The SDL video driver */
|
||||
|
||||
typedef struct SDL_WindowShaper SDL_WindowShaper;
|
||||
typedef struct SDL_ShapeDriver SDL_ShapeDriver;
|
||||
typedef struct SDL_VideoDisplay SDL_VideoDisplay;
|
||||
typedef struct SDL_VideoDevice SDL_VideoDevice;
|
||||
|
||||
/* Define the SDL window-shaper structure */
|
||||
struct SDL_WindowShaper
|
||||
{
|
||||
/* The window associated with the shaper */
|
||||
SDL_Window *window;
|
||||
|
||||
/* The user's specified coordinates for the window, for once we give it a shape. */
|
||||
Uint32 userx,usery;
|
||||
|
||||
/* The parameters for shape calculation. */
|
||||
SDL_WindowShapeMode mode;
|
||||
|
||||
/* Has this window been assigned a shape? */
|
||||
SDL_bool hasshape;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Define the SDL shape driver structure */
|
||||
struct SDL_ShapeDriver
|
||||
{
|
||||
SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
|
||||
int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
|
||||
int (*ResizeWindowShape)(SDL_Window *window);
|
||||
};
|
||||
|
||||
typedef struct SDL_WindowUserData
|
||||
{
|
||||
char *name;
|
||||
void *data;
|
||||
struct SDL_WindowUserData *next;
|
||||
} SDL_WindowUserData;
|
||||
|
||||
/* Define the SDL window structure, corresponding to toplevel windows */
|
||||
struct SDL_Window
|
||||
{
|
||||
const void *magic;
|
||||
Uint32 id;
|
||||
char *title;
|
||||
SDL_Surface *icon;
|
||||
int x, y;
|
||||
int w, h;
|
||||
int min_w, min_h;
|
||||
int max_w, max_h;
|
||||
Uint32 flags;
|
||||
|
||||
/* Stored position and size for windowed mode */
|
||||
SDL_Rect windowed;
|
||||
|
||||
SDL_DisplayMode fullscreen_mode;
|
||||
|
||||
float brightness;
|
||||
Uint16 *gamma;
|
||||
Uint16 *saved_gamma; /* (just offset into gamma) */
|
||||
|
||||
SDL_Surface *surface;
|
||||
SDL_bool surface_valid;
|
||||
|
||||
SDL_WindowShaper *shaper;
|
||||
|
||||
SDL_WindowUserData *data;
|
||||
|
||||
void *driverdata;
|
||||
|
||||
SDL_Window *prev;
|
||||
SDL_Window *next;
|
||||
};
|
||||
#define FULLSCREEN_VISIBLE(W) \
|
||||
(((W)->flags & SDL_WINDOW_FULLSCREEN) && \
|
||||
((W)->flags & SDL_WINDOW_SHOWN) && \
|
||||
!((W)->flags & SDL_WINDOW_MINIMIZED))
|
||||
|
||||
/*
|
||||
* Define the SDL display structure This corresponds to physical monitors
|
||||
* attached to the system.
|
||||
*/
|
||||
struct SDL_VideoDisplay
|
||||
{
|
||||
char *name;
|
||||
int max_display_modes;
|
||||
int num_display_modes;
|
||||
SDL_DisplayMode *display_modes;
|
||||
SDL_DisplayMode desktop_mode;
|
||||
SDL_DisplayMode current_mode;
|
||||
|
||||
SDL_Window *fullscreen_window;
|
||||
|
||||
SDL_VideoDevice *device;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Forward declaration */
|
||||
struct SDL_SysWMinfo;
|
||||
|
||||
/* Define the SDL video driver structure */
|
||||
#define _THIS SDL_VideoDevice *_this
|
||||
|
||||
struct SDL_VideoDevice
|
||||
{
|
||||
/* * * */
|
||||
/* The name of this video driver */
|
||||
const char *name;
|
||||
|
||||
/* * * */
|
||||
/* Initialization/Query functions */
|
||||
|
||||
/*
|
||||
* Initialize the native video subsystem, filling in the list of
|
||||
* displays for this driver, returning 0 or -1 if there's an error.
|
||||
*/
|
||||
int (*VideoInit) (_THIS);
|
||||
|
||||
/*
|
||||
* Reverse the effects VideoInit() -- called if VideoInit() fails or
|
||||
* if the application is shutting down the video subsystem.
|
||||
*/
|
||||
void (*VideoQuit) (_THIS);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Display functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get the bounds of a display
|
||||
*/
|
||||
int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
|
||||
|
||||
/*
|
||||
* Get a list of the available display modes for a display.
|
||||
*/
|
||||
void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
|
||||
|
||||
/*
|
||||
* Setting the display mode is independent of creating windows, so
|
||||
* when the display mode is changed, all existing windows should have
|
||||
* their data updated accordingly, including the display surfaces
|
||||
* associated with them.
|
||||
*/
|
||||
int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Window functions
|
||||
*/
|
||||
int (*CreateWindow) (_THIS, SDL_Window * window);
|
||||
int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
|
||||
void (*SetWindowTitle) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
|
||||
void (*SetWindowPosition) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowSize) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
|
||||
void (*ShowWindow) (_THIS, SDL_Window * window);
|
||||
void (*HideWindow) (_THIS, SDL_Window * window);
|
||||
void (*RaiseWindow) (_THIS, SDL_Window * window);
|
||||
void (*MaximizeWindow) (_THIS, SDL_Window * window);
|
||||
void (*MinimizeWindow) (_THIS, SDL_Window * window);
|
||||
void (*RestoreWindow) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
|
||||
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
|
||||
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
|
||||
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
|
||||
void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
|
||||
void (*DestroyWindow) (_THIS, SDL_Window * window);
|
||||
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
|
||||
int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
|
||||
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
|
||||
void (*OnWindowEnter) (_THIS, SDL_Window * window);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Shaped-window functions
|
||||
*/
|
||||
SDL_ShapeDriver shape_driver;
|
||||
|
||||
/* Get some platform dependent window information */
|
||||
SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
|
||||
struct SDL_SysWMinfo * info);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* OpenGL support
|
||||
*/
|
||||
int (*GL_LoadLibrary) (_THIS, const char *path);
|
||||
void *(*GL_GetProcAddress) (_THIS, const char *proc);
|
||||
void (*GL_UnloadLibrary) (_THIS);
|
||||
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
|
||||
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
|
||||
int (*GL_SetSwapInterval) (_THIS, int interval);
|
||||
int (*GL_GetSwapInterval) (_THIS);
|
||||
void (*GL_SwapWindow) (_THIS, SDL_Window * window);
|
||||
void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Event manager functions
|
||||
*/
|
||||
void (*PumpEvents) (_THIS);
|
||||
|
||||
/* Suspend the screensaver */
|
||||
void (*SuspendScreenSaver) (_THIS);
|
||||
|
||||
/* Text input */
|
||||
void (*StartTextInput) (_THIS);
|
||||
void (*StopTextInput) (_THIS);
|
||||
void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
|
||||
|
||||
/* Screen keyboard */
|
||||
SDL_bool (*HasScreenKeyboardSupport) (_THIS);
|
||||
void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
|
||||
void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
|
||||
SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
|
||||
|
||||
/* Clipboard */
|
||||
int (*SetClipboardText) (_THIS, const char *text);
|
||||
char * (*GetClipboardText) (_THIS);
|
||||
SDL_bool (*HasClipboardText) (_THIS);
|
||||
|
||||
/* MessageBox */
|
||||
int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
|
||||
|
||||
/* * * */
|
||||
/* Data common to all drivers */
|
||||
SDL_bool suspend_screensaver;
|
||||
int num_displays;
|
||||
SDL_VideoDisplay *displays;
|
||||
SDL_Window *windows;
|
||||
Uint8 window_magic;
|
||||
Uint32 next_object_id;
|
||||
char * clipboard_text;
|
||||
|
||||
/* * * */
|
||||
/* Data used by the GL drivers */
|
||||
struct
|
||||
{
|
||||
int red_size;
|
||||
int green_size;
|
||||
int blue_size;
|
||||
int alpha_size;
|
||||
int depth_size;
|
||||
int buffer_size;
|
||||
int stencil_size;
|
||||
int double_buffer;
|
||||
int accum_red_size;
|
||||
int accum_green_size;
|
||||
int accum_blue_size;
|
||||
int accum_alpha_size;
|
||||
int stereo;
|
||||
int multisamplebuffers;
|
||||
int multisamplesamples;
|
||||
int accelerated;
|
||||
int major_version;
|
||||
int minor_version;
|
||||
int flags;
|
||||
int profile_mask;
|
||||
int share_with_current_context;
|
||||
int framebuffer_srgb_capable;
|
||||
int retained_backing;
|
||||
int driver_loaded;
|
||||
char driver_path[256];
|
||||
void *dll_handle;
|
||||
} gl_config;
|
||||
|
||||
/* * * */
|
||||
/* 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
|
||||
it always has, and the thread-local storage for the general case.
|
||||
*/
|
||||
SDL_Window *current_glwin;
|
||||
SDL_GLContext current_glctx;
|
||||
SDL_TLSID current_glwin_tls;
|
||||
SDL_TLSID current_glctx_tls;
|
||||
|
||||
/* * * */
|
||||
/* Data private to this driver */
|
||||
void *driverdata;
|
||||
struct SDL_GLDriverData *gl_data;
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
struct SDL_EGL_VideoData *egl_data;
|
||||
#endif
|
||||
|
||||
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
||||
struct SDL_PrivateGLESData *gles_data;
|
||||
#endif
|
||||
|
||||
/* * * */
|
||||
/* The function used to dispose of this structure */
|
||||
void (*free) (_THIS);
|
||||
};
|
||||
|
||||
typedef struct VideoBootStrap
|
||||
{
|
||||
const char *name;
|
||||
const char *desc;
|
||||
int (*available) (void);
|
||||
SDL_VideoDevice *(*create) (int devindex);
|
||||
} VideoBootStrap;
|
||||
|
||||
#if SDL_VIDEO_DRIVER_COCOA
|
||||
extern VideoBootStrap COCOA_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_X11
|
||||
extern VideoBootStrap X11_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DIRECTFB
|
||||
extern VideoBootStrap DirectFB_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
extern VideoBootStrap WINDOWS_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
extern VideoBootStrap WINRT_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
extern VideoBootStrap HAIKU_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_PANDORA
|
||||
extern VideoBootStrap PND_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
extern VideoBootStrap UIKIT_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
extern VideoBootStrap Android_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_PSP
|
||||
extern VideoBootStrap PSP_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_RPI
|
||||
extern VideoBootStrap RPI_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DUMMY
|
||||
extern VideoBootStrap DUMMY_bootstrap;
|
||||
#endif
|
||||
|
||||
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
|
||||
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
|
||||
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
|
||||
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
|
||||
extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
|
||||
extern void *SDL_GetDisplayDriverData( int displayIndex );
|
||||
|
||||
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
|
||||
|
||||
extern void SDL_OnWindowShown(SDL_Window * window);
|
||||
extern void SDL_OnWindowHidden(SDL_Window * window);
|
||||
extern void SDL_OnWindowResized(SDL_Window * window);
|
||||
extern void SDL_OnWindowMinimized(SDL_Window * window);
|
||||
extern void SDL_OnWindowRestored(SDL_Window * window);
|
||||
extern void SDL_OnWindowEnter(SDL_Window * window);
|
||||
extern void SDL_OnWindowLeave(SDL_Window * window);
|
||||
extern void SDL_OnWindowFocusGained(SDL_Window * window);
|
||||
extern void SDL_OnWindowFocusLost(SDL_Window * window);
|
||||
extern void SDL_UpdateWindowGrab(SDL_Window * window);
|
||||
extern SDL_Window * SDL_GetFocusWindow(void);
|
||||
|
||||
extern SDL_bool SDL_ShouldAllowTopmost(void);
|
||||
|
||||
#endif /* _SDL_sysvideo_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_sysvideo_h
|
||||
#define _SDL_sysvideo_h
|
||||
|
||||
#include "SDL_messagebox.h"
|
||||
#include "SDL_shape.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
/* The SDL video driver */
|
||||
|
||||
typedef struct SDL_WindowShaper SDL_WindowShaper;
|
||||
typedef struct SDL_ShapeDriver SDL_ShapeDriver;
|
||||
typedef struct SDL_VideoDisplay SDL_VideoDisplay;
|
||||
typedef struct SDL_VideoDevice SDL_VideoDevice;
|
||||
|
||||
/* Define the SDL window-shaper structure */
|
||||
struct SDL_WindowShaper
|
||||
{
|
||||
/* The window associated with the shaper */
|
||||
SDL_Window *window;
|
||||
|
||||
/* The user's specified coordinates for the window, for once we give it a shape. */
|
||||
Uint32 userx,usery;
|
||||
|
||||
/* The parameters for shape calculation. */
|
||||
SDL_WindowShapeMode mode;
|
||||
|
||||
/* Has this window been assigned a shape? */
|
||||
SDL_bool hasshape;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Define the SDL shape driver structure */
|
||||
struct SDL_ShapeDriver
|
||||
{
|
||||
SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
|
||||
int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
|
||||
int (*ResizeWindowShape)(SDL_Window *window);
|
||||
};
|
||||
|
||||
typedef struct SDL_WindowUserData
|
||||
{
|
||||
char *name;
|
||||
void *data;
|
||||
struct SDL_WindowUserData *next;
|
||||
} SDL_WindowUserData;
|
||||
|
||||
/* Define the SDL window structure, corresponding to toplevel windows */
|
||||
struct SDL_Window
|
||||
{
|
||||
const void *magic;
|
||||
Uint32 id;
|
||||
char *title;
|
||||
SDL_Surface *icon;
|
||||
int x, y;
|
||||
int w, h;
|
||||
int min_w, min_h;
|
||||
int max_w, max_h;
|
||||
Uint32 flags;
|
||||
|
||||
/* Stored position and size for windowed mode */
|
||||
SDL_Rect windowed;
|
||||
|
||||
SDL_DisplayMode fullscreen_mode;
|
||||
|
||||
float brightness;
|
||||
Uint16 *gamma;
|
||||
Uint16 *saved_gamma; /* (just offset into gamma) */
|
||||
|
||||
SDL_Surface *surface;
|
||||
SDL_bool surface_valid;
|
||||
|
||||
SDL_WindowShaper *shaper;
|
||||
|
||||
SDL_WindowUserData *data;
|
||||
|
||||
void *driverdata;
|
||||
|
||||
SDL_Window *prev;
|
||||
SDL_Window *next;
|
||||
};
|
||||
#define FULLSCREEN_VISIBLE(W) \
|
||||
(((W)->flags & SDL_WINDOW_FULLSCREEN) && \
|
||||
((W)->flags & SDL_WINDOW_SHOWN) && \
|
||||
!((W)->flags & SDL_WINDOW_MINIMIZED))
|
||||
|
||||
/*
|
||||
* Define the SDL display structure This corresponds to physical monitors
|
||||
* attached to the system.
|
||||
*/
|
||||
struct SDL_VideoDisplay
|
||||
{
|
||||
char *name;
|
||||
int max_display_modes;
|
||||
int num_display_modes;
|
||||
SDL_DisplayMode *display_modes;
|
||||
SDL_DisplayMode desktop_mode;
|
||||
SDL_DisplayMode current_mode;
|
||||
|
||||
SDL_Window *fullscreen_window;
|
||||
|
||||
SDL_VideoDevice *device;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Forward declaration */
|
||||
struct SDL_SysWMinfo;
|
||||
|
||||
/* Define the SDL video driver structure */
|
||||
#define _THIS SDL_VideoDevice *_this
|
||||
|
||||
struct SDL_VideoDevice
|
||||
{
|
||||
/* * * */
|
||||
/* The name of this video driver */
|
||||
const char *name;
|
||||
|
||||
/* * * */
|
||||
/* Initialization/Query functions */
|
||||
|
||||
/*
|
||||
* Initialize the native video subsystem, filling in the list of
|
||||
* displays for this driver, returning 0 or -1 if there's an error.
|
||||
*/
|
||||
int (*VideoInit) (_THIS);
|
||||
|
||||
/*
|
||||
* Reverse the effects VideoInit() -- called if VideoInit() fails or
|
||||
* if the application is shutting down the video subsystem.
|
||||
*/
|
||||
void (*VideoQuit) (_THIS);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Display functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get the bounds of a display
|
||||
*/
|
||||
int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
|
||||
|
||||
/*
|
||||
* Get a list of the available display modes for a display.
|
||||
*/
|
||||
void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
|
||||
|
||||
/*
|
||||
* Setting the display mode is independent of creating windows, so
|
||||
* when the display mode is changed, all existing windows should have
|
||||
* their data updated accordingly, including the display surfaces
|
||||
* associated with them.
|
||||
*/
|
||||
int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Window functions
|
||||
*/
|
||||
int (*CreateWindow) (_THIS, SDL_Window * window);
|
||||
int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
|
||||
void (*SetWindowTitle) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
|
||||
void (*SetWindowPosition) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowSize) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
|
||||
void (*ShowWindow) (_THIS, SDL_Window * window);
|
||||
void (*HideWindow) (_THIS, SDL_Window * window);
|
||||
void (*RaiseWindow) (_THIS, SDL_Window * window);
|
||||
void (*MaximizeWindow) (_THIS, SDL_Window * window);
|
||||
void (*MinimizeWindow) (_THIS, SDL_Window * window);
|
||||
void (*RestoreWindow) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
|
||||
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
|
||||
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
|
||||
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
|
||||
void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
|
||||
void (*DestroyWindow) (_THIS, SDL_Window * window);
|
||||
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
|
||||
int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
|
||||
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
|
||||
void (*OnWindowEnter) (_THIS, SDL_Window * window);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Shaped-window functions
|
||||
*/
|
||||
SDL_ShapeDriver shape_driver;
|
||||
|
||||
/* Get some platform dependent window information */
|
||||
SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
|
||||
struct SDL_SysWMinfo * info);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* OpenGL support
|
||||
*/
|
||||
int (*GL_LoadLibrary) (_THIS, const char *path);
|
||||
void *(*GL_GetProcAddress) (_THIS, const char *proc);
|
||||
void (*GL_UnloadLibrary) (_THIS);
|
||||
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
|
||||
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
|
||||
int (*GL_SetSwapInterval) (_THIS, int interval);
|
||||
int (*GL_GetSwapInterval) (_THIS);
|
||||
void (*GL_SwapWindow) (_THIS, SDL_Window * window);
|
||||
void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Event manager functions
|
||||
*/
|
||||
void (*PumpEvents) (_THIS);
|
||||
|
||||
/* Suspend the screensaver */
|
||||
void (*SuspendScreenSaver) (_THIS);
|
||||
|
||||
/* Text input */
|
||||
void (*StartTextInput) (_THIS);
|
||||
void (*StopTextInput) (_THIS);
|
||||
void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
|
||||
|
||||
/* Screen keyboard */
|
||||
SDL_bool (*HasScreenKeyboardSupport) (_THIS);
|
||||
void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
|
||||
void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
|
||||
SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
|
||||
|
||||
/* Clipboard */
|
||||
int (*SetClipboardText) (_THIS, const char *text);
|
||||
char * (*GetClipboardText) (_THIS);
|
||||
SDL_bool (*HasClipboardText) (_THIS);
|
||||
|
||||
/* MessageBox */
|
||||
int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
|
||||
|
||||
/* * * */
|
||||
/* Data common to all drivers */
|
||||
SDL_bool suspend_screensaver;
|
||||
int num_displays;
|
||||
SDL_VideoDisplay *displays;
|
||||
SDL_Window *windows;
|
||||
Uint8 window_magic;
|
||||
Uint32 next_object_id;
|
||||
char * clipboard_text;
|
||||
|
||||
/* * * */
|
||||
/* Data used by the GL drivers */
|
||||
struct
|
||||
{
|
||||
int red_size;
|
||||
int green_size;
|
||||
int blue_size;
|
||||
int alpha_size;
|
||||
int depth_size;
|
||||
int buffer_size;
|
||||
int stencil_size;
|
||||
int double_buffer;
|
||||
int accum_red_size;
|
||||
int accum_green_size;
|
||||
int accum_blue_size;
|
||||
int accum_alpha_size;
|
||||
int stereo;
|
||||
int multisamplebuffers;
|
||||
int multisamplesamples;
|
||||
int accelerated;
|
||||
int major_version;
|
||||
int minor_version;
|
||||
int flags;
|
||||
int profile_mask;
|
||||
int share_with_current_context;
|
||||
int framebuffer_srgb_capable;
|
||||
int retained_backing;
|
||||
int driver_loaded;
|
||||
char driver_path[256];
|
||||
void *dll_handle;
|
||||
} gl_config;
|
||||
|
||||
/* * * */
|
||||
/* 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
|
||||
it always has, and the thread-local storage for the general case.
|
||||
*/
|
||||
SDL_Window *current_glwin;
|
||||
SDL_GLContext current_glctx;
|
||||
SDL_TLSID current_glwin_tls;
|
||||
SDL_TLSID current_glctx_tls;
|
||||
|
||||
/* * * */
|
||||
/* Data private to this driver */
|
||||
void *driverdata;
|
||||
struct SDL_GLDriverData *gl_data;
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
struct SDL_EGL_VideoData *egl_data;
|
||||
#endif
|
||||
|
||||
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
||||
struct SDL_PrivateGLESData *gles_data;
|
||||
#endif
|
||||
|
||||
/* * * */
|
||||
/* The function used to dispose of this structure */
|
||||
void (*free) (_THIS);
|
||||
};
|
||||
|
||||
typedef struct VideoBootStrap
|
||||
{
|
||||
const char *name;
|
||||
const char *desc;
|
||||
int (*available) (void);
|
||||
SDL_VideoDevice *(*create) (int devindex);
|
||||
} VideoBootStrap;
|
||||
|
||||
#if SDL_VIDEO_DRIVER_COCOA
|
||||
extern VideoBootStrap COCOA_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_X11
|
||||
extern VideoBootStrap X11_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DIRECTFB
|
||||
extern VideoBootStrap DirectFB_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
extern VideoBootStrap WINDOWS_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
extern VideoBootStrap WINRT_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
extern VideoBootStrap HAIKU_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_PANDORA
|
||||
extern VideoBootStrap PND_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
extern VideoBootStrap UIKIT_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
extern VideoBootStrap Android_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_PSP
|
||||
extern VideoBootStrap PSP_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_RPI
|
||||
extern VideoBootStrap RPI_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DUMMY
|
||||
extern VideoBootStrap DUMMY_bootstrap;
|
||||
#endif
|
||||
|
||||
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
|
||||
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
|
||||
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
|
||||
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
|
||||
extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
|
||||
extern void *SDL_GetDisplayDriverData( int displayIndex );
|
||||
|
||||
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
|
||||
|
||||
extern void SDL_OnWindowShown(SDL_Window * window);
|
||||
extern void SDL_OnWindowHidden(SDL_Window * window);
|
||||
extern void SDL_OnWindowResized(SDL_Window * window);
|
||||
extern void SDL_OnWindowMinimized(SDL_Window * window);
|
||||
extern void SDL_OnWindowRestored(SDL_Window * window);
|
||||
extern void SDL_OnWindowEnter(SDL_Window * window);
|
||||
extern void SDL_OnWindowLeave(SDL_Window * window);
|
||||
extern void SDL_OnWindowFocusGained(SDL_Window * window);
|
||||
extern void SDL_OnWindowFocusLost(SDL_Window * window);
|
||||
extern void SDL_UpdateWindowGrab(SDL_Window * window);
|
||||
extern SDL_Window * SDL_GetFocusWindow(void);
|
||||
|
||||
extern SDL_bool SDL_ShouldAllowTopmost(void);
|
||||
|
||||
#endif /* _SDL_sysvideo_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -22,15 +22,15 @@
|
|||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/*
|
||||
* Windows includes:
|
||||
*/
|
||||
#include <Windows.h>
|
||||
using namespace Windows::UI::Core;
|
||||
using Windows::UI::Core::CoreCursor;
|
||||
|
||||
/*
|
||||
* SDL includes:
|
||||
/*
|
||||
* Windows includes:
|
||||
*/
|
||||
#include <Windows.h>
|
||||
using namespace Windows::UI::Core;
|
||||
using Windows::UI::Core::CoreCursor;
|
||||
|
||||
/*
|
||||
* SDL includes:
|
||||
*/
|
||||
#include "SDL_winrtevents_c.h"
|
||||
#include "../../core/winrt/SDL_winrtapp_common.h"
|
||||
|
@ -63,89 +63,89 @@ WINRT_PumpEvents(_THIS)
|
|||
|
||||
|
||||
/* XAML Thread management */
|
||||
|
||||
enum SDL_XAMLAppThreadState
|
||||
{
|
||||
ThreadState_NotLaunched = 0,
|
||||
ThreadState_Running,
|
||||
ThreadState_Yielding
|
||||
|
||||
enum SDL_XAMLAppThreadState
|
||||
{
|
||||
ThreadState_NotLaunched = 0,
|
||||
ThreadState_Running,
|
||||
ThreadState_Yielding
|
||||
};
|
||||
|
||||
static SDL_XAMLAppThreadState _threadState = ThreadState_NotLaunched;
|
||||
static SDL_Thread * _XAMLThread = nullptr;
|
||||
static SDL_mutex * _mutex = nullptr;
|
||||
static SDL_cond * _cond = nullptr;
|
||||
|
||||
static void
|
||||
WINRT_YieldXAMLThread()
|
||||
{
|
||||
SDL_LockMutex(_mutex);
|
||||
SDL_assert(_threadState == ThreadState_Running);
|
||||
_threadState = ThreadState_Yielding;
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
SDL_CondSignal(_cond);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Running) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_XAMLThreadMain(void * userdata)
|
||||
{
|
||||
// TODO, WinRT: pass the C-style main() a reasonably realistic
|
||||
// representation of command line arguments.
|
||||
int argc = 0;
|
||||
char **argv = NULL;
|
||||
return WINRT_SDLAppEntryPoint(argc, argv);
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_CycleXAMLThread()
|
||||
{
|
||||
switch (_threadState) {
|
||||
case ThreadState_NotLaunched:
|
||||
{
|
||||
_cond = SDL_CreateCond();
|
||||
|
||||
_mutex = SDL_CreateMutex();
|
||||
_threadState = ThreadState_Running;
|
||||
_XAMLThread = SDL_CreateThread(WINRT_XAMLThreadMain, "SDL/XAML App Thread", nullptr);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Yielding) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ThreadState_Running:
|
||||
{
|
||||
SDL_assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
case ThreadState_Yielding:
|
||||
{
|
||||
SDL_LockMutex(_mutex);
|
||||
SDL_assert(_threadState == ThreadState_Yielding);
|
||||
_threadState = ThreadState_Running;
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
SDL_CondSignal(_cond);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Yielding) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
}
|
||||
}
|
||||
static SDL_XAMLAppThreadState _threadState = ThreadState_NotLaunched;
|
||||
static SDL_Thread * _XAMLThread = nullptr;
|
||||
static SDL_mutex * _mutex = nullptr;
|
||||
static SDL_cond * _cond = nullptr;
|
||||
|
||||
static void
|
||||
WINRT_YieldXAMLThread()
|
||||
{
|
||||
SDL_LockMutex(_mutex);
|
||||
SDL_assert(_threadState == ThreadState_Running);
|
||||
_threadState = ThreadState_Yielding;
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
SDL_CondSignal(_cond);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Running) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_XAMLThreadMain(void * userdata)
|
||||
{
|
||||
// TODO, WinRT: pass the C-style main() a reasonably realistic
|
||||
// representation of command line arguments.
|
||||
int argc = 0;
|
||||
char **argv = NULL;
|
||||
return WINRT_SDLAppEntryPoint(argc, argv);
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_CycleXAMLThread()
|
||||
{
|
||||
switch (_threadState) {
|
||||
case ThreadState_NotLaunched:
|
||||
{
|
||||
_cond = SDL_CreateCond();
|
||||
|
||||
_mutex = SDL_CreateMutex();
|
||||
_threadState = ThreadState_Running;
|
||||
_XAMLThread = SDL_CreateThread(WINRT_XAMLThreadMain, "SDL/XAML App Thread", nullptr);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Yielding) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ThreadState_Running:
|
||||
{
|
||||
SDL_assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
case ThreadState_Yielding:
|
||||
{
|
||||
SDL_LockMutex(_mutex);
|
||||
SDL_assert(_threadState == ThreadState_Yielding);
|
||||
_threadState = ThreadState_Running;
|
||||
SDL_UnlockMutex(_mutex);
|
||||
|
||||
SDL_CondSignal(_cond);
|
||||
|
||||
SDL_LockMutex(_mutex);
|
||||
while (_threadState != ThreadState_Yielding) {
|
||||
SDL_CondWait(_cond, _mutex);
|
||||
}
|
||||
SDL_UnlockMutex(_mutex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT */
|
||||
|
|
|
@ -46,9 +46,9 @@ extern void WINRT_PumpEvents(_THIS);
|
|||
#ifdef __cplusplus_winrt
|
||||
|
||||
/* Pointers (Mice, Touch, etc.) */
|
||||
typedef enum {
|
||||
NormalizeZeroToOne,
|
||||
TransformToSDLWindowSize
|
||||
typedef enum {
|
||||
NormalizeZeroToOne,
|
||||
TransformToSDLWindowSize
|
||||
} WINRT_CursorNormalizationType;
|
||||
extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window,
|
||||
Windows::Foundation::Point rawPosition,
|
||||
|
|
|
@ -1,301 +1,301 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/* Standard C++11 includes */
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
/* Windows-specific includes */
|
||||
#include <Windows.h>
|
||||
#include <agile.h>
|
||||
|
||||
|
||||
/* SDL-specific includes */
|
||||
#include <SDL.h>
|
||||
#include "SDL_winrtevents_c.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../../events/scancodes_windows.h"
|
||||
#include "../../events/SDL_keyboard_c.h"
|
||||
}
|
||||
|
||||
|
||||
static SDL_Scancode WinRT_Official_Keycodes[] = {
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
|
||||
SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
|
||||
SDL_SCANCODE_UNKNOWN, // -- 7
|
||||
SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
|
||||
SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
|
||||
SDL_SCANCODE_UNKNOWN, // -- 10
|
||||
SDL_SCANCODE_UNKNOWN, // -- 11
|
||||
SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
|
||||
SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
|
||||
SDL_SCANCODE_UNKNOWN, // -- 14
|
||||
SDL_SCANCODE_UNKNOWN, // -- 15
|
||||
SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
|
||||
SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
|
||||
SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
|
||||
SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
|
||||
SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
|
||||
SDL_SCANCODE_UNKNOWN, // -- 22
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
|
||||
SDL_SCANCODE_UNKNOWN, // -- 26
|
||||
SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31 (maybe SDL_SCANCODE_MODE ?)
|
||||
SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
|
||||
SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
|
||||
SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
|
||||
SDL_SCANCODE_END, // VirtualKey.End -- 35
|
||||
SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
|
||||
SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
|
||||
SDL_SCANCODE_UP, // VirtualKey.Up -- 38
|
||||
SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
|
||||
SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
|
||||
SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42 (maybe SDL_SCANCODE_PRINTSCREEN ?)
|
||||
SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
|
||||
SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
|
||||
SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
|
||||
SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
|
||||
SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
|
||||
SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
|
||||
SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
|
||||
SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
|
||||
SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
|
||||
SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
|
||||
SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
|
||||
SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
|
||||
SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
|
||||
SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
|
||||
SDL_SCANCODE_UNKNOWN, // -- 58
|
||||
SDL_SCANCODE_UNKNOWN, // -- 59
|
||||
SDL_SCANCODE_UNKNOWN, // -- 60
|
||||
SDL_SCANCODE_UNKNOWN, // -- 61
|
||||
SDL_SCANCODE_UNKNOWN, // -- 62
|
||||
SDL_SCANCODE_UNKNOWN, // -- 63
|
||||
SDL_SCANCODE_UNKNOWN, // -- 64
|
||||
SDL_SCANCODE_A, // VirtualKey.A -- 65
|
||||
SDL_SCANCODE_B, // VirtualKey.B -- 66
|
||||
SDL_SCANCODE_C, // VirtualKey.C -- 67
|
||||
SDL_SCANCODE_D, // VirtualKey.D -- 68
|
||||
SDL_SCANCODE_E, // VirtualKey.E -- 69
|
||||
SDL_SCANCODE_F, // VirtualKey.F -- 70
|
||||
SDL_SCANCODE_G, // VirtualKey.G -- 71
|
||||
SDL_SCANCODE_H, // VirtualKey.H -- 72
|
||||
SDL_SCANCODE_I, // VirtualKey.I -- 73
|
||||
SDL_SCANCODE_J, // VirtualKey.J -- 74
|
||||
SDL_SCANCODE_K, // VirtualKey.K -- 75
|
||||
SDL_SCANCODE_L, // VirtualKey.L -- 76
|
||||
SDL_SCANCODE_M, // VirtualKey.M -- 77
|
||||
SDL_SCANCODE_N, // VirtualKey.N -- 78
|
||||
SDL_SCANCODE_O, // VirtualKey.O -- 79
|
||||
SDL_SCANCODE_P, // VirtualKey.P -- 80
|
||||
SDL_SCANCODE_Q, // VirtualKey.Q -- 81
|
||||
SDL_SCANCODE_R, // VirtualKey.R -- 82
|
||||
SDL_SCANCODE_S, // VirtualKey.S -- 83
|
||||
SDL_SCANCODE_T, // VirtualKey.T -- 84
|
||||
SDL_SCANCODE_U, // VirtualKey.U -- 85
|
||||
SDL_SCANCODE_V, // VirtualKey.V -- 86
|
||||
SDL_SCANCODE_W, // VirtualKey.W -- 87
|
||||
SDL_SCANCODE_X, // VirtualKey.X -- 88
|
||||
SDL_SCANCODE_Y, // VirtualKey.Y -- 89
|
||||
SDL_SCANCODE_Z, // VirtualKey.Z -- 90
|
||||
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_APPLICATION, // VirtualKey.Application -- 93
|
||||
SDL_SCANCODE_UNKNOWN, // -- 94
|
||||
SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
|
||||
SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
|
||||
SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
|
||||
SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
|
||||
SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
|
||||
SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
|
||||
SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
|
||||
SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
|
||||
SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
|
||||
SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
|
||||
SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
|
||||
SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
|
||||
SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
|
||||
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_KP_DIVIDE, // VirtualKey.Divide -- 111
|
||||
SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
|
||||
SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
|
||||
SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
|
||||
SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
|
||||
SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
|
||||
SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
|
||||
SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
|
||||
SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
|
||||
SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
|
||||
SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
|
||||
SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
|
||||
SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
|
||||
SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
|
||||
SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
|
||||
SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
|
||||
SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
|
||||
SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
|
||||
SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
|
||||
SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
|
||||
SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
|
||||
SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
|
||||
SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
|
||||
SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
|
||||
SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
|
||||
SDL_SCANCODE_UNKNOWN, // -- 136
|
||||
SDL_SCANCODE_UNKNOWN, // -- 137
|
||||
SDL_SCANCODE_UNKNOWN, // -- 138
|
||||
SDL_SCANCODE_UNKNOWN, // -- 139
|
||||
SDL_SCANCODE_UNKNOWN, // -- 140
|
||||
SDL_SCANCODE_UNKNOWN, // -- 141
|
||||
SDL_SCANCODE_UNKNOWN, // -- 142
|
||||
SDL_SCANCODE_UNKNOWN, // -- 143
|
||||
SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
|
||||
SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
|
||||
SDL_SCANCODE_UNKNOWN, // -- 146
|
||||
SDL_SCANCODE_UNKNOWN, // -- 147
|
||||
SDL_SCANCODE_UNKNOWN, // -- 148
|
||||
SDL_SCANCODE_UNKNOWN, // -- 149
|
||||
SDL_SCANCODE_UNKNOWN, // -- 150
|
||||
SDL_SCANCODE_UNKNOWN, // -- 151
|
||||
SDL_SCANCODE_UNKNOWN, // -- 152
|
||||
SDL_SCANCODE_UNKNOWN, // -- 153
|
||||
SDL_SCANCODE_UNKNOWN, // -- 154
|
||||
SDL_SCANCODE_UNKNOWN, // -- 155
|
||||
SDL_SCANCODE_UNKNOWN, // -- 156
|
||||
SDL_SCANCODE_UNKNOWN, // -- 157
|
||||
SDL_SCANCODE_UNKNOWN, // -- 158
|
||||
SDL_SCANCODE_UNKNOWN, // -- 159
|
||||
SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
|
||||
SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
|
||||
SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
|
||||
SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
|
||||
SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
|
||||
SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
|
||||
};
|
||||
|
||||
static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
|
||||
|
||||
static SDL_Scancode
|
||||
TranslateKeycode(int keycode)
|
||||
{
|
||||
if (WinRT_Unofficial_Keycodes.empty()) {
|
||||
/* Set up a table of undocumented (by Microsoft), WinRT-specific,
|
||||
key codes: */
|
||||
// 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[222] = SDL_SCANCODE_BACKSLASH;
|
||||
}
|
||||
|
||||
/* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
|
||||
http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
|
||||
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
|
||||
//SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
|
||||
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
|
||||
if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
|
||||
scancode = WinRT_Official_Keycodes[keycode];
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
|
||||
scancode = WinRT_Unofficial_Keycodes[keycode];
|
||||
}
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
if (keycode < SDL_arraysize(windows_scancode_table)) {
|
||||
scancode = windows_scancode_table[keycode];
|
||||
}
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
|
||||
}
|
||||
return scancode;
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
|
||||
{
|
||||
SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
|
||||
#if 0
|
||||
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",
|
||||
(args->Handled ? "1" : "0"),
|
||||
(args->KeyStatus.IsExtendedKey ? "1" : "0"),
|
||||
(args->KeyStatus.IsKeyReleased ? "1" : "0"),
|
||||
(args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
|
||||
args->KeyStatus.RepeatCount,
|
||||
args->KeyStatus.ScanCode,
|
||||
(args->KeyStatus.WasKeyDown ? "1" : "0"),
|
||||
args->VirtualKey,
|
||||
sdlScancode,
|
||||
SDL_GetScancodeName(sdlScancode),
|
||||
keycode,
|
||||
SDL_GetKeyName(keycode));
|
||||
//args->Handled = true;
|
||||
//VirtualKey vkey = args->VirtualKey;
|
||||
#endif
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
|
||||
{
|
||||
SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
|
||||
#if 0
|
||||
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",
|
||||
(args->Handled ? "1" : "0"),
|
||||
(args->KeyStatus.IsExtendedKey ? "1" : "0"),
|
||||
(args->KeyStatus.IsKeyReleased ? "1" : "0"),
|
||||
(args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
|
||||
args->KeyStatus.RepeatCount,
|
||||
args->KeyStatus.ScanCode,
|
||||
(args->KeyStatus.WasKeyDown ? "1" : "0"),
|
||||
args->VirtualKey,
|
||||
sdlScancode,
|
||||
SDL_GetScancodeName(sdlScancode),
|
||||
keycode,
|
||||
SDL_GetKeyName(keycode));
|
||||
//args->Handled = true;
|
||||
#endif
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
|
||||
}
|
||||
|
||||
#endif // SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/* Standard C++11 includes */
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
/* Windows-specific includes */
|
||||
#include <Windows.h>
|
||||
#include <agile.h>
|
||||
|
||||
|
||||
/* SDL-specific includes */
|
||||
#include <SDL.h>
|
||||
#include "SDL_winrtevents_c.h"
|
||||
|
||||
extern "C" {
|
||||
#include "../../events/scancodes_windows.h"
|
||||
#include "../../events/SDL_keyboard_c.h"
|
||||
}
|
||||
|
||||
|
||||
static SDL_Scancode WinRT_Official_Keycodes[] = {
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.None -- 0
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.LeftButton -- 1
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.RightButton -- 2
|
||||
SDL_SCANCODE_CANCEL, // VirtualKey.Cancel -- 3
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.MiddleButton -- 4
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton1 -- 5
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.XButton2 -- 6
|
||||
SDL_SCANCODE_UNKNOWN, // -- 7
|
||||
SDL_SCANCODE_BACKSPACE, // VirtualKey.Back -- 8
|
||||
SDL_SCANCODE_TAB, // VirtualKey.Tab -- 9
|
||||
SDL_SCANCODE_UNKNOWN, // -- 10
|
||||
SDL_SCANCODE_UNKNOWN, // -- 11
|
||||
SDL_SCANCODE_CLEAR, // VirtualKey.Clear -- 12
|
||||
SDL_SCANCODE_RETURN, // VirtualKey.Enter -- 13
|
||||
SDL_SCANCODE_UNKNOWN, // -- 14
|
||||
SDL_SCANCODE_UNKNOWN, // -- 15
|
||||
SDL_SCANCODE_LSHIFT, // VirtualKey.Shift -- 16
|
||||
SDL_SCANCODE_LCTRL, // VirtualKey.Control -- 17
|
||||
SDL_SCANCODE_MENU, // VirtualKey.Menu -- 18
|
||||
SDL_SCANCODE_PAUSE, // VirtualKey.Pause -- 19
|
||||
SDL_SCANCODE_CAPSLOCK, // VirtualKey.CapitalLock -- 20
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Kana or VirtualKey.Hangul -- 21
|
||||
SDL_SCANCODE_UNKNOWN, // -- 22
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Junja -- 23
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Final -- 24
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Hanja or VirtualKey.Kanji -- 25
|
||||
SDL_SCANCODE_UNKNOWN, // -- 26
|
||||
SDL_SCANCODE_ESCAPE, // VirtualKey.Escape -- 27
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Convert -- 28
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.NonConvert -- 29
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Accept -- 30
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.ModeChange -- 31 (maybe SDL_SCANCODE_MODE ?)
|
||||
SDL_SCANCODE_SPACE, // VirtualKey.Space -- 32
|
||||
SDL_SCANCODE_PAGEUP, // VirtualKey.PageUp -- 33
|
||||
SDL_SCANCODE_PAGEDOWN, // VirtualKey.PageDown -- 34
|
||||
SDL_SCANCODE_END, // VirtualKey.End -- 35
|
||||
SDL_SCANCODE_HOME, // VirtualKey.Home -- 36
|
||||
SDL_SCANCODE_LEFT, // VirtualKey.Left -- 37
|
||||
SDL_SCANCODE_UP, // VirtualKey.Up -- 38
|
||||
SDL_SCANCODE_RIGHT, // VirtualKey.Right -- 39
|
||||
SDL_SCANCODE_DOWN, // VirtualKey.Down -- 40
|
||||
SDL_SCANCODE_SELECT, // VirtualKey.Select -- 41
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Print -- 42 (maybe SDL_SCANCODE_PRINTSCREEN ?)
|
||||
SDL_SCANCODE_EXECUTE, // VirtualKey.Execute -- 43
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Snapshot -- 44
|
||||
SDL_SCANCODE_INSERT, // VirtualKey.Insert -- 45
|
||||
SDL_SCANCODE_DELETE, // VirtualKey.Delete -- 46
|
||||
SDL_SCANCODE_HELP, // VirtualKey.Help -- 47
|
||||
SDL_SCANCODE_0, // VirtualKey.Number0 -- 48
|
||||
SDL_SCANCODE_1, // VirtualKey.Number1 -- 49
|
||||
SDL_SCANCODE_2, // VirtualKey.Number2 -- 50
|
||||
SDL_SCANCODE_3, // VirtualKey.Number3 -- 51
|
||||
SDL_SCANCODE_4, // VirtualKey.Number4 -- 52
|
||||
SDL_SCANCODE_5, // VirtualKey.Number5 -- 53
|
||||
SDL_SCANCODE_6, // VirtualKey.Number6 -- 54
|
||||
SDL_SCANCODE_7, // VirtualKey.Number7 -- 55
|
||||
SDL_SCANCODE_8, // VirtualKey.Number8 -- 56
|
||||
SDL_SCANCODE_9, // VirtualKey.Number9 -- 57
|
||||
SDL_SCANCODE_UNKNOWN, // -- 58
|
||||
SDL_SCANCODE_UNKNOWN, // -- 59
|
||||
SDL_SCANCODE_UNKNOWN, // -- 60
|
||||
SDL_SCANCODE_UNKNOWN, // -- 61
|
||||
SDL_SCANCODE_UNKNOWN, // -- 62
|
||||
SDL_SCANCODE_UNKNOWN, // -- 63
|
||||
SDL_SCANCODE_UNKNOWN, // -- 64
|
||||
SDL_SCANCODE_A, // VirtualKey.A -- 65
|
||||
SDL_SCANCODE_B, // VirtualKey.B -- 66
|
||||
SDL_SCANCODE_C, // VirtualKey.C -- 67
|
||||
SDL_SCANCODE_D, // VirtualKey.D -- 68
|
||||
SDL_SCANCODE_E, // VirtualKey.E -- 69
|
||||
SDL_SCANCODE_F, // VirtualKey.F -- 70
|
||||
SDL_SCANCODE_G, // VirtualKey.G -- 71
|
||||
SDL_SCANCODE_H, // VirtualKey.H -- 72
|
||||
SDL_SCANCODE_I, // VirtualKey.I -- 73
|
||||
SDL_SCANCODE_J, // VirtualKey.J -- 74
|
||||
SDL_SCANCODE_K, // VirtualKey.K -- 75
|
||||
SDL_SCANCODE_L, // VirtualKey.L -- 76
|
||||
SDL_SCANCODE_M, // VirtualKey.M -- 77
|
||||
SDL_SCANCODE_N, // VirtualKey.N -- 78
|
||||
SDL_SCANCODE_O, // VirtualKey.O -- 79
|
||||
SDL_SCANCODE_P, // VirtualKey.P -- 80
|
||||
SDL_SCANCODE_Q, // VirtualKey.Q -- 81
|
||||
SDL_SCANCODE_R, // VirtualKey.R -- 82
|
||||
SDL_SCANCODE_S, // VirtualKey.S -- 83
|
||||
SDL_SCANCODE_T, // VirtualKey.T -- 84
|
||||
SDL_SCANCODE_U, // VirtualKey.U -- 85
|
||||
SDL_SCANCODE_V, // VirtualKey.V -- 86
|
||||
SDL_SCANCODE_W, // VirtualKey.W -- 87
|
||||
SDL_SCANCODE_X, // VirtualKey.X -- 88
|
||||
SDL_SCANCODE_Y, // VirtualKey.Y -- 89
|
||||
SDL_SCANCODE_Z, // VirtualKey.Z -- 90
|
||||
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_APPLICATION, // VirtualKey.Application -- 93
|
||||
SDL_SCANCODE_UNKNOWN, // -- 94
|
||||
SDL_SCANCODE_SLEEP, // VirtualKey.Sleep -- 95
|
||||
SDL_SCANCODE_KP_0, // VirtualKey.NumberPad0 -- 96
|
||||
SDL_SCANCODE_KP_1, // VirtualKey.NumberPad1 -- 97
|
||||
SDL_SCANCODE_KP_2, // VirtualKey.NumberPad2 -- 98
|
||||
SDL_SCANCODE_KP_3, // VirtualKey.NumberPad3 -- 99
|
||||
SDL_SCANCODE_KP_4, // VirtualKey.NumberPad4 -- 100
|
||||
SDL_SCANCODE_KP_5, // VirtualKey.NumberPad5 -- 101
|
||||
SDL_SCANCODE_KP_6, // VirtualKey.NumberPad6 -- 102
|
||||
SDL_SCANCODE_KP_7, // VirtualKey.NumberPad7 -- 103
|
||||
SDL_SCANCODE_KP_8, // VirtualKey.NumberPad8 -- 104
|
||||
SDL_SCANCODE_KP_9, // VirtualKey.NumberPad9 -- 105
|
||||
SDL_SCANCODE_KP_MULTIPLY, // VirtualKey.Multiply -- 106
|
||||
SDL_SCANCODE_KP_PLUS, // VirtualKey.Add -- 107
|
||||
SDL_SCANCODE_UNKNOWN, // VirtualKey.Separator -- 108
|
||||
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_KP_DIVIDE, // VirtualKey.Divide -- 111
|
||||
SDL_SCANCODE_F1, // VirtualKey.F1 -- 112
|
||||
SDL_SCANCODE_F2, // VirtualKey.F2 -- 113
|
||||
SDL_SCANCODE_F3, // VirtualKey.F3 -- 114
|
||||
SDL_SCANCODE_F4, // VirtualKey.F4 -- 115
|
||||
SDL_SCANCODE_F5, // VirtualKey.F5 -- 116
|
||||
SDL_SCANCODE_F6, // VirtualKey.F6 -- 117
|
||||
SDL_SCANCODE_F7, // VirtualKey.F7 -- 118
|
||||
SDL_SCANCODE_F8, // VirtualKey.F8 -- 119
|
||||
SDL_SCANCODE_F9, // VirtualKey.F9 -- 120
|
||||
SDL_SCANCODE_F10, // VirtualKey.F10 -- 121
|
||||
SDL_SCANCODE_F11, // VirtualKey.F11 -- 122
|
||||
SDL_SCANCODE_F12, // VirtualKey.F12 -- 123
|
||||
SDL_SCANCODE_F13, // VirtualKey.F13 -- 124
|
||||
SDL_SCANCODE_F14, // VirtualKey.F14 -- 125
|
||||
SDL_SCANCODE_F15, // VirtualKey.F15 -- 126
|
||||
SDL_SCANCODE_F16, // VirtualKey.F16 -- 127
|
||||
SDL_SCANCODE_F17, // VirtualKey.F17 -- 128
|
||||
SDL_SCANCODE_F18, // VirtualKey.F18 -- 129
|
||||
SDL_SCANCODE_F19, // VirtualKey.F19 -- 130
|
||||
SDL_SCANCODE_F20, // VirtualKey.F20 -- 131
|
||||
SDL_SCANCODE_F21, // VirtualKey.F21 -- 132
|
||||
SDL_SCANCODE_F22, // VirtualKey.F22 -- 133
|
||||
SDL_SCANCODE_F23, // VirtualKey.F23 -- 134
|
||||
SDL_SCANCODE_F24, // VirtualKey.F24 -- 135
|
||||
SDL_SCANCODE_UNKNOWN, // -- 136
|
||||
SDL_SCANCODE_UNKNOWN, // -- 137
|
||||
SDL_SCANCODE_UNKNOWN, // -- 138
|
||||
SDL_SCANCODE_UNKNOWN, // -- 139
|
||||
SDL_SCANCODE_UNKNOWN, // -- 140
|
||||
SDL_SCANCODE_UNKNOWN, // -- 141
|
||||
SDL_SCANCODE_UNKNOWN, // -- 142
|
||||
SDL_SCANCODE_UNKNOWN, // -- 143
|
||||
SDL_SCANCODE_NUMLOCKCLEAR, // VirtualKey.NumberKeyLock -- 144
|
||||
SDL_SCANCODE_SCROLLLOCK, // VirtualKey.Scroll -- 145
|
||||
SDL_SCANCODE_UNKNOWN, // -- 146
|
||||
SDL_SCANCODE_UNKNOWN, // -- 147
|
||||
SDL_SCANCODE_UNKNOWN, // -- 148
|
||||
SDL_SCANCODE_UNKNOWN, // -- 149
|
||||
SDL_SCANCODE_UNKNOWN, // -- 150
|
||||
SDL_SCANCODE_UNKNOWN, // -- 151
|
||||
SDL_SCANCODE_UNKNOWN, // -- 152
|
||||
SDL_SCANCODE_UNKNOWN, // -- 153
|
||||
SDL_SCANCODE_UNKNOWN, // -- 154
|
||||
SDL_SCANCODE_UNKNOWN, // -- 155
|
||||
SDL_SCANCODE_UNKNOWN, // -- 156
|
||||
SDL_SCANCODE_UNKNOWN, // -- 157
|
||||
SDL_SCANCODE_UNKNOWN, // -- 158
|
||||
SDL_SCANCODE_UNKNOWN, // -- 159
|
||||
SDL_SCANCODE_LSHIFT, // VirtualKey.LeftShift -- 160
|
||||
SDL_SCANCODE_RSHIFT, // VirtualKey.RightShift -- 161
|
||||
SDL_SCANCODE_LCTRL, // VirtualKey.LeftControl -- 162
|
||||
SDL_SCANCODE_RCTRL, // VirtualKey.RightControl -- 163
|
||||
SDL_SCANCODE_MENU, // VirtualKey.LeftMenu -- 164
|
||||
SDL_SCANCODE_MENU, // VirtualKey.RightMenu -- 165
|
||||
};
|
||||
|
||||
static std::unordered_map<int, SDL_Scancode> WinRT_Unofficial_Keycodes;
|
||||
|
||||
static SDL_Scancode
|
||||
TranslateKeycode(int keycode)
|
||||
{
|
||||
if (WinRT_Unofficial_Keycodes.empty()) {
|
||||
/* Set up a table of undocumented (by Microsoft), WinRT-specific,
|
||||
key codes: */
|
||||
// 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[222] = SDL_SCANCODE_BACKSLASH;
|
||||
}
|
||||
|
||||
/* Try to get a documented, WinRT, 'VirtualKey' first (as documented at
|
||||
http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
|
||||
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
|
||||
//SDL_Log("WinRT TranslateKeycode, keycode=%d\n", (int)keycode);
|
||||
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
|
||||
if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
|
||||
scancode = WinRT_Official_Keycodes[keycode];
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
if (WinRT_Unofficial_Keycodes.find(keycode) != WinRT_Unofficial_Keycodes.end()) {
|
||||
scancode = WinRT_Unofficial_Keycodes[keycode];
|
||||
}
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
if (keycode < SDL_arraysize(windows_scancode_table)) {
|
||||
scancode = windows_scancode_table[keycode];
|
||||
}
|
||||
}
|
||||
if (scancode == SDL_SCANCODE_UNKNOWN) {
|
||||
SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
|
||||
}
|
||||
return scancode;
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
|
||||
{
|
||||
SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
|
||||
#if 0
|
||||
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",
|
||||
(args->Handled ? "1" : "0"),
|
||||
(args->KeyStatus.IsExtendedKey ? "1" : "0"),
|
||||
(args->KeyStatus.IsKeyReleased ? "1" : "0"),
|
||||
(args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
|
||||
args->KeyStatus.RepeatCount,
|
||||
args->KeyStatus.ScanCode,
|
||||
(args->KeyStatus.WasKeyDown ? "1" : "0"),
|
||||
args->VirtualKey,
|
||||
sdlScancode,
|
||||
SDL_GetScancodeName(sdlScancode),
|
||||
keycode,
|
||||
SDL_GetKeyName(keycode));
|
||||
//args->Handled = true;
|
||||
//VirtualKey vkey = args->VirtualKey;
|
||||
#endif
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
|
||||
{
|
||||
SDL_Scancode sdlScancode = TranslateKeycode((int)args->VirtualKey);
|
||||
#if 0
|
||||
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",
|
||||
(args->Handled ? "1" : "0"),
|
||||
(args->KeyStatus.IsExtendedKey ? "1" : "0"),
|
||||
(args->KeyStatus.IsKeyReleased ? "1" : "0"),
|
||||
(args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
|
||||
args->KeyStatus.RepeatCount,
|
||||
args->KeyStatus.ScanCode,
|
||||
(args->KeyStatus.WasKeyDown ? "1" : "0"),
|
||||
args->VirtualKey,
|
||||
sdlScancode,
|
||||
SDL_GetScancodeName(sdlScancode),
|
||||
keycode,
|
||||
SDL_GetKeyName(keycode));
|
||||
//args->Handled = true;
|
||||
#endif
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
|
||||
}
|
||||
|
||||
#endif // SDL_VIDEO_DRIVER_WINRT
|
||||
|
|
|
@ -1,166 +1,166 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/*
|
||||
* Windows includes:
|
||||
*/
|
||||
#include <Windows.h>
|
||||
using namespace Windows::UI::Core;
|
||||
using Windows::UI::Core::CoreCursor;
|
||||
|
||||
/*
|
||||
* SDL includes:
|
||||
*/
|
||||
extern "C" {
|
||||
#include "SDL_assert.h"
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
#include "../../events/SDL_touch_c.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_log.h"
|
||||
}
|
||||
|
||||
#include "../../core/winrt/SDL_winrtapp_direct3d.h"
|
||||
#include "SDL_winrtvideo_cpp.h"
|
||||
#include "SDL_winrtmouse_c.h"
|
||||
|
||||
|
||||
extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE;
|
||||
|
||||
|
||||
static SDL_Cursor *
|
||||
WINRT_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
CoreCursorType cursorType = CoreCursorType::Arrow;
|
||||
|
||||
switch(id)
|
||||
{
|
||||
default:
|
||||
SDL_assert(0);
|
||||
return NULL;
|
||||
case SDL_SYSTEM_CURSOR_ARROW: cursorType = CoreCursorType::Arrow; break;
|
||||
case SDL_SYSTEM_CURSOR_IBEAM: cursorType = CoreCursorType::IBeam; break;
|
||||
case SDL_SYSTEM_CURSOR_WAIT: cursorType = CoreCursorType::Wait; break;
|
||||
case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
|
||||
case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENWSE: cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENESW: cursorType = CoreCursorType::SizeNortheastSouthwest; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEWE: cursorType = CoreCursorType::SizeWestEast; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENS: cursorType = CoreCursorType::SizeNorthSouth; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEALL: cursorType = CoreCursorType::SizeAll; break;
|
||||
case SDL_SYSTEM_CURSOR_NO: cursorType = CoreCursorType::UniversalNo; break;
|
||||
case SDL_SYSTEM_CURSOR_HAND: cursorType = CoreCursorType::Hand; break;
|
||||
}
|
||||
|
||||
cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
|
||||
if (cursor) {
|
||||
/* 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
|
||||
to be referenced by the SDL_cursor's driverdata field, which is
|
||||
a void pointer.
|
||||
*/
|
||||
CoreCursor ^* theCursor = new CoreCursor^(nullptr);
|
||||
*theCursor = ref new CoreCursor(cursorType, 0);
|
||||
cursor->driverdata = (void *) theCursor;
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
WINRT_CreateDefaultCursor()
|
||||
{
|
||||
return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||
}
|
||||
|
||||
static void
|
||||
WINRT_FreeCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
if (cursor->driverdata) {
|
||||
CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
|
||||
*theCursor = nullptr; // Release the COM reference to the CoreCursor
|
||||
delete theCursor; // Delete the pointer to the COM reference
|
||||
}
|
||||
SDL_free(cursor);
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_ShowCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
// TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled.
|
||||
if ( ! CoreWindow::GetForCurrentThread()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cursor) {
|
||||
CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
|
||||
CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
|
||||
} else {
|
||||
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
WINRT_UsingRelativeMouseMode = enabled;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_InitMouse(_THIS)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
/* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for
|
||||
the following features, AFAIK:
|
||||
- custom cursors (multiple system cursors are, however, available)
|
||||
- programmatically moveable cursors
|
||||
*/
|
||||
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
//mouse->CreateCursor = WINRT_CreateCursor;
|
||||
mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
|
||||
mouse->ShowCursor = WINRT_ShowCursor;
|
||||
mouse->FreeCursor = WINRT_FreeCursor;
|
||||
//mouse->WarpMouse = WINRT_WarpMouse;
|
||||
mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
|
||||
|
||||
SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_QuitMouse(_THIS)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
/*
|
||||
* Windows includes:
|
||||
*/
|
||||
#include <Windows.h>
|
||||
using namespace Windows::UI::Core;
|
||||
using Windows::UI::Core::CoreCursor;
|
||||
|
||||
/*
|
||||
* SDL includes:
|
||||
*/
|
||||
extern "C" {
|
||||
#include "SDL_assert.h"
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
#include "../../events/SDL_touch_c.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_log.h"
|
||||
}
|
||||
|
||||
#include "../../core/winrt/SDL_winrtapp_direct3d.h"
|
||||
#include "SDL_winrtvideo_cpp.h"
|
||||
#include "SDL_winrtmouse_c.h"
|
||||
|
||||
|
||||
extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE;
|
||||
|
||||
|
||||
static SDL_Cursor *
|
||||
WINRT_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
CoreCursorType cursorType = CoreCursorType::Arrow;
|
||||
|
||||
switch(id)
|
||||
{
|
||||
default:
|
||||
SDL_assert(0);
|
||||
return NULL;
|
||||
case SDL_SYSTEM_CURSOR_ARROW: cursorType = CoreCursorType::Arrow; break;
|
||||
case SDL_SYSTEM_CURSOR_IBEAM: cursorType = CoreCursorType::IBeam; break;
|
||||
case SDL_SYSTEM_CURSOR_WAIT: cursorType = CoreCursorType::Wait; break;
|
||||
case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
|
||||
case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENWSE: cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENESW: cursorType = CoreCursorType::SizeNortheastSouthwest; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEWE: cursorType = CoreCursorType::SizeWestEast; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENS: cursorType = CoreCursorType::SizeNorthSouth; break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEALL: cursorType = CoreCursorType::SizeAll; break;
|
||||
case SDL_SYSTEM_CURSOR_NO: cursorType = CoreCursorType::UniversalNo; break;
|
||||
case SDL_SYSTEM_CURSOR_HAND: cursorType = CoreCursorType::Hand; break;
|
||||
}
|
||||
|
||||
cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
|
||||
if (cursor) {
|
||||
/* 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
|
||||
to be referenced by the SDL_cursor's driverdata field, which is
|
||||
a void pointer.
|
||||
*/
|
||||
CoreCursor ^* theCursor = new CoreCursor^(nullptr);
|
||||
*theCursor = ref new CoreCursor(cursorType, 0);
|
||||
cursor->driverdata = (void *) theCursor;
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor *
|
||||
WINRT_CreateDefaultCursor()
|
||||
{
|
||||
return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||
}
|
||||
|
||||
static void
|
||||
WINRT_FreeCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
if (cursor->driverdata) {
|
||||
CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
|
||||
*theCursor = nullptr; // Release the COM reference to the CoreCursor
|
||||
delete theCursor; // Delete the pointer to the COM reference
|
||||
}
|
||||
SDL_free(cursor);
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_ShowCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
// TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled.
|
||||
if ( ! CoreWindow::GetForCurrentThread()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cursor) {
|
||||
CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
|
||||
CoreWindow::GetForCurrentThread()->PointerCursor = *theCursor;
|
||||
} else {
|
||||
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
WINRT_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
WINRT_UsingRelativeMouseMode = enabled;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_InitMouse(_THIS)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
/* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for
|
||||
the following features, AFAIK:
|
||||
- custom cursors (multiple system cursors are, however, available)
|
||||
- programmatically moveable cursors
|
||||
*/
|
||||
|
||||
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
||||
//mouse->CreateCursor = WINRT_CreateCursor;
|
||||
mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
|
||||
mouse->ShowCursor = WINRT_ShowCursor;
|
||||
mouse->FreeCursor = WINRT_FreeCursor;
|
||||
//mouse->WarpMouse = WINRT_WarpMouse;
|
||||
mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
|
||||
|
||||
SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
WINRT_QuitMouse(_THIS)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,50 +1,50 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
// TODO: WinRT, make this file compile via C code
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
/* EGL implementation of SDL OpenGL support */
|
||||
|
||||
#include "SDL_winrtvideo_cpp.h"
|
||||
extern "C" {
|
||||
#include "SDL_winrtopengles.h"
|
||||
}
|
||||
|
||||
#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((NativeDisplayType) -3)
|
||||
|
||||
extern "C" int
|
||||
WINRT_GLES_LoadLibrary(_THIS, const char *path) {
|
||||
return SDL_EGL_LoadLibrary(_this, path, EGL_D3D11_ONLY_DISPLAY_ANGLE);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
SDL_EGL_CreateContext_impl(WINRT)
|
||||
SDL_EGL_SwapWindow_impl(WINRT)
|
||||
SDL_EGL_MakeCurrent_impl(WINRT)
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
// TODO: WinRT, make this file compile via C code
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
/* EGL implementation of SDL OpenGL support */
|
||||
|
||||
#include "SDL_winrtvideo_cpp.h"
|
||||
extern "C" {
|
||||
#include "SDL_winrtopengles.h"
|
||||
}
|
||||
|
||||
#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((NativeDisplayType) -3)
|
||||
|
||||
extern "C" int
|
||||
WINRT_GLES_LoadLibrary(_THIS, const char *path) {
|
||||
return SDL_EGL_LoadLibrary(_this, path, EGL_D3D11_ONLY_DISPLAY_ANGLE);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
SDL_EGL_CreateContext_impl(WINRT)
|
||||
SDL_EGL_SwapWindow_impl(WINRT)
|
||||
SDL_EGL_MakeCurrent_impl(WINRT)
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
|
|
|
@ -1,48 +1,48 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_winrtopengles_h
|
||||
#define _SDL_winrtopengles_h
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
/* OpenGLES functions */
|
||||
#define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute
|
||||
#define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress
|
||||
#define WINRT_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
||||
#define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
|
||||
#define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
||||
#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext
|
||||
|
||||
extern int WINRT_GLES_LoadLibrary(_THIS, const char *path);
|
||||
extern SDL_GLContext WINRT_GLES_CreateContext(_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);
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
#endif /* _SDL_winrtopengles_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifndef _SDL_winrtopengles_h
|
||||
#define _SDL_winrtopengles_h
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
/* OpenGLES functions */
|
||||
#define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute
|
||||
#define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress
|
||||
#define WINRT_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
||||
#define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
|
||||
#define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
||||
#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext
|
||||
|
||||
extern int WINRT_GLES_LoadLibrary(_THIS, const char *path);
|
||||
extern SDL_GLContext WINRT_GLES_CreateContext(_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);
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
#endif /* _SDL_winrtopengles_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
|
@ -32,363 +32,363 @@
|
|||
extern "C" {
|
||||
#include "../SDL_sysvideo.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"
|
||||
}
|
||||
|
||||
/* File-specific globals: */
|
||||
static SDL_TouchID WINRT_TouchID = 1;
|
||||
static unsigned int WINRT_LeftFingerDown = 0;
|
||||
|
||||
|
||||
void
|
||||
WINRT_InitTouch(_THIS)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/* File-specific globals: */
|
||||
static SDL_TouchID WINRT_TouchID = 1;
|
||||
static unsigned int WINRT_LeftFingerDown = 0;
|
||||
|
||||
|
||||
void
|
||||
WINRT_InitTouch(_THIS)
|
||||
{
|
||||
SDL_AddTouch(WINRT_TouchID, "");
|
||||
}
|
||||
|
||||
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));
|
||||
//
|
||||
// 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)
|
||||
{
|
||||
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
|
||||
|
|
|
@ -113,14 +113,14 @@ WINRT_CreateDevice(int devindex)
|
|||
device->PumpEvents = WINRT_PumpEvents;
|
||||
device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
|
||||
#ifdef SDL_VIDEO_OPENGL_EGL
|
||||
device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
|
||||
device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
|
||||
device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
|
||||
device->GL_CreateContext = WINRT_GLES_CreateContext;
|
||||
device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
|
||||
device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
|
||||
device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
|
||||
device->GL_SwapWindow = WINRT_GLES_SwapWindow;
|
||||
device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
|
||||
device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
|
||||
device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
|
||||
device->GL_CreateContext = WINRT_GLES_CreateContext;
|
||||
device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
|
||||
device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
|
||||
device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
|
||||
device->GL_SwapWindow = WINRT_GLES_SwapWindow;
|
||||
device->GL_DeleteContext = WINRT_GLES_DeleteContext;
|
||||
#endif
|
||||
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.
|
||||
TODO, WinRT: try tracking keyboard and mouse focus state with respect to snapped apps
|
||||
*/
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_SetKeyboardFocus(window);
|
||||
|
||||
/* Make sure the WinRT app's IFramworkView can post events on
|
||||
|
|
|
@ -44,36 +44,36 @@ extern SDL_Window * WINRT_GlobalSDLWindow;
|
|||
/* The global, WinRT, video device. */
|
||||
extern SDL_VideoDevice * WINRT_GlobalSDLVideoDevice;
|
||||
|
||||
/* 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.
|
||||
|
||||
This function will return 0 on success, -1 on failure.
|
||||
|
||||
If this function succeeds, be sure to call SDL_free on the
|
||||
SDL_DisplayMode's driverdata field.
|
||||
*/
|
||||
extern int WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode);
|
||||
|
||||
/* Duplicates a display mode, copying over driverdata as necessary */
|
||||
extern int WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src);
|
||||
|
||||
/* Display mode internals */
|
||||
typedef struct
|
||||
{
|
||||
Windows::Graphics::Display::DisplayOrientations currentOrientation;
|
||||
/* 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.
|
||||
|
||||
This function will return 0 on success, -1 on failure.
|
||||
|
||||
If this function succeeds, be sure to call SDL_free on the
|
||||
SDL_DisplayMode's driverdata field.
|
||||
*/
|
||||
extern int WINRT_CalcDisplayModeUsingNativeWindow(SDL_DisplayMode * mode);
|
||||
|
||||
/* Duplicates a display mode, copying over driverdata as necessary */
|
||||
extern int WINRT_DuplicateDisplayMode(SDL_DisplayMode * dest, const SDL_DisplayMode * src);
|
||||
|
||||
/* Display mode internals */
|
||||
typedef struct
|
||||
{
|
||||
Windows::Graphics::Display::DisplayOrientations currentOrientation;
|
||||
} SDL_DisplayModeData;
|
||||
|
||||
#ifdef __cplusplus_winrt
|
||||
|
||||
/* Internal window data */
|
||||
struct SDL_WindowData
|
||||
{
|
||||
SDL_Window *sdlWindow;
|
||||
Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
|
||||
#ifdef SDL_VIDEO_OPENGL_EGL
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
struct SDL_WindowData
|
||||
{
|
||||
SDL_Window *sdlWindow;
|
||||
Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
|
||||
#ifdef SDL_VIDEO_OPENGL_EGL
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // ifdef __cplusplus_winrt
|
||||
|
|
288
test/loopwave.c
288
test/loopwave.c
|
@ -1,144 +1,144 @@
|
|||
/*
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
|
||||
/* Program to load a wave file and loop playing it using SDL sound */
|
||||
|
||||
/* loopwaves.c is much more robust in handling WAVE files --
|
||||
This is only for simple WAVEs
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_audio.h"
|
||||
|
||||
struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
int soundpos; /* Current play position */
|
||||
} wave;
|
||||
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
||||
void SDLCALL
|
||||
fillerup(void *unused, Uint8 * stream, int len)
|
||||
{
|
||||
Uint8 *waveptr;
|
||||
int waveleft;
|
||||
|
||||
/* Set up the pointers */
|
||||
waveptr = wave.sound + wave.soundpos;
|
||||
waveleft = wave.soundlen - wave.soundpos;
|
||||
|
||||
/* Go! */
|
||||
while (waveleft <= len) {
|
||||
SDL_memcpy(stream, waveptr, waveleft);
|
||||
stream += waveleft;
|
||||
len -= waveleft;
|
||||
waveptr = wave.sound;
|
||||
waveleft = wave.soundlen;
|
||||
wave.soundpos = 0;
|
||||
}
|
||||
SDL_memcpy(stream, waveptr, len);
|
||||
wave.soundpos += len;
|
||||
}
|
||||
|
||||
static int done = 0;
|
||||
void
|
||||
poked(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char filename[4096];
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (argc >= 1) {
|
||||
SDL_strlcpy(filename, argv[1], sizeof(filename));
|
||||
} else {
|
||||
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
|
||||
}
|
||||
/* Load the wave file into memory */
|
||||
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());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
wave.spec.callback = fillerup;
|
||||
#if HAVE_SIGNAL_H
|
||||
/* Set the signals */
|
||||
#ifdef SIGHUP
|
||||
signal(SIGHUP, poked);
|
||||
#endif
|
||||
signal(SIGINT, poked);
|
||||
#ifdef SIGQUIT
|
||||
signal(SIGQUIT, poked);
|
||||
#endif
|
||||
signal(SIGTERM, poked);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Show the list of available drivers */
|
||||
SDL_Log("Available audio drivers:");
|
||||
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
|
||||
SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
|
||||
}
|
||||
|
||||
/* Initialize fillerup() variables */
|
||||
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
SDL_FreeWAV(wave.sound);
|
||||
quit(2);
|
||||
}
|
||||
|
||||
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudio(0);
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
SDL_Delay(1000);
|
||||
|
||||
/* Clean up on signal */
|
||||
SDL_CloseAudio();
|
||||
SDL_FreeWAV(wave.sound);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
|
||||
/* Program to load a wave file and loop playing it using SDL sound */
|
||||
|
||||
/* loopwaves.c is much more robust in handling WAVE files --
|
||||
This is only for simple WAVEs
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_audio.h"
|
||||
|
||||
struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
int soundpos; /* Current play position */
|
||||
} wave;
|
||||
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
||||
void SDLCALL
|
||||
fillerup(void *unused, Uint8 * stream, int len)
|
||||
{
|
||||
Uint8 *waveptr;
|
||||
int waveleft;
|
||||
|
||||
/* Set up the pointers */
|
||||
waveptr = wave.sound + wave.soundpos;
|
||||
waveleft = wave.soundlen - wave.soundpos;
|
||||
|
||||
/* Go! */
|
||||
while (waveleft <= len) {
|
||||
SDL_memcpy(stream, waveptr, waveleft);
|
||||
stream += waveleft;
|
||||
len -= waveleft;
|
||||
waveptr = wave.sound;
|
||||
waveleft = wave.soundlen;
|
||||
wave.soundpos = 0;
|
||||
}
|
||||
SDL_memcpy(stream, waveptr, len);
|
||||
wave.soundpos += len;
|
||||
}
|
||||
|
||||
static int done = 0;
|
||||
void
|
||||
poked(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char filename[4096];
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (argc >= 1) {
|
||||
SDL_strlcpy(filename, argv[1], sizeof(filename));
|
||||
} else {
|
||||
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
|
||||
}
|
||||
/* Load the wave file into memory */
|
||||
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());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
wave.spec.callback = fillerup;
|
||||
#if HAVE_SIGNAL_H
|
||||
/* Set the signals */
|
||||
#ifdef SIGHUP
|
||||
signal(SIGHUP, poked);
|
||||
#endif
|
||||
signal(SIGINT, poked);
|
||||
#ifdef SIGQUIT
|
||||
signal(SIGQUIT, poked);
|
||||
#endif
|
||||
signal(SIGTERM, poked);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Show the list of available drivers */
|
||||
SDL_Log("Available audio drivers:");
|
||||
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
|
||||
SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
|
||||
}
|
||||
|
||||
/* Initialize fillerup() variables */
|
||||
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
SDL_FreeWAV(wave.sound);
|
||||
quit(2);
|
||||
}
|
||||
|
||||
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudio(0);
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
SDL_Delay(1000);
|
||||
|
||||
/* Clean up on signal */
|
||||
SDL_CloseAudio();
|
||||
SDL_FreeWAV(wave.sound);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -1,99 +1,99 @@
|
|||
/*
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
|
||||
/* Simple test of the SDL threading code */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
static SDL_TLSID tls;
|
||||
static int alive = 0;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
int SDLCALL
|
||||
ThreadFunc(void *data)
|
||||
{
|
||||
SDL_TLSSet(tls, "baby thread", NULL);
|
||||
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
|
||||
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
|
||||
while (alive) {
|
||||
SDL_Log("Thread '%s' is alive!\n", (char *) data);
|
||||
SDL_Delay(1 * 1000);
|
||||
}
|
||||
SDL_Log("Thread '%s' exiting!\n", (char *) data);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
killed(int sig)
|
||||
{
|
||||
SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
|
||||
SDL_Delay(5 * 1000);
|
||||
alive = 0;
|
||||
quit(0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
tls = SDL_TLSCreate();
|
||||
SDL_assert(tls);
|
||||
SDL_TLSSet(tls, "main thread", NULL);
|
||||
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
|
||||
|
||||
alive = 1;
|
||||
thread = SDL_CreateThread(ThreadFunc, "One", "#1");
|
||||
if (thread == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
SDL_Delay(5 * 1000);
|
||||
SDL_Log("Waiting for thread #1\n");
|
||||
alive = 0;
|
||||
SDL_WaitThread(thread, NULL);
|
||||
|
||||
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
|
||||
|
||||
alive = 1;
|
||||
signal(SIGTERM, killed);
|
||||
thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
|
||||
if (thread == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
raise(SIGTERM);
|
||||
|
||||
SDL_Quit(); /* Never reached */
|
||||
return (0); /* Never reached */
|
||||
}
|
||||
/*
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
|
||||
/* Simple test of the SDL threading code */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
static SDL_TLSID tls;
|
||||
static int alive = 0;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
int SDLCALL
|
||||
ThreadFunc(void *data)
|
||||
{
|
||||
SDL_TLSSet(tls, "baby thread", NULL);
|
||||
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
|
||||
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
|
||||
while (alive) {
|
||||
SDL_Log("Thread '%s' is alive!\n", (char *) data);
|
||||
SDL_Delay(1 * 1000);
|
||||
}
|
||||
SDL_Log("Thread '%s' exiting!\n", (char *) data);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
killed(int sig)
|
||||
{
|
||||
SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
|
||||
SDL_Delay(5 * 1000);
|
||||
alive = 0;
|
||||
quit(0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
tls = SDL_TLSCreate();
|
||||
SDL_assert(tls);
|
||||
SDL_TLSSet(tls, "main thread", NULL);
|
||||
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
|
||||
|
||||
alive = 1;
|
||||
thread = SDL_CreateThread(ThreadFunc, "One", "#1");
|
||||
if (thread == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
SDL_Delay(5 * 1000);
|
||||
SDL_Log("Waiting for thread #1\n");
|
||||
alive = 0;
|
||||
SDL_WaitThread(thread, NULL);
|
||||
|
||||
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
|
||||
|
||||
alive = 1;
|
||||
signal(SIGTERM, killed);
|
||||
thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
|
||||
if (thread == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
raise(SIGTERM);
|
||||
|
||||
SDL_Quit(); /* Never reached */
|
||||
return (0); /* Never reached */
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue