diff options
Diffstat (limited to 'platform/windows/os_windows.cpp')
-rw-r--r-- | platform/windows/os_windows.cpp | 530 |
1 files changed, 471 insertions, 59 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index a10152a025..1fb8e6dbd0 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "drivers/gles2/rasterizer_gles2.h" -#include "drivers/gles1/rasterizer_gles1.h" + #include "os_windows.h" #include "drivers/nedmalloc/memory_pool_static_nedmalloc.h" #include "drivers/unix/memory_pool_static_malloc.h" @@ -54,8 +54,17 @@ #include "io/marshalls.h" #include "shlobj.h" +#include <regstr.h> + static const WORD MAX_CONSOLE_LINES = 1500; +extern "C" { +#ifdef _MSC_VER + _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; +#else + __attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001; +#endif +} //#define STDOUT_FILE @@ -130,11 +139,11 @@ void RedirectIOToConsole() { int OS_Windows::get_video_driver_count() const { - return 2; + return 1; } const char * OS_Windows::get_video_driver_name(int p_driver) const { - return p_driver==0?"GLES2":"GLES1"; + return "GLES2"; } OS::VideoMode OS_Windows::get_default_video_mode() const { @@ -162,6 +171,8 @@ void OS_Windows::initialize_core() { last_button_state=0; //RedirectIOToConsole(); + maximized=false; + minimized=false; ThreadWindows::make_default(); SemaphoreWindows::make_default(); @@ -312,11 +323,21 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { 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); } break; case WM_MOUSEMOVE: { if (outside) { + //mouse enter + + 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; @@ -412,6 +433,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_RBUTTONUP: case WM_MOUSEWHEEL: case WM_LBUTTONDBLCLK: + case WM_RBUTTONDBLCLK: /*case WM_XBUTTONDOWN: case WM_XBUTTONUP: */{ @@ -465,6 +487,12 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { 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; @@ -586,10 +614,11 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { ERR_BREAK(key_event_pos >= KEY_EVENT_BUFFER_SIZE); + // Make sure we don't include modifiers for the modifier key itself. KeyEvent ke; - ke.mod_state.shift=shift_mem; - ke.mod_state.alt=alt_mem; - ke.mod_state.control=control_mem; + 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; @@ -677,6 +706,53 @@ LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { } + +String OS_Windows::get_joystick_name(int id, JOYCAPS jcaps) +{ + char buffer [256]; + char OEM [256]; + HKEY hKey; + DWORD sz; + int res; + + _snprintf(buffer, sizeof(buffer), "%s\\%s\\%s", + REGSTR_PATH_JOYCONFIG, jcaps.szRegKey, + REGSTR_KEY_JOYCURR ); + res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey); + if (res != ERROR_SUCCESS) + { + res = RegOpenKeyEx(HKEY_CURRENT_USER, buffer, 0, KEY_QUERY_VALUE, &hKey); + if (res != ERROR_SUCCESS) + return ""; + } + + sz = sizeof(OEM); + _snprintf( buffer, sizeof(buffer), "Joystick%d%s", id + 1, REGSTR_VAL_JOYOEMNAME); + res = RegQueryValueEx ( hKey, buffer, 0, 0, (LPBYTE) OEM, &sz); + RegCloseKey ( hKey ); + if (res != ERROR_SUCCESS) + return ""; + + _snprintf( buffer, sizeof(buffer), "%s\\%s", REGSTR_PATH_JOYOEM, OEM); + res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey); + if (res != ERROR_SUCCESS) + { + res = RegOpenKeyEx(HKEY_CURRENT_USER, buffer, 0, KEY_QUERY_VALUE, &hKey); + if (res != ERROR_SUCCESS) + return ""; + } + + + sz = sizeof(buffer); + res = RegQueryValueEx(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, (LPBYTE) buffer, + &sz); + RegCloseKey(hKey); + if (res != ERROR_SUCCESS) + return ""; + + return String(buffer); +} + void OS_Windows::probe_joysticks() { static uint32_t last_attached = 0; @@ -718,7 +794,13 @@ void OS_Windows::probe_joysticks() { JOYCAPS jcaps; MMRESULT res = joyGetDevCaps(JOYSTICKID1 + i, &jcaps, sizeof(jcaps)); if (res == JOYERR_NOERROR) { - joy.name = jcaps.szPname; + String name = get_joystick_name(JOYSTICKID1 + i, jcaps); + if ( name == "") + joy.name = jcaps.szPname; + else + joy.name = name; + + }; }; @@ -944,6 +1026,23 @@ void OS_Windows::process_joysticks() { }; }; + +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; + + self->monitor_info.push_back(minfo); + + return TRUE; +} + + void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { @@ -982,6 +1081,10 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ } + EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,0); + + print_line("DETECTED MONITORS: "+itos(monitor_info.size())); + pre_fs_valid=true; if (video_mode.fullscreen) { DEVMODE current; @@ -1004,6 +1107,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ video_mode.fullscreen=false; }*/ + pre_fs_valid=false; } DWORD dwExStyle; @@ -1083,7 +1187,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ physics_server = memnew( PhysicsServerSW ); physics_server->init(); - physics_2d_server = memnew( Physics2DServerSW ); + physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); physics_2d_server->init(); if (!is_no_window_mode_enabled()) { @@ -1246,7 +1350,9 @@ void OS_Windows::finalize() { memdelete(main_loop); main_loop=NULL; - + + memdelete(input); + visual_server->finish(); memdelete(visual_server); #ifdef OPENGL_ENABLED @@ -1269,11 +1375,10 @@ void OS_Windows::finalize() { // memdelete(debugger_connection_console); //} - audio_server->finish(); - memdelete(audio_server); memdelete(sample_manager); - memdelete(input); + audio_server->finish(); + memdelete(audio_server); physics_server->finish(); memdelete(physics_server); @@ -1281,6 +1386,9 @@ void OS_Windows::finalize() { physics_2d_server->finish(); memdelete(physics_2d_server); + joystick_change_queue.clear(); + monitor_info.clear(); + } void OS_Windows::finalize_core() { @@ -1374,9 +1482,13 @@ void OS_Windows::warp_mouse_pos(const Point2& p_to) { old_y=p_to.y; } else { - SetCursorPos(p_to.x, p_to.y); - } + POINT p; + p.x=p_to.x; + p.y=p_to.y; + ClientToScreen(hWnd,&p); + SetCursorPos(p.x,p.y); + } } Point2 OS_Windows::get_mouse_pos() const { @@ -1408,73 +1520,341 @@ void OS_Windows::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) } -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) { +int OS_Windows::get_screen_count() const { + + return monitor_info.size(); +} +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) + return i; + } + + return 0; +} +void OS_Windows::set_current_screen(int p_screen){ + + 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)); + +} + +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 ); + +} +Point2 OS_Windows::get_window_position() const{ + + RECT r; + GetWindowRect(hWnd,&r); + return Point2(r.left,r.top); +} +void OS_Windows::set_window_position(const Point2& p_position){ + + RECT r; + 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{ + + RECT r; + GetClientRect(hWnd,&r); + return Vector2(r.right-r.left,r.bottom-r.top); + +} +void OS_Windows::set_window_size(const Size2 p_size){ + + video_mode.width=p_size.width; + video_mode.height=p_size.height; + + if (video_mode.fullscreen) { + return; + } + + + RECT 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; + + + //print_line("PRE: "+itos(rect.left)+","+itos(rect.top)+","+itos(rect.right-rect.left)+","+itos(rect.bottom-rect.top)); + + /*if (video_mode.resizable) { + AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); + } else { + AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW, FALSE); + }*/ + + //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); + +} +void OS_Windows::set_window_fullscreen(bool p_enabled){ + + if (video_mode.fullscreen==p_enabled) + return; + + + + if (p_enabled) { + + + if (pre_fs_valid) { + 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)); + } - HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE); - if (!hCon || hCon==INVALID_HANDLE_VALUE) { - if (p_rationale && p_rationale[0]) { - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_rationale); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + int cs = get_current_screen(); + Point2 pos = get_screen_position(cs); + Size2 size = get_screen_size(cs); + /* 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); + MoveWindow(hWnd, pos.x, pos.y, size.width, size.height, TRUE); + + video_mode.fullscreen=true; + + + } else { + + RECT rect; + + if (pre_fs_valid) { + rect=pre_fs_rect; + } else { + 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); } else { - print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_code); - print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line); + 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); + } + + video_mode.fullscreen=false; + pre_fs_valid=true; +/* + DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + DWORD dwStyle=WS_OVERLAPPEDWINDOW; + if (!video_mode.resizable) { + dwStyle &= ~WS_THICKFRAME; + dwStyle &= ~WS_MAXIMIZEBOX; } + AdjustWindowRectEx(&pre_fs_rect, dwStyle, FALSE, dwExStyle); + video_mode.fullscreen=false; + video_mode.width=pre_fs_rect.right-pre_fs_rect.left; + video_mode.height=pre_fs_rect.bottom-pre_fs_rect.top; +*/ + } + +// MoveWindow(hWnd,r.left,r.top,p_size.x,p_size.y,TRUE); + + +} +bool OS_Windows::is_window_fullscreen() const{ + + return video_mode.fullscreen; +} +void OS_Windows::set_window_resizable(bool 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; + if (!p_enabled) { + dwStyle &= ~WS_THICKFRAME; + dwStyle &= ~WS_MAXIMIZEBOX; + } + AdjustWindowRectEx(&pre_fs_rect, dwStyle, FALSE, dwExStyle); + */ + + if (!video_mode.fullscreen) { + if (p_enabled) { + SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); + } else { + SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE); + + } + + RECT rect; + GetWindowRect(hWnd,&rect); + MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + } + + video_mode.resizable=p_enabled; + +} +bool OS_Windows::is_window_resizable() const{ + + return video_mode.resizable; +} +void OS_Windows::set_window_minimized(bool p_enabled){ + + if (p_enabled) { + maximized=false; + minimized=true; + ShowWindow(hWnd,SW_MINIMIZE); } else { + ShowWindow(hWnd,SW_RESTORE); + maximized=false; + minimized=false; + } +} +bool OS_Windows::is_window_minimized() const{ - CONSOLE_SCREEN_BUFFER_INFO sbi; //original - GetConsoleScreenBufferInfo(hCon,&sbi); + return minimized; - SetConsoleTextAttribute(hCon,sbi.wAttributes); +} +void OS_Windows::set_window_maximized(bool p_enabled){ + + if (p_enabled) { + maximized=true; + minimized=false; + ShowWindow(hWnd,SW_MAXIMIZE); + } else { + ShowWindow(hWnd,SW_RESTORE); + maximized=false; + minimized=false; + } +} +bool OS_Windows::is_window_maximized() const{ + + return maximized; +} +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; + if (p_rationale && p_rationale[0]) + err_details = p_rationale; + else + err_details = p_code; - uint32_t basecol=0; switch(p_type) { - case ERR_ERROR: basecol = FOREGROUND_RED; break; - case ERR_WARNING: basecol = FOREGROUND_RED|FOREGROUND_GREEN; break; - case ERR_SCRIPT: basecol = FOREGROUND_GREEN; break; + case ERR_ERROR: + print("ERROR: %s: %s\n", p_function, err_details); + print(" At: %s:%i\n", p_file, p_line); + break; + case ERR_WARNING: + print("WARNING: %s: %s\n", p_function, err_details); + print(" At: %s:%i\n", p_file, p_line); + break; + case ERR_SCRIPT: + print("SCRIPT ERROR: %s: %s\n", p_function, err_details); + print(" At: %s:%i\n", p_file, p_line); + break; } - if (p_rationale && p_rationale[0]) { + } else { - SetConsoleTextAttribute(hCon,basecol|FOREGROUND_INTENSITY); + CONSOLE_SCREEN_BUFFER_INFO sbi; //original + GetConsoleScreenBufferInfo(hCon, &sbi); + + WORD current_fg = sbi.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); + WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY); + + uint32_t basecol = 0; + 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; + } + basecol |= current_bg; + if (p_rationale && p_rationale[0]) { + + SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY); switch(p_type) { case ERR_ERROR: print("ERROR: "); break; case ERR_WARNING: print("WARNING: "); break; case ERR_SCRIPT: print("SCRIPT ERROR: "); break; } - SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY); - print(" %s\n",p_rationale); - SetConsoleTextAttribute(hCon,basecol); - print("At: "); - SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN); - print(" %s:%i\n",p_file,p_line); + SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY); + print("%s\n", p_rationale); + SetConsoleTextAttribute(hCon, basecol); + switch (p_type) { + case ERR_ERROR: print(" At: "); break; + case ERR_WARNING: print(" At: "); break; + case ERR_SCRIPT: print(" At: "); break; + } + + SetConsoleTextAttribute(hCon, current_fg | current_bg); + print("%s:%i\n", p_file, p_line); } else { - SetConsoleTextAttribute(hCon,basecol|FOREGROUND_INTENSITY); + + SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY); 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; + 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; } - SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY); - print(" %s\n",p_code); - SetConsoleTextAttribute(hCon,basecol); - print("At: "); - SetConsoleTextAttribute(hCon,FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN); - print(" %s:%i\n",p_file,p_line); + + SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY); + print("%s\n", p_code); + + SetConsoleTextAttribute(hCon, basecol); + switch (p_type) { + case ERR_ERROR: print(" At: "); break; + case ERR_WARNING: print(" At: "); break; + case ERR_SCRIPT: print(" At: "); break; + } + + SetConsoleTextAttribute(hCon, current_fg | current_bg); + print("%s:%i\n", p_file, p_line); } - SetConsoleTextAttribute(hCon,sbi.wAttributes); + SetConsoleTextAttribute(hCon, sbi.wAttributes); } - } @@ -1483,10 +1863,14 @@ String OS_Windows::get_name() { return "Windows"; } -OS::Date OS_Windows::get_date() const { +OS::Date OS_Windows::get_date(bool utc) const { SYSTEMTIME systemtime; - GetSystemTime(&systemtime); + if (utc) + GetSystemTime(&systemtime); + else + GetLocalTime(&systemtime); + Date date; date.day=systemtime.wDay; date.month=Month(systemtime.wMonth); @@ -1495,10 +1879,13 @@ OS::Date OS_Windows::get_date() const { date.dst=false; return date; } -OS::Time OS_Windows::get_time() const { +OS::Time OS_Windows::get_time(bool utc) const { SYSTEMTIME systemtime; - GetLocalTime(&systemtime); + if (utc) + GetSystemTime(&systemtime); + else + GetLocalTime(&systemtime); Time time; time.hour=systemtime.wHour; @@ -1507,6 +1894,23 @@ OS::Time OS_Windows::get_time() const { return time; } +OS::TimeZoneInfo OS_Windows::get_time_zone_info() const { + TIME_ZONE_INFORMATION info; + bool daylight = false; + if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) + daylight = true; + + TimeZoneInfo ret; + if (daylight) { + ret.name = info.DaylightName; + } else { + ret.name = info.StandardName; + } + + ret.bias = info.Bias; + return ret; +} + uint64_t OS_Windows::get_unix_time() const { FILETIME ft; @@ -1529,6 +1933,12 @@ uint64_t OS_Windows::get_unix_time() const { return (*(uint64_t*)&ft - *(uint64_t*)&fep) / 10000000; }; +uint64_t OS_Windows::get_system_time_msec() const { + SYSTEMTIME st; + GetSystemTime(&st); + return st.wMilliseconds; +} + void OS_Windows::delay_usec(uint32_t p_usec) const { if (p_usec < 1000) @@ -1709,7 +2119,7 @@ String OS_Windows::get_executable_path() const { wchar_t bufname[4096]; GetModuleFileNameW(NULL,bufname,4096); String s= bufname; - print_line("EXEC PATHPó: "+s); + print_line("EXEC PATHP??: "+s); return s; } @@ -1774,12 +2184,13 @@ bool OS_Windows::has_environment(const String& p_var) const { String OS_Windows::get_environment(const String& p_var) const { - char* val = getenv(p_var.utf8().get_data()); - if (val) - return val; - + wchar_t wval[0x7Fff]; // MSDN says 32767 char is the maximum + int wlen = GetEnvironmentVariableW(p_var.c_str(),wval,0x7Fff); + if ( wlen > 0 ) { + return wval; + } return ""; -}; +} String OS_Windows::get_stdin_string(bool p_block) { @@ -1795,6 +2206,7 @@ String OS_Windows::get_stdin_string(bool p_block) { void OS_Windows::move_window_to_foreground() { SetForegroundWindow(hWnd); + BringWindowToTop(hWnd); } |