diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /platform/windows | |
parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) |
A Whole New World (clang-format edition)
I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?
I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon
A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format
A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
Diffstat (limited to 'platform/windows')
-rw-r--r-- | platform/windows/context_gl_win.cpp | 126 | ||||
-rw-r--r-- | platform/windows/context_gl_win.h | 12 | ||||
-rw-r--r-- | platform/windows/ctxgl_procaddr.cpp | 14 | ||||
-rw-r--r-- | platform/windows/ctxgl_procaddr.h | 3 | ||||
-rw-r--r-- | platform/windows/export/export.cpp | 3 | ||||
-rw-r--r-- | platform/windows/godot_win.cpp | 202 | ||||
-rw-r--r-- | platform/windows/joypad.cpp | 95 | ||||
-rw-r--r-- | platform/windows/joypad.h | 38 | ||||
-rw-r--r-- | platform/windows/key_mapping_win.cpp | 373 | ||||
-rw-r--r-- | platform/windows/key_mapping_win.h | 9 | ||||
-rw-r--r-- | platform/windows/lang_table.h | 296 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 1455 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 105 | ||||
-rw-r--r-- | platform/windows/packet_peer_udp_winsock.cpp | 124 | ||||
-rw-r--r-- | platform/windows/packet_peer_udp_winsock.h | 14 | ||||
-rw-r--r-- | platform/windows/power_windows.cpp | 83 | ||||
-rw-r--r-- | platform/windows/stream_peer_winsock.cpp | 48 | ||||
-rw-r--r-- | platform/windows/stream_peer_winsock.h | 19 | ||||
-rw-r--r-- | platform/windows/tcp_server_winsock.cpp | 21 | ||||
-rw-r--r-- | platform/windows/tcp_server_winsock.h | 5 |
20 files changed, 1413 insertions, 1632 deletions
diff --git a/platform/windows/context_gl_win.cpp b/platform/windows/context_gl_win.cpp index 7a81dfef77..d737502bf5 100644 --- a/platform/windows/context_gl_win.cpp +++ b/platform/windows/context_gl_win.cpp @@ -45,25 +45,21 @@ //#include "drivers/opengl/glwrapper.h" //#include "ctxgl_procaddr.h" -#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define WGL_CONTEXT_FLAGS_ARB 0x2094 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 -typedef HGLRC (APIENTRY* PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const int*); - +typedef HGLRC(APIENTRY *PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const int *); void ContextGL_Win::release_current() { - - wglMakeCurrent(hDC,NULL); - + wglMakeCurrent(hDC, NULL); } - void ContextGL_Win::make_current() { - wglMakeCurrent(hDC,hRC); + wglMakeCurrent(hDC, hRC); } int ContextGL_Win::get_window_width() { @@ -98,10 +94,9 @@ static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) { void ContextGL_Win::set_use_vsync(bool p_use) { if (wglSwapIntervalEXT) { - wglSwapIntervalEXT(p_use?1:0); + wglSwapIntervalEXT(p_use ? 1 : 0); } - use_vsync=p_use; - + use_vsync = p_use; } bool ContextGL_Win::is_using_vsync() const { @@ -109,112 +104,109 @@ bool ContextGL_Win::is_using_vsync() const { return use_vsync; } -#define _WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 +#define _WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 Error ContextGL_Win::initialize() { - static PIXELFORMATDESCRIPTOR pfd= { - sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor + static PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, - PFD_DRAW_TO_WINDOW | // Format Must Support Window - PFD_SUPPORT_OPENGL | // Format Must Support OpenGL - PFD_DOUBLEBUFFER, + PFD_DRAW_TO_WINDOW | // Format Must Support Window + PFD_SUPPORT_OPENGL | // Format Must Support OpenGL + PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 24, - 0, 0, 0, 0, 0, 0, // Color Bits Ignored - 0,// No Alpha Buffer - 0,// Shift Bit Ignored - 0,// No Accumulation Buffer - 0, 0, 0, 0,// Accumulation Bits Ignored - 24,// 24Bit Z-Buffer (Depth Buffer) - 0,// No Stencil Buffer - 0,// No Auxiliary Buffer + 0, 0, 0, 0, 0, 0, // Color Bits Ignored + 0, // No Alpha Buffer + 0, // Shift Bit Ignored + 0, // No Accumulation Buffer + 0, 0, 0, 0, // Accumulation Bits Ignored + 24, // 24Bit Z-Buffer (Depth Buffer) + 0, // No Stencil Buffer + 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer - 0,// Reserved - 0, 0, 0 // Layer Masks Ignored + 0, // Reserved + 0, 0, 0 // Layer Masks Ignored }; - if (!(hDC=GetDC(hWnd))) { - MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); - return ERR_CANT_CREATE; // Return FALSE + if (!(hDC = GetDC(hWnd))) { + MessageBox(NULL, "Can't Create A GL Device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return ERR_CANT_CREATE; // Return FALSE } - if (!(pixel_format=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format? + if (!(pixel_format = ChoosePixelFormat(hDC, &pfd))) // Did Windows Find A Matching Pixel Format? { - MessageBox(NULL,"Can't Find A Suitable pixel_format.","ERROR",MB_OK|MB_ICONEXCLAMATION); - return ERR_CANT_CREATE; // Return FALSE + MessageBox(NULL, "Can't Find A Suitable pixel_format.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return ERR_CANT_CREATE; // Return FALSE } - if(!SetPixelFormat(hDC,pixel_format,&pfd)) // Are We Able To Set The Pixel Format? + if (!SetPixelFormat(hDC, pixel_format, &pfd)) // Are We Able To Set The Pixel Format? { - MessageBox(NULL,"Can't Set The pixel_format.","ERROR",MB_OK|MB_ICONEXCLAMATION); - return ERR_CANT_CREATE; // Return FALSE + MessageBox(NULL, "Can't Set The pixel_format.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return ERR_CANT_CREATE; // Return FALSE } - if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context? + if (!(hRC = wglCreateContext(hDC))) // Are We Able To Get A Rendering Context? { - MessageBox(NULL,"Can't Create A Temporary GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); - return ERR_CANT_CREATE; // Return FALSE + MessageBox(NULL, "Can't Create A Temporary GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return ERR_CANT_CREATE; // Return FALSE } - wglMakeCurrent(hDC,hRC); + wglMakeCurrent(hDC, hRC); if (opengl_3_context) { int attribs[] = { - WGL_CONTEXT_MAJOR_VERSION_ARB, 3,//we want a 3.3 context - WGL_CONTEXT_MINOR_VERSION_ARB, 3, - //and it shall be forward compatible so that we can only use up to date functionality - WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB|_WGL_CONTEXT_DEBUG_BIT_ARB, - 0}; //zero indicates the end of the array + WGL_CONTEXT_MAJOR_VERSION_ARB, 3, //we want a 3.3 context + WGL_CONTEXT_MINOR_VERSION_ARB, 3, + //and it shall be forward compatible so that we can only use up to date functionality + WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | _WGL_CONTEXT_DEBUG_BIT_ARB, + 0 + }; //zero indicates the end of the array PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; //pointer to the method - wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress("wglCreateContextAttribsARB"); + wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); - if(wglCreateContextAttribsARB == NULL) //OpenGL 3.0 is not supported + if (wglCreateContextAttribsARB == NULL) //OpenGL 3.0 is not supported { - MessageBox(NULL,"Cannot get Proc Adress for CreateContextAttribs", "ERROR",MB_OK|MB_ICONEXCLAMATION); + MessageBox(NULL, "Cannot get Proc Adress for CreateContextAttribs", "ERROR", MB_OK | MB_ICONEXCLAMATION); wglDeleteContext(hRC); return ERR_CANT_CREATE; } HGLRC new_hRC; - if (!(new_hRC=wglCreateContextAttribsARB(hDC,0, attribs))) - { + if (!(new_hRC = wglCreateContextAttribsARB(hDC, 0, attribs))) { wglDeleteContext(hRC); - MessageBox(NULL,"Can't Create An OpenGL 3.3 Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); - return ERR_CANT_CREATE; // Return false + MessageBox(NULL, "Can't Create An OpenGL 3.3 Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return ERR_CANT_CREATE; // Return false } - wglMakeCurrent(hDC,NULL); + wglMakeCurrent(hDC, NULL); wglDeleteContext(hRC); - hRC=new_hRC; + hRC = new_hRC; - if (!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context + if (!wglMakeCurrent(hDC, hRC)) // Try To Activate The Rendering Context { - MessageBox(NULL,"Can't Activate The GL 3.3 Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); - return ERR_CANT_CREATE; // Return FALSE + MessageBox(NULL, "Can't Activate The GL 3.3 Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return ERR_CANT_CREATE; // Return FALSE } printf("Activated GL 3.3 context"); } - wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress ("wglSwapIntervalEXT"); + wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); //glWrapperInit(wrapper_get_proc_address); return OK; } -ContextGL_Win::ContextGL_Win(HWND hwnd,bool p_opengl_3_context) { +ContextGL_Win::ContextGL_Win(HWND hwnd, bool p_opengl_3_context) { - opengl_3_context=p_opengl_3_context; - hWnd=hwnd; - use_vsync=false; + opengl_3_context = p_opengl_3_context; + hWnd = hwnd; + use_vsync = false; } ContextGL_Win::~ContextGL_Win() { - - } - #endif diff --git a/platform/windows/context_gl_win.h b/platform/windows/context_gl_win.h index 96b54c6c14..383197ba7f 100644 --- a/platform/windows/context_gl_win.h +++ b/platform/windows/context_gl_win.h @@ -42,14 +42,13 @@ #ifndef CONTEXT_GL_WIN_H #define CONTEXT_GL_WIN_H - -#include "os/os.h" #include "drivers/gl_context/context_gl.h" #include "error_list.h" +#include "os/os.h" #include <windows.h> -typedef bool (APIENTRY *PFNWGLSWAPINTERVALEXTPROC) (int interval); +typedef bool(APIENTRY *PFNWGLSWAPINTERVALEXTPROC)(int interval); class ContextGL_Win : public ContextGL { @@ -60,11 +59,9 @@ class ContextGL_Win : public ContextGL { bool opengl_3_context; bool use_vsync; - PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; -public: - +public: virtual void release_current(); virtual void make_current(); @@ -78,9 +75,8 @@ public: virtual void set_use_vsync(bool p_use); virtual bool is_using_vsync() const; - ContextGL_Win(HWND hwnd,bool p_opengl_3_context); + ContextGL_Win(HWND hwnd, bool p_opengl_3_context); ~ContextGL_Win(); - }; #endif diff --git a/platform/windows/ctxgl_procaddr.cpp b/platform/windows/ctxgl_procaddr.cpp index bc8611dce4..79c6f219f3 100644 --- a/platform/windows/ctxgl_procaddr.cpp +++ b/platform/windows/ctxgl_procaddr.cpp @@ -31,7 +31,7 @@ #include <GL/gl.h> #include <stdio.h> -static PROC _gl_procs[]={ +static PROC _gl_procs[] = { (PROC)glCullFace, (PROC)glFrontFace, (PROC)glHint, @@ -99,7 +99,7 @@ static PROC _gl_procs[]={ 0 }; -static const char* _gl_proc_names[]={ +static const char *_gl_proc_names[] = { "glCullFace", "glFrontFace", "glHint", @@ -167,15 +167,15 @@ static const char* _gl_proc_names[]={ 0 }; -PROC get_gl_proc_address(const char* p_address) { +PROC get_gl_proc_address(const char *p_address) { - PROC proc = wglGetProcAddress((const CHAR*)p_address); + PROC proc = wglGetProcAddress((const CHAR *)p_address); if (!proc) { - int i=0; - while(_gl_procs[i]) { + int i = 0; + while (_gl_procs[i]) { - if (strcmp(p_address,_gl_proc_names[i])==0) { + if (strcmp(p_address, _gl_proc_names[i]) == 0) { return _gl_procs[i]; } i++; diff --git a/platform/windows/ctxgl_procaddr.h b/platform/windows/ctxgl_procaddr.h index 72f39e71ac..da17fbcbbe 100644 --- a/platform/windows/ctxgl_procaddr.h +++ b/platform/windows/ctxgl_procaddr.h @@ -32,7 +32,6 @@ #ifdef OPENGL_ENABLED #include <windows.h> - -PROC get_gl_proc_address(const char* p_address); +PROC get_gl_proc_address(const char *p_address); #endif #endif // CTXGL_PROCADDR_H diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp index 44c0acdb2e..bb51474a8c 100644 --- a/platform/windows/export/export.cpp +++ b/platform/windows/export/export.cpp @@ -27,8 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "export.h" -#include "platform/windows/logo.h" #include "editor/editor_export.h" +#include "platform/windows/logo.h" void register_windows_exporter() { @@ -51,4 +51,3 @@ void register_windows_exporter() { #endif } - diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp index 5260f7f641..f8f5fe8231 100644 --- a/platform/windows/godot_win.cpp +++ b/platform/windows/godot_win.cpp @@ -26,127 +26,123 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "os_windows.h" #include "main/main.h" -#include <stdio.h> +#include "os_windows.h" #include <locale.h> +#include <stdio.h> + +PCHAR * +CommandLineToArgvA( + PCHAR CmdLine, + int *_argc) { + PCHAR *argv; + PCHAR _argv; + ULONG len; + ULONG argc; + CHAR a; + ULONG i, j; + + BOOLEAN in_QM; + BOOLEAN in_TEXT; + BOOLEAN in_SPACE; + + len = strlen(CmdLine); + i = ((len + 2) / 2) * sizeof(PVOID) + sizeof(PVOID); + + argv = (PCHAR *)GlobalAlloc(GMEM_FIXED, + i + (len + 2) * sizeof(CHAR)); + + _argv = (PCHAR)(((PUCHAR)argv) + i); + + argc = 0; + argv[argc] = _argv; + in_QM = FALSE; + in_TEXT = FALSE; + in_SPACE = TRUE; + i = 0; + j = 0; + + while ((a = CmdLine[i])) { + if (in_QM) { + if (a == '\"') { + in_QM = FALSE; + } else { + _argv[j] = a; + j++; + } + } else { + switch (a) { + case '\"': + in_QM = TRUE; + in_TEXT = TRUE; + if (in_SPACE) { + argv[argc] = _argv + j; + argc++; + } + in_SPACE = FALSE; + break; + case ' ': + case '\t': + case '\n': + case '\r': + if (in_TEXT) { + _argv[j] = '\0'; + j++; + } + in_TEXT = FALSE; + in_SPACE = TRUE; + break; + default: + in_TEXT = TRUE; + if (in_SPACE) { + argv[argc] = _argv + j; + argc++; + } + _argv[j] = a; + j++; + in_SPACE = FALSE; + break; + } + } + i++; + } + _argv[j] = '\0'; + argv[argc] = NULL; + + (*_argc) = argc; + return argv; +} -PCHAR* - CommandLineToArgvA( - PCHAR CmdLine, - int* _argc - ) - { - PCHAR* argv; - PCHAR _argv; - ULONG len; - ULONG argc; - CHAR a; - ULONG i, j; - - BOOLEAN in_QM; - BOOLEAN in_TEXT; - BOOLEAN in_SPACE; - - len = strlen(CmdLine); - i = ((len+2)/2)*sizeof(PVOID) + sizeof(PVOID); - - argv = (PCHAR*)GlobalAlloc(GMEM_FIXED, - i + (len+2)*sizeof(CHAR)); - - _argv = (PCHAR)(((PUCHAR)argv)+i); - - argc = 0; - argv[argc] = _argv; - in_QM = FALSE; - in_TEXT = FALSE; - in_SPACE = TRUE; - i = 0; - j = 0; - - while( (a = CmdLine[i]) ) { - if(in_QM) { - if(a == '\"') { - in_QM = FALSE; - } else { - _argv[j] = a; - j++; - } - } else { - switch(a) { - case '\"': - in_QM = TRUE; - in_TEXT = TRUE; - if(in_SPACE) { - argv[argc] = _argv+j; - argc++; - } - in_SPACE = FALSE; - break; - case ' ': - case '\t': - case '\n': - case '\r': - if(in_TEXT) { - _argv[j] = '\0'; - j++; - } - in_TEXT = FALSE; - in_SPACE = TRUE; - break; - default: - in_TEXT = TRUE; - if(in_SPACE) { - argv[argc] = _argv+j; - argc++; - } - _argv[j] = a; - j++; - in_SPACE = FALSE; - break; - } - } - i++; - } - _argv[j] = '\0'; - argv[argc] = NULL; - - (*_argc) = argc; - return argv; - } - -char* wc_to_utf8(const wchar_t* wc) { - int ulen = WideCharToMultiByte(CP_UTF8,0,wc,-1,NULL,0,NULL,NULL); - char * ubuf = new char[ulen + 1]; - WideCharToMultiByte(CP_UTF8,0,wc,-1,ubuf,ulen,NULL,NULL); +char *wc_to_utf8(const wchar_t *wc) { + int ulen = WideCharToMultiByte(CP_UTF8, 0, wc, -1, NULL, 0, NULL, NULL); + char *ubuf = new char[ulen + 1]; + WideCharToMultiByte(CP_UTF8, 0, wc, -1, ubuf, ulen, NULL, NULL); ubuf[ulen] = 0; return ubuf; } -int widechar_main(int argc, wchar_t** argv) { +int widechar_main(int argc, wchar_t **argv) { OS_Windows os(NULL); setlocale(LC_CTYPE, ""); - char ** argv_utf8 = new char*[argc]; + char **argv_utf8 = new char *[argc]; - for(int i=0; i<argc; ++i) { + for (int i = 0; i < argc; ++i) { argv_utf8[i] = wc_to_utf8(argv[i]); } Error err = Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]); - if (err!=OK) + if (err != OK) return 255; - if (Main::start()) os.run(); Main::cleanup(); - - for (int i=0; i<argc; ++i) { + for (int i = 0; i < argc; ++i) { delete[] argv_utf8[i]; } delete[] argv_utf8; @@ -154,17 +150,17 @@ int widechar_main(int argc, wchar_t** argv) { return os.get_exit_code(); }; -int main(int _argc, char** _argv) { +int main(int _argc, char **_argv) { // _argc and _argv are ignored // we are going to use the WideChar version of them instead LPWSTR *wc_argv; - int argc; - int result; + int argc; + int result; wc_argv = CommandLineToArgvW(GetCommandLineW(), &argc); - if( NULL == wc_argv ) { + if (NULL == wc_argv) { wprintf(L"CommandLineToArgvW failed\n"); return 0; } @@ -177,7 +173,7 @@ int main(int _argc, char** _argv) { HINSTANCE godot_hinstance = NULL; -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { godot_hinstance = hInstance; - return main(0,NULL); + return main(0, NULL); } diff --git a/platform/windows/joypad.cpp b/platform/windows/joypad.cpp index 4c1eeb425a..2472940ef3 100644 --- a/platform/windows/joypad.cpp +++ b/platform/windows/joypad.cpp @@ -27,22 +27,25 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "joypad.h" -#include <iostream> -#include <wbemidl.h> #include <oleauto.h> +#include <wbemidl.h> +#include <iostream> #ifndef __GNUC__ #define __builtin_bswap32 _byteswap_ulong #endif -DWORD WINAPI _xinput_get_state(DWORD dwUserIndex, XINPUT_STATE* pState) { return ERROR_DEVICE_NOT_CONNECTED; } -DWORD WINAPI _xinput_set_state(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration) { return ERROR_DEVICE_NOT_CONNECTED; } +DWORD WINAPI _xinput_get_state(DWORD dwUserIndex, XINPUT_STATE *pState) { + return ERROR_DEVICE_NOT_CONNECTED; +} +DWORD WINAPI _xinput_set_state(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration) { + return ERROR_DEVICE_NOT_CONNECTED; +} JoypadWindows::JoypadWindows() { - } -JoypadWindows::JoypadWindows(InputDefault* _input, HWND* hwnd) { +JoypadWindows::JoypadWindows(InputDefault *_input, HWND *hwnd) { input = _input; hWnd = hwnd; @@ -57,9 +60,8 @@ JoypadWindows::JoypadWindows(InputDefault* _input, HWND* hwnd) { for (int i = 0; i < JOYPADS_MAX; i++) attached_joypads[i] = false; - HRESULT result; - result = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&dinput, NULL); + result = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&dinput, NULL); if (FAILED(result)) { printf("failed init DINPUT: %ld\n", result); } @@ -73,7 +75,6 @@ JoypadWindows::~JoypadWindows() { unload_xinput(); } - bool JoypadWindows::have_device(const GUID &p_guid) { for (int i = 0; i < JOYPADS_MAX; i++) { @@ -87,7 +88,6 @@ bool JoypadWindows::have_device(const GUID &p_guid) { return false; } - // adapted from SDL2, works a lot better than the MSDN version bool JoypadWindows::is_xinput_device(const GUID *p_guid) { @@ -104,7 +104,7 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) { if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { return false; } - dev_list = (PRAWINPUTDEVICELIST) malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count); + dev_list = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count); if (!dev_list) return false; if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { @@ -119,7 +119,7 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) { UINT nameSize = sizeof(dev_name); rdi.cbSize = rdiSize; - if ( (dev_list[i].dwType == RIM_TYPEHID) && + if ((dev_list[i].dwType == RIM_TYPEHID) && (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1) && (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == (LONG)p_guid->Data1) && (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) && @@ -133,7 +133,7 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) { return false; } -bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE* instance) { +bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) { HRESULT hr; int num = input->get_unused_joy_id(); @@ -142,7 +142,7 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE* instance) { return false; d_joypads[joypad_count] = dinput_gamepad(); - dinput_gamepad* joy = &d_joypads[joypad_count]; + dinput_gamepad *joy = &d_joypads[joypad_count]; const DWORD devtype = (instance->dwDevType & 0xFF); @@ -162,8 +162,8 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE* instance) { const GUID &guid = instance->guidProduct; char uid[128]; sprintf(uid, "%08lx%04hx%04hx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", - __builtin_bswap32(guid.Data1), guid.Data2, guid.Data3, - guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], + __builtin_bswap32(guid.Data1), guid.Data2, guid.Data3, + guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); id_to_change = joypad_count; @@ -216,7 +216,6 @@ void JoypadWindows::setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_ dinput_gamepad &joy = d_joypads[p_joy_id]; - res = IDirectInputDevice8_SetProperty(joy.di_joy, DIPROP_RANGE, &prop_range.diph); if (FAILED(res)) return; @@ -235,10 +234,9 @@ void JoypadWindows::setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_ } } -BOOL CALLBACK JoypadWindows::enumCallback(const DIDEVICEINSTANCE* instance, void* pContext) { - +BOOL CALLBACK JoypadWindows::enumCallback(const DIDEVICEINSTANCE *instance, void *pContext) { - JoypadWindows* self = (JoypadWindows*)pContext; + JoypadWindows *self = (JoypadWindows *)pContext; if (self->is_xinput_device(&instance->guidProduct)) { return DIENUM_CONTINUE; } @@ -248,7 +246,7 @@ BOOL CALLBACK JoypadWindows::enumCallback(const DIDEVICEINSTANCE* instance, void BOOL CALLBACK JoypadWindows::objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context) { - JoypadWindows* self = (JoypadWindows*)context; + JoypadWindows *self = (JoypadWindows *)context; self->setup_joypad_object(instance, self->id_to_change); return DIENUM_CONTINUE; @@ -284,7 +282,7 @@ void JoypadWindows::probe_joypads() { ZeroMemory(&x_joypads[i].state, sizeof(XINPUT_STATE)); dwResult = xinput_get_state(i, &x_joypads[i].state); - if ( dwResult == ERROR_SUCCESS) { + if (dwResult == ERROR_SUCCESS) { int id = input->get_unused_joy_id(); if (id != -1 && !x_joypads[i].attached) { @@ -295,10 +293,9 @@ void JoypadWindows::probe_joypads() { x_joypads[i].ff_end_timestamp = 0; x_joypads[i].vibrating = false; attached_joypads[id] = true; - input->joy_connection_changed(id, true, "XInput Gamepad","__XINPUT_DEVICE__"); + input->joy_connection_changed(id, true, "XInput Gamepad", "__XINPUT_DEVICE__"); } - } - else if (x_joypads[i].attached) { + } else if (x_joypads[i].attached) { x_joypads[i].attached = false; attached_joypads[x_joypads[i].id] = false; @@ -344,12 +341,12 @@ unsigned int JoypadWindows::process_joypads(unsigned int p_last_id) { button_mask = button_mask * 2; } - p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_0, axis_correct(joy.state.Gamepad.sThumbLX, true)); - p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_1, axis_correct(joy.state.Gamepad.sThumbLY, true, false, true)); - p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_2, axis_correct(joy.state.Gamepad.sThumbRX, true)); - p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_3, axis_correct(joy.state.Gamepad.sThumbRY, true, false, true)); - p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_4, axis_correct(joy.state.Gamepad.bLeftTrigger, true, true)); - p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_5, axis_correct(joy.state.Gamepad.bRightTrigger, true, true)); + p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_0, axis_correct(joy.state.Gamepad.sThumbLX, true)); + p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_1, axis_correct(joy.state.Gamepad.sThumbLY, true, false, true)); + p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_2, axis_correct(joy.state.Gamepad.sThumbRX, true)); + p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_3, axis_correct(joy.state.Gamepad.sThumbRY, true, false, true)); + p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_4, axis_correct(joy.state.Gamepad.bLeftTrigger, true, true)); + p_last_id = input->joy_axis(p_last_id, joy.id, JOY_AXIS_5, axis_correct(joy.state.Gamepad.bRightTrigger, true, true)); joy.last_packet = joy.state.dwPacketNumber; } uint64_t timestamp = input->get_joy_vibration_timestamp(joy.id); @@ -370,7 +367,7 @@ unsigned int JoypadWindows::process_joypads(unsigned int p_last_id) { for (int i = 0; i < JOYPADS_MAX; i++) { - dinput_gamepad* joy = &d_joypads[i]; + dinput_gamepad *joy = &d_joypads[i]; if (!joy->attached) continue; @@ -398,8 +395,7 @@ unsigned int JoypadWindows::process_joypads(unsigned int p_last_id) { p_last_id = input->joy_button(p_last_id, joy->id, j, true); joy->last_buttons[j] = true; } - } - else { + } else { if (joy->last_buttons[j]) { @@ -416,7 +412,7 @@ unsigned int JoypadWindows::process_joypads(unsigned int p_last_id) { for (int j = 0; j < joy->joy_axis.size(); j++) { - for (int k=0; k<count; k++) { + for (int k = 0; k < count; k++) { if (joy->joy_axis[j] == axes[k]) { p_last_id = input->joy_axis(p_last_id, joy->id, j, axis_correct(values[k])); break; @@ -438,38 +434,31 @@ unsigned int JoypadWindows::post_hat(unsigned int p_last_id, int p_device, DWORD dpad_val = InputDefault::HAT_MASK_UP; - } - else if (p_dpad == 4500) { + } else if (p_dpad == 4500) { dpad_val = (InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_RIGHT); - } - else if (p_dpad == 9000) { + } else if (p_dpad == 9000) { dpad_val = InputDefault::HAT_MASK_RIGHT; - } - else if (p_dpad == 13500) { + } else if (p_dpad == 13500) { dpad_val = (InputDefault::HAT_MASK_RIGHT | InputDefault::HAT_MASK_DOWN); - } - else if (p_dpad == 18000) { + } else if (p_dpad == 18000) { dpad_val = InputDefault::HAT_MASK_DOWN; - } - else if (p_dpad == 22500) { + } else if (p_dpad == 22500) { dpad_val = (InputDefault::HAT_MASK_DOWN | InputDefault::HAT_MASK_LEFT); - } - else if (p_dpad == 27000) { + } else if (p_dpad == 27000) { dpad_val = InputDefault::HAT_MASK_LEFT; - } - else if (p_dpad == 31500) { + } else if (p_dpad == 31500) { dpad_val = (InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_UP); } @@ -494,8 +483,7 @@ InputDefault::JoyAxis JoypadWindows::axis_correct(int p_val, bool p_xinput, bool jx.min = -1; if (p_val < 0) { jx.value = (float)p_val / MAX_JOY_AXIS; - } - else { + } else { jx.value = (float)p_val / (MAX_JOY_AXIS - 1); } if (p_negate) { @@ -526,7 +514,7 @@ void JoypadWindows::joypad_vibration_stop_xinput(int p_device, uint64_t p_timest xinput_gamepad &joy = x_joypads[p_device]; if (joy.attached) { XINPUT_VIBRATION effect; - effect.wLeftMotorSpeed = 0; + effect.wLeftMotorSpeed = 0; effect.wRightMotorSpeed = 0; if (xinput_set_state(p_device, &effect) == ERROR_SUCCESS) { joy.ff_timestamp = p_timestamp; @@ -535,12 +523,11 @@ void JoypadWindows::joypad_vibration_stop_xinput(int p_device, uint64_t p_timest } } - void JoypadWindows::load_xinput() { xinput_get_state = &_xinput_get_state; xinput_set_state = &_xinput_set_state; - xinput_dll = LoadLibrary( "XInput1_4.dll" ); + xinput_dll = LoadLibrary("XInput1_4.dll"); if (!xinput_dll) { xinput_dll = LoadLibrary("XInput1_3.dll"); if (!xinput_dll) { diff --git a/platform/windows/joypad.h b/platform/windows/joypad.h index d6670c90db..7e4f6ff328 100644 --- a/platform/windows/joypad.h +++ b/platform/windows/joypad.h @@ -34,30 +34,28 @@ #include <dinput.h> #include <xinput.h> // on unix the file is called "xinput.h", on windows I'm sure it won't mind -#ifndef SAFE_RELEASE // when Windows Media Device M? is not present +#ifndef SAFE_RELEASE // when Windows Media Device M? is not present #define SAFE_RELEASE(x) \ -if(x != NULL) \ -{ \ - x->Release(); \ - x = NULL; \ -} + if (x != NULL) { \ + x->Release(); \ + x = NULL; \ + } #endif #ifndef XUSER_MAX_COUNT #define XUSER_MAX_COUNT 4 #endif -class JoypadWindows -{ +class JoypadWindows { public: JoypadWindows(); - JoypadWindows(InputDefault* _input, HWND* hwnd); + JoypadWindows(InputDefault *_input, HWND *hwnd); ~JoypadWindows(); void probe_joypads(); unsigned int process_joypads(unsigned int p_last_id); -private: +private: enum { JOYPADS_MAX = 16, JOY_AXIS_COUNT = 6, @@ -110,13 +108,13 @@ private: } }; - typedef DWORD (WINAPI *XInputGetState_t) (DWORD dwUserIndex, XINPUT_STATE* pState); - typedef DWORD (WINAPI *XInputSetState_t) (DWORD dwUserIndex, XINPUT_VIBRATION* pVibration); + typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex, XINPUT_STATE *pState); + typedef DWORD(WINAPI *XInputSetState_t)(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration); - HWND* hWnd; + HWND *hWnd; HANDLE xinput_dll; LPDIRECTINPUT8 dinput; - InputDefault* input; + InputDefault *input; int id_to_change; int joypad_count; @@ -124,10 +122,10 @@ private: dinput_gamepad d_joypads[JOYPADS_MAX]; xinput_gamepad x_joypads[XUSER_MAX_COUNT]; - static BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* p_instance, void* p_context); - static BOOL CALLBACK objectsCallback(const DIDEVICEOBJECTINSTANCE* instance, void* context); + static BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE *p_instance, void *p_context); + static BOOL CALLBACK objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context); - void setup_joypad_object(const DIDEVICEOBJECTINSTANCE* ob, int p_joy_id); + void setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id); void close_joypad(int id = -1); void load_xinput(); void unload_xinput(); @@ -135,8 +133,8 @@ private: unsigned int post_hat(unsigned int p_last_id, int p_device, DWORD p_dpad); bool have_device(const GUID &p_guid); - bool is_xinput_device(const GUID* p_guid); - bool setup_dinput_joypad(const DIDEVICEINSTANCE* instance); + bool is_xinput_device(const GUID *p_guid); + bool setup_dinput_joypad(const DIDEVICEINSTANCE *instance); void joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); void joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp); @@ -146,5 +144,3 @@ private: }; #endif - - diff --git a/platform/windows/key_mapping_win.cpp b/platform/windows/key_mapping_win.cpp index 9ab222e9ee..51cdba65d5 100644 --- a/platform/windows/key_mapping_win.cpp +++ b/platform/windows/key_mapping_win.cpp @@ -36,202 +36,198 @@ struct _WinTranslatePair { unsigned int keycode; }; +static _WinTranslatePair _vk_to_keycode[] = { -static _WinTranslatePair _vk_to_keycode[]={ + { KEY_BACKSPACE, VK_BACK }, // (0x08) // backspace + { KEY_TAB, VK_TAB }, //(0x09) -{ KEY_BACKSPACE, VK_BACK },// (0x08) // backspace -{ KEY_TAB, VK_TAB },//(0x09) + //VK_CLEAR (0x0C) -//VK_CLEAR (0x0C) + { KEY_RETURN, VK_RETURN }, //(0x0D) -{ KEY_RETURN, VK_RETURN },//(0x0D) + { KEY_SHIFT, VK_SHIFT }, //(0x10) -{ KEY_SHIFT, VK_SHIFT },//(0x10) + { KEY_CONTROL, VK_CONTROL }, //(0x11) + + { KEY_MENU, VK_MENU }, //(0x12) + + { KEY_PAUSE, VK_PAUSE }, //(0x13) + + { KEY_CAPSLOCK, VK_CAPITAL }, //(0x14) + + { KEY_ESCAPE, VK_ESCAPE }, //(0x1B) + + { KEY_SPACE, VK_SPACE }, //(0x20) + + { KEY_PAGEUP, VK_PRIOR }, //(0x21) + + { KEY_PAGEDOWN, VK_NEXT }, //(0x22) + + { KEY_END, VK_END }, //(0x23) + + { KEY_HOME, VK_HOME }, //(0x24) + + { KEY_LEFT, VK_LEFT }, //(0x25) + + { KEY_UP, VK_UP }, //(0x26) + + { KEY_RIGHT, VK_RIGHT }, //(0x27) + + { KEY_DOWN, VK_DOWN }, // (0x28) + + //VK_SELECT (0x29) + + { KEY_PRINT, VK_PRINT }, // (0x2A) + + //VK_EXECUTE (0x2B) + + { KEY_PRINT, VK_SNAPSHOT }, // (0x2C) + + { KEY_INSERT, VK_INSERT }, // (0x2D) + + { KEY_DELETE, VK_DELETE }, // (0x2E) + + { KEY_HELP, VK_HELP }, // (0x2F) + + { KEY_0, (0x30) }, ////0 key + { KEY_1, (0x31) }, ////1 key + { KEY_2, (0x32) }, ////2 key + { KEY_3, (0x33) }, ////3 key + { KEY_4, (0x34) }, ////4 key + { KEY_5, (0x35) }, ////5 key + { KEY_6, (0x36) }, ////6 key + { KEY_7, (0x37) }, ////7 key + { KEY_8, (0x38) }, ////8 key + { KEY_9, (0x39) }, ////9 key + { KEY_A, (0x41) }, ////A key + { KEY_B, (0x42) }, ////B key + { KEY_C, (0x43) }, ////C key + { KEY_D, (0x44) }, ////D key + { KEY_E, (0x45) }, ////E key + { KEY_F, (0x46) }, ////F key + { KEY_G, (0x47) }, ////G key + { KEY_H, (0x48) }, ////H key + { KEY_I, (0x49) }, ////I key + { KEY_J, (0x4A) }, ////J key + { KEY_K, (0x4B) }, ////K key + { KEY_L, (0x4C) }, ////L key + { KEY_M, (0x4D) }, ////M key + { KEY_N, (0x4E) }, ////N key + { KEY_O, (0x4F) }, ////O key + { KEY_P, (0x50) }, ////P key + { KEY_Q, (0x51) }, ////Q key + { KEY_R, (0x52) }, ////R key + { KEY_S, (0x53) }, ////S key + { KEY_T, (0x54) }, ////T key + { KEY_U, (0x55) }, ////U key + { KEY_V, (0x56) }, ////V key + { KEY_W, (0x57) }, ////W key + { KEY_X, (0x58) }, ////X key + { KEY_Y, (0x59) }, ////Y key + { KEY_Z, (0x5A) }, ////Z key -{ KEY_CONTROL, VK_CONTROL },//(0x11) - -{ KEY_MENU, VK_MENU },//(0x12) - -{ KEY_PAUSE, VK_PAUSE },//(0x13) - -{ KEY_CAPSLOCK, VK_CAPITAL },//(0x14) - -{ KEY_ESCAPE, VK_ESCAPE },//(0x1B) - -{ KEY_SPACE, VK_SPACE },//(0x20) - -{ KEY_PAGEUP,VK_PRIOR },//(0x21) - -{ KEY_PAGEDOWN, VK_NEXT },//(0x22) - -{ KEY_END, VK_END },//(0x23) - -{ KEY_HOME, VK_HOME },//(0x24) - -{ KEY_LEFT, VK_LEFT },//(0x25) - -{ KEY_UP, VK_UP },//(0x26) - -{ KEY_RIGHT,VK_RIGHT },//(0x27) - -{ KEY_DOWN, VK_DOWN},// (0x28) - -//VK_SELECT (0x29) - -{ KEY_PRINT, VK_PRINT},// (0x2A) - -//VK_EXECUTE (0x2B) - -{ KEY_PRINT, VK_SNAPSHOT},// (0x2C) - -{ KEY_INSERT, VK_INSERT},// (0x2D) - -{ KEY_DELETE, VK_DELETE},// (0x2E) - -{ KEY_HELP, VK_HELP},// (0x2F) - - -{ KEY_0, (0x30) },////0 key -{ KEY_1, (0x31) },////1 key -{ KEY_2, (0x32) },////2 key -{ KEY_3, (0x33) },////3 key -{ KEY_4, (0x34) },////4 key -{ KEY_5, (0x35) },////5 key -{ KEY_6, (0x36) },////6 key -{ KEY_7, (0x37) },////7 key -{ KEY_8, (0x38) },////8 key -{ KEY_9, (0x39) },////9 key -{ KEY_A, (0x41) },////A key -{ KEY_B, (0x42) },////B key -{ KEY_C, (0x43) },////C key -{ KEY_D, (0x44) },////D key -{ KEY_E, (0x45) },////E key -{ KEY_F, (0x46) },////F key -{ KEY_G, (0x47) },////G key -{ KEY_H, (0x48) },////H key -{ KEY_I, (0x49) },////I key -{ KEY_J, (0x4A) },////J key -{ KEY_K, (0x4B) },////K key -{ KEY_L, (0x4C) },////L key -{ KEY_M, (0x4D) },////M key -{ KEY_N, (0x4E) },////N key -{ KEY_O, (0x4F) },////O key -{ KEY_P, (0x50) },////P key -{ KEY_Q, (0x51) },////Q key -{ KEY_R, (0x52) },////R key -{ KEY_S, (0x53) },////S key -{ KEY_T, (0x54) },////T key -{ KEY_U, (0x55) },////U key -{ KEY_V, (0x56) },////V key -{ KEY_W, (0x57) },////W key -{ KEY_X, (0x58) },////X key -{ KEY_Y, (0x59) },////Y key -{ KEY_Z, (0x5A) },////Z key - -{ KEY_MASK_META, VK_LWIN },//(0x5B) -{ KEY_MASK_META, VK_RWIN },//(0x5C) -//VK_APPS (0x5D) -{ KEY_STANDBY,VK_SLEEP },//(0x5F) -{ KEY_KP_0,VK_NUMPAD0 },//(0x60) -{ KEY_KP_1,VK_NUMPAD1 },//(0x61) -{ KEY_KP_2,VK_NUMPAD2 },//(0x62) -{ KEY_KP_3,VK_NUMPAD3 },//(0x63) -{ KEY_KP_4,VK_NUMPAD4 },//(0x64) -{ KEY_KP_5,VK_NUMPAD5 },//(0x65) -{ KEY_KP_6,VK_NUMPAD6 },//(0x66) -{ KEY_KP_7,VK_NUMPAD7 },//(0x67) -{ KEY_KP_8,VK_NUMPAD8 },//(0x68) -{ KEY_KP_9,VK_NUMPAD9 },//(0x69) -{ KEY_KP_MULTIPLY,VK_MULTIPLY},// (0x6A) -{ KEY_KP_ADD,VK_ADD},// (0x6B) -//VK_SEPARATOR (0x6C) -{ KEY_KP_SUBTRACT,VK_SUBTRACT},// (0x6D) -{ KEY_KP_PERIOD,VK_DECIMAL},// (0x6E) -{ KEY_KP_DIVIDE,VK_DIVIDE},// (0x6F) -{ KEY_F1,VK_F1},// (0x70) -{ KEY_F2,VK_F2},// (0x71) -{ KEY_F3,VK_F3},// (0x72) -{ KEY_F4,VK_F4},// (0x73) -{ KEY_F5,VK_F5},// (0x74) -{ KEY_F6,VK_F6},// (0x75) -{ KEY_F7,VK_F7},// (0x76) -{ KEY_F8,VK_F8},// (0x77) -{ KEY_F9,VK_F9},// (0x78) -{ KEY_F10,VK_F10},// (0x79) -{ KEY_F11,VK_F11},// (0x7A) -{ KEY_F12,VK_F12},// (0x7B) -{ KEY_F13,VK_F13},// (0x7C) -{ KEY_F14,VK_F14},// (0x7D) -{ KEY_F15,VK_F15},// (0x7E) -{ KEY_F16,VK_F16},// (0x7F) -{ KEY_NUMLOCK,VK_NUMLOCK},// (0x90) -{ KEY_SCROLLLOCK,VK_SCROLL},// (0x91) -{ KEY_SHIFT,VK_LSHIFT},// (0xA0) -{ KEY_SHIFT,VK_RSHIFT},// (0xA1) -{ KEY_CONTROL,VK_LCONTROL},// (0xA2) -{ KEY_CONTROL,VK_RCONTROL},// (0xA3) -{ KEY_MENU,VK_LMENU},// (0xA4) -{ KEY_MENU,VK_RMENU},// (0xA5) - - -{ KEY_BACK,VK_BROWSER_BACK},// (0xA6) - -{ KEY_FORWARD,VK_BROWSER_FORWARD},// (0xA7) - -{ KEY_REFRESH,VK_BROWSER_REFRESH},// (0xA8) - -{ KEY_STOP,VK_BROWSER_STOP},// (0xA9) - -{ KEY_SEARCH,VK_BROWSER_SEARCH},// (0xAA) - -{ KEY_FAVORITES, VK_BROWSER_FAVORITES},// (0xAB) - -{ KEY_HOMEPAGE,VK_BROWSER_HOME},// (0xAC) - -{ KEY_VOLUMEMUTE,VK_VOLUME_MUTE},// (0xAD) - -{ KEY_VOLUMEDOWN,VK_VOLUME_DOWN},// (0xAE) - -{ KEY_VOLUMEUP,VK_VOLUME_UP},// (0xAF) - - -{ KEY_MEDIANEXT,VK_MEDIA_NEXT_TRACK},// (0xB0) - -{ KEY_MEDIAPREVIOUS,VK_MEDIA_PREV_TRACK},// (0xB1) - -{ KEY_MEDIASTOP,VK_MEDIA_STOP},// (0xB2) - -//VK_MEDIA_PLAY_PAUSE (0xB3) - -{ KEY_LAUNCHMAIL, VK_LAUNCH_MAIL},// (0xB4) - -{ KEY_LAUNCHMEDIA,VK_LAUNCH_MEDIA_SELECT},// (0xB5) - -{ KEY_LAUNCH0,VK_LAUNCH_APP1},// (0xB6) - -{ KEY_LAUNCH1,VK_LAUNCH_APP2},// (0xB7) - -{ KEY_SEMICOLON,VK_OEM_1},// (0xBA) - - -{ KEY_EQUAL, VK_OEM_PLUS},// (0xBB) // Windows 2000/XP: For any country/region, the '+' key -{ KEY_COLON,VK_OEM_COMMA},// (0xBC) // Windows 2000/XP: For any country/region, the ',' key -{ KEY_MINUS,VK_OEM_MINUS},// (0xBD) // Windows 2000/XP: For any country/region, the '-' key -{ KEY_PERIOD,VK_OEM_PERIOD},// (0xBE) // Windows 2000/XP: For any country/region, the '.' key -{ KEY_SLASH,VK_OEM_2},// (0xBF) //Windows 2000/XP: For the US standard keyboard, the '/?' key - -{KEY_QUOTELEFT, VK_OEM_3},// (0xC0) -{KEY_BRACELEFT,VK_OEM_4},// (0xDB) -{KEY_BACKSLASH,VK_OEM_5},// (0xDC) -{KEY_BRACERIGHT,VK_OEM_6},// (0xDD) -{KEY_APOSTROPHE, VK_OEM_7},// (0xDE) -/* + { KEY_MASK_META, VK_LWIN }, //(0x5B) + { KEY_MASK_META, VK_RWIN }, //(0x5C) + //VK_APPS (0x5D) + { KEY_STANDBY, VK_SLEEP }, //(0x5F) + { KEY_KP_0, VK_NUMPAD0 }, //(0x60) + { KEY_KP_1, VK_NUMPAD1 }, //(0x61) + { KEY_KP_2, VK_NUMPAD2 }, //(0x62) + { KEY_KP_3, VK_NUMPAD3 }, //(0x63) + { KEY_KP_4, VK_NUMPAD4 }, //(0x64) + { KEY_KP_5, VK_NUMPAD5 }, //(0x65) + { KEY_KP_6, VK_NUMPAD6 }, //(0x66) + { KEY_KP_7, VK_NUMPAD7 }, //(0x67) + { KEY_KP_8, VK_NUMPAD8 }, //(0x68) + { KEY_KP_9, VK_NUMPAD9 }, //(0x69) + { KEY_KP_MULTIPLY, VK_MULTIPLY }, // (0x6A) + { KEY_KP_ADD, VK_ADD }, // (0x6B) + //VK_SEPARATOR (0x6C) + { KEY_KP_SUBTRACT, VK_SUBTRACT }, // (0x6D) + { KEY_KP_PERIOD, VK_DECIMAL }, // (0x6E) + { KEY_KP_DIVIDE, VK_DIVIDE }, // (0x6F) + { KEY_F1, VK_F1 }, // (0x70) + { KEY_F2, VK_F2 }, // (0x71) + { KEY_F3, VK_F3 }, // (0x72) + { KEY_F4, VK_F4 }, // (0x73) + { KEY_F5, VK_F5 }, // (0x74) + { KEY_F6, VK_F6 }, // (0x75) + { KEY_F7, VK_F7 }, // (0x76) + { KEY_F8, VK_F8 }, // (0x77) + { KEY_F9, VK_F9 }, // (0x78) + { KEY_F10, VK_F10 }, // (0x79) + { KEY_F11, VK_F11 }, // (0x7A) + { KEY_F12, VK_F12 }, // (0x7B) + { KEY_F13, VK_F13 }, // (0x7C) + { KEY_F14, VK_F14 }, // (0x7D) + { KEY_F15, VK_F15 }, // (0x7E) + { KEY_F16, VK_F16 }, // (0x7F) + { KEY_NUMLOCK, VK_NUMLOCK }, // (0x90) + { KEY_SCROLLLOCK, VK_SCROLL }, // (0x91) + { KEY_SHIFT, VK_LSHIFT }, // (0xA0) + { KEY_SHIFT, VK_RSHIFT }, // (0xA1) + { KEY_CONTROL, VK_LCONTROL }, // (0xA2) + { KEY_CONTROL, VK_RCONTROL }, // (0xA3) + { KEY_MENU, VK_LMENU }, // (0xA4) + { KEY_MENU, VK_RMENU }, // (0xA5) + + { KEY_BACK, VK_BROWSER_BACK }, // (0xA6) + + { KEY_FORWARD, VK_BROWSER_FORWARD }, // (0xA7) + + { KEY_REFRESH, VK_BROWSER_REFRESH }, // (0xA8) + + { KEY_STOP, VK_BROWSER_STOP }, // (0xA9) + + { KEY_SEARCH, VK_BROWSER_SEARCH }, // (0xAA) + + { KEY_FAVORITES, VK_BROWSER_FAVORITES }, // (0xAB) + + { KEY_HOMEPAGE, VK_BROWSER_HOME }, // (0xAC) + + { KEY_VOLUMEMUTE, VK_VOLUME_MUTE }, // (0xAD) + + { KEY_VOLUMEDOWN, VK_VOLUME_DOWN }, // (0xAE) + + { KEY_VOLUMEUP, VK_VOLUME_UP }, // (0xAF) + + { KEY_MEDIANEXT, VK_MEDIA_NEXT_TRACK }, // (0xB0) + + { KEY_MEDIAPREVIOUS, VK_MEDIA_PREV_TRACK }, // (0xB1) + + { KEY_MEDIASTOP, VK_MEDIA_STOP }, // (0xB2) + + //VK_MEDIA_PLAY_PAUSE (0xB3) + + { KEY_LAUNCHMAIL, VK_LAUNCH_MAIL }, // (0xB4) + + { KEY_LAUNCHMEDIA, VK_LAUNCH_MEDIA_SELECT }, // (0xB5) + + { KEY_LAUNCH0, VK_LAUNCH_APP1 }, // (0xB6) + + { KEY_LAUNCH1, VK_LAUNCH_APP2 }, // (0xB7) + + { KEY_SEMICOLON, VK_OEM_1 }, // (0xBA) + + { KEY_EQUAL, VK_OEM_PLUS }, // (0xBB) // Windows 2000/XP: For any country/region, the '+' key + { KEY_COLON, VK_OEM_COMMA }, // (0xBC) // Windows 2000/XP: For any country/region, the ',' key + { KEY_MINUS, VK_OEM_MINUS }, // (0xBD) // Windows 2000/XP: For any country/region, the '-' key + { KEY_PERIOD, VK_OEM_PERIOD }, // (0xBE) // Windows 2000/XP: For any country/region, the '.' key + { KEY_SLASH, VK_OEM_2 }, // (0xBF) //Windows 2000/XP: For the US standard keyboard, the '/?' key + + { KEY_QUOTELEFT, VK_OEM_3 }, // (0xC0) + { KEY_BRACELEFT, VK_OEM_4 }, // (0xDB) + { KEY_BACKSLASH, VK_OEM_5 }, // (0xDC) + { KEY_BRACERIGHT, VK_OEM_6 }, // (0xDD) + { KEY_APOSTROPHE, VK_OEM_7 }, // (0xDE) + /* {VK_OEM_8 (0xDF) {VK_OEM_102 (0xE2) // Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard */ -//{ KEY_PLAY, VK_PLAY},// (0xFA) + //{ KEY_PLAY, VK_PLAY},// (0xFA) -{KEY_UNKNOWN, 0} }; + { KEY_UNKNOWN, 0 } +}; /* VK_ZOOM (0xFB) @@ -242,15 +238,14 @@ VK_OEM_CLEAR (0xFE) unsigned int KeyMappingWindows::get_keysym(unsigned int p_code) { - for(int i=0;_vk_to_keycode[i].keysym!=KEY_UNKNOWN;i++) { + for (int i = 0; _vk_to_keycode[i].keysym != KEY_UNKNOWN; i++) { - if (_vk_to_keycode[i].keycode==p_code) { + if (_vk_to_keycode[i].keycode == p_code) { //printf("outcode: %x\n",_vk_to_keycode[i].keysym); return _vk_to_keycode[i].keysym; } } - return KEY_UNKNOWN; } diff --git a/platform/windows/key_mapping_win.h b/platform/windows/key_mapping_win.h index 2f1b36d9f2..fbc79635c2 100644 --- a/platform/windows/key_mapping_win.h +++ b/platform/windows/key_mapping_win.h @@ -29,23 +29,18 @@ #ifndef KEY_MAPPING_WINDOWS_H #define KEY_MAPPING_WINDOWS_H - #include "os/keyboard.h" #include <windows.h> #include <winuser.h> - class KeyMappingWindows { - KeyMappingWindows() {}; -public: + KeyMappingWindows(){}; +public: static unsigned int get_keysym(unsigned int p_code); - }; - - #endif diff --git a/platform/windows/lang_table.h b/platform/windows/lang_table.h index bacbf89e85..7fe509d3e0 100644 --- a/platform/windows/lang_table.h +++ b/platform/windows/lang_table.h @@ -37,154 +37,154 @@ struct _WinLocale { int sublang; }; -static const _WinLocale _win_locales[]={ -{"ar", LANG_ARABIC,SUBLANG_NEUTRAL}, -{"ar_AE", LANG_ARABIC,SUBLANG_ARABIC_UAE}, -{"ar_BH", LANG_ARABIC,SUBLANG_ARABIC_BAHRAIN}, -{"ar_DZ", LANG_ARABIC,SUBLANG_ARABIC_ALGERIA}, -{"ar_EG", LANG_ARABIC,SUBLANG_ARABIC_EGYPT}, -{"ar_IQ", LANG_ARABIC,SUBLANG_ARABIC_IRAQ}, -{"ar_JO", LANG_ARABIC,SUBLANG_ARABIC_JORDAN}, -{"ar_KW", LANG_ARABIC,SUBLANG_ARABIC_KUWAIT}, -{"ar_LB", LANG_ARABIC,SUBLANG_ARABIC_LEBANON}, -{"ar_LY", LANG_ARABIC,SUBLANG_ARABIC_LIBYA}, -{"ar_MA", LANG_ARABIC,SUBLANG_ARABIC_MOROCCO}, -{"ar_OM", LANG_ARABIC,SUBLANG_ARABIC_OMAN}, -{"ar_QA", LANG_ARABIC,SUBLANG_ARABIC_QATAR}, -{"ar_SA", LANG_ARABIC,SUBLANG_ARABIC_SAUDI_ARABIA}, -//no sudan -{"ar_SY", LANG_ARABIC,SUBLANG_ARABIC_SYRIA}, -{"ar_TN", LANG_ARABIC,SUBLANG_ARABIC_TUNISIA}, -{"ar_YE", LANG_ARABIC,SUBLANG_ARABIC_YEMEN}, -{"be", LANG_BELARUSIAN,SUBLANG_NEUTRAL}, -{"be_BY", LANG_BELARUSIAN,SUBLANG_BELARUSIAN_BELARUS}, -{"bg", LANG_BULGARIAN,SUBLANG_NEUTRAL}, -{"bg_BG", LANG_BULGARIAN,SUBLANG_BULGARIAN_BULGARIA}, -{"ca", LANG_CATALAN,SUBLANG_NEUTRAL}, -{"ca_ES", LANG_CATALAN,SUBLANG_CATALAN_CATALAN}, -{"cs", LANG_CZECH,SUBLANG_NEUTRAL}, -{"cs_CZ", LANG_CZECH,SUBLANG_CZECH_CZECH_REPUBLIC}, -{"da", LANG_DANISH,SUBLANG_NEUTRAL}, -{"da_DK", LANG_DANISH,SUBLANG_DANISH_DENMARK}, -{"de", LANG_GERMAN,SUBLANG_NEUTRAL}, -{"de_AT", LANG_GERMAN,SUBLANG_GERMAN_AUSTRIAN}, -{"de_CH", LANG_GERMAN,SUBLANG_GERMAN_SWISS}, -{"de_DE", LANG_GERMAN,SUBLANG_GERMAN}, -{"de_LU", LANG_GERMAN,SUBLANG_GERMAN_LUXEMBOURG}, -{"el", LANG_GREEK,SUBLANG_NEUTRAL}, -{"el_GR", LANG_GREEK,SUBLANG_GREEK_GREECE}, -//{"en_029", LANG_ENGLISH,SUBLANG_ENGLISH_CARIBBEAN}, -{"en", LANG_ENGLISH,SUBLANG_NEUTRAL}, -{"en_AU", LANG_ENGLISH,SUBLANG_ENGLISH_AUS}, -{"en_CA", LANG_ENGLISH,SUBLANG_ENGLISH_CAN}, -{"en_GB", LANG_ENGLISH,SUBLANG_ENGLISH_UK}, -//{"en_IE", LANG_ENGLISH,SUBLANG_ENGLISH_IRELAND}, -{"en_IN", LANG_ENGLISH,SUBLANG_ENGLISH_INDIA}, -//MT -{"en_NZ", LANG_ENGLISH,SUBLANG_ENGLISH_NZ}, -{"en_PH", LANG_ENGLISH,SUBLANG_ENGLISH_PHILIPPINES}, -{"en_SG", LANG_ENGLISH,SUBLANG_ENGLISH_SINGAPORE}, -{"en_US", LANG_ENGLISH,SUBLANG_ENGLISH_US}, -{"en_ZA", LANG_ENGLISH,SUBLANG_ENGLISH_SOUTH_AFRICA}, -{"es", LANG_SPANISH,SUBLANG_NEUTRAL}, -{"es_AR", LANG_SPANISH,SUBLANG_SPANISH_ARGENTINA}, -{"es_BO", LANG_SPANISH,SUBLANG_SPANISH_BOLIVIA}, -{"es_CL", LANG_SPANISH,SUBLANG_SPANISH_CHILE}, -{"es_CO", LANG_SPANISH,SUBLANG_SPANISH_COLOMBIA}, -{"es_CR", LANG_SPANISH,SUBLANG_SPANISH_COSTA_RICA}, -{"es_DO", LANG_SPANISH,SUBLANG_SPANISH_DOMINICAN_REPUBLIC}, -{"es_EC", LANG_SPANISH,SUBLANG_SPANISH_ECUADOR}, -{"es_ES", LANG_SPANISH,SUBLANG_SPANISH}, -{"es_GT", LANG_SPANISH,SUBLANG_SPANISH_GUATEMALA}, -{"es_HN", LANG_SPANISH,SUBLANG_SPANISH_HONDURAS}, -{"es_MX", LANG_SPANISH,SUBLANG_SPANISH_MEXICAN}, -{"es_NI", LANG_SPANISH,SUBLANG_SPANISH_NICARAGUA}, -{"es_PA", LANG_SPANISH,SUBLANG_SPANISH_PANAMA}, -{"es_PE", LANG_SPANISH,SUBLANG_SPANISH_PERU}, -{"es_PR", LANG_SPANISH,SUBLANG_SPANISH_PUERTO_RICO}, -{"es_PY", LANG_SPANISH,SUBLANG_SPANISH_PARAGUAY}, -{"es_SV", LANG_SPANISH,SUBLANG_SPANISH_EL_SALVADOR}, -{"es_US", LANG_SPANISH,SUBLANG_SPANISH_US}, -{"es_UY", LANG_SPANISH,SUBLANG_SPANISH_URUGUAY}, -{"es_VE", LANG_SPANISH,SUBLANG_SPANISH_VENEZUELA}, -{"et", LANG_ESTONIAN,SUBLANG_NEUTRAL}, -{"et_EE", LANG_ESTONIAN,SUBLANG_ESTONIAN_ESTONIA}, -{"fi", LANG_FINNISH,SUBLANG_NEUTRAL}, -{"fi_FI", LANG_FINNISH,SUBLANG_FINNISH_FINLAND}, -{"fr", LANG_FRENCH,SUBLANG_NEUTRAL}, -{"fr_BE", LANG_FRENCH,SUBLANG_FRENCH_BELGIAN}, -{"fr_CA", LANG_FRENCH,SUBLANG_FRENCH_CANADIAN}, -{"fr_CH", LANG_FRENCH,SUBLANG_FRENCH_SWISS}, -{"fr_FR", LANG_FRENCH,SUBLANG_FRENCH}, -{"fr_LU", LANG_FRENCH,SUBLANG_FRENCH_LUXEMBOURG}, -{"ga", LANG_IRISH,SUBLANG_NEUTRAL}, -{"ga_IE", LANG_IRISH,SUBLANG_IRISH_IRELAND}, -{"hi", LANG_HINDI,SUBLANG_NEUTRAL}, -{"hi_IN", LANG_HINDI,SUBLANG_HINDI_INDIA}, -{"hr", LANG_CROATIAN,SUBLANG_NEUTRAL}, -{"hr_HR", LANG_CROATIAN,SUBLANG_CROATIAN_CROATIA}, -{"hu", LANG_HUNGARIAN,SUBLANG_NEUTRAL}, -{"hu_HU", LANG_HUNGARIAN,SUBLANG_HUNGARIAN_HUNGARY}, -{"in", LANG_ARMENIAN,SUBLANG_NEUTRAL}, -{"in_ID", LANG_INDONESIAN,SUBLANG_INDONESIAN_INDONESIA}, -{"is", LANG_ICELANDIC,SUBLANG_NEUTRAL}, -{"is_IS", LANG_ICELANDIC,SUBLANG_ICELANDIC_ICELAND}, -{"it", LANG_ITALIAN,SUBLANG_NEUTRAL}, -{"it_CH", LANG_ITALIAN,SUBLANG_ITALIAN_SWISS}, -{"it_IT", LANG_ITALIAN,SUBLANG_ITALIAN}, -{"iw", LANG_HEBREW,SUBLANG_NEUTRAL}, -{"iw_IL", LANG_HEBREW,SUBLANG_HEBREW_ISRAEL}, -{"ja", LANG_JAPANESE,SUBLANG_NEUTRAL}, -{"ja_JP", LANG_JAPANESE,SUBLANG_JAPANESE_JAPAN}, -{"ko", LANG_KOREAN,SUBLANG_NEUTRAL}, -{"ko_KR", LANG_KOREAN,SUBLANG_KOREAN}, -{"lt", LANG_LITHUANIAN,SUBLANG_NEUTRAL}, -//{"lt_LT", LANG_LITHUANIAN,SUBLANG_LITHUANIAN_LITHUANIA}, -{"lv", LANG_LATVIAN,SUBLANG_NEUTRAL}, -{"lv_LV", LANG_LATVIAN,SUBLANG_LATVIAN_LATVIA}, -{"mk", LANG_MACEDONIAN,SUBLANG_NEUTRAL}, -{"mk_MK", LANG_MACEDONIAN,SUBLANG_MACEDONIAN_MACEDONIA}, -{"ms", LANG_MALAY,SUBLANG_NEUTRAL}, -{"ms_MY", LANG_MALAY,SUBLANG_MALAY_MALAYSIA}, -{"mt", LANG_MALTESE,SUBLANG_NEUTRAL}, -{"mt_MT", LANG_MALTESE,SUBLANG_MALTESE_MALTA}, -{"nl", LANG_DUTCH,SUBLANG_NEUTRAL}, -{"nl_BE", LANG_DUTCH,SUBLANG_DUTCH_BELGIAN}, -{"nl_NL", LANG_DUTCH,SUBLANG_DUTCH}, -{"no", LANG_NORWEGIAN,SUBLANG_NEUTRAL}, -{"no_NO", LANG_NORWEGIAN,SUBLANG_NORWEGIAN_BOKMAL}, -{"no_NO_NY", LANG_NORWEGIAN,SUBLANG_NORWEGIAN_NYNORSK}, -{"pl", LANG_POLISH,SUBLANG_NEUTRAL}, -{"pl_PL", LANG_POLISH,SUBLANG_POLISH_POLAND}, -{"pt", LANG_PORTUGUESE,SUBLANG_NEUTRAL}, -{"pt_BR", LANG_PORTUGUESE,SUBLANG_PORTUGUESE_BRAZILIAN}, -{"pt_PT", LANG_PORTUGUESE,SUBLANG_PORTUGUESE}, -{"ro", LANG_ROMANIAN,SUBLANG_NEUTRAL}, -{"ro_RO", LANG_ROMANIAN,SUBLANG_ROMANIAN_ROMANIA}, -{"ru", LANG_RUSSIAN,SUBLANG_NEUTRAL}, -{"ru_RU", LANG_RUSSIAN,SUBLANG_RUSSIAN_RUSSIA}, -{"sk", LANG_SLOVAK,SUBLANG_NEUTRAL}, -{"sk_SK", LANG_SLOVAK,SUBLANG_SLOVAK_SLOVAKIA}, -{"sl", LANG_SLOVENIAN,SUBLANG_NEUTRAL}, -{"sl_SI", LANG_SLOVENIAN,SUBLANG_SLOVENIAN_SLOVENIA}, -{"sq", LANG_ALBANIAN,SUBLANG_NEUTRAL}, -{"sq_AL", LANG_ALBANIAN,SUBLANG_ALBANIAN_ALBANIA}, -{"sr", LANG_SERBIAN_NEUTRAL,SUBLANG_NEUTRAL}, -{"sv", LANG_SWEDISH,SUBLANG_NEUTRAL}, -{"sv_SE", LANG_SWEDISH,SUBLANG_SWEDISH}, -{"th", LANG_THAI,SUBLANG_NEUTRAL}, -{"th_TH", LANG_THAI,SUBLANG_THAI_THAILAND}, -{"tr", LANG_TURKISH,SUBLANG_NEUTRAL}, -{"tr_TR", LANG_TURKISH,SUBLANG_TURKISH_TURKEY}, -{"uk", LANG_UKRAINIAN,SUBLANG_NEUTRAL}, -{"uk_UA", LANG_UKRAINIAN,SUBLANG_UKRAINIAN_UKRAINE}, -{"vi", LANG_VIETNAMESE,SUBLANG_NEUTRAL}, -{"vi_VN", LANG_VIETNAMESE,SUBLANG_VIETNAMESE_VIETNAM}, -{"zh", LANG_CHINESE,SUBLANG_NEUTRAL}, -{"zh_CN", LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED}, -{"zh_HK", LANG_CHINESE,SUBLANG_CHINESE_HONGKONG}, -{"zh_SG", LANG_CHINESE,SUBLANG_CHINESE_SINGAPORE}, -{0, 0,0}, +static const _WinLocale _win_locales[] = { + { "ar", LANG_ARABIC, SUBLANG_NEUTRAL }, + { "ar_AE", LANG_ARABIC, SUBLANG_ARABIC_UAE }, + { "ar_BH", LANG_ARABIC, SUBLANG_ARABIC_BAHRAIN }, + { "ar_DZ", LANG_ARABIC, SUBLANG_ARABIC_ALGERIA }, + { "ar_EG", LANG_ARABIC, SUBLANG_ARABIC_EGYPT }, + { "ar_IQ", LANG_ARABIC, SUBLANG_ARABIC_IRAQ }, + { "ar_JO", LANG_ARABIC, SUBLANG_ARABIC_JORDAN }, + { "ar_KW", LANG_ARABIC, SUBLANG_ARABIC_KUWAIT }, + { "ar_LB", LANG_ARABIC, SUBLANG_ARABIC_LEBANON }, + { "ar_LY", LANG_ARABIC, SUBLANG_ARABIC_LIBYA }, + { "ar_MA", LANG_ARABIC, SUBLANG_ARABIC_MOROCCO }, + { "ar_OM", LANG_ARABIC, SUBLANG_ARABIC_OMAN }, + { "ar_QA", LANG_ARABIC, SUBLANG_ARABIC_QATAR }, + { "ar_SA", LANG_ARABIC, SUBLANG_ARABIC_SAUDI_ARABIA }, + //no sudan + { "ar_SY", LANG_ARABIC, SUBLANG_ARABIC_SYRIA }, + { "ar_TN", LANG_ARABIC, SUBLANG_ARABIC_TUNISIA }, + { "ar_YE", LANG_ARABIC, SUBLANG_ARABIC_YEMEN }, + { "be", LANG_BELARUSIAN, SUBLANG_NEUTRAL }, + { "be_BY", LANG_BELARUSIAN, SUBLANG_BELARUSIAN_BELARUS }, + { "bg", LANG_BULGARIAN, SUBLANG_NEUTRAL }, + { "bg_BG", LANG_BULGARIAN, SUBLANG_BULGARIAN_BULGARIA }, + { "ca", LANG_CATALAN, SUBLANG_NEUTRAL }, + { "ca_ES", LANG_CATALAN, SUBLANG_CATALAN_CATALAN }, + { "cs", LANG_CZECH, SUBLANG_NEUTRAL }, + { "cs_CZ", LANG_CZECH, SUBLANG_CZECH_CZECH_REPUBLIC }, + { "da", LANG_DANISH, SUBLANG_NEUTRAL }, + { "da_DK", LANG_DANISH, SUBLANG_DANISH_DENMARK }, + { "de", LANG_GERMAN, SUBLANG_NEUTRAL }, + { "de_AT", LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN }, + { "de_CH", LANG_GERMAN, SUBLANG_GERMAN_SWISS }, + { "de_DE", LANG_GERMAN, SUBLANG_GERMAN }, + { "de_LU", LANG_GERMAN, SUBLANG_GERMAN_LUXEMBOURG }, + { "el", LANG_GREEK, SUBLANG_NEUTRAL }, + { "el_GR", LANG_GREEK, SUBLANG_GREEK_GREECE }, + //{"en_029", LANG_ENGLISH,SUBLANG_ENGLISH_CARIBBEAN}, + { "en", LANG_ENGLISH, SUBLANG_NEUTRAL }, + { "en_AU", LANG_ENGLISH, SUBLANG_ENGLISH_AUS }, + { "en_CA", LANG_ENGLISH, SUBLANG_ENGLISH_CAN }, + { "en_GB", LANG_ENGLISH, SUBLANG_ENGLISH_UK }, + //{"en_IE", LANG_ENGLISH,SUBLANG_ENGLISH_IRELAND}, + { "en_IN", LANG_ENGLISH, SUBLANG_ENGLISH_INDIA }, + //MT + { "en_NZ", LANG_ENGLISH, SUBLANG_ENGLISH_NZ }, + { "en_PH", LANG_ENGLISH, SUBLANG_ENGLISH_PHILIPPINES }, + { "en_SG", LANG_ENGLISH, SUBLANG_ENGLISH_SINGAPORE }, + { "en_US", LANG_ENGLISH, SUBLANG_ENGLISH_US }, + { "en_ZA", LANG_ENGLISH, SUBLANG_ENGLISH_SOUTH_AFRICA }, + { "es", LANG_SPANISH, SUBLANG_NEUTRAL }, + { "es_AR", LANG_SPANISH, SUBLANG_SPANISH_ARGENTINA }, + { "es_BO", LANG_SPANISH, SUBLANG_SPANISH_BOLIVIA }, + { "es_CL", LANG_SPANISH, SUBLANG_SPANISH_CHILE }, + { "es_CO", LANG_SPANISH, SUBLANG_SPANISH_COLOMBIA }, + { "es_CR", LANG_SPANISH, SUBLANG_SPANISH_COSTA_RICA }, + { "es_DO", LANG_SPANISH, SUBLANG_SPANISH_DOMINICAN_REPUBLIC }, + { "es_EC", LANG_SPANISH, SUBLANG_SPANISH_ECUADOR }, + { "es_ES", LANG_SPANISH, SUBLANG_SPANISH }, + { "es_GT", LANG_SPANISH, SUBLANG_SPANISH_GUATEMALA }, + { "es_HN", LANG_SPANISH, SUBLANG_SPANISH_HONDURAS }, + { "es_MX", LANG_SPANISH, SUBLANG_SPANISH_MEXICAN }, + { "es_NI", LANG_SPANISH, SUBLANG_SPANISH_NICARAGUA }, + { "es_PA", LANG_SPANISH, SUBLANG_SPANISH_PANAMA }, + { "es_PE", LANG_SPANISH, SUBLANG_SPANISH_PERU }, + { "es_PR", LANG_SPANISH, SUBLANG_SPANISH_PUERTO_RICO }, + { "es_PY", LANG_SPANISH, SUBLANG_SPANISH_PARAGUAY }, + { "es_SV", LANG_SPANISH, SUBLANG_SPANISH_EL_SALVADOR }, + { "es_US", LANG_SPANISH, SUBLANG_SPANISH_US }, + { "es_UY", LANG_SPANISH, SUBLANG_SPANISH_URUGUAY }, + { "es_VE", LANG_SPANISH, SUBLANG_SPANISH_VENEZUELA }, + { "et", LANG_ESTONIAN, SUBLANG_NEUTRAL }, + { "et_EE", LANG_ESTONIAN, SUBLANG_ESTONIAN_ESTONIA }, + { "fi", LANG_FINNISH, SUBLANG_NEUTRAL }, + { "fi_FI", LANG_FINNISH, SUBLANG_FINNISH_FINLAND }, + { "fr", LANG_FRENCH, SUBLANG_NEUTRAL }, + { "fr_BE", LANG_FRENCH, SUBLANG_FRENCH_BELGIAN }, + { "fr_CA", LANG_FRENCH, SUBLANG_FRENCH_CANADIAN }, + { "fr_CH", LANG_FRENCH, SUBLANG_FRENCH_SWISS }, + { "fr_FR", LANG_FRENCH, SUBLANG_FRENCH }, + { "fr_LU", LANG_FRENCH, SUBLANG_FRENCH_LUXEMBOURG }, + { "ga", LANG_IRISH, SUBLANG_NEUTRAL }, + { "ga_IE", LANG_IRISH, SUBLANG_IRISH_IRELAND }, + { "hi", LANG_HINDI, SUBLANG_NEUTRAL }, + { "hi_IN", LANG_HINDI, SUBLANG_HINDI_INDIA }, + { "hr", LANG_CROATIAN, SUBLANG_NEUTRAL }, + { "hr_HR", LANG_CROATIAN, SUBLANG_CROATIAN_CROATIA }, + { "hu", LANG_HUNGARIAN, SUBLANG_NEUTRAL }, + { "hu_HU", LANG_HUNGARIAN, SUBLANG_HUNGARIAN_HUNGARY }, + { "in", LANG_ARMENIAN, SUBLANG_NEUTRAL }, + { "in_ID", LANG_INDONESIAN, SUBLANG_INDONESIAN_INDONESIA }, + { "is", LANG_ICELANDIC, SUBLANG_NEUTRAL }, + { "is_IS", LANG_ICELANDIC, SUBLANG_ICELANDIC_ICELAND }, + { "it", LANG_ITALIAN, SUBLANG_NEUTRAL }, + { "it_CH", LANG_ITALIAN, SUBLANG_ITALIAN_SWISS }, + { "it_IT", LANG_ITALIAN, SUBLANG_ITALIAN }, + { "iw", LANG_HEBREW, SUBLANG_NEUTRAL }, + { "iw_IL", LANG_HEBREW, SUBLANG_HEBREW_ISRAEL }, + { "ja", LANG_JAPANESE, SUBLANG_NEUTRAL }, + { "ja_JP", LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN }, + { "ko", LANG_KOREAN, SUBLANG_NEUTRAL }, + { "ko_KR", LANG_KOREAN, SUBLANG_KOREAN }, + { "lt", LANG_LITHUANIAN, SUBLANG_NEUTRAL }, + //{"lt_LT", LANG_LITHUANIAN,SUBLANG_LITHUANIAN_LITHUANIA}, + { "lv", LANG_LATVIAN, SUBLANG_NEUTRAL }, + { "lv_LV", LANG_LATVIAN, SUBLANG_LATVIAN_LATVIA }, + { "mk", LANG_MACEDONIAN, SUBLANG_NEUTRAL }, + { "mk_MK", LANG_MACEDONIAN, SUBLANG_MACEDONIAN_MACEDONIA }, + { "ms", LANG_MALAY, SUBLANG_NEUTRAL }, + { "ms_MY", LANG_MALAY, SUBLANG_MALAY_MALAYSIA }, + { "mt", LANG_MALTESE, SUBLANG_NEUTRAL }, + { "mt_MT", LANG_MALTESE, SUBLANG_MALTESE_MALTA }, + { "nl", LANG_DUTCH, SUBLANG_NEUTRAL }, + { "nl_BE", LANG_DUTCH, SUBLANG_DUTCH_BELGIAN }, + { "nl_NL", LANG_DUTCH, SUBLANG_DUTCH }, + { "no", LANG_NORWEGIAN, SUBLANG_NEUTRAL }, + { "no_NO", LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL }, + { "no_NO_NY", LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK }, + { "pl", LANG_POLISH, SUBLANG_NEUTRAL }, + { "pl_PL", LANG_POLISH, SUBLANG_POLISH_POLAND }, + { "pt", LANG_PORTUGUESE, SUBLANG_NEUTRAL }, + { "pt_BR", LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN }, + { "pt_PT", LANG_PORTUGUESE, SUBLANG_PORTUGUESE }, + { "ro", LANG_ROMANIAN, SUBLANG_NEUTRAL }, + { "ro_RO", LANG_ROMANIAN, SUBLANG_ROMANIAN_ROMANIA }, + { "ru", LANG_RUSSIAN, SUBLANG_NEUTRAL }, + { "ru_RU", LANG_RUSSIAN, SUBLANG_RUSSIAN_RUSSIA }, + { "sk", LANG_SLOVAK, SUBLANG_NEUTRAL }, + { "sk_SK", LANG_SLOVAK, SUBLANG_SLOVAK_SLOVAKIA }, + { "sl", LANG_SLOVENIAN, SUBLANG_NEUTRAL }, + { "sl_SI", LANG_SLOVENIAN, SUBLANG_SLOVENIAN_SLOVENIA }, + { "sq", LANG_ALBANIAN, SUBLANG_NEUTRAL }, + { "sq_AL", LANG_ALBANIAN, SUBLANG_ALBANIAN_ALBANIA }, + { "sr", LANG_SERBIAN_NEUTRAL, SUBLANG_NEUTRAL }, + { "sv", LANG_SWEDISH, SUBLANG_NEUTRAL }, + { "sv_SE", LANG_SWEDISH, SUBLANG_SWEDISH }, + { "th", LANG_THAI, SUBLANG_NEUTRAL }, + { "th_TH", LANG_THAI, SUBLANG_THAI_THAILAND }, + { "tr", LANG_TURKISH, SUBLANG_NEUTRAL }, + { "tr_TR", LANG_TURKISH, SUBLANG_TURKISH_TURKEY }, + { "uk", LANG_UKRAINIAN, SUBLANG_NEUTRAL }, + { "uk_UA", LANG_UKRAINIAN, SUBLANG_UKRAINIAN_UKRAINE }, + { "vi", LANG_VIETNAMESE, SUBLANG_NEUTRAL }, + { "vi_VN", LANG_VIETNAMESE, SUBLANG_VIETNAMESE_VIETNAM }, + { "zh", LANG_CHINESE, SUBLANG_NEUTRAL }, + { "zh_CN", LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED }, + { "zh_HK", LANG_CHINESE, SUBLANG_CHINESE_HONGKONG }, + { "zh_SG", LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE }, + { 0, 0, 0 }, }; #endif // LANG_TABLE_H diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 8a347e5f32..2046ae9f44 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -30,35 +30,35 @@ #include "os_windows.h" #include "drivers/gles3/rasterizer_gles3.h" -#include "drivers/windows/thread_windows.h" -#include "drivers/windows/semaphore_windows.h" +#include "drivers/windows/dir_access_windows.h" +#include "drivers/windows/file_access_windows.h" #include "drivers/windows/mutex_windows.h" #include "drivers/windows/rw_lock_windows.h" -#include "drivers/windows/file_access_windows.h" -#include "drivers/windows/dir_access_windows.h" -#include "servers/visual/visual_server_raster.h" +#include "drivers/windows/semaphore_windows.h" +#include "drivers/windows/thread_windows.h" #include "servers/audio_server.h" +#include "servers/visual/visual_server_raster.h" //#include "servers/visual/visual_server_wrap_mt.h" -#include "main/main.h" -#include "tcp_server_winsock.h" -#include "packet_peer_udp_winsock.h" -#include "stream_peer_winsock.h" -#include "lang_table.h" #include "global_config.h" #include "io/marshalls.h" #include "joypad.h" +#include "lang_table.h" +#include "main/main.h" +#include "packet_peer_udp_winsock.h" +#include "stream_peer_winsock.h" +#include "tcp_server_winsock.h" -#include <shlobj.h> -#include <regstr.h> #include <process.h> +#include <regstr.h> +#include <shlobj.h> static const WORD MAX_CONSOLE_LINES = 1500; extern "C" { #ifdef _MSC_VER - _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; +_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; #else - __attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001; +__attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001; #endif } @@ -88,13 +88,13 @@ void RedirectIOToConsole() { GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), - &coninfo); + &coninfo); coninfo.dwSize.Y = MAX_CONSOLE_LINES; SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), - coninfo.dwSize); + coninfo.dwSize); // redirect unbuffered STDOUT to the console @@ -102,11 +102,11 @@ void RedirectIOToConsole() { hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); - fp = _fdopen( hConHandle, "w" ); + fp = _fdopen(hConHandle, "w"); *stdout = *fp; - setvbuf( stdout, NULL, _IONBF, 0 ); + setvbuf(stdout, NULL, _IONBF, 0); // redirect unbuffered STDIN to the console @@ -114,11 +114,11 @@ void RedirectIOToConsole() { hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); - fp = _fdopen( hConHandle, "r" ); + fp = _fdopen(hConHandle, "r"); *stdin = *fp; - setvbuf( stdin, NULL, _IONBF, 0 ); + setvbuf(stdin, NULL, _IONBF, 0); // redirect unbuffered STDERR to the console @@ -126,11 +126,11 @@ void RedirectIOToConsole() { hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); - fp = _fdopen( hConHandle, "w" ); + fp = _fdopen(hConHandle, "w"); *stderr = *fp; - setvbuf( stderr, NULL, _IONBF, 0 ); + setvbuf(stderr, NULL, _IONBF, 0); // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog @@ -141,37 +141,35 @@ int OS_Windows::get_video_driver_count() const { return 1; } -const char * OS_Windows::get_video_driver_name(int p_driver) const { +const char *OS_Windows::get_video_driver_name(int p_driver) const { return "GLES2"; } OS::VideoMode OS_Windows::get_default_video_mode() const { - return VideoMode(1024,600,false); + return VideoMode(1024, 600, false); } int OS_Windows::get_audio_driver_count() const { return AudioDriverManager::get_driver_count(); } -const char * OS_Windows::get_audio_driver_name(int p_driver) const { +const char *OS_Windows::get_audio_driver_name(int p_driver) const { - AudioDriver* driver = AudioDriverManager::get_driver(p_driver); - ERR_FAIL_COND_V( !driver, "" ); + AudioDriver *driver = AudioDriverManager::get_driver(p_driver); + ERR_FAIL_COND_V(!driver, ""); return AudioDriverManager::get_driver(p_driver)->get_name(); } - void OS_Windows::initialize_core() { - - last_button_state=0; + last_button_state = 0; //RedirectIOToConsole(); - maximized=false; - minimized=false; - borderless=false; + maximized = false; + minimized = false; + borderless = false; ThreadWindows::make_default(); SemaphoreWindows::make_default(); @@ -190,9 +188,8 @@ void OS_Windows::initialize_core() { StreamPeerWinsock::make_default(); PacketPeerUDPWinsock::make_default(); - - // We need to know how often the clock is updated - if( !QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second) ) + // We need to know how often the clock is updated + if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second)) ticks_per_second = 1000; // If timeAtGameStart is 0 then we get the time since // the start of the computer when we call GetGameTime() @@ -203,9 +200,7 @@ void OS_Windows::initialize_core() { IP_Unix::make_default(); - cursor_shape=CURSOR_ARROW; - - + cursor_shape = CURSOR_ARROW; } bool OS_Windows::can_draw() const { @@ -215,20 +210,19 @@ bool OS_Windows::can_draw() const { #define MI_WP_SIGNATURE 0xFF515700 #define SIGNATURE_MASK 0xFFFFFF00 -#define IsPenEvent(dw) (((dw) & SIGNATURE_MASK) == MI_WP_SIGNATURE) - +#define IsPenEvent(dw) (((dw)&SIGNATURE_MASK) == MI_WP_SIGNATURE) void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) { InputEvent event; event.type = InputEvent::SCREEN_TOUCH; - event.ID=++last_id; + event.ID = ++last_id; event.screen_touch.index = idx; event.screen_touch.pressed = p_pressed; - event.screen_touch.x=p_x; - event.screen_touch.y=p_y; + event.screen_touch.x = p_x; + event.screen_touch.y = p_y; if (main_loop) { input->parse_input_event(event); @@ -239,41 +233,38 @@ void OS_Windows::_drag_event(int p_x, int p_y, int idx) { InputEvent event; event.type = InputEvent::SCREEN_DRAG; - event.ID=++last_id; + event.ID = ++last_id; event.screen_drag.index = idx; - event.screen_drag.x=p_x; - event.screen_drag.y=p_y; + event.screen_drag.x = p_x; + event.screen_drag.y = p_y; if (main_loop) input->parse_input_event(event); }; -LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { +LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - - switch (uMsg) // Check For Windows Messages + switch (uMsg) // Check For Windows Messages { - case WM_SETFOCUS: - { + case WM_SETFOCUS: { window_has_focus = true; // Re-capture cursor if we're in one of the capture modes - if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) { + if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { SetCapture(hWnd); } break; } - case WM_KILLFOCUS: - { + case WM_KILLFOCUS: { window_has_focus = false; // Release capture if we're in one of the capture modes - if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) { + if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { ReleaseCapture(); } break; } - case WM_ACTIVATE: // Watch For Window Activate Message + case WM_ACTIVATE: // Watch For Window Activate Message { minimized = HIWORD(wParam) != 0; if (!main_loop) { @@ -282,23 +273,23 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE) { main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); - alt_mem=false; - control_mem=false; - shift_mem=false; - if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) { + alt_mem = false; + control_mem = false; + shift_mem = false; + if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { RECT clipRect; GetClientRect(hWnd, &clipRect); - ClientToScreen(hWnd, (POINT*) &clipRect.left); - ClientToScreen(hWnd, (POINT*) &clipRect.right); + ClientToScreen(hWnd, (POINT *)&clipRect.left); + ClientToScreen(hWnd, (POINT *)&clipRect.right); ClipCursor(&clipRect); SetCapture(hWnd); } } else { main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); - alt_mem=false; + alt_mem = false; }; - return 0; // Return To The Message Loop + return 0; // Return To The Message Loop } case WM_PAINT: @@ -306,32 +297,32 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { Main::force_redraw(); break; - case WM_SYSCOMMAND: // Intercept System Commands + case WM_SYSCOMMAND: // Intercept System Commands { - switch (wParam) // Check System Calls + switch (wParam) // Check System Calls { - case SC_SCREENSAVE: // Screensaver Trying To Start? - case SC_MONITORPOWER: // Monitor Trying To Enter Powersave? - return 0; // Prevent From Happening + case SC_SCREENSAVE: // Screensaver Trying To Start? + case SC_MONITORPOWER: // Monitor Trying To Enter Powersave? + return 0; // Prevent From Happening case SC_KEYMENU: - if ((lParam>>16)<=0) + if ((lParam >> 16) <= 0) return 0; } - break; // Exit + break; // Exit } - case WM_CLOSE: // Did We Receive A Close Message? + case WM_CLOSE: // Did We Receive A Close Message? { if (main_loop) main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST); //force_quit=true; - return 0; // Jump Back + return 0; // Jump Back } case WM_MOUSELEAVE: { - old_invalid=true; - outside=true; - if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED) + old_invalid = true; + outside = true; + if (main_loop && mouse_mode != MOUSE_MODE_CAPTURED) main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT); if (input) input->set_mouse_in_window(false); @@ -342,28 +333,27 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { if (outside) { //mouse enter - if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED) + if (main_loop && mouse_mode != MOUSE_MODE_CAPTURED) main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER); if (input) input->set_mouse_in_window(true); - CursorShape c=cursor_shape; - cursor_shape=CURSOR_MAX; + CursorShape c = cursor_shape; + cursor_shape = CURSOR_MAX; set_cursor_shape(c); - outside=false; + outside = false; //Once-Off notification, must call again.... TRACKMOUSEEVENT tme; - tme.cbSize=sizeof(TRACKMOUSEEVENT); - tme.dwFlags=TME_LEAVE; - tme.hwndTrack=hWnd; - tme.dwHoverTime=HOVER_DEFAULT; + tme.cbSize = sizeof(TRACKMOUSEEVENT); + tme.dwFlags = TME_LEAVE; + tme.hwndTrack = hWnd; + tme.dwHoverTime = HOVER_DEFAULT; TrackMouseEvent(&tme); - } // Don't calculate relative mouse movement if we don't have focus in CAPTURED mode. - if (!window_has_focus && mouse_mode==MOUSE_MODE_CAPTURED) + if (!window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED) break; /* LPARAM extra = GetMessageExtraInfo(); @@ -378,64 +368,60 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { }; */ - InputEvent event; - event.type=InputEvent::MOUSE_MOTION; - event.ID=++last_id; - InputEventMouseMotion &mm=event.mouse_motion; - - mm.mod.control=(wParam&MK_CONTROL)!=0; - mm.mod.shift=(wParam&MK_SHIFT)!=0; - mm.mod.alt=alt_mem; - - mm.button_mask|=(wParam&MK_LBUTTON)?(1<<0):0; - mm.button_mask|=(wParam&MK_RBUTTON)?(1<<1):0; - mm.button_mask|=(wParam&MK_MBUTTON)?(1<<2):0; - last_button_state=mm.button_mask; + event.type = InputEvent::MOUSE_MOTION; + event.ID = ++last_id; + InputEventMouseMotion &mm = event.mouse_motion; + + mm.mod.control = (wParam & MK_CONTROL) != 0; + mm.mod.shift = (wParam & MK_SHIFT) != 0; + mm.mod.alt = alt_mem; + + mm.button_mask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0; + mm.button_mask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0; + mm.button_mask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0; + last_button_state = mm.button_mask; /*mm.button_mask|=(wParam&MK_XBUTTON1)?(1<<5):0; mm.button_mask|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ - mm.x=GET_X_LPARAM(lParam); - mm.y=GET_Y_LPARAM(lParam); - - if (mouse_mode==MOUSE_MODE_CAPTURED) { + mm.x = GET_X_LPARAM(lParam); + mm.y = GET_Y_LPARAM(lParam); - Point2i c(video_mode.width/2,video_mode.height/2); + if (mouse_mode == MOUSE_MODE_CAPTURED) { + + Point2i c(video_mode.width / 2, video_mode.height / 2); old_x = c.x; old_y = c.y; - if (Point2i(mm.x,mm.y)==c) { - center=c; + if (Point2i(mm.x, mm.y) == c) { + center = c; return 0; } - Point2i ncenter(mm.x,mm.y); - center=ncenter; - POINT pos = { (int) c.x, (int) c.y }; + Point2i ncenter(mm.x, mm.y); + center = ncenter; + POINT pos = { (int)c.x, (int)c.y }; ClientToScreen(hWnd, &pos); SetCursorPos(pos.x, pos.y); - } - input->set_mouse_pos(Point2(mm.x,mm.y)); - mm.speed_x=input->get_last_mouse_speed().x; - mm.speed_y=input->get_last_mouse_speed().y; + input->set_mouse_pos(Point2(mm.x, mm.y)); + mm.speed_x = input->get_last_mouse_speed().x; + mm.speed_y = input->get_last_mouse_speed().y; if (old_invalid) { - old_x=mm.x; - old_y=mm.y; - old_invalid=false; + old_x = mm.x; + old_y = mm.y; + old_invalid = false; } - mm.relative_x=mm.x-old_x; - mm.relative_y=mm.y-old_y; - old_x=mm.x; - old_y=mm.y; + mm.relative_x = mm.x - old_x; + mm.relative_y = mm.y - old_y; + old_x = mm.x; + old_y = mm.y; if (window_has_focus && main_loop) input->parse_input_event(event); - - } break; case WM_LBUTTONDOWN: case WM_LBUTTONUP: @@ -447,10 +433,10 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_MOUSEHWHEEL: case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: - /*case WM_XBUTTONDOWN: - case WM_XBUTTONUP: */{ + /*case WM_XBUTTONDOWN: + case WM_XBUTTONUP: */ { - /* + /* LPARAM extra = GetMessageExtraInfo(); if (IsPenEvent(extra)) { @@ -463,76 +449,74 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { }; */ - InputEvent event; - event.type=InputEvent::MOUSE_BUTTON; - event.ID=++last_id; - InputEventMouseButton &mb=event.mouse_button; - - switch (uMsg) { - case WM_LBUTTONDOWN: { - mb.pressed=true; - mb.button_index=1; - } break; - case WM_LBUTTONUP: { - mb.pressed=false; - mb.button_index=1; - } break; - case WM_MBUTTONDOWN: { - mb.pressed=true; - mb.button_index=3; - - } break; - case WM_MBUTTONUP: { - mb.pressed=false; - mb.button_index=3; - } break; - case WM_RBUTTONDOWN: { - mb.pressed=true; - mb.button_index=2; - } break; - case WM_RBUTTONUP: { - mb.pressed=false; - mb.button_index=2; - } break; - case WM_LBUTTONDBLCLK: { - - mb.pressed=true; - mb.button_index=1; - mb.doubleclick = true; - } break; - case WM_RBUTTONDBLCLK: { - - mb.pressed=true; - mb.button_index=2; - mb.doubleclick = true; - } break; - case WM_MOUSEWHEEL: { - - mb.pressed=true; - int motion = (short)HIWORD(wParam); - if (!motion) - return 0; - - - if (motion>0) - mb.button_index= BUTTON_WHEEL_UP; - else - mb.button_index= BUTTON_WHEEL_DOWN; - - - } break; - case WM_MOUSEHWHEEL: { - - mb.pressed = true; - int motion = (short)HIWORD(wParam); - if (!motion) - return 0; - - if (motion<0) - mb.button_index = BUTTON_WHEEL_LEFT; - else - mb.button_index = BUTTON_WHEEL_RIGHT; - } break; + InputEvent event; + event.type = InputEvent::MOUSE_BUTTON; + event.ID = ++last_id; + InputEventMouseButton &mb = event.mouse_button; + + switch (uMsg) { + case WM_LBUTTONDOWN: { + mb.pressed = true; + mb.button_index = 1; + } break; + case WM_LBUTTONUP: { + mb.pressed = false; + mb.button_index = 1; + } break; + case WM_MBUTTONDOWN: { + mb.pressed = true; + mb.button_index = 3; + + } break; + case WM_MBUTTONUP: { + mb.pressed = false; + mb.button_index = 3; + } break; + case WM_RBUTTONDOWN: { + mb.pressed = true; + mb.button_index = 2; + } break; + case WM_RBUTTONUP: { + mb.pressed = false; + mb.button_index = 2; + } break; + case WM_LBUTTONDBLCLK: { + + mb.pressed = true; + mb.button_index = 1; + mb.doubleclick = true; + } break; + case WM_RBUTTONDBLCLK: { + + mb.pressed = true; + mb.button_index = 2; + mb.doubleclick = true; + } break; + case WM_MOUSEWHEEL: { + + mb.pressed = true; + int motion = (short)HIWORD(wParam); + if (!motion) + return 0; + + if (motion > 0) + mb.button_index = BUTTON_WHEEL_UP; + else + mb.button_index = BUTTON_WHEEL_DOWN; + + } break; + case WM_MOUSEHWHEEL: { + + mb.pressed = true; + int motion = (short)HIWORD(wParam); + if (!motion) + return 0; + + if (motion < 0) + mb.button_index = BUTTON_WHEEL_LEFT; + else + mb.button_index = BUTTON_WHEEL_RIGHT; + } break; /* case WM_XBUTTONDOWN: { mb.pressed=true; @@ -542,75 +526,68 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { mb.pressed=true; mb.button_index=(HIWORD(wParam)==XBUTTON1)?6:7; } break;*/ - default: { return 0; } - } - + default: { return 0; } + } - mb.mod.control=(wParam&MK_CONTROL)!=0; - mb.mod.shift=(wParam&MK_SHIFT)!=0; - mb.mod.alt=alt_mem; - //mb.mod.alt=(wParam&MK_MENU)!=0; - mb.button_mask|=(wParam&MK_LBUTTON)?(1<<0):0; - mb.button_mask|=(wParam&MK_RBUTTON)?(1<<1):0; - mb.button_mask|=(wParam&MK_MBUTTON)?(1<<2):0; + mb.mod.control = (wParam & MK_CONTROL) != 0; + mb.mod.shift = (wParam & MK_SHIFT) != 0; + mb.mod.alt = alt_mem; + //mb.mod.alt=(wParam&MK_MENU)!=0; + mb.button_mask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0; + mb.button_mask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0; + mb.button_mask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0; - last_button_state=mb.button_mask; - /* + last_button_state = mb.button_mask; + /* mb.button_mask|=(wParam&MK_XBUTTON1)?(1<<5):0; mb.button_mask|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ - mb.x=GET_X_LPARAM(lParam); - mb.y=GET_Y_LPARAM(lParam); + mb.x = GET_X_LPARAM(lParam); + mb.y = GET_Y_LPARAM(lParam); - if (mouse_mode==MOUSE_MODE_CAPTURED) { + if (mouse_mode == MOUSE_MODE_CAPTURED) { - mb.x=old_x; - mb.y=old_y; - } - - mb.global_x=mb.x; - mb.global_y=mb.y; + mb.x = old_x; + mb.y = old_y; + } + mb.global_x = mb.x; + mb.global_y = mb.y; - if (uMsg != WM_MOUSEWHEEL) { - if (mb.pressed) { + if (uMsg != WM_MOUSEWHEEL) { + if (mb.pressed) { - if (++pressrc>0) - SetCapture(hWnd); - } else { + if (++pressrc > 0) + SetCapture(hWnd); + } else { - - if (--pressrc<=0) { - ReleaseCapture(); - pressrc=0; + if (--pressrc <= 0) { + ReleaseCapture(); + pressrc = 0; + } } + } else if (mouse_mode != MOUSE_MODE_CAPTURED) { + // for reasons unknown to mankind, wheel comes in screen cordinates + POINT coords; + coords.x = mb.x; + coords.y = mb.y; - } - } else if (mouse_mode!=MOUSE_MODE_CAPTURED) { - // for reasons unknown to mankind, wheel comes in screen cordinates - POINT coords; - coords.x = mb.x; - coords.y = mb.y; - - ScreenToClient(hWnd, &coords); + ScreenToClient(hWnd, &coords); - mb.x = coords.x; - mb.y = coords.y; - } + mb.x = coords.x; + mb.y = coords.y; + } - if (main_loop) { - input->parse_input_event(event); - if (mb.pressed && mb.button_index>3) { - //send release for mouse wheel - mb.pressed=false; - event.ID=++last_id; + if (main_loop) { input->parse_input_event(event); - + if (mb.pressed && mb.button_index > 3) { + //send release for mouse wheel + mb.pressed = false; + event.ID = ++last_id; + input->parse_input_event(event); + } } } - - - - } break; + break; case WM_SIZE: { int window_w = LOWORD(lParam); @@ -623,7 +600,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { } break; case WM_ENTERSIZEMOVE: { - move_timer_id = SetTimer(hWnd, 1, USER_TIMER_MINIMUM,(TIMERPROC) NULL); + move_timer_id = SetTimer(hWnd, 1, USER_TIMER_MINIMUM, (TIMERPROC)NULL); } break; case WM_EXITSIZEMOVE: { KillTimer(hWnd, move_timer_id); @@ -640,15 +617,14 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_KEYUP: case WM_KEYDOWN: { - - if (wParam==VK_SHIFT) - shift_mem=uMsg==WM_KEYDOWN; - if (wParam==VK_CONTROL) - control_mem=uMsg==WM_KEYDOWN; - if (wParam==VK_MENU) { - alt_mem=(uMsg==WM_KEYDOWN || uMsg==WM_SYSKEYDOWN); - if (lParam&(1<<24)) - gr_mem=alt_mem; + if (wParam == VK_SHIFT) + shift_mem = uMsg == WM_KEYDOWN; + if (wParam == VK_CONTROL) + control_mem = uMsg == WM_KEYDOWN; + if (wParam == VK_MENU) { + alt_mem = (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN); + if (lParam & (1 << 24)) + gr_mem = alt_mem; } /* @@ -656,7 +632,6 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { meta_mem=uMsg==WM_KEYDOWN; */ - } //fallthrough case WM_CHAR: { @@ -664,17 +639,16 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { // Make sure we don't include modifiers for the modifier key itself. KeyEvent ke; - ke.mod_state.shift= (wParam != VK_SHIFT) ? shift_mem : false; - ke.mod_state.alt= (! (wParam == VK_MENU && (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN))) ? alt_mem : false; - ke.mod_state.control= (wParam != VK_CONTROL) ? control_mem : false; - ke.mod_state.meta=meta_mem; - ke.uMsg=uMsg; - - if (ke.uMsg==WM_SYSKEYDOWN) - ke.uMsg=WM_KEYDOWN; - if (ke.uMsg==WM_SYSKEYUP) - ke.uMsg=WM_KEYUP; + ke.mod_state.shift = (wParam != VK_SHIFT) ? shift_mem : false; + ke.mod_state.alt = (!(wParam == VK_MENU && (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN))) ? alt_mem : false; + ke.mod_state.control = (wParam != VK_CONTROL) ? control_mem : false; + ke.mod_state.meta = meta_mem; + ke.uMsg = uMsg; + if (ke.uMsg == WM_SYSKEYDOWN) + ke.uMsg = WM_KEYDOWN; + if (ke.uMsg == WM_SYSKEYUP) + ke.uMsg = WM_KEYUP; /*if (ke.uMsg==WM_KEYDOWN && alt_mem && uMsg!=WM_SYSKEYDOWN) { //altgr hack for intl keyboards, not sure how good it is @@ -684,10 +658,9 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { print_line("") }*/ - - ke.wParam=wParam; - ke.lParam=lParam; - key_event_buffer[key_event_pos++]=ke; + ke.wParam = wParam; + ke.lParam = lParam; + key_event_buffer[key_event_pos++] = ke; } break; case WM_INPUTLANGCHANGEREQUEST: { @@ -695,15 +668,15 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { print_line("input lang change"); } break; - #if WINVER >= 0x0601 // for windows 7 +#if WINVER >= 0x0601 // for windows 7 case WM_TOUCH: { BOOL bHandled = FALSE; UINT cInputs = LOWORD(wParam); PTOUCHINPUT pInputs = memnew_arr(TOUCHINPUT, cInputs); - if (pInputs){ - if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))){ - for (UINT i=0; i < cInputs; i++){ + if (pInputs) { + if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) { + for (UINT i = 0; i < cInputs; i++) { TOUCHINPUT ti = pInputs[i]; //do something with each touch input entry if (ti.dwFlags & TOUCHEVENTF_MOVE) { @@ -715,11 +688,11 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { }; } bHandled = TRUE; - }else{ - /* handle the error here */ + } else { + /* handle the error here */ } memdelete_arr(pInputs); - }else{ + } else { /* handle the error here, probably out of memory */ } if (bHandled) { @@ -729,22 +702,21 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { } break; - #endif +#endif case WM_DEVICECHANGE: { joypad->probe_joypads(); } break; case WM_SETCURSOR: { - if(LOWORD(lParam) == HTCLIENT) { - if(window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED)) { + if (LOWORD(lParam) == HTCLIENT) { + if (window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED)) { //Hide the cursor - if(hCursor == NULL) + if (hCursor == NULL) hCursor = SetCursor(NULL); else SetCursor(NULL); - } - else { - if(hCursor != NULL) { + } else { + if (hCursor != NULL) { SetCursor(hCursor); hCursor = NULL; } @@ -755,30 +727,27 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_DROPFILES: { HDROP hDropInfo = NULL; - hDropInfo = (HDROP) wParam; - const int buffsize=4096; + hDropInfo = (HDROP)wParam; + const int buffsize = 4096; wchar_t buf[buffsize]; - int fcount = DragQueryFileW(hDropInfo, 0xFFFFFFFF,NULL,0); + int fcount = DragQueryFileW(hDropInfo, 0xFFFFFFFF, NULL, 0); Vector<String> files; - for(int i=0;i<fcount;i++) { + for (int i = 0; i < fcount; i++) { DragQueryFileW(hDropInfo, i, buf, buffsize); - String file=buf; + String file = buf; files.push_back(file); } if (files.size() && main_loop) { - main_loop->drop_files(files,0); + main_loop->drop_files(files, 0); } - } break; - - default: { if (user_proc) { @@ -788,119 +757,102 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { }; } - return DefWindowProcW(hWnd,uMsg,wParam,lParam); - + return DefWindowProcW(hWnd, uMsg, wParam, lParam); } -LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { +LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - OS_Windows *os_win = static_cast<OS_Windows*>(OS::get_singleton()); + OS_Windows *os_win = static_cast<OS_Windows *>(OS::get_singleton()); if (os_win) - return os_win->WndProc(hWnd,uMsg,wParam,lParam); + return os_win->WndProc(hWnd, uMsg, wParam, lParam); else - return DefWindowProcW(hWnd,uMsg,wParam,lParam); - + return DefWindowProcW(hWnd, uMsg, wParam, lParam); } - - void OS_Windows::process_key_events() { - for(int i=0;i<key_event_pos;i++) { + for (int i = 0; i < key_event_pos; i++) { KeyEvent &ke = key_event_buffer[i]; - switch(ke.uMsg) { + switch (ke.uMsg) { case WM_CHAR: { - if ((i==0 && ke.uMsg==WM_CHAR) || (i>0 && key_event_buffer[i-1].uMsg==WM_CHAR)) - { - InputEvent event; - event.type=InputEvent::KEY; - event.ID=++last_id; - InputEventKey &k=event.key; - - - k.mod=ke.mod_state; - k.pressed=true; - k.scancode=KeyMappingWindows::get_keysym(ke.wParam); - k.unicode=ke.wParam; - if (k.unicode && gr_mem) { - k.mod.alt=false; - k.mod.control=false; - } + if ((i == 0 && ke.uMsg == WM_CHAR) || (i > 0 && key_event_buffer[i - 1].uMsg == WM_CHAR)) { + InputEvent event; + event.type = InputEvent::KEY; + event.ID = ++last_id; + InputEventKey &k = event.key; + + k.mod = ke.mod_state; + k.pressed = true; + k.scancode = KeyMappingWindows::get_keysym(ke.wParam); + k.unicode = ke.wParam; + if (k.unicode && gr_mem) { + k.mod.alt = false; + k.mod.control = false; + } - if (k.unicode<32) - k.unicode=0; + if (k.unicode < 32) + k.unicode = 0; - input->parse_input_event(event); - } + input->parse_input_event(event); + } //do nothing } break; case WM_KEYUP: case WM_KEYDOWN: { - InputEvent event; - event.type=InputEvent::KEY; - event.ID=++last_id; - InputEventKey &k=event.key; + event.type = InputEvent::KEY; + event.ID = ++last_id; + InputEventKey &k = event.key; + k.mod = ke.mod_state; + k.pressed = (ke.uMsg == WM_KEYDOWN); - k.mod=ke.mod_state; - k.pressed=(ke.uMsg==WM_KEYDOWN); - - k.scancode=KeyMappingWindows::get_keysym(ke.wParam); - if (i+1 < key_event_pos && key_event_buffer[i+1].uMsg==WM_CHAR) - k.unicode=key_event_buffer[i+1].wParam; + k.scancode = KeyMappingWindows::get_keysym(ke.wParam); + if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) + k.unicode = key_event_buffer[i + 1].wParam; if (k.unicode && gr_mem) { - k.mod.alt=false; - k.mod.control=false; + k.mod.alt = false; + k.mod.control = false; } - if (k.unicode<32) - k.unicode=0; - - + if (k.unicode < 32) + k.unicode = 0; - k.echo=(ke.uMsg==WM_KEYDOWN && (ke.lParam&(1<<30))); + k.echo = (ke.uMsg == WM_KEYDOWN && (ke.lParam & (1 << 30))); input->parse_input_event(event); - } break; } } - key_event_pos=0; + key_event_pos = 0; } -enum _MonitorDpiType -{ - MDT_Effective_DPI = 0, - MDT_Angular_DPI = 1, - MDT_Raw_DPI = 2, - MDT_Default = MDT_Effective_DPI +enum _MonitorDpiType { + MDT_Effective_DPI = 0, + MDT_Angular_DPI = 1, + MDT_Raw_DPI = 2, + MDT_Default = MDT_Effective_DPI }; - -static int QueryDpiForMonitor(HMONITOR hmon, _MonitorDpiType dpiType= MDT_Default) -{ - +static int QueryDpiForMonitor(HMONITOR hmon, _MonitorDpiType dpiType = MDT_Default) { int dpiX = 96, dpiY = 96; static HMODULE Shcore = NULL; - typedef HRESULT (WINAPI* GetDPIForMonitor_t)(HMONITOR hmonitor, _MonitorDpiType dpiType, UINT *dpiX, UINT *dpiY); + typedef HRESULT(WINAPI * GetDPIForMonitor_t)(HMONITOR hmonitor, _MonitorDpiType dpiType, UINT * dpiX, UINT * dpiY); static GetDPIForMonitor_t getDPIForMonitor = NULL; - if (Shcore == NULL) - { + if (Shcore == NULL) { Shcore = LoadLibraryW(L"Shcore.dll"); getDPIForMonitor = Shcore ? (GetDPIForMonitor_t)GetProcAddress(Shcore, "GetDpiForMonitor") : NULL; - if ((Shcore == NULL) || (getDPIForMonitor == NULL)) - { + if ((Shcore == NULL) || (getDPIForMonitor == NULL)) { if (Shcore) FreeLibrary(Shcore); Shcore = (HMODULE)INVALID_HANDLE_VALUE; @@ -910,49 +862,41 @@ static int QueryDpiForMonitor(HMONITOR hmon, _MonitorDpiType dpiType= MDT_Defaul UINT x = 0, y = 0; HRESULT hr = E_FAIL; bool bSet = false; - if (hmon && (Shcore != (HMODULE)INVALID_HANDLE_VALUE)) - { - hr = getDPIForMonitor(hmon, dpiType/*MDT_Effective_DPI*/, &x, &y); - if (SUCCEEDED(hr) && (x > 0) && (y > 0)) - { + if (hmon && (Shcore != (HMODULE)INVALID_HANDLE_VALUE)) { + hr = getDPIForMonitor(hmon, dpiType /*MDT_Effective_DPI*/, &x, &y); + if (SUCCEEDED(hr) && (x > 0) && (y > 0)) { dpiX = (int)x; dpiY = (int)y; } - } - else - { + } else { static int overallX = 0, overallY = 0; - if (overallX <= 0 || overallY <= 0) - { + if (overallX <= 0 || overallY <= 0) { HDC hdc = GetDC(NULL); - if (hdc) - { + if (hdc) { overallX = GetDeviceCaps(hdc, LOGPIXELSX); overallY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); } } - if (overallX > 0 && overallY > 0) - { - dpiX = overallX; dpiY = overallY; + if (overallX > 0 && overallY > 0) { + dpiX = overallX; + dpiY = overallY; } } - - return (dpiX+dpiY)/2; + return (dpiX + dpiY) / 2; } - -BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { - OS_Windows *self=(OS_Windows*)OS::get_singleton(); +BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + OS_Windows *self = (OS_Windows *)OS::get_singleton(); MonitorInfo minfo; - minfo.hMonitor=hMonitor; - minfo.hdcMonitor=hdcMonitor; - minfo.rect.pos.x=lprcMonitor->left; - minfo.rect.pos.y=lprcMonitor->top; - minfo.rect.size.x=lprcMonitor->right - lprcMonitor->left; - minfo.rect.size.y=lprcMonitor->bottom - lprcMonitor->top; + minfo.hMonitor = hMonitor; + minfo.hdcMonitor = hdcMonitor; + minfo.rect.pos.x = lprcMonitor->left; + minfo.rect.pos.y = lprcMonitor->top; + minfo.rect.size.x = lprcMonitor->right - lprcMonitor->left; + minfo.rect.size.y = lprcMonitor->bottom - lprcMonitor->top; minfo.dpi = QueryDpiForMonitor(hMonitor); @@ -961,59 +905,55 @@ BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPR return TRUE; } +void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { -void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { - - + main_loop = NULL; + outside = true; + window_has_focus = true; + WNDCLASSEXW wc; - main_loop=NULL; - outside=true; - window_has_focus=true; - WNDCLASSEXW wc; - - video_mode=p_desired; + video_mode = p_desired; //printf("**************** desired %s, mode %s\n", p_desired.fullscreen?"true":"false", video_mode.fullscreen?"true":"false"); RECT WindowRect; - WindowRect.left=0; - WindowRect.right=video_mode.width; - WindowRect.top=0; - WindowRect.bottom=video_mode.height; + WindowRect.left = 0; + WindowRect.right = video_mode.width; + WindowRect.top = 0; + WindowRect.bottom = video_mode.height; - memset(&wc,0,sizeof(WNDCLASSEXW)); - wc.cbSize=sizeof(WNDCLASSEXW); - wc.style= CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS; + memset(&wc, 0, sizeof(WNDCLASSEXW)); + wc.cbSize = sizeof(WNDCLASSEXW); + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS; wc.lpfnWndProc = (WNDPROC)::WndProc; wc.cbClsExtra = 0; - wc.cbWndExtra= 0; + wc.cbWndExtra = 0; //wc.hInstance = hInstance; wc.hInstance = godot_hinstance ? godot_hinstance : GetModuleHandle(NULL); wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); - wc.hCursor = NULL;//LoadCursor(NULL, IDC_ARROW); + wc.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = L"Engine"; + wc.lpszMenuName = NULL; + wc.lpszClassName = L"Engine"; if (!RegisterClassExW(&wc)) { - MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); - return; // Return + MessageBox(NULL, "Failed To Register The Window Class.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return; // Return } + EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, 0); - EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,0); - - print_line("DETECTED MONITORS: "+itos(monitor_info.size())); - pre_fs_valid=true; + print_line("DETECTED MONITORS: " + itos(monitor_info.size())); + pre_fs_valid = true; if (video_mode.fullscreen) { DEVMODE current; - memset(¤t,0,sizeof(current)); + memset(¤t, 0, sizeof(current)); EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, ¤t); - WindowRect.right = current.dmPelsWidth; + WindowRect.right = current.dmPelsWidth; WindowRect.bottom = current.dmPelsHeight; -/* DEVMODE dmScreenSettings; + /* DEVMODE dmScreenSettings; memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize=sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = video_mode.width; @@ -1026,20 +966,20 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ video_mode.fullscreen=false; }*/ - pre_fs_valid=false; + pre_fs_valid = false; } - DWORD dwExStyle; - DWORD dwStyle; + DWORD dwExStyle; + DWORD dwStyle; - if (video_mode.fullscreen||video_mode.borderless_window) { + if (video_mode.fullscreen || video_mode.borderless_window) { - dwExStyle=WS_EX_APPWINDOW; - dwStyle=WS_POPUP; + dwExStyle = WS_EX_APPWINDOW; + dwStyle = WS_POPUP; } else { - dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; - dwStyle=WS_OVERLAPPEDWINDOW; + dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + dwStyle = WS_OVERLAPPEDWINDOW; if (!video_mode.resizable) { dwStyle &= ~WS_THICKFRAME; dwStyle &= ~WS_MAXIMIZEBOX; @@ -1048,16 +988,15 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); - - char* windowid = getenv("GODOT_WINDOWID"); + char *windowid = getenv("GODOT_WINDOWID"); if (windowid) { - // strtoull on mingw - #ifdef MINGW_ENABLED +// strtoull on mingw +#ifdef MINGW_ENABLED hWnd = (HWND)strtoull(windowid, NULL, 0); - #else +#else hWnd = (HWND)_strtoui64(windowid, NULL, 0); - #endif +#endif SetLastError(0); user_proc = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC); SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)(WNDPROC)::WndProc); @@ -1070,24 +1009,22 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ RECT rect; if (!GetClientRect(hWnd, &rect)) { - MessageBoxW(NULL,L"Window Creation Error.",L"ERROR",MB_OK|MB_ICONEXCLAMATION); - return; // Return FALSE + MessageBoxW(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); + return; // Return FALSE }; video_mode.width = rect.right; video_mode.height = rect.bottom; video_mode.fullscreen = false; } else { - if (!(hWnd=CreateWindowExW(dwExStyle,L"Engine",L"", dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, (GetSystemMetrics(SM_CXSCREEN)-WindowRect.right)/2, (GetSystemMetrics(SM_CYSCREEN)-WindowRect.bottom)/2, WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top, NULL,NULL, hInstance,NULL))) { - MessageBoxW(NULL,L"Window Creation Error.",L"ERROR",MB_OK|MB_ICONEXCLAMATION); - return; // Return FALSE + if (!(hWnd = CreateWindowExW(dwExStyle, L"Engine", L"", dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, (GetSystemMetrics(SM_CXSCREEN) - WindowRect.right) / 2, (GetSystemMetrics(SM_CYSCREEN) - WindowRect.bottom) / 2, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, NULL, NULL, hInstance, NULL))) { + MessageBoxW(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); + return; // Return FALSE } - - }; #if defined(OPENGL_ENABLED) - gl_context = memnew( ContextGL_Win(hWnd,true) ); + gl_context = memnew(ContextGL_Win(hWnd, true)); gl_context->initialize(); RasterizerGLES3::register_config(); @@ -1095,27 +1032,27 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ RasterizerGLES3::make_current(); #endif - visual_server = memnew( VisualServerRaster ); - // FIXME: Reimplement threaded rendering? Or remove? + visual_server = memnew(VisualServerRaster); + // FIXME: Reimplement threaded rendering? Or remove? /* if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } */ - physics_server = memnew( PhysicsServerSW ); + physics_server = memnew(PhysicsServerSW); physics_server->init(); physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); physics_2d_server->init(); if (!is_no_window_mode_enabled()) { - ShowWindow(hWnd,SW_SHOW); // Show The Window - SetForegroundWindow(hWnd); // Slightly Higher Priority - SetFocus(hWnd); // Sets Keyboard Focus To + ShowWindow(hWnd, SW_SHOW); // Show The Window + SetForegroundWindow(hWnd); // Slightly Higher Priority + SetFocus(hWnd); // Sets Keyboard Focus To } -/* + /* DEVMODE dmScreenSettings; // Device Mode memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure @@ -1131,35 +1068,35 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ */ visual_server->init(); - input = memnew( InputDefault ); - joypad = memnew (JoypadWindows(input, &hWnd)); + input = memnew(InputDefault); + joypad = memnew(JoypadWindows(input, &hWnd)); - power_manager = memnew( PowerWindows ); + power_manager = memnew(PowerWindows); AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); - if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) { + if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) { ERR_PRINT("Initializing audio failed."); } TRACKMOUSEEVENT tme; - tme.cbSize=sizeof(TRACKMOUSEEVENT); - tme.dwFlags=TME_LEAVE; - tme.hwndTrack=hWnd; - tme.dwHoverTime=HOVER_DEFAULT; + tme.cbSize = sizeof(TRACKMOUSEEVENT); + tme.dwFlags = TME_LEAVE; + tme.hwndTrack = hWnd; + tme.dwHoverTime = HOVER_DEFAULT; TrackMouseEvent(&tme); //RegisterTouchWindow(hWnd, 0); // Windows 7 _ensure_data_dir(); - DragAcceptFiles(hWnd,true); + DragAcceptFiles(hWnd, true); move_timer_id = 1; } -void OS_Windows::set_clipboard(const String& p_text) { +void OS_Windows::set_clipboard(const String &p_text) { if (!OpenClipboard(hWnd)) { ERR_EXPLAIN("Unable to open clipboard."); @@ -1212,7 +1149,7 @@ String OS_Windows::get_clipboard() const { LPWSTR ptr = (LPWSTR)GlobalLock(mem); if (ptr != NULL) { - ret = String((CharType*)ptr); + ret = String((CharType *)ptr); GlobalUnlock(mem); }; }; @@ -1225,7 +1162,7 @@ String OS_Windows::get_clipboard() const { LPTSTR ptr = (LPTSTR)GlobalLock(mem); if (ptr != NULL) { - ret.parse_utf8((const char*)ptr); + ret.parse_utf8((const char *)ptr); GlobalUnlock(mem); }; }; @@ -1236,26 +1173,25 @@ String OS_Windows::get_clipboard() const { return ret; }; - void OS_Windows::delete_main_loop() { if (main_loop) memdelete(main_loop); - main_loop=NULL; + main_loop = NULL; } -void OS_Windows::set_main_loop( MainLoop * p_main_loop ) { +void OS_Windows::set_main_loop(MainLoop *p_main_loop) { input->set_main_loop(p_main_loop); - main_loop=p_main_loop; + main_loop = p_main_loop; } void OS_Windows::finalize() { - if(main_loop) + if (main_loop) memdelete(main_loop); - main_loop=NULL; + main_loop = NULL; for (int i = 0; i < get_audio_driver_count(); i++) { AudioDriverManager::get_driver(i)->finish(); @@ -1294,30 +1230,28 @@ void OS_Windows::finalize_core() { memdelete(process_map); - TCPServerWinsock::cleanup(); StreamPeerWinsock::cleanup(); } -void OS_Windows::vprint(const char* p_format, va_list p_list, bool p_stderr) { +void OS_Windows::vprint(const char *p_format, va_list p_list, bool p_stderr) { const unsigned int BUFFER_SIZE = 16384; - char buf[BUFFER_SIZE+1]; // +1 for the terminating character - int len = vsnprintf(buf,BUFFER_SIZE,p_format,p_list); - if (len<=0) + char buf[BUFFER_SIZE + 1]; // +1 for the terminating character + int len = vsnprintf(buf, BUFFER_SIZE, p_format, p_list); + if (len <= 0) return; - if(len >= BUFFER_SIZE) + if (len >= BUFFER_SIZE) len = BUFFER_SIZE; // Output is too big, will be truncated - buf[len]=0; - + buf[len] = 0; - int wlen = MultiByteToWideChar(CP_UTF8,0,buf,len,NULL,0); - if (wlen<0) + int wlen = MultiByteToWideChar(CP_UTF8, 0, buf, len, NULL, 0); + if (wlen < 0) return; - wchar_t *wbuf = (wchar_t*)malloc((len+1)*sizeof(wchar_t)); - MultiByteToWideChar(CP_UTF8,0,buf,len,wbuf,wlen); - wbuf[wlen]=0; + wchar_t *wbuf = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); + MultiByteToWideChar(CP_UTF8, 0, buf, len, wbuf, wlen); + wbuf[wlen] = 0; if (p_stderr) fwprintf(stderr, L"%ls", wbuf); @@ -1325,36 +1259,36 @@ void OS_Windows::vprint(const char* p_format, va_list p_list, bool p_stderr) { wprintf(L"%ls", wbuf); #ifdef STDOUT_FILE - //vwfprintf(stdo,p_format,p_list); +//vwfprintf(stdo,p_format,p_list); #endif free(wbuf); fflush(stdout); }; -void OS_Windows::alert(const String& p_alert,const String& p_title) { +void OS_Windows::alert(const String &p_alert, const String &p_title) { if (!is_no_window_mode_enabled()) MessageBoxW(NULL, p_alert.c_str(), p_title.c_str(), MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL); else - print_line("ALERT: "+p_alert); + print_line("ALERT: " + p_alert); } void OS_Windows::set_mouse_mode(MouseMode p_mode) { - if (mouse_mode==p_mode) + if (mouse_mode == p_mode) return; - mouse_mode=p_mode; - if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) { + mouse_mode = p_mode; + if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { RECT clipRect; GetClientRect(hWnd, &clipRect); - ClientToScreen(hWnd, (POINT*) &clipRect.left); - ClientToScreen(hWnd, (POINT*) &clipRect.right); + ClientToScreen(hWnd, (POINT *)&clipRect.left); + ClientToScreen(hWnd, (POINT *)&clipRect.right); ClipCursor(&clipRect); - center=Point2i(video_mode.width/2,video_mode.height/2); - POINT pos = { (int) center.x, (int) center.y }; + center = Point2i(video_mode.width / 2, video_mode.height / 2); + POINT pos = { (int)center.x, (int)center.y }; ClientToScreen(hWnd, &pos); - if (mouse_mode==MOUSE_MODE_CAPTURED) + if (mouse_mode == MOUSE_MODE_CAPTURED) SetCursorPos(pos.x, pos.y); } else { ReleaseCapture(); @@ -1368,28 +1302,25 @@ void OS_Windows::set_mouse_mode(MouseMode p_mode) { } } -OS_Windows::MouseMode OS_Windows::get_mouse_mode() const{ - +OS_Windows::MouseMode OS_Windows::get_mouse_mode() const { return mouse_mode; } +void OS_Windows::warp_mouse_pos(const Point2 &p_to) { + if (mouse_mode == MOUSE_MODE_CAPTURED) { -void OS_Windows::warp_mouse_pos(const Point2& p_to) { - - if (mouse_mode==MOUSE_MODE_CAPTURED) { - - old_x=p_to.x; - old_y=p_to.y; + old_x = p_to.x; + old_y = p_to.y; } else { POINT p; - p.x=p_to.x; - p.y=p_to.y; - ClientToScreen(hWnd,&p); + p.x = p_to.x; + p.y = p_to.y; + ClientToScreen(hWnd, &p); - SetCursorPos(p.x,p.y); + SetCursorPos(p.x, p.y); } } @@ -1403,110 +1334,98 @@ int OS_Windows::get_mouse_button_state() const { return last_button_state; } -void OS_Windows::set_window_title(const String& p_title) { +void OS_Windows::set_window_title(const String &p_title) { - SetWindowTextW(hWnd,p_title.c_str()); + SetWindowTextW(hWnd, p_title.c_str()); } -void OS_Windows::set_video_mode(const VideoMode& p_video_mode,int p_screen) { - - +void OS_Windows::set_video_mode(const VideoMode &p_video_mode, int p_screen) { } OS::VideoMode OS_Windows::get_video_mode(int p_screen) const { return video_mode; } -void OS_Windows::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const { - - +void OS_Windows::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const { } int OS_Windows::get_screen_count() const { return monitor_info.size(); } -int OS_Windows::get_current_screen() const{ +int OS_Windows::get_current_screen() const { - HMONITOR monitor = MonitorFromWindow(hWnd,MONITOR_DEFAULTTONEAREST); - for(int i=0;i<monitor_info.size();i++) { - if (monitor_info[i].hMonitor==monitor) + HMONITOR monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); + for (int i = 0; i < monitor_info.size(); i++) { + if (monitor_info[i].hMonitor == monitor) return i; } return 0; } -void OS_Windows::set_current_screen(int p_screen){ +void OS_Windows::set_current_screen(int p_screen) { - ERR_FAIL_INDEX(p_screen,monitor_info.size()); + ERR_FAIL_INDEX(p_screen, monitor_info.size()); Vector2 ofs = get_window_position() - get_screen_position(get_current_screen()); - set_window_position(ofs+get_screen_position(p_screen)); - + set_window_position(ofs + get_screen_position(p_screen)); } -Point2 OS_Windows::get_screen_position(int p_screen) const{ - - ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),Point2()); - return Vector2( monitor_info[p_screen].rect.pos ); +Point2 OS_Windows::get_screen_position(int p_screen) const { + ERR_FAIL_INDEX_V(p_screen, monitor_info.size(), Point2()); + return Vector2(monitor_info[p_screen].rect.pos); } -Size2 OS_Windows::get_screen_size(int p_screen) const{ - - ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),Point2()); - return Vector2( monitor_info[p_screen].rect.size ); +Size2 OS_Windows::get_screen_size(int p_screen) const { + ERR_FAIL_INDEX_V(p_screen, monitor_info.size(), Point2()); + return Vector2(monitor_info[p_screen].rect.size); } int OS_Windows::get_screen_dpi(int p_screen) const { - ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),72); - UINT dpix,dpiy; + ERR_FAIL_INDEX_V(p_screen, monitor_info.size(), 72); + UINT dpix, dpiy; return monitor_info[p_screen].dpi; - } -Point2 OS_Windows::get_window_position() const{ +Point2 OS_Windows::get_window_position() const { RECT r; - GetWindowRect(hWnd,&r); - return Point2(r.left,r.top); + GetWindowRect(hWnd, &r); + return Point2(r.left, r.top); } -void OS_Windows::set_window_position(const Point2& p_position){ +void OS_Windows::set_window_position(const Point2 &p_position) { if (video_mode.fullscreen) return; RECT r; - GetWindowRect(hWnd,&r); - MoveWindow(hWnd,p_position.x,p_position.y,r.right-r.left,r.bottom-r.top,TRUE); - + GetWindowRect(hWnd, &r); + MoveWindow(hWnd, p_position.x, p_position.y, r.right - r.left, r.bottom - r.top, TRUE); } -Size2 OS_Windows::get_window_size() const{ +Size2 OS_Windows::get_window_size() const { RECT r; - GetClientRect(hWnd,&r); - return Vector2(r.right-r.left,r.bottom-r.top); - + GetClientRect(hWnd, &r); + return Vector2(r.right - r.left, r.bottom - r.top); } -void OS_Windows::set_window_size(const Size2 p_size){ +void OS_Windows::set_window_size(const Size2 p_size) { - video_mode.width=p_size.width; - video_mode.height=p_size.height; + video_mode.width = p_size.width; + video_mode.height = p_size.height; if (video_mode.fullscreen) { return; } - RECT crect; - GetClientRect(hWnd,&crect); + GetClientRect(hWnd, &crect); RECT rect; - GetWindowRect(hWnd,&rect); - int dx = (rect.right-rect.left)-(crect.right-crect.left); - int dy = (rect.bottom-rect.top)-(crect.bottom-crect.top); - - rect.right=rect.left+p_size.width+dx; - rect.bottom=rect.top+p_size.height+dy; + GetWindowRect(hWnd, &rect); + int dx = (rect.right - rect.left) - (crect.right - crect.left); + int dy = (rect.bottom - rect.top) - (crect.bottom - crect.top); + rect.right = rect.left + p_size.width + dx; + rect.bottom = rect.top + p_size.height + dy; //print_line("PRE: "+itos(rect.left)+","+itos(rect.top)+","+itos(rect.right-rect.left)+","+itos(rect.bottom-rect.top)); @@ -1518,73 +1437,65 @@ void OS_Windows::set_window_size(const Size2 p_size){ //print_line("POST: "+itos(rect.left)+","+itos(rect.top)+","+itos(rect.right-rect.left)+","+itos(rect.bottom-rect.top)); - MoveWindow(hWnd,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE); - + MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE); } -void OS_Windows::set_window_fullscreen(bool p_enabled){ +void OS_Windows::set_window_fullscreen(bool p_enabled) { - if (video_mode.fullscreen==p_enabled) + if (video_mode.fullscreen == p_enabled) return; - - if (p_enabled) { - if (pre_fs_valid) { - GetWindowRect(hWnd,&pre_fs_rect); + GetWindowRect(hWnd, &pre_fs_rect); //print_line("A: "+itos(pre_fs_rect.left)+","+itos(pre_fs_rect.top)+","+itos(pre_fs_rect.right-pre_fs_rect.left)+","+itos(pre_fs_rect.bottom-pre_fs_rect.top)); //MapWindowPoints(hWnd, GetParent(hWnd), (LPPOINT) &pre_fs_rect, 2); //print_line("B: "+itos(pre_fs_rect.left)+","+itos(pre_fs_rect.top)+","+itos(pre_fs_rect.right-pre_fs_rect.left)+","+itos(pre_fs_rect.bottom-pre_fs_rect.top)); } - int cs = get_current_screen(); Point2 pos = get_screen_position(cs); Size2 size = get_screen_size(cs); - /* r.left = pos.x; + /* r.left = pos.x; r.top = pos.y; r.bottom = pos.y+size.y; r.right = pos.x+size.x; */ SetWindowLongPtr(hWnd, GWL_STYLE, - WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); + WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); MoveWindow(hWnd, pos.x, pos.y, size.width, size.height, TRUE); - video_mode.fullscreen=true; - + video_mode.fullscreen = true; } else { RECT rect; if (pre_fs_valid) { - rect=pre_fs_rect; + rect = pre_fs_rect; } else { - rect.left=0; - rect.right=video_mode.width; - rect.top=0; - rect.bottom=video_mode.height; + rect.left = 0; + rect.right = video_mode.width; + rect.top = 0; + rect.bottom = video_mode.height; } - - if (video_mode.resizable) { SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); //AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); - MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE); } else { SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE); //AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW, FALSE); - MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE); } - video_mode.fullscreen=false; - pre_fs_valid=true; -/* + video_mode.fullscreen = false; + pre_fs_valid = true; + /* DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; DWORD dwStyle=WS_OVERLAPPEDWINDOW; if (!video_mode.resizable) { @@ -1599,18 +1510,16 @@ void OS_Windows::set_window_fullscreen(bool p_enabled){ } //MoveWindow(hWnd,r.left,r.top,p_size.x,p_size.y,TRUE); - - } -bool OS_Windows::is_window_fullscreen() const{ +bool OS_Windows::is_window_fullscreen() const { return video_mode.fullscreen; } -void OS_Windows::set_window_resizable(bool p_enabled){ +void OS_Windows::set_window_resizable(bool p_enabled) { - if (video_mode.resizable==p_enabled) + if (video_mode.resizable == p_enabled) return; -/* + /* GetWindowRect(hWnd,&pre_fs_rect); DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; DWORD dwStyle=WS_OVERLAPPEDWINDOW; @@ -1626,56 +1535,52 @@ void OS_Windows::set_window_resizable(bool p_enabled){ SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); } else { SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_MINIMIZEBOX | WS_POPUPWINDOW | WS_VISIBLE); - } RECT rect; - GetWindowRect(hWnd,&rect); - MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + GetWindowRect(hWnd, &rect); + MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE); } - video_mode.resizable=p_enabled; - + video_mode.resizable = p_enabled; } -bool OS_Windows::is_window_resizable() const{ +bool OS_Windows::is_window_resizable() const { return video_mode.resizable; } -void OS_Windows::set_window_minimized(bool p_enabled){ +void OS_Windows::set_window_minimized(bool p_enabled) { if (p_enabled) { - maximized=false; - minimized=true; - ShowWindow(hWnd,SW_MINIMIZE); + maximized = false; + minimized = true; + ShowWindow(hWnd, SW_MINIMIZE); } else { - ShowWindow(hWnd,SW_RESTORE); - maximized=false; - minimized=false; + ShowWindow(hWnd, SW_RESTORE); + maximized = false; + minimized = false; } } -bool OS_Windows::is_window_minimized() const{ +bool OS_Windows::is_window_minimized() const { return minimized; - } -void OS_Windows::set_window_maximized(bool p_enabled){ +void OS_Windows::set_window_maximized(bool p_enabled) { if (p_enabled) { - maximized=true; - minimized=false; - ShowWindow(hWnd,SW_MAXIMIZE); + maximized = true; + minimized = false; + ShowWindow(hWnd, SW_MAXIMIZE); } else { - ShowWindow(hWnd,SW_RESTORE); - maximized=false; - minimized=false; + ShowWindow(hWnd, SW_RESTORE); + maximized = false; + minimized = false; } } -bool OS_Windows::is_window_maximized() const{ +bool OS_Windows::is_window_maximized() const { return maximized; } - void OS_Windows::set_borderless_window(int p_borderless) { video_mode.borderless_window = p_borderless; } @@ -1695,18 +1600,18 @@ void OS_Windows::request_attention() { FlashWindowEx(&info); } -void OS_Windows::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) { +void OS_Windows::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) { HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); if (!hCon || hCon == INVALID_HANDLE_VALUE) { - const char* err_details; + const char *err_details; if (p_rationale && p_rationale[0]) err_details = p_rationale; else err_details = p_code; - switch(p_type) { + switch (p_type) { case ERR_ERROR: print("ERROR: %s: %s\n", p_function, err_details); print(" At: %s:%i\n", p_file, p_line); @@ -1734,7 +1639,7 @@ void OS_Windows::print_error(const char* p_function, const char* p_file, int p_l WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY); uint32_t basecol = 0; - switch(p_type) { + switch (p_type) { case ERR_ERROR: basecol = FOREGROUND_RED; break; case ERR_WARNING: basecol = FOREGROUND_RED | FOREGROUND_GREEN; break; case ERR_SCRIPT: basecol = FOREGROUND_RED | FOREGROUND_BLUE; break; @@ -1746,7 +1651,7 @@ void OS_Windows::print_error(const char* p_function, const char* p_file, int p_l if (p_rationale && p_rationale[0]) { SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY); - switch(p_type) { + switch (p_type) { case ERR_ERROR: print("ERROR: "); break; case ERR_WARNING: print("WARNING: "); break; case ERR_SCRIPT: print("SCRIPT ERROR: "); break; @@ -1770,7 +1675,7 @@ void OS_Windows::print_error(const char* p_function, const char* p_file, int p_l } else { SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY); - switch(p_type) { + switch (p_type) { case ERR_ERROR: print("ERROR: %s: ", p_function); break; case ERR_WARNING: print("WARNING: %s: ", p_function); break; case ERR_SCRIPT: print("SCRIPT ERROR: %s: ", p_function); break; @@ -1796,7 +1701,6 @@ void OS_Windows::print_error(const char* p_function, const char* p_file, int p_l } } - String OS_Windows::get_name() { return "Windows"; @@ -1811,11 +1715,11 @@ OS::Date OS_Windows::get_date(bool utc) const { GetLocalTime(&systemtime); Date date; - date.day=systemtime.wDay; - date.month=Month(systemtime.wMonth); - date.weekday=Weekday(systemtime.wDayOfWeek); - date.year=systemtime.wYear; - date.dst=false; + date.day = systemtime.wDay; + date.month = Month(systemtime.wMonth); + date.weekday = Weekday(systemtime.wDayOfWeek); + date.year = systemtime.wYear; + date.dst = false; return date; } OS::Time OS_Windows::get_time(bool utc) const { @@ -1827,9 +1731,9 @@ OS::Time OS_Windows::get_time(bool utc) const { GetLocalTime(&systemtime); Time time; - time.hour=systemtime.wHour; - time.min=systemtime.wMinute; - time.sec=systemtime.wSecond; + time.hour = systemtime.wHour; + time.min = systemtime.wMinute; + time.sec = systemtime.wSecond; return time; } @@ -1869,80 +1773,74 @@ uint64_t OS_Windows::get_unix_time() const { FILETIME fep; SystemTimeToFileTime(&ep, &fep); - return (*(uint64_t*)&ft - *(uint64_t*)&fep) / 10000000; + return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000; }; uint64_t OS_Windows::get_system_time_secs() const { - const uint64_t WINDOWS_TICK = 10000000; const uint64_t SEC_TO_UNIX_EPOCH = 11644473600LL; SYSTEMTIME st; GetSystemTime(&st); FILETIME ft; - SystemTimeToFileTime(&st,&ft); + SystemTimeToFileTime(&st, &ft); uint64_t ret; - ret=ft.dwHighDateTime; - ret<<=32; - ret|=ft.dwLowDateTime; + ret = ft.dwHighDateTime; + ret <<= 32; + ret |= ft.dwLowDateTime; return (uint64_t)(ret / WINDOWS_TICK - SEC_TO_UNIX_EPOCH); } void OS_Windows::delay_usec(uint32_t p_usec) const { - if (p_usec < 1000) - Sleep(1); - else - Sleep(p_usec / 1000); - + if (p_usec < 1000) + Sleep(1); + else + Sleep(p_usec / 1000); } uint64_t OS_Windows::get_ticks_usec() const { - uint64_t ticks; - uint64_t time; - // This is the number of clock ticks since start - if( !QueryPerformanceCounter((LARGE_INTEGER *)&ticks) ) - ticks = (UINT64)timeGetTime(); - // Divide by frequency to get the time in seconds - time = ticks * 1000000L / ticks_per_second; - // Subtract the time at game start to get - // the time since the game started - time -= ticks_start; - return time; + uint64_t ticks; + uint64_t time; + // This is the number of clock ticks since start + if (!QueryPerformanceCounter((LARGE_INTEGER *)&ticks)) + ticks = (UINT64)timeGetTime(); + // Divide by frequency to get the time in seconds + time = ticks * 1000000L / ticks_per_second; + // Subtract the time at game start to get + // the time since the game started + time -= ticks_start; + return time; } - void OS_Windows::process_events() { MSG msg; last_id = joypad->process_joypads(last_id); - while(PeekMessageW(&msg,NULL,0,0,PM_REMOVE)) { - + while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessageW(&msg); - } process_key_events(); - } void OS_Windows::set_cursor_shape(CursorShape p_shape) { - ERR_FAIL_INDEX(p_shape,CURSOR_MAX); + ERR_FAIL_INDEX(p_shape, CURSOR_MAX); - if (cursor_shape==p_shape) + if (cursor_shape == p_shape) return; - static const LPCTSTR win_cursors[CURSOR_MAX]={ + static const LPCTSTR win_cursors[CURSOR_MAX] = { IDC_ARROW, IDC_IBEAM, - IDC_HAND,//finger + IDC_HAND, //finger IDC_CROSS, IDC_WAIT, IDC_APPSTARTING, @@ -1959,50 +1857,48 @@ void OS_Windows::set_cursor_shape(CursorShape p_shape) { IDC_HELP }; - SetCursor(LoadCursor(hInstance,win_cursors[p_shape])); - cursor_shape=p_shape; + SetCursor(LoadCursor(hInstance, win_cursors[p_shape])); + cursor_shape = p_shape; } -Error OS_Windows::execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id,String* r_pipe,int *r_exitcode) { +Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) { if (p_blocking && r_pipe) { - String argss; - argss="\"\""+p_path+"\""; - - for (const List<String>::Element* E=p_arguments.front(); E; E=E->next()) { + argss = "\"\"" + p_path + "\""; + + for (const List<String>::Element *E = p_arguments.front(); E; E = E->next()) { - argss+=String(" \"")+E->get()+"\""; + argss += String(" \"") + E->get() + "\""; } //print_line("ARGS: "+argss); //argss+"\""; //argss+=" 2>nul"; - FILE* f=_wpopen(argss.c_str(),L"r"); + FILE *f = _wpopen(argss.c_str(), L"r"); - ERR_FAIL_COND_V(!f,ERR_CANT_OPEN); + ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); char buf[65535]; - while(fgets(buf,65535,f)) { + while (fgets(buf, 65535, f)) { - (*r_pipe)+=buf; + (*r_pipe) += buf; } int rv = _pclose(f); if (r_exitcode) - *r_exitcode=rv; + *r_exitcode = rv; return OK; } - String cmdline = "\""+p_path+"\""; - const List<String>::Element* I = p_arguments.front(); + String cmdline = "\"" + p_path + "\""; + const List<String>::Element *I = p_arguments.front(); while (I) { - - cmdline += " \""+I->get() + "\""; + cmdline += " \"" + I->get() + "\""; I = I->next(); }; @@ -2010,16 +1906,16 @@ Error OS_Windows::execute(const String& p_path, const List<String>& p_arguments, //cmdline+="\""; ProcessInfo pi; - ZeroMemory( &pi.si, sizeof(pi.si) ); + ZeroMemory(&pi.si, sizeof(pi.si)); pi.si.cb = sizeof(pi.si); - ZeroMemory( &pi.pi, sizeof(pi.pi) ); - LPSTARTUPINFOW si_w = (LPSTARTUPINFOW) &pi.si; + ZeroMemory(&pi.pi, sizeof(pi.pi)); + LPSTARTUPINFOW si_w = (LPSTARTUPINFOW)&pi.si; - print_line("running cmdline: "+cmdline); + print_line("running cmdline: " + cmdline); Vector<CharType> modstr; //windows wants to change this no idea why modstr.resize(cmdline.size()); - for(int i=0;i<cmdline.size();i++) - modstr[i]=cmdline[i]; + for (int i = 0; i < cmdline.size(); i++) + modstr[i] = cmdline[i]; int ret = CreateProcessW(NULL, modstr.ptr(), NULL, NULL, 0, NORMAL_PRIORITY_CLASS, NULL, NULL, si_w, &pi.pi); ERR_FAIL_COND_V(ret == 0, ERR_CANT_FORK); @@ -2027,7 +1923,7 @@ Error OS_Windows::execute(const String& p_path, const List<String>& p_arguments, DWORD ret = WaitForSingleObject(pi.pi.hProcess, INFINITE); if (r_exitcode) - *r_exitcode=ret; + *r_exitcode = ret; } else { @@ -2040,7 +1936,7 @@ Error OS_Windows::execute(const String& p_path, const List<String>& p_arguments, return OK; }; -Error OS_Windows::kill(const ProcessID& p_pid) { +Error OS_Windows::kill(const ProcessID &p_pid) { HANDLE h; @@ -2054,16 +1950,16 @@ Error OS_Windows::kill(const ProcessID& p_pid) { int ret = TerminateProcess(h, 0); - return ret != 0?OK:FAILED; + return ret != 0 ? OK : FAILED; }; int OS_Windows::get_process_ID() const { return _getpid(); } -Error OS_Windows::set_cwd(const String& p_cwd) { +Error OS_Windows::set_cwd(const String &p_cwd) { - if (_wchdir(p_cwd.c_str())!=0) + if (_wchdir(p_cwd.c_str()) != 0) return ERR_CANT_OPEN; return OK; @@ -2072,17 +1968,16 @@ Error OS_Windows::set_cwd(const String& p_cwd) { String OS_Windows::get_executable_path() const { wchar_t bufname[4096]; - GetModuleFileNameW(NULL,bufname,4096); - String s= bufname; - print_line("EXEC PATHP??: "+s); + GetModuleFileNameW(NULL, bufname, 4096); + String s = bufname; + print_line("EXEC PATHP??: " + s); return s; } -void OS_Windows::set_icon(const Image& p_icon) { +void OS_Windows::set_icon(const Image &p_icon) { - - Image icon=p_icon; - if (icon.get_format()!=Image::FORMAT_RGBA8) + Image icon = p_icon; + if (icon.get_format() != Image::FORMAT_RGBA8) icon.convert(Image::FORMAT_RGBA8); int w = icon.get_width(); int h = icon.get_height(); @@ -2093,55 +1988,53 @@ void OS_Windows::set_icon(const Image& p_icon) { v.resize(icon_len); BYTE *icon_bmp = &v[0]; - encode_uint32(40,&icon_bmp[0]); - encode_uint32(w,&icon_bmp[4]); - encode_uint32(h*2,&icon_bmp[8]); - encode_uint16(1,&icon_bmp[12]); - encode_uint16(32,&icon_bmp[14]); - encode_uint32(BI_RGB,&icon_bmp[16]); - encode_uint32(w*h*4,&icon_bmp[20]); - encode_uint32(0,&icon_bmp[24]); - encode_uint32(0,&icon_bmp[28]); - encode_uint32(0,&icon_bmp[32]); - encode_uint32(0,&icon_bmp[36]); - - uint8_t *wr=&icon_bmp[40]; - PoolVector<uint8_t>::Read r= icon.get_data().read(); - - for(int i=0;i<h;i++) { - - for(int j=0;j<w;j++) { - - const uint8_t *rpx = &r[((h-i-1)*w+j)*4]; - uint8_t *wpx = &wr[(i*w+j)*4]; - wpx[0]=rpx[2]; - wpx[1]=rpx[1]; - wpx[2]=rpx[0]; - wpx[3]=rpx[3]; + encode_uint32(40, &icon_bmp[0]); + encode_uint32(w, &icon_bmp[4]); + encode_uint32(h * 2, &icon_bmp[8]); + encode_uint16(1, &icon_bmp[12]); + encode_uint16(32, &icon_bmp[14]); + encode_uint32(BI_RGB, &icon_bmp[16]); + encode_uint32(w * h * 4, &icon_bmp[20]); + encode_uint32(0, &icon_bmp[24]); + encode_uint32(0, &icon_bmp[28]); + encode_uint32(0, &icon_bmp[32]); + encode_uint32(0, &icon_bmp[36]); + + uint8_t *wr = &icon_bmp[40]; + PoolVector<uint8_t>::Read r = icon.get_data().read(); + + for (int i = 0; i < h; i++) { + + for (int j = 0; j < w; j++) { + + const uint8_t *rpx = &r[((h - i - 1) * w + j) * 4]; + uint8_t *wpx = &wr[(i * w + j) * 4]; + wpx[0] = rpx[2]; + wpx[1] = rpx[1]; + wpx[2] = rpx[0]; + wpx[3] = rpx[3]; } } - HICON hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000); /* Set the icon for the window */ - SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon); + SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hicon); /* Set the icon in the task manager (should we do this?) */ - SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM) hicon); + SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hicon); } - -bool OS_Windows::has_environment(const String& p_var) const { +bool OS_Windows::has_environment(const String &p_var) const { return getenv(p_var.utf8().get_data()) != NULL; }; -String OS_Windows::get_environment(const String& p_var) const { +String OS_Windows::get_environment(const String &p_var) const { wchar_t wval[0x7Fff]; // MSDN says 32767 char is the maximum - int wlen = GetEnvironmentVariableW(p_var.c_str(),wval,0x7Fff); - if ( wlen > 0 ) { + int wlen = GetEnvironmentVariableW(p_var.c_str(), wval, 0x7Fff); + if (wlen > 0) { return wval; } return ""; @@ -2151,23 +2044,20 @@ String OS_Windows::get_stdin_string(bool p_block) { if (p_block) { char buff[1024]; - return fgets(buff,1024,stdin); + return fgets(buff, 1024, stdin); }; return String(); } - void OS_Windows::enable_for_stealing_focus(ProcessID pid) { AllowSetForegroundWindow(pid); - } void OS_Windows::move_window_to_foreground() { SetForegroundWindow(hWnd); - } Error OS_Windows::shell_open(String p_uri) { @@ -2176,38 +2066,35 @@ Error OS_Windows::shell_open(String p_uri) { return OK; } - String OS_Windows::get_locale() const { const _WinLocale *wl = &_win_locales[0]; LANGID langid = GetUserDefaultUILanguage(); String neutral; - int lang = langid&((1<<9)-1); - int sublang = langid&~((1<<9)-1); + int lang = langid & ((1 << 9) - 1); + int sublang = langid & ~((1 << 9) - 1); - while(wl->locale) { + while (wl->locale) { - if (wl->main_lang==lang && wl->sublang==SUBLANG_NEUTRAL) - neutral=wl->locale; + if (wl->main_lang == lang && wl->sublang == SUBLANG_NEUTRAL) + neutral = wl->locale; - if (lang==wl->main_lang && sublang==wl->sublang) + if (lang == wl->main_lang && sublang == wl->sublang) return wl->locale; - wl++; } - if (neutral!="") + if (neutral != "") return neutral; return "en"; } - OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const { - - unsigned long azerty[] = { + + unsigned long azerty[] = { 0x00020401, // Arabic (102) AZERTY 0x0001080c, // Belgian (Comma) 0x0000080c, // Belgian French @@ -2240,27 +2127,28 @@ OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const { 0 // <--- STOP MARK }; - char name[ KL_NAMELENGTH + 1 ]; name[0] = 0; - GetKeyboardLayoutNameA( name ); + char name[KL_NAMELENGTH + 1]; + name[0] = 0; + GetKeyboardLayoutNameA(name); unsigned long hex = strtoul(name, NULL, 16); - int i=0; - while( azerty[i] != 0 ) { + int i = 0; + while (azerty[i] != 0) { if (azerty[i] == hex) return LATIN_KEYBOARD_AZERTY; i++; } i = 0; - while( qwertz[i] != 0 ) { + while (qwertz[i] != 0) { if (qwertz[i] == hex) return LATIN_KEYBOARD_QWERTZ; i++; } - + i = 0; - while( dvorak[i] != 0 ) { + while (dvorak[i] != 0) { if (dvorak[i] == hex) return LATIN_KEYBOARD_DVORAK; - i++; + i++; } return LATIN_KEYBOARD_QWERTY; @@ -2269,7 +2157,6 @@ OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const { void OS_Windows::release_rendering_thread() { gl_context->release_current(); - } void OS_Windows::make_rendering_thread() { @@ -2282,7 +2169,6 @@ void OS_Windows::swap_buffers() { gl_context->swap_buffers(); } - void OS_Windows::run() { if (!main_loop) @@ -2290,24 +2176,21 @@ void OS_Windows::run() { main_loop->init(); - uint64_t last_ticks=get_ticks_usec(); + uint64_t last_ticks = get_ticks_usec(); - int frames=0; - uint64_t frame=0; + int frames = 0; + uint64_t frame = 0; while (!force_quit) { process_events(); // get rid of pending events - if (Main::iteration()==true) + if (Main::iteration() == true) break; }; main_loop->finish(); - } - - MainLoop *OS_Windows::get_main_loop() const { return main_loop; @@ -2315,62 +2198,56 @@ MainLoop *OS_Windows::get_main_loop() const { String OS_Windows::get_system_dir(SystemDir p_dir) const { - int id; - - - switch(p_dir) { + switch (p_dir) { case SYSTEM_DIR_DESKTOP: { - id=CSIDL_DESKTOPDIRECTORY; + id = CSIDL_DESKTOPDIRECTORY; } break; case SYSTEM_DIR_DCIM: { - id=CSIDL_MYPICTURES; + id = CSIDL_MYPICTURES; } break; case SYSTEM_DIR_DOCUMENTS: { - id=CSIDL_PERSONAL; + id = CSIDL_PERSONAL; } break; case SYSTEM_DIR_DOWNLOADS: { - id=0x000C ; + id = 0x000C; } break; case SYSTEM_DIR_MOVIES: { - id=CSIDL_MYVIDEO; + id = CSIDL_MYVIDEO; } break; case SYSTEM_DIR_MUSIC: { - id=CSIDL_MYMUSIC; + id = CSIDL_MYMUSIC; } break; case SYSTEM_DIR_PICTURES: { - id=CSIDL_MYPICTURES; + id = CSIDL_MYPICTURES; } break; case SYSTEM_DIR_RINGTONES: { - id=CSIDL_MYMUSIC; + id = CSIDL_MYMUSIC; } break; } WCHAR szPath[MAX_PATH]; - HRESULT res = SHGetFolderPathW(NULL,id,NULL,0,szPath); - ERR_FAIL_COND_V(res!=S_OK,String()); + HRESULT res = SHGetFolderPathW(NULL, id, NULL, 0, szPath); + ERR_FAIL_COND_V(res != S_OK, String()); return String(szPath); - } String OS_Windows::get_data_dir() const { String an = get_safe_application_name(); - if (an!="") { + if (an != "") { if (has_environment("APPDATA")) { bool use_godot = GlobalConfig::get_singleton()->get("application/use_shared_user_dir"); if (!use_godot) - return (OS::get_singleton()->get_environment("APPDATA")+"/"+an).replace("\\","/"); + return (OS::get_singleton()->get_environment("APPDATA") + "/" + an).replace("\\", "/"); else - return (OS::get_singleton()->get_environment("APPDATA")+"/Godot/app_userdata/"+an).replace("\\","/"); + return (OS::get_singleton()->get_environment("APPDATA") + "/Godot/app_userdata/" + an).replace("\\", "/"); } } return GlobalConfig::get_singleton()->get_resource_path(); - - } bool OS_Windows::is_joy_known(int p_device) { @@ -2387,7 +2264,7 @@ void OS_Windows::set_use_vsync(bool p_enable) { gl_context->set_use_vsync(p_enable); } -bool OS_Windows::is_vsync_enabled() const{ +bool OS_Windows::is_vsync_enabled() const { if (gl_context) return gl_context->is_using_vsync(); @@ -2407,30 +2284,29 @@ int OS_Windows::get_power_percent_left() { return power_manager->get_power_percent_left(); } -bool OS_Windows::check_feature_support(const String& p_feature) { +bool OS_Windows::check_feature_support(const String &p_feature) { return VisualServer::get_singleton()->has_os_feature(p_feature); - } OS_Windows::OS_Windows(HINSTANCE _hInstance) { - key_event_pos=0; - force_quit=false; - alt_mem=false; - gr_mem=false; - shift_mem=false; - control_mem=false; - meta_mem=false; + key_event_pos = 0; + force_quit = false; + alt_mem = false; + gr_mem = false; + shift_mem = false; + control_mem = false; + meta_mem = false; minimized = false; - hInstance=_hInstance; - pressrc=0; - old_invalid=true; - last_id=0; - mouse_mode=MOUSE_MODE_VISIBLE; + hInstance = _hInstance; + pressrc = 0; + old_invalid = true; + last_id = 0; + mouse_mode = MOUSE_MODE_VISIBLE; #ifdef STDOUT_FILE - stdo=fopen("stdout.txt","wb"); + stdo = fopen("stdout.txt", "wb"); #endif user_proc = NULL; @@ -2440,15 +2316,10 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) { #ifdef XAUDIO2_ENABLED AudioDriverManager::add_driver(&driver_xaudio2); #endif - } - -OS_Windows::~OS_Windows() -{ +OS_Windows::~OS_Windows() { #ifdef STDOUT_FILE fclose(stdo); #endif } - - diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index c8cacac7a2..e7376d6800 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -29,30 +29,29 @@ #ifndef OS_WINDOWS_H #define OS_WINDOWS_H +#include "context_gl_win.h" +#include "drivers/rtaudio/audio_driver_rtaudio.h" #include "os/input.h" #include "os/os.h" #include "power_windows.h" -#include "context_gl_win.h" -#include "servers/visual_server.h" -#include "servers/visual/rasterizer.h" -#include "servers/physics/physics_server_sw.h" #include "servers/audio_server.h" -#include "drivers/rtaudio/audio_driver_rtaudio.h" +#include "servers/physics/physics_server_sw.h" +#include "servers/visual/rasterizer.h" +#include "servers/visual_server.h" #ifdef XAUDIO2_ENABLED #include "drivers/xaudio2/audio_driver_xaudio2.h" #endif #include "drivers/unix/ip_unix.h" +#include "key_mapping_win.h" +#include "main/input_default.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/physics_2d/physics_2d_server_wrap_mt.h" -#include "main/input_default.h" -#include "key_mapping_win.h" - -#include <windows.h> -#include <windowsx.h> -#include <io.h> #include <fcntl.h> +#include <io.h> #include <stdio.h> +#include <windows.h> +#include <windowsx.h> /** @author Juan Linietsky <reduzio@gmail.com> @@ -60,33 +59,29 @@ class JoypadWindows; class OS_Windows : public OS { - enum { - KEY_EVENT_BUFFER_SIZE=512 + enum { + KEY_EVENT_BUFFER_SIZE = 512 }; FILE *stdo; - struct KeyEvent { InputModifierState mod_state; UINT uMsg; - WPARAM wParam; - LPARAM lParam; - + WPARAM wParam; + LPARAM lParam; }; KeyEvent key_event_buffer[KEY_EVENT_BUFFER_SIZE]; int key_event_pos; - uint64_t ticks_start; uint64_t ticks_per_second; - - bool old_invalid; - bool outside; - int old_x,old_y; + bool old_invalid; + bool outside; + int old_x, old_y; Point2i center; unsigned int last_id; #if defined(OPENGL_ENABLED) @@ -96,8 +91,8 @@ class OS_Windows : public OS { PhysicsServer *physics_server; Physics2DServer *physics_2d_server; int pressrc; - HDC hDC; // Private GDI Device Context - HINSTANCE hInstance; // Holds The Instance Of The Application + HDC hDC; // Private GDI Device Context + HINSTANCE hInstance; // Holds The Instance Of The Application HWND hWnd; uint32_t move_timer_id; @@ -141,17 +136,17 @@ class OS_Windows : public OS { // functions used by main to initialize/deintialize the OS protected: virtual int get_video_driver_count() const; - virtual const char * get_video_driver_name(int p_driver) const; + virtual const char *get_video_driver_name(int p_driver) const; virtual VideoMode get_default_video_mode() const; virtual int get_audio_driver_count() const; - virtual const char * get_audio_driver_name(int p_driver) const; + virtual const char *get_audio_driver_name(int p_driver) const; virtual void initialize_core(); - virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); + virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); - virtual void set_main_loop( MainLoop * p_main_loop ); + virtual void set_main_loop(MainLoop *p_main_loop); virtual void delete_main_loop(); virtual void finalize(); @@ -165,15 +160,13 @@ protected: STARTUPINFO si; PROCESS_INFORMATION pi; }; - Map<ProcessID, ProcessInfo>* process_map; + Map<ProcessID, ProcessInfo> *process_map; struct MonitorInfo { HMONITOR hMonitor; HDC hdcMonitor; Rect2 rect; int dpi; - - }; bool pre_fs_valid; @@ -183,40 +176,38 @@ protected: bool minimized; bool borderless; - static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); - + static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); public: - LRESULT WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type); - void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type); - - virtual void vprint(const char *p_format, va_list p_list, bool p_stderr=false); - virtual void alert(const String& p_alert,const String& p_title="ALERT!"); + virtual void vprint(const char *p_format, va_list p_list, bool p_stderr = false); + virtual void alert(const String &p_alert, const String &p_title = "ALERT!"); String get_stdin_string(bool p_block); void set_mouse_mode(MouseMode p_mode); MouseMode get_mouse_mode() const; - virtual void warp_mouse_pos(const Point2& p_to); + virtual void warp_mouse_pos(const Point2 &p_to); virtual Point2 get_mouse_pos() const; virtual int get_mouse_button_state() const; - virtual void set_window_title(const String& p_title); + virtual void set_window_title(const String &p_title); - virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); - virtual VideoMode get_video_mode(int p_screen=0) const; - virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; + virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0); + virtual VideoMode get_video_mode(int p_screen = 0) const; + virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const; virtual int get_screen_count() const; virtual int get_current_screen() const; virtual void set_current_screen(int p_screen); - virtual Point2 get_screen_position(int p_screen=0) const; - virtual Size2 get_screen_size(int p_screen=0) const; - virtual int get_screen_dpi(int p_screen=0) const; + virtual Point2 get_screen_position(int p_screen = 0) const; + virtual Size2 get_screen_size(int p_screen = 0) const; + virtual int get_screen_dpi(int p_screen = 0) const; virtual Point2 get_window_position() const; - virtual void set_window_position(const Point2& p_position); + virtual void set_window_position(const Point2 &p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2 p_size); virtual void set_window_fullscreen(bool p_enabled); @@ -243,35 +234,34 @@ public: virtual uint64_t get_system_time_secs() const; virtual bool can_draw() const; - virtual Error set_cwd(const String& p_cwd); + virtual Error set_cwd(const String &p_cwd); virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; - virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL); - virtual Error kill(const ProcessID& p_pid); + virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL); + virtual Error kill(const ProcessID &p_pid); virtual int get_process_ID() const; - virtual bool has_environment(const String& p_var) const; - virtual String get_environment(const String& p_var) const; + virtual bool has_environment(const String &p_var) const; + virtual String get_environment(const String &p_var) const; - virtual void set_clipboard(const String& p_text); + virtual void set_clipboard(const String &p_text); virtual String get_clipboard() const; void set_cursor_shape(CursorShape p_shape); - void set_icon(const Image& p_icon); + void set_icon(const Image &p_icon); virtual String get_executable_path() const; virtual String get_locale() const; - virtual LatinKeyboardVariant get_latin_keyboard_variant() const; + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; virtual void enable_for_stealing_focus(ProcessID pid); virtual void move_window_to_foreground(); virtual String get_data_dir() const; virtual String get_system_dir(SystemDir p_dir) const; - virtual void release_rendering_thread(); virtual void make_rendering_thread(); virtual void swap_buffers(); @@ -292,11 +282,10 @@ public: virtual int get_power_seconds_left(); virtual int get_power_percent_left(); - virtual bool check_feature_support(const String& p_feature); + virtual bool check_feature_support(const String &p_feature); OS_Windows(HINSTANCE _hInstance); ~OS_Windows(); - }; #endif diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp index 276b9b6634..2df8addece 100644 --- a/platform/windows/packet_peer_udp_winsock.cpp +++ b/platform/windows/packet_peer_udp_winsock.cpp @@ -35,19 +35,19 @@ int PacketPeerUDPWinsock::get_available_packet_count() const { - Error err = const_cast<PacketPeerUDPWinsock*>(this)->_poll(false); - if (err!=OK) + Error err = const_cast<PacketPeerUDPWinsock *>(this)->_poll(false); + if (err != OK) return 0; return queue_count; } -Error PacketPeerUDPWinsock::get_packet(const uint8_t **r_buffer,int &r_buffer_size) const{ +Error PacketPeerUDPWinsock::get_packet(const uint8_t **r_buffer, int &r_buffer_size) const { - Error err = const_cast<PacketPeerUDPWinsock*>(this)->_poll(false); - if (err!=OK) + Error err = const_cast<PacketPeerUDPWinsock *>(this)->_poll(false); + if (err != OK) return err; - if (queue_count==0) + if (queue_count == 0) return ERR_UNAVAILABLE; uint32_t size; @@ -55,31 +55,30 @@ Error PacketPeerUDPWinsock::get_packet(const uint8_t **r_buffer,int &r_buffer_si rb.read(&type, 1, true); if (type == IP::TYPE_IPV4) { uint8_t ip[4]; - rb.read(ip,4,true); + rb.read(ip, 4, true); packet_ip.set_ipv4(ip); } else { uint8_t ip[16]; - rb.read(ip,16,true); + rb.read(ip, 16, true); packet_ip.set_ipv6(ip); }; - rb.read((uint8_t*)&packet_port,4,true); - rb.read((uint8_t*)&size,4,true); - rb.read(packet_buffer,size,true); + rb.read((uint8_t *)&packet_port, 4, true); + rb.read((uint8_t *)&size, 4, true); + rb.read(packet_buffer, size, true); --queue_count; - *r_buffer=packet_buffer; - r_buffer_size=size; + *r_buffer = packet_buffer; + r_buffer_size = size; return OK; - } -Error PacketPeerUDPWinsock::put_packet(const uint8_t *p_buffer,int p_buffer_size){ +Error PacketPeerUDPWinsock::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V(!peer_addr.is_valid(), ERR_UNCONFIGURED); - if(sock_type==IP::TYPE_NONE) + if (sock_type == IP::TYPE_NONE) sock_type = peer_addr.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; int sock = _get_socket(); - ERR_FAIL_COND_V( sock == -1, FAILED ); + ERR_FAIL_COND_V(sock == -1, FAILED); struct sockaddr_storage addr; size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port, sock_type); @@ -87,7 +86,7 @@ Error PacketPeerUDPWinsock::put_packet(const uint8_t *p_buffer,int p_buffer_size errno = 0; int err; - while ( (err = sendto(sock, (const char*)p_buffer, p_buffer_size, 0, (struct sockaddr*)&addr, addr_size)) != p_buffer_size) { + while ((err = sendto(sock, (const char *)p_buffer, p_buffer_size, 0, (struct sockaddr *)&addr, addr_size)) != p_buffer_size) { if (WSAGetLastError() != WSAEWOULDBLOCK) { return FAILED; @@ -97,21 +96,20 @@ Error PacketPeerUDPWinsock::put_packet(const uint8_t *p_buffer,int p_buffer_size return OK; } -int PacketPeerUDPWinsock::get_max_packet_size() const{ +int PacketPeerUDPWinsock::get_max_packet_size() const { return 512; // uhm maybe not } - void PacketPeerUDPWinsock::_set_blocking(bool p_blocking) { //am no windows expert //hope this is the right thing - if (blocking==p_blocking) + if (blocking == p_blocking) return; - blocking=p_blocking; - unsigned long par = blocking?0:1; + blocking = p_blocking; + unsigned long par = blocking ? 0 : 1; if (ioctlsocket(sockfd, FIONBIO, &par)) { perror("setting non-block mode"); //close(); @@ -121,69 +119,67 @@ void PacketPeerUDPWinsock::_set_blocking(bool p_blocking) { Error PacketPeerUDPWinsock::listen(int p_port, IP_Address p_bind_address, int p_recv_buffer_size) { - ERR_FAIL_COND_V(sockfd!=-1,ERR_ALREADY_IN_USE); - ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(),ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(sockfd != -1, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); sock_type = IP::TYPE_ANY; - if(p_bind_address.is_valid()) + if (p_bind_address.is_valid()) sock_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; int sock = _get_socket(); - if (sock == -1 ) + if (sock == -1) return ERR_CANT_CREATE; - struct sockaddr_storage addr = {0}; + struct sockaddr_storage addr = { 0 }; size_t addr_size = _set_listen_sockaddr(&addr, p_port, sock_type, IP_Address()); - if (bind(sock, (struct sockaddr*)&addr, addr_size) == -1 ) { + if (bind(sock, (struct sockaddr *)&addr, addr_size) == -1) { close(); return ERR_UNAVAILABLE; } - blocking=true; + blocking = true; printf("UDP Connection listening on port %i\n", p_port); rb.resize(nearest_shift(p_recv_buffer_size)); return OK; } -void PacketPeerUDPWinsock::close(){ +void PacketPeerUDPWinsock::close() { if (sockfd != -1) ::closesocket(sockfd); - sockfd=-1; + sockfd = -1; sock_type = IP::TYPE_NONE; rb.resize(16); - queue_count=0; + queue_count = 0; } - Error PacketPeerUDPWinsock::wait() { return _poll(true); } Error PacketPeerUDPWinsock::_poll(bool p_wait) { - if (sockfd==-1) { + if (sockfd == -1) { return FAILED; } _set_blocking(p_wait); - - struct sockaddr_storage from = {0}; + struct sockaddr_storage from = { 0 }; int len = sizeof(struct sockaddr_storage); int ret; - while ( (ret = recvfrom(sockfd, (char*)recv_buffer, MIN((int)sizeof(recv_buffer),MAX(rb.space_left()-24, 0)), 0, (struct sockaddr*)&from, &len)) > 0) { + while ((ret = recvfrom(sockfd, (char *)recv_buffer, MIN((int)sizeof(recv_buffer), MAX(rb.space_left() - 24, 0)), 0, (struct sockaddr *)&from, &len)) > 0) { uint32_t port = 0; if (from.ss_family == AF_INET) { uint8_t type = (uint8_t)IP::TYPE_IPV4; rb.write(&type, 1); - struct sockaddr_in* sin_from = (struct sockaddr_in*)&from; - rb.write((uint8_t*)&sin_from->sin_addr, 4); + struct sockaddr_in *sin_from = (struct sockaddr_in *)&from; + rb.write((uint8_t *)&sin_from->sin_addr, 4); port = ntohs(sin_from->sin_port); } else if (from.ss_family == AF_INET6) { @@ -191,8 +187,8 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) { uint8_t type = (uint8_t)IP::TYPE_IPV6; rb.write(&type, 1); - struct sockaddr_in6* s6_from = (struct sockaddr_in6*)&from; - rb.write((uint8_t*)&s6_from->sin6_addr, 16); + struct sockaddr_in6 *s6_from = (struct sockaddr_in6 *)&from; + rb.write((uint8_t *)&s6_from->sin6_addr, 16); port = ntohs(s6_from->sin6_port); @@ -202,44 +198,39 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) { rb.write(&type, 1); }; - rb.write((uint8_t*)&port, 4); - rb.write((uint8_t*)&ret, 4); + rb.write((uint8_t *)&port, 4); + rb.write((uint8_t *)&ret, 4); rb.write(recv_buffer, ret); len = sizeof(struct sockaddr_storage); ++queue_count; }; - if (ret == SOCKET_ERROR){ + if (ret == SOCKET_ERROR) { int error = WSAGetLastError(); - if (error == WSAEWOULDBLOCK){ + if (error == WSAEWOULDBLOCK) { // Expected when doing non-blocking sockets, retry later. - } - else if (error == WSAECONNRESET){ + } else if (error == WSAECONNRESET) { // If the remote target does not accept messages, this error may occur, but is harmless. // Once the remote target gets available, this message will disappear for new messages. - } - else - { + } else { close(); return FAILED; } } - if (ret == 0) { close(); return FAILED; }; - return OK; } -bool PacketPeerUDPWinsock::is_listening() const{ +bool PacketPeerUDPWinsock::is_listening() const { - return sockfd!=-1; + return sockfd != -1; } IP_Address PacketPeerUDPWinsock::get_packet_address() const { @@ -247,14 +238,14 @@ IP_Address PacketPeerUDPWinsock::get_packet_address() const { return packet_ip; } -int PacketPeerUDPWinsock::get_packet_port() const{ +int PacketPeerUDPWinsock::get_packet_port() const { return packet_port; } int PacketPeerUDPWinsock::_get_socket() { - ERR_FAIL_COND_V(sock_type==IP::TYPE_NONE,-1); + ERR_FAIL_COND_V(sock_type == IP::TYPE_NONE, -1); if (sockfd != -1) return sockfd; @@ -264,11 +255,10 @@ int PacketPeerUDPWinsock::_get_socket() { return sockfd; } +void PacketPeerUDPWinsock::set_dest_address(const IP_Address &p_address, int p_port) { -void PacketPeerUDPWinsock::set_dest_address(const IP_Address& p_address,int p_port) { - - peer_addr=p_address; - peer_port=p_port; + peer_addr = p_address; + peer_port = p_port; } void PacketPeerUDPWinsock::make_default() { @@ -276,19 +266,17 @@ void PacketPeerUDPWinsock::make_default() { PacketPeerUDP::_create = PacketPeerUDPWinsock::_create; }; - -PacketPeerUDP* PacketPeerUDPWinsock::_create() { +PacketPeerUDP *PacketPeerUDPWinsock::_create() { return memnew(PacketPeerUDPWinsock); }; - PacketPeerUDPWinsock::PacketPeerUDPWinsock() { - sockfd=-1; - packet_port=0; - queue_count=0; - peer_port=0; + sockfd = -1; + packet_port = 0; + queue_count = 0; + peer_port = 0; sock_type = IP::TYPE_NONE; rb.resize(16); } diff --git a/platform/windows/packet_peer_udp_winsock.h b/platform/windows/packet_peer_udp_winsock.h index dcd9da9a79..62107364af 100644 --- a/platform/windows/packet_peer_udp_winsock.h +++ b/platform/windows/packet_peer_udp_winsock.h @@ -34,9 +34,8 @@ class PacketPeerUDPWinsock : public PacketPeerUDP { - enum { - PACKET_BUFFER_SIZE=65536 + PACKET_BUFFER_SIZE = 65536 }; mutable RingBuffer<uint8_t> rb; @@ -53,7 +52,7 @@ class PacketPeerUDPWinsock : public PacketPeerUDP { _FORCE_INLINE_ int _get_socket(); - static PacketPeerUDP* _create(); + static PacketPeerUDP *_create(); bool blocking; void _set_blocking(bool p_blocking); @@ -61,14 +60,13 @@ class PacketPeerUDPWinsock : public PacketPeerUDP { Error _poll(bool p_wait); public: - virtual int get_available_packet_count() const; - virtual Error get_packet(const uint8_t **r_buffer,int &r_buffer_size) const; - virtual Error put_packet(const uint8_t *p_buffer,int p_buffer_size); + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const; + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); virtual int get_max_packet_size() const; - virtual Error listen(int p_port, IP_Address p_bind_address=IP_Address("*"), int p_recv_buffer_size=65536); + virtual Error listen(int p_port, IP_Address p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); virtual void close(); virtual Error wait(); virtual bool is_listening() const; @@ -76,7 +74,7 @@ public: virtual IP_Address get_packet_address() const; virtual int get_packet_port() const; - virtual void set_dest_address(const IP_Address& p_address,int p_port); + virtual void set_dest_address(const IP_Address &p_address, int p_port); static void make_default(); PacketPeerUDPWinsock(); diff --git a/platform/windows/power_windows.cpp b/platform/windows/power_windows.cpp index 899b620a24..d4641cd4ec 100644 --- a/platform/windows/power_windows.cpp +++ b/platform/windows/power_windows.cpp @@ -31,53 +31,50 @@ // CODE CHUNK IMPORTED FROM SDL 2.0 -bool PowerWindows::GetPowerInfo_Windows() -{ - SYSTEM_POWER_STATUS status; - bool need_details = FALSE; +bool PowerWindows::GetPowerInfo_Windows() { + SYSTEM_POWER_STATUS status; + bool need_details = FALSE; - /* This API should exist back to Win95. */ - if (!GetSystemPowerStatus(&status)) - { - /* !!! FIXME: push GetLastError() into GetError() */ - power_state = POWERSTATE_UNKNOWN; - } else if (status.BatteryFlag == 0xFF) { /* unknown state */ - power_state = POWERSTATE_UNKNOWN; - } else if (status.BatteryFlag & (1 << 7)) { /* no battery */ - power_state = POWERSTATE_NO_BATTERY; - } else if (status.BatteryFlag & (1 << 3)) { /* charging */ - power_state = POWERSTATE_CHARGING; - need_details = TRUE; - } else if (status.ACLineStatus == 1) { - power_state = POWERSTATE_CHARGED; /* on AC, not charging. */ - need_details = TRUE; - } else { - power_state = POWERSTATE_ON_BATTERY; /* not on AC. */ - need_details = TRUE; - } + /* This API should exist back to Win95. */ + if (!GetSystemPowerStatus(&status)) { + /* !!! FIXME: push GetLastError() into GetError() */ + power_state = POWERSTATE_UNKNOWN; + } else if (status.BatteryFlag == 0xFF) { /* unknown state */ + power_state = POWERSTATE_UNKNOWN; + } else if (status.BatteryFlag & (1 << 7)) { /* no battery */ + power_state = POWERSTATE_NO_BATTERY; + } else if (status.BatteryFlag & (1 << 3)) { /* charging */ + power_state = POWERSTATE_CHARGING; + need_details = TRUE; + } else if (status.ACLineStatus == 1) { + power_state = POWERSTATE_CHARGED; /* on AC, not charging. */ + need_details = TRUE; + } else { + power_state = POWERSTATE_ON_BATTERY; /* not on AC. */ + need_details = TRUE; + } - percent_left = -1; - nsecs_left = -1; - if (need_details) { - const int pct = (int) status.BatteryLifePercent; - const int secs = (int) status.BatteryLifeTime; + percent_left = -1; + nsecs_left = -1; + if (need_details) { + const int pct = (int)status.BatteryLifePercent; + const int secs = (int)status.BatteryLifeTime; - if (pct != 255) { /* 255 == unknown */ - percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ - } - if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */ - nsecs_left = secs; - } - } + if (pct != 255) { /* 255 == unknown */ + percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ + } + if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */ + nsecs_left = secs; + } + } - return TRUE; /* always the definitive answer on Windows. */ + return TRUE; /* always the definitive answer on Windows. */ } PowerState PowerWindows::get_power_state() { if (GetPowerInfo_Windows()) { return power_state; - } - else { + } else { return POWERSTATE_UNKNOWN; } } @@ -85,8 +82,7 @@ PowerState PowerWindows::get_power_state() { int PowerWindows::get_power_seconds_left() { if (GetPowerInfo_Windows()) { return nsecs_left; - } - else { + } else { return -1; } } @@ -94,14 +90,13 @@ int PowerWindows::get_power_seconds_left() { int PowerWindows::get_power_percent_left() { if (GetPowerInfo_Windows()) { return percent_left; - } - else { + } else { return -1; } } -PowerWindows::PowerWindows() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { - +PowerWindows::PowerWindows() + : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { } PowerWindows::~PowerWindows() { diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp index 106eb6a5f5..abf182c72a 100644 --- a/platform/windows/stream_peer_winsock.cpp +++ b/platform/windows/stream_peer_winsock.cpp @@ -37,7 +37,7 @@ int winsock_refcount = 0; -StreamPeerTCP* StreamPeerWinsock::_create() { +StreamPeerTCP *StreamPeerWinsock::_create() { return memnew(StreamPeerWinsock); }; @@ -48,7 +48,7 @@ void StreamPeerWinsock::make_default() { if (winsock_refcount == 0) { WSADATA data; - WSAStartup(MAKEWORD(2,2), &data); + WSAStartup(MAKEWORD(2, 2), &data); }; ++winsock_refcount; }; @@ -62,7 +62,6 @@ void StreamPeerWinsock::cleanup() { }; }; - Error StreamPeerWinsock::_block(int p_sockfd, bool p_read, bool p_write) const { fd_set read, write; @@ -85,7 +84,7 @@ Error StreamPeerWinsock::_poll_connection() const { struct sockaddr_storage their_addr; size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type); - if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == SOCKET_ERROR) { + if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == SOCKET_ERROR) { int err = WSAGetLastError(); if (err == WSAEISCONN) { @@ -108,7 +107,7 @@ Error StreamPeerWinsock::_poll_connection() const { return OK; }; -Error StreamPeerWinsock::write(const uint8_t* p_data,int p_bytes, int &r_sent, bool p_block) { +Error StreamPeerWinsock::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) { if (status == STATUS_NONE || status == STATUS_ERROR) { @@ -135,7 +134,7 @@ Error StreamPeerWinsock::write(const uint8_t* p_data,int p_bytes, int &r_sent, b while (data_to_send) { - int sent_amount = send(sockfd, (const char*)offset, data_to_send, 0); + int sent_amount = send(sockfd, (const char *)offset, data_to_send, 0); if (sent_amount == -1) { @@ -166,7 +165,7 @@ Error StreamPeerWinsock::write(const uint8_t* p_data,int p_bytes, int &r_sent, b return OK; }; -Error StreamPeerWinsock::read(uint8_t* p_buffer, int p_bytes,int &r_received, bool p_block) { +Error StreamPeerWinsock::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) { if (!is_connected_to_host()) { @@ -191,7 +190,7 @@ Error StreamPeerWinsock::read(uint8_t* p_buffer, int p_bytes,int &r_received, bo while (to_read) { - int read = recv(sockfd, (char*)p_buffer + total_read, to_read, 0); + int read = recv(sockfd, (char *)p_buffer + total_read, to_read, 0); if (read == -1) { @@ -224,24 +223,24 @@ Error StreamPeerWinsock::read(uint8_t* p_buffer, int p_bytes,int &r_received, bo return OK; }; -Error StreamPeerWinsock::put_data(const uint8_t* p_data,int p_bytes) { +Error StreamPeerWinsock::put_data(const uint8_t *p_data, int p_bytes) { int total; return write(p_data, p_bytes, total, true); }; -Error StreamPeerWinsock::put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent) { +Error StreamPeerWinsock::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { return write(p_data, p_bytes, r_sent, false); }; -Error StreamPeerWinsock::get_data(uint8_t* p_buffer, int p_bytes) { +Error StreamPeerWinsock::get_data(uint8_t *p_buffer, int p_bytes) { int total; return read(p_buffer, p_bytes, total, true); }; -Error StreamPeerWinsock::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received) { +Error StreamPeerWinsock::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { return read(p_buffer, p_bytes, r_received, false); }; @@ -255,7 +254,6 @@ StreamPeerTCP::Status StreamPeerWinsock::get_status() const { return status; }; - bool StreamPeerWinsock::is_connected_to_host() const { if (status == STATUS_NONE || status == STATUS_ERROR) { @@ -266,14 +264,14 @@ bool StreamPeerWinsock::is_connected_to_host() const { return true; }; - return (sockfd!=INVALID_SOCKET); + return (sockfd != INVALID_SOCKET); }; void StreamPeerWinsock::disconnect_from_host() { if (sockfd != INVALID_SOCKET) closesocket(sockfd); - sockfd=INVALID_SOCKET; + sockfd = INVALID_SOCKET; sock_type = IP::TYPE_NONE; status = STATUS_NONE; @@ -291,13 +289,13 @@ void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, peer_port = p_port; }; -Error StreamPeerWinsock::connect_to_host(const IP_Address& p_host, uint16_t p_port) { +Error StreamPeerWinsock::connect_to_host(const IP_Address &p_host, uint16_t p_port) { - ERR_FAIL_COND_V( !p_host.is_valid(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); sock_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; sockfd = _socket_create(sock_type, SOCK_STREAM, IPPROTO_TCP); - if (sockfd == INVALID_SOCKET) { + if (sockfd == INVALID_SOCKET) { ERR_PRINT("Socket creation failed!"); disconnect_from_host(); //perror("socket"); @@ -314,7 +312,7 @@ Error StreamPeerWinsock::connect_to_host(const IP_Address& p_host, uint16_t p_po struct sockaddr_storage their_addr; size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, sock_type); - if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == SOCKET_ERROR) { + if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == SOCKET_ERROR) { if (WSAGetLastError() != WSAEWOULDBLOCK) { ERR_PRINT("Connection to remote host failed!"); @@ -333,18 +331,17 @@ Error StreamPeerWinsock::connect_to_host(const IP_Address& p_host, uint16_t p_po }; void StreamPeerWinsock::set_nodelay(bool p_enabled) { - ERR_FAIL_COND(!is_connected_to_host()); - int flag=p_enabled?1:0; - setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int)); + ERR_FAIL_COND(!is_connected_to_host()); + int flag = p_enabled ? 1 : 0; + setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)); } int StreamPeerWinsock::get_available_bytes() const { unsigned long len; - int ret = ioctlsocket(sockfd,FIONREAD,&len); - ERR_FAIL_COND_V(ret==-1,0) + int ret = ioctlsocket(sockfd, FIONREAD, &len); + ERR_FAIL_COND_V(ret == -1, 0) return len; - } IP_Address StreamPeerWinsock::get_connected_host() const { @@ -370,5 +367,4 @@ StreamPeerWinsock::~StreamPeerWinsock() { disconnect_from_host(); }; - #endif diff --git a/platform/windows/stream_peer_winsock.h b/platform/windows/stream_peer_winsock.h index 7cf60fc10e..c8c2dd4feb 100644 --- a/platform/windows/stream_peer_winsock.h +++ b/platform/windows/stream_peer_winsock.h @@ -39,7 +39,6 @@ class StreamPeerWinsock : public StreamPeerTCP { protected: - mutable Status status; IP::Type sock_type; @@ -52,20 +51,19 @@ protected: IP_Address peer_host; int peer_port; - Error write(const uint8_t* p_data,int p_bytes, int &r_sent, bool p_block); - Error read(uint8_t* p_buffer, int p_bytes,int &r_received, bool p_block); + Error write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block); + Error read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block); - static StreamPeerTCP* _create(); + static StreamPeerTCP *_create(); public: + virtual Error connect_to_host(const IP_Address &p_host, uint16_t p_port); - virtual Error connect_to_host(const IP_Address& p_host, uint16_t p_port); - - virtual Error put_data(const uint8_t* p_data,int p_bytes); - virtual Error put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent); + virtual Error put_data(const uint8_t *p_data, int p_bytes); + virtual Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent); - virtual Error get_data(uint8_t* p_buffer, int p_bytes); - virtual Error get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received); + virtual Error get_data(uint8_t *p_buffer, int p_bytes); + virtual Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received); virtual int get_available_bytes() const; @@ -83,7 +81,6 @@ public: virtual void set_nodelay(bool p_enabled); - StreamPeerWinsock(); ~StreamPeerWinsock(); }; diff --git a/platform/windows/tcp_server_winsock.cpp b/platform/windows/tcp_server_winsock.cpp index 883741b115..67713f5d1c 100644 --- a/platform/windows/tcp_server_winsock.cpp +++ b/platform/windows/tcp_server_winsock.cpp @@ -37,7 +37,7 @@ extern int winsock_refcount; -TCP_Server* TCPServerWinsock::_create() { +TCP_Server *TCPServerWinsock::_create() { return memnew(TCPServerWinsock); }; @@ -48,7 +48,7 @@ void TCPServerWinsock::make_default() { if (winsock_refcount == 0) { WSADATA data; - WSAStartup(MAKEWORD(2,2), &data); + WSAStartup(MAKEWORD(2, 2), &data); }; ++winsock_refcount; }; @@ -62,10 +62,9 @@ void TCPServerWinsock::cleanup() { }; }; +Error TCPServerWinsock::listen(uint16_t p_port, const IP_Address p_bind_address) { -Error TCPServerWinsock::listen(uint16_t p_port,const IP_Address p_bind_address) { - - ERR_FAIL_COND_V(listen_sockfd!=-1,ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V(listen_sockfd != -1, ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); int sockfd; @@ -75,7 +74,6 @@ Error TCPServerWinsock::listen(uint16_t p_port,const IP_Address p_bind_address) if (p_bind_address.is_valid()) sock_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; - sockfd = _socket_create(sock_type, SOCK_STREAM, IPPROTO_TCP); ERR_FAIL_COND_V(sockfd == INVALID_SOCKET, FAILED); @@ -89,13 +87,12 @@ Error TCPServerWinsock::listen(uint16_t p_port,const IP_Address p_bind_address) struct sockaddr_storage my_addr; size_t addr_size = _set_listen_sockaddr(&my_addr, p_port, sock_type, p_bind_address); - int reuse=1; - if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) { + int reuse = 1; + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) { printf("REUSEADDR failed!"); } - if (bind(sockfd, (struct sockaddr *)&my_addr, addr_size) != SOCKET_ERROR) { if (::listen(sockfd, SOMAXCONN) == SOCKET_ERROR) { @@ -103,8 +100,7 @@ Error TCPServerWinsock::listen(uint16_t p_port,const IP_Address p_bind_address) closesocket(sockfd); ERR_FAIL_V(FAILED); }; - } - else { + } else { return ERR_ALREADY_IN_USE; }; @@ -143,7 +139,6 @@ bool TCPServerWinsock::is_connection_available() const { return false; }; - Ref<StreamPeerTCP> TCPServerWinsock::take_connection() { if (!is_connection_available()) { @@ -175,7 +170,6 @@ void TCPServerWinsock::stop() { sock_type = IP::TYPE_NONE; }; - TCPServerWinsock::TCPServerWinsock() { listen_sockfd = INVALID_SOCKET; @@ -186,4 +180,3 @@ TCPServerWinsock::~TCPServerWinsock() { stop(); }; - diff --git a/platform/windows/tcp_server_winsock.h b/platform/windows/tcp_server_winsock.h index afbd1e9c87..d7b1aee054 100644 --- a/platform/windows/tcp_server_winsock.h +++ b/platform/windows/tcp_server_winsock.h @@ -36,11 +36,10 @@ class TCPServerWinsock : public TCP_Server { int listen_sockfd; IP::Type sock_type; - static TCP_Server* _create(); + static TCP_Server *_create(); public: - - virtual Error listen(uint16_t p_port, const IP_Address p_bind_address=IP_Address("*")); + virtual Error listen(uint16_t p_port, const IP_Address p_bind_address = IP_Address("*")); virtual bool is_connection_available() const; virtual Ref<StreamPeerTCP> take_connection(); |