2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* os_windows.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2015-01-10 20:35:26 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os_windows.h"
|
2016-12-21 05:29:58 +00:00
|
|
|
|
2017-01-02 20:38:20 +00:00
|
|
|
#include "drivers/gles3/rasterizer_gles3.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "drivers/windows/dir_access_windows.h"
|
|
|
|
#include "drivers/windows/file_access_windows.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "drivers/windows/mutex_windows.h"
|
2017-01-08 14:13:12 +00:00
|
|
|
#include "drivers/windows/rw_lock_windows.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "drivers/windows/semaphore_windows.h"
|
|
|
|
#include "drivers/windows/thread_windows.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "io/marshalls.h"
|
2017-01-08 20:05:51 +00:00
|
|
|
#include "joypad.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "lang_table.h"
|
|
|
|
#include "main/main.h"
|
|
|
|
#include "packet_peer_udp_winsock.h"
|
2017-06-10 13:15:33 +00:00
|
|
|
#include "servers/audio_server.h"
|
|
|
|
#include "servers/visual/visual_server_raster.h"
|
|
|
|
#include "servers/visual/visual_server_wrap_mt.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "stream_peer_winsock.h"
|
|
|
|
#include "tcp_server_winsock.h"
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
#include "version_generated.gen.h"
|
2017-09-22 05:56:02 +00:00
|
|
|
#include "windows_terminal_logger.h"
|
2014-12-02 17:02:41 +00:00
|
|
|
|
2016-04-29 16:57:57 +00:00
|
|
|
#include <process.h>
|
2017-03-05 15:44:50 +00:00
|
|
|
#include <regstr.h>
|
|
|
|
#include <shlobj.h>
|
2015-02-12 03:17:29 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
static const WORD MAX_CONSOLE_LINES = 1500;
|
|
|
|
|
2015-01-17 01:48:35 +00:00
|
|
|
extern "C" {
|
2015-01-17 18:06:29 +00:00
|
|
|
#ifdef _MSC_VER
|
2017-03-05 15:44:50 +00:00
|
|
|
_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
|
2015-01-17 18:06:29 +00:00
|
|
|
#else
|
2017-03-05 15:44:50 +00:00
|
|
|
__attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001;
|
2015-01-17 18:06:29 +00:00
|
|
|
#endif
|
2015-01-17 01:48:35 +00:00
|
|
|
}
|
2014-12-02 17:02:41 +00:00
|
|
|
|
2017-08-18 18:46:13 +00:00
|
|
|
// Workaround mingw-w64 < 4.0 bug
|
|
|
|
#ifndef WM_TOUCH
|
|
|
|
#define WM_TOUCH 576
|
2016-02-04 16:16:22 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
extern HINSTANCE godot_hinstance;
|
|
|
|
|
|
|
|
void RedirectIOToConsole() {
|
|
|
|
|
|
|
|
int hConHandle;
|
|
|
|
|
|
|
|
intptr_t lStdHandle;
|
|
|
|
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO coninfo;
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
// allocate a console for this app
|
|
|
|
|
|
|
|
AllocConsole();
|
|
|
|
|
|
|
|
// set the screen buffer to be big enough to let us scroll text
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
&coninfo);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
coninfo.dwSize.Y = MAX_CONSOLE_LINES;
|
|
|
|
|
|
|
|
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
coninfo.dwSize);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// redirect unbuffered STDOUT to the console
|
|
|
|
|
|
|
|
lStdHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
fp = _fdopen(hConHandle, "w");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
*stdout = *fp;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// redirect unbuffered STDIN to the console
|
|
|
|
|
|
|
|
lStdHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
|
|
|
|
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
fp = _fdopen(hConHandle, "r");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
*stdin = *fp;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
setvbuf(stdin, NULL, _IONBF, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// redirect unbuffered STDERR to the console
|
|
|
|
|
|
|
|
lStdHandle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
|
|
|
|
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
fp = _fdopen(hConHandle, "w");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
*stderr = *fp;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
setvbuf(stderr, NULL, _IONBF, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
|
|
|
|
|
|
|
|
// point to console as well
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_Windows::get_video_driver_count() const {
|
|
|
|
|
2015-01-10 20:35:26 +00:00
|
|
|
return 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
const char *OS_Windows::get_video_driver_name(int p_driver) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-19 16:52:18 +00:00
|
|
|
return "GLES3";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int OS_Windows::get_audio_driver_count() const {
|
|
|
|
|
2017-01-15 19:06:14 +00:00
|
|
|
return AudioDriverManager::get_driver_count();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
const char *OS_Windows::get_audio_driver_name(int p_driver) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
|
|
|
|
ERR_FAIL_COND_V(!driver, "");
|
2017-01-15 19:06:14 +00:00
|
|
|
return AudioDriverManager::get_driver(p_driver)->get_name();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::initialize_core() {
|
|
|
|
|
2017-09-08 01:01:49 +00:00
|
|
|
crash_handler.initialize();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_button_state = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//RedirectIOToConsole();
|
2017-03-05 15:44:50 +00:00
|
|
|
maximized = false;
|
|
|
|
minimized = false;
|
|
|
|
borderless = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
ThreadWindows::make_default();
|
|
|
|
SemaphoreWindows::make_default();
|
|
|
|
MutexWindows::make_default();
|
2017-01-08 14:13:12 +00:00
|
|
|
RWLockWindows::make_default();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
|
|
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
|
|
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_FILESYSTEM);
|
|
|
|
//FileAccessBufferedFA<FileAccessWindows>::make_default();
|
|
|
|
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_RESOURCES);
|
|
|
|
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_USERDATA);
|
|
|
|
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
|
|
|
|
TCPServerWinsock::make_default();
|
|
|
|
StreamPeerWinsock::make_default();
|
2014-11-12 14:23:23 +00:00
|
|
|
PacketPeerUDPWinsock::make_default();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
// We need to know how often the clock is updated
|
|
|
|
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second))
|
2014-02-10 01:10:30 +00:00
|
|
|
ticks_per_second = 1000;
|
|
|
|
// If timeAtGameStart is 0 then we get the time since
|
|
|
|
// the start of the computer when we call GetGameTime()
|
|
|
|
ticks_start = 0;
|
|
|
|
ticks_start = get_ticks_usec();
|
|
|
|
|
|
|
|
process_map = memnew((Map<ProcessID, ProcessInfo>));
|
|
|
|
|
|
|
|
IP_Unix::make_default();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cursor_shape = CURSOR_ARROW;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_Windows::can_draw() const {
|
|
|
|
|
|
|
|
return !minimized;
|
|
|
|
};
|
|
|
|
|
2014-09-03 02:13:40 +00:00
|
|
|
#define MI_WP_SIGNATURE 0xFF515700
|
|
|
|
#define SIGNATURE_MASK 0xFFFFFF00
|
2017-03-05 15:44:50 +00:00
|
|
|
#define IsPenEvent(dw) (((dw)&SIGNATURE_MASK) == MI_WP_SIGNATURE)
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2014-09-22 03:50:48 +00:00
|
|
|
void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) {
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventScreenTouch> event;
|
|
|
|
event.instance();
|
|
|
|
event->set_index(idx);
|
|
|
|
event->set_pressed(p_pressed);
|
2017-06-03 08:54:24 +00:00
|
|
|
event->set_position(Vector2(p_x, p_y));
|
2014-09-03 02:13:40 +00:00
|
|
|
|
|
|
|
if (main_loop) {
|
|
|
|
input->parse_input_event(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-22 03:50:48 +00:00
|
|
|
void OS_Windows::_drag_event(int p_x, int p_y, int idx) {
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventScreenDrag> event;
|
|
|
|
event.instance();
|
|
|
|
event->set_index(idx);
|
2017-06-03 08:54:24 +00:00
|
|
|
event->set_position(Vector2(p_x, p_y));
|
2014-09-03 02:13:40 +00:00
|
|
|
|
|
|
|
if (main_loop)
|
|
|
|
input->parse_input_event(event);
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (uMsg) // Check For Windows Messages
|
2014-02-10 01:10:30 +00:00
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
case WM_SETFOCUS: {
|
2017-01-25 18:21:41 +00:00
|
|
|
window_has_focus = true;
|
|
|
|
// Re-capture cursor if we're in one of the capture modes
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
|
2017-01-25 18:21:41 +00:00
|
|
|
SetCapture(hWnd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
case WM_KILLFOCUS: {
|
2017-01-25 18:21:41 +00:00
|
|
|
window_has_focus = false;
|
|
|
|
|
|
|
|
// Release capture if we're in one of the capture modes
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
|
2017-01-25 18:21:41 +00:00
|
|
|
ReleaseCapture();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
case WM_ACTIVATE: // Watch For Window Activate Message
|
2014-02-10 01:10:30 +00:00
|
|
|
{
|
|
|
|
minimized = HIWORD(wParam) != 0;
|
|
|
|
if (!main_loop) {
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE) {
|
|
|
|
|
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
|
2017-03-05 15:44:50 +00:00
|
|
|
alt_mem = false;
|
|
|
|
control_mem = false;
|
|
|
|
shift_mem = false;
|
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
|
2014-02-10 01:10:30 +00:00
|
|
|
RECT clipRect;
|
|
|
|
GetClientRect(hWnd, &clipRect);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClientToScreen(hWnd, (POINT *)&clipRect.left);
|
|
|
|
ClientToScreen(hWnd, (POINT *)&clipRect.right);
|
2014-02-10 01:10:30 +00:00
|
|
|
ClipCursor(&clipRect);
|
|
|
|
SetCapture(hWnd);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
|
2017-03-05 15:44:50 +00:00
|
|
|
alt_mem = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return 0; // Return To The Message Loop
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_PAINT:
|
|
|
|
|
|
|
|
Main::force_redraw();
|
|
|
|
break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case WM_SYSCOMMAND: // Intercept System Commands
|
2014-02-10 01:10:30 +00:00
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (wParam) // Check System Calls
|
2014-02-10 01:10:30 +00:00
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
case SC_SCREENSAVE: // Screensaver Trying To Start?
|
|
|
|
case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
|
|
|
|
return 0; // Prevent From Happening
|
2014-02-10 01:10:30 +00:00
|
|
|
case SC_KEYMENU:
|
2017-03-05 15:44:50 +00:00
|
|
|
if ((lParam >> 16) <= 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
break; // Exit
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case WM_CLOSE: // Did We Receive A Close Message?
|
2014-02-10 01:10:30 +00:00
|
|
|
{
|
|
|
|
if (main_loop)
|
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
|
|
|
|
//force_quit=true;
|
2017-03-05 15:44:50 +00:00
|
|
|
return 0; // Jump Back
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
case WM_MOUSELEAVE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
old_invalid = true;
|
|
|
|
outside = true;
|
|
|
|
if (main_loop && mouse_mode != MOUSE_MODE_CAPTURED)
|
2015-09-24 21:06:15 +00:00
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT);
|
|
|
|
if (input)
|
|
|
|
input->set_mouse_in_window(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case WM_MOUSEMOVE: {
|
|
|
|
|
2014-09-03 02:13:40 +00:00
|
|
|
if (outside) {
|
2015-09-24 21:06:15 +00:00
|
|
|
//mouse enter
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (main_loop && mouse_mode != MOUSE_MODE_CAPTURED)
|
2015-09-24 21:06:15 +00:00
|
|
|
main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER);
|
|
|
|
if (input)
|
|
|
|
input->set_mouse_in_window(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
CursorShape c = cursor_shape;
|
|
|
|
cursor_shape = CURSOR_MAX;
|
2014-09-03 02:13:40 +00:00
|
|
|
set_cursor_shape(c);
|
2017-03-05 15:44:50 +00:00
|
|
|
outside = false;
|
2014-09-03 02:13:40 +00:00
|
|
|
|
|
|
|
//Once-Off notification, must call again....
|
|
|
|
TRACKMOUSEEVENT tme;
|
2017-03-05 15:44:50 +00:00
|
|
|
tme.cbSize = sizeof(TRACKMOUSEEVENT);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = hWnd;
|
|
|
|
tme.dwHoverTime = HOVER_DEFAULT;
|
2014-09-03 02:13:40 +00:00
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
}
|
|
|
|
|
2017-01-25 18:21:41 +00:00
|
|
|
// Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED)
|
2017-01-25 18:21:41 +00:00
|
|
|
break;
|
2014-09-22 03:50:48 +00:00
|
|
|
/*
|
2014-09-03 02:13:40 +00:00
|
|
|
LPARAM extra = GetMessageExtraInfo();
|
|
|
|
if (IsPenEvent(extra)) {
|
|
|
|
|
|
|
|
int idx = extra & 0x7f;
|
|
|
|
_drag_event(idx, uMsg, wParam, lParam);
|
|
|
|
if (idx != 0) {
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
// fallthrough for mouse event
|
|
|
|
};
|
2014-09-22 03:50:48 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseMotion> mm;
|
|
|
|
mm.instance();
|
|
|
|
|
|
|
|
mm->set_control((wParam & MK_CONTROL) != 0);
|
|
|
|
mm->set_shift((wParam & MK_SHIFT) != 0);
|
|
|
|
mm->set_alt(alt_mem);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int bmask = 0;
|
|
|
|
bmask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0;
|
|
|
|
bmask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0;
|
|
|
|
bmask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0;
|
|
|
|
mm->set_button_mask(bmask);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
last_button_state = mm->get_button_mask();
|
|
|
|
/*mm->get_button_mask()|=(wParam&MK_XBUTTON1)?(1<<5):0;
|
|
|
|
mm->get_button_mask()|=(wParam&MK_XBUTTON2)?(1<<6):0;*/
|
2017-06-03 08:54:24 +00:00
|
|
|
mm->set_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED) {
|
|
|
|
|
|
|
|
Point2i c(video_mode.width / 2, video_mode.height / 2);
|
2017-02-11 03:54:36 +00:00
|
|
|
old_x = c.x;
|
|
|
|
old_y = c.y;
|
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
if (mm->get_position() == c) {
|
2017-03-05 15:44:50 +00:00
|
|
|
center = c;
|
2014-02-10 01:10:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
Point2i ncenter = mm->get_position();
|
2017-03-05 15:44:50 +00:00
|
|
|
center = ncenter;
|
|
|
|
POINT pos = { (int)c.x, (int)c.y };
|
2014-02-10 01:10:30 +00:00
|
|
|
ClientToScreen(hWnd, &pos);
|
|
|
|
SetCursorPos(pos.x, pos.y);
|
|
|
|
}
|
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
input->set_mouse_position(mm->get_position());
|
2017-05-20 15:38:03 +00:00
|
|
|
mm->set_speed(input->get_last_mouse_speed());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (old_invalid) {
|
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
old_x = mm->get_position().x;
|
|
|
|
old_y = mm->get_position().y;
|
2017-03-05 15:44:50 +00:00
|
|
|
old_invalid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
mm->set_relative(Vector2(mm->get_position() - Vector2(old_x, old_y)));
|
|
|
|
old_x = mm->get_position().x;
|
|
|
|
old_y = mm->get_position().y;
|
2017-01-25 18:21:41 +00:00
|
|
|
if (window_has_focus && main_loop)
|
2017-05-20 15:38:03 +00:00
|
|
|
input->parse_input_event(mm);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_MOUSEWHEEL:
|
2016-02-04 16:16:22 +00:00
|
|
|
case WM_MOUSEHWHEEL:
|
2014-02-10 01:10:30 +00:00
|
|
|
case WM_LBUTTONDBLCLK:
|
2015-03-25 02:58:22 +00:00
|
|
|
case WM_RBUTTONDBLCLK:
|
2017-03-05 15:44:50 +00:00
|
|
|
/*case WM_XBUTTONDOWN:
|
|
|
|
case WM_XBUTTONUP: */ {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/*
|
2014-09-03 02:13:40 +00:00
|
|
|
LPARAM extra = GetMessageExtraInfo();
|
|
|
|
if (IsPenEvent(extra)) {
|
|
|
|
|
|
|
|
int idx = extra & 0x7f;
|
|
|
|
_touch_event(idx, uMsg, wParam, lParam);
|
|
|
|
if (idx != 0) {
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
// fallthrough for mouse event
|
|
|
|
};
|
2014-09-22 03:50:48 +00:00
|
|
|
*/
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseButton> mb;
|
|
|
|
mb.instance();
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_LBUTTONDOWN: {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(true);
|
|
|
|
mb->set_button_index(1);
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
case WM_LBUTTONUP: {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(false);
|
|
|
|
mb->set_button_index(1);
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
case WM_MBUTTONDOWN: {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(true);
|
|
|
|
mb->set_button_index(3);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case WM_MBUTTONUP: {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(false);
|
|
|
|
mb->set_button_index(3);
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
case WM_RBUTTONDOWN: {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(true);
|
|
|
|
mb->set_button_index(2);
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
case WM_RBUTTONUP: {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(false);
|
|
|
|
mb->set_button_index(2);
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
case WM_LBUTTONDBLCLK: {
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(true);
|
|
|
|
mb->set_button_index(1);
|
|
|
|
mb->set_doubleclick(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
case WM_RBUTTONDBLCLK: {
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(true);
|
|
|
|
mb->set_button_index(2);
|
|
|
|
mb->set_doubleclick(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
case WM_MOUSEWHEEL: {
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
int motion = (short)HIWORD(wParam);
|
|
|
|
if (!motion)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (motion > 0)
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_button_index(BUTTON_WHEEL_UP);
|
2017-03-05 15:44:50 +00:00
|
|
|
else
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_button_index(BUTTON_WHEEL_DOWN);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case WM_MOUSEHWHEEL: {
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_pressed(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
int motion = (short)HIWORD(wParam);
|
|
|
|
if (!motion)
|
|
|
|
return 0;
|
|
|
|
|
2017-02-21 22:45:31 +00:00
|
|
|
if (motion < 0) {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_button_index(BUTTON_WHEEL_LEFT);
|
|
|
|
mb->set_factor(fabs((double)motion / (double)WHEEL_DELTA));
|
2017-02-21 22:45:31 +00:00
|
|
|
} else {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_button_index(BUTTON_WHEEL_RIGHT);
|
|
|
|
mb->set_factor(fabs((double)motion / (double)WHEEL_DELTA));
|
2017-02-21 22:45:31 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
/*
|
|
|
|
case WM_XBUTTONDOWN: {
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->is_pressed()=true;
|
|
|
|
mb->get_button_index()=(HIWORD(wParam)==XBUTTON1)?6:7;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case WM_XBUTTONUP:
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->is_pressed()=true;
|
|
|
|
mb->get_button_index()=(HIWORD(wParam)==XBUTTON1)?6:7;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;*/
|
2017-03-05 15:44:50 +00:00
|
|
|
default: { return 0; }
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->set_control((wParam & MK_CONTROL) != 0);
|
|
|
|
mb->set_shift((wParam & MK_SHIFT) != 0);
|
|
|
|
mb->set_alt(alt_mem);
|
|
|
|
//mb->get_alt()=(wParam&MK_MENU)!=0;
|
|
|
|
int bmask = 0;
|
|
|
|
bmask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0;
|
|
|
|
bmask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0;
|
|
|
|
bmask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0;
|
|
|
|
mb->set_button_mask(bmask);
|
|
|
|
|
|
|
|
last_button_state = mb->get_button_mask();
|
2017-03-05 15:44:50 +00:00
|
|
|
/*
|
2017-05-20 15:38:03 +00:00
|
|
|
mb->get_button_mask()|=(wParam&MK_XBUTTON1)?(1<<5):0;
|
|
|
|
mb->get_button_mask()|=(wParam&MK_XBUTTON2)?(1<<6):0;*/
|
2017-06-03 08:54:24 +00:00
|
|
|
mb->set_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
mb->set_position(Vector2(old_x, old_y));
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (uMsg != WM_MOUSEWHEEL) {
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->is_pressed()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (++pressrc > 0)
|
|
|
|
SetCapture(hWnd);
|
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (--pressrc <= 0) {
|
|
|
|
ReleaseCapture();
|
|
|
|
pressrc = 0;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (mouse_mode != MOUSE_MODE_CAPTURED) {
|
|
|
|
// for reasons unknown to mankind, wheel comes in screen cordinates
|
|
|
|
POINT coords;
|
2017-06-03 08:54:24 +00:00
|
|
|
coords.x = mb->get_position().x;
|
|
|
|
coords.y = mb->get_position().y;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ScreenToClient(hWnd, &coords);
|
2016-07-21 15:13:35 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
mb->set_position(Vector2(coords.x, coords.y));
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-15 16:34:57 +00:00
|
|
|
mb->set_global_position(mb->get_position());
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (main_loop) {
|
2017-05-20 15:38:03 +00:00
|
|
|
input->parse_input_event(mb);
|
|
|
|
if (mb->is_pressed() && mb->get_button_index() > 3) {
|
2017-03-05 15:44:50 +00:00
|
|
|
//send release for mouse wheel
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseButton> mbd = mb->duplicate();
|
|
|
|
mbd->set_pressed(false);
|
|
|
|
input->parse_input_event(mbd);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case WM_SIZE: {
|
2016-06-26 21:31:31 +00:00
|
|
|
int window_w = LOWORD(lParam);
|
|
|
|
int window_h = HIWORD(lParam);
|
|
|
|
if (window_w > 0 && window_h > 0) {
|
|
|
|
video_mode.width = window_w;
|
|
|
|
video_mode.height = window_h;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
//return 0; // Jump Back
|
|
|
|
} break;
|
2016-07-01 13:31:37 +00:00
|
|
|
|
|
|
|
case WM_ENTERSIZEMOVE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
move_timer_id = SetTimer(hWnd, 1, USER_TIMER_MINIMUM, (TIMERPROC)NULL);
|
2016-07-01 13:31:37 +00:00
|
|
|
} break;
|
|
|
|
case WM_EXITSIZEMOVE: {
|
|
|
|
KillTimer(hWnd, move_timer_id);
|
|
|
|
} break;
|
|
|
|
case WM_TIMER: {
|
|
|
|
if (wParam == move_timer_id) {
|
|
|
|
process_key_events();
|
|
|
|
Main::iteration();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_KEYDOWN: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
/*
|
|
|
|
if (wParam==VK_WIN) TODO wtf is this?
|
|
|
|
meta_mem=uMsg==WM_KEYDOWN;
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} //fallthrough
|
|
|
|
case WM_CHAR: {
|
|
|
|
|
|
|
|
ERR_BREAK(key_event_pos >= KEY_EVENT_BUFFER_SIZE);
|
|
|
|
|
2015-01-18 07:06:20 +00:00
|
|
|
// Make sure we don't include modifiers for the modifier key itself.
|
2014-02-10 01:10:30 +00:00
|
|
|
KeyEvent ke;
|
2017-05-20 15:38:03 +00:00
|
|
|
ke.shift = (wParam != VK_SHIFT) ? shift_mem : false;
|
|
|
|
ke.alt = (!(wParam == VK_MENU && (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN))) ? alt_mem : false;
|
|
|
|
ke.control = (wParam != VK_CONTROL) ? control_mem : false;
|
|
|
|
ke.meta = meta_mem;
|
2017-03-05 15:44:50 +00:00
|
|
|
ke.uMsg = uMsg;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ke.uMsg == WM_SYSKEYDOWN)
|
|
|
|
ke.uMsg = WM_KEYDOWN;
|
|
|
|
if (ke.uMsg == WM_SYSKEYUP)
|
|
|
|
ke.uMsg = WM_KEYUP;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/*if (ke.uMsg==WM_KEYDOWN && alt_mem && uMsg!=WM_SYSKEYDOWN) {
|
|
|
|
//altgr hack for intl keyboards, not sure how good it is
|
|
|
|
//windows is weeeeird
|
|
|
|
ke.mod_state.alt=false;
|
|
|
|
ke.mod_state.control=false;
|
|
|
|
print_line("")
|
|
|
|
}*/
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ke.wParam = wParam;
|
|
|
|
ke.lParam = lParam;
|
|
|
|
key_event_buffer[key_event_pos++] = ke;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case WM_INPUTLANGCHANGEREQUEST: {
|
|
|
|
|
|
|
|
print_line("input lang change");
|
|
|
|
} break;
|
2014-09-22 03:50:48 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#if WINVER >= 0x0601 // for windows 7
|
2014-09-22 03:50:48 +00:00
|
|
|
case WM_TOUCH: {
|
|
|
|
|
|
|
|
BOOL bHandled = FALSE;
|
|
|
|
UINT cInputs = LOWORD(wParam);
|
|
|
|
PTOUCHINPUT pInputs = memnew_arr(TOUCHINPUT, cInputs);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (pInputs) {
|
|
|
|
if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) {
|
|
|
|
for (UINT i = 0; i < cInputs; i++) {
|
2014-09-22 03:50:48 +00:00
|
|
|
TOUCHINPUT ti = pInputs[i];
|
|
|
|
//do something with each touch input entry
|
|
|
|
if (ti.dwFlags & TOUCHEVENTF_MOVE) {
|
|
|
|
|
|
|
|
_drag_event(ti.x / 100, ti.y / 100, ti.dwID);
|
|
|
|
} else if (ti.dwFlags & (TOUCHEVENTF_UP | TOUCHEVENTF_DOWN)) {
|
|
|
|
|
|
|
|
_touch_event(ti.dwFlags & TOUCHEVENTF_DOWN != 0, ti.x / 100, ti.y / 100, ti.dwID);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
bHandled = TRUE;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
|
|
|
/* handle the error here */
|
2014-09-22 03:50:48 +00:00
|
|
|
}
|
|
|
|
memdelete_arr(pInputs);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
2014-09-22 03:50:48 +00:00
|
|
|
/* handle the error here, probably out of memory */
|
|
|
|
}
|
|
|
|
if (bHandled) {
|
|
|
|
CloseTouchInputHandle((HTOUCHINPUT)lParam);
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#endif
|
2015-12-18 05:12:53 +00:00
|
|
|
case WM_DEVICECHANGE: {
|
|
|
|
|
2017-01-08 20:05:51 +00:00
|
|
|
joypad->probe_joypads();
|
2015-12-18 05:12:53 +00:00
|
|
|
} break;
|
2016-05-09 13:18:08 +00:00
|
|
|
case WM_SETCURSOR: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (LOWORD(lParam) == HTCLIENT) {
|
|
|
|
if (window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED)) {
|
2016-05-09 13:18:08 +00:00
|
|
|
//Hide the cursor
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hCursor == NULL)
|
2016-05-09 13:18:08 +00:00
|
|
|
hCursor = SetCursor(NULL);
|
2016-05-09 13:46:05 +00:00
|
|
|
else
|
|
|
|
SetCursor(NULL);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
|
|
|
if (hCursor != NULL) {
|
2016-05-09 13:18:08 +00:00
|
|
|
SetCursor(hCursor);
|
|
|
|
hCursor = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2016-05-27 17:18:40 +00:00
|
|
|
case WM_DROPFILES: {
|
|
|
|
|
2017-08-21 19:15:36 +00:00
|
|
|
HDROP hDropInfo = (HDROP)wParam;
|
2017-03-05 15:44:50 +00:00
|
|
|
const int buffsize = 4096;
|
2016-05-27 17:18:40 +00:00
|
|
|
wchar_t buf[buffsize];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int fcount = DragQueryFileW(hDropInfo, 0xFFFFFFFF, NULL, 0);
|
2016-05-27 17:18:40 +00:00
|
|
|
|
|
|
|
Vector<String> files;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < fcount; i++) {
|
2016-05-27 17:18:40 +00:00
|
|
|
|
|
|
|
DragQueryFileW(hDropInfo, i, buf, buffsize);
|
2017-03-05 15:44:50 +00:00
|
|
|
String file = buf;
|
2016-05-27 17:18:40 +00:00
|
|
|
files.push_back(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (files.size() && main_loop) {
|
2017-03-05 15:44:50 +00:00
|
|
|
main_loop->drop_files(files, 0);
|
2016-05-27 17:18:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
default: {
|
|
|
|
|
|
|
|
if (user_proc) {
|
|
|
|
|
|
|
|
return CallWindowProcW(user_proc, hWnd, uMsg, wParam, lParam);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS_Windows *os_win = static_cast<OS_Windows *>(OS::get_singleton());
|
2014-02-10 01:10:30 +00:00
|
|
|
if (os_win)
|
2017-03-05 15:44:50 +00:00
|
|
|
return os_win->WndProc(hWnd, uMsg, wParam, lParam);
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::process_key_events() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < key_event_pos; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
KeyEvent &ke = key_event_buffer[i];
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (ke.uMsg) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case WM_CHAR: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if ((i == 0 && ke.uMsg == WM_CHAR) || (i > 0 && key_event_buffer[i - 1].uMsg == WM_CHAR)) {
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventKey> k;
|
|
|
|
k.instance();
|
|
|
|
|
|
|
|
k->set_shift(ke.shift);
|
|
|
|
k->set_alt(ke.alt);
|
|
|
|
k->set_control(ke.control);
|
|
|
|
k->set_metakey(ke.meta);
|
|
|
|
k->set_pressed(true);
|
|
|
|
k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam));
|
|
|
|
k->set_unicode(ke.wParam);
|
|
|
|
if (k->get_unicode() && gr_mem) {
|
|
|
|
k->set_alt(false);
|
|
|
|
k->set_control(false);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-03-11 05:21:18 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (k->get_unicode() < 32)
|
|
|
|
k->set_unicode(0);
|
2014-03-11 05:21:18 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
input->parse_input_event(k);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//do nothing
|
|
|
|
} break;
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_KEYDOWN: {
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventKey> k;
|
|
|
|
k.instance();
|
|
|
|
|
|
|
|
k->set_shift(ke.shift);
|
|
|
|
k->set_alt(ke.alt);
|
|
|
|
k->set_control(ke.control);
|
|
|
|
k->set_metakey(ke.meta);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
k->set_pressed(ke.uMsg == WM_KEYDOWN);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-07-26 18:35:54 +00:00
|
|
|
if ((ke.lParam & (1 << 24)) && (ke.wParam == VK_RETURN)) {
|
|
|
|
// Special case for Numpad Enter key
|
2017-08-06 13:26:07 +00:00
|
|
|
k->set_scancode(KEY_KP_ENTER);
|
2017-07-26 18:35:54 +00:00
|
|
|
} else {
|
|
|
|
k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam));
|
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
|
|
|
|
if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) {
|
|
|
|
k->set_unicode(key_event_buffer[i + 1].wParam);
|
|
|
|
}
|
|
|
|
if (k->get_unicode() && gr_mem) {
|
|
|
|
k->set_alt(false);
|
|
|
|
k->set_control(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (k->get_unicode() < 32)
|
|
|
|
k->set_unicode(0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
k->set_echo((ke.uMsg == WM_KEYDOWN && (ke.lParam & (1 << 30))));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
input->parse_input_event(k);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
key_event_pos = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
enum _MonitorDpiType {
|
|
|
|
MDT_Effective_DPI = 0,
|
|
|
|
MDT_Angular_DPI = 1,
|
|
|
|
MDT_Raw_DPI = 2,
|
|
|
|
MDT_Default = MDT_Effective_DPI
|
2016-06-01 15:43:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static int QueryDpiForMonitor(HMONITOR hmon, _MonitorDpiType dpiType = MDT_Default) {
|
2016-06-01 15:43:30 +00:00
|
|
|
|
|
|
|
int dpiX = 96, dpiY = 96;
|
|
|
|
|
|
|
|
static HMODULE Shcore = NULL;
|
2017-03-05 15:44:50 +00:00
|
|
|
typedef HRESULT(WINAPI * GetDPIForMonitor_t)(HMONITOR hmonitor, _MonitorDpiType dpiType, UINT * dpiX, UINT * dpiY);
|
2016-06-01 15:43:30 +00:00
|
|
|
static GetDPIForMonitor_t getDPIForMonitor = NULL;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (Shcore == NULL) {
|
2016-06-01 15:43:30 +00:00
|
|
|
Shcore = LoadLibraryW(L"Shcore.dll");
|
|
|
|
getDPIForMonitor = Shcore ? (GetDPIForMonitor_t)GetProcAddress(Shcore, "GetDpiForMonitor") : NULL;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if ((Shcore == NULL) || (getDPIForMonitor == NULL)) {
|
2016-06-01 15:43:30 +00:00
|
|
|
if (Shcore)
|
|
|
|
FreeLibrary(Shcore);
|
|
|
|
Shcore = (HMODULE)INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT x = 0, y = 0;
|
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
bool bSet = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hmon && (Shcore != (HMODULE)INVALID_HANDLE_VALUE)) {
|
|
|
|
hr = getDPIForMonitor(hmon, dpiType /*MDT_Effective_DPI*/, &x, &y);
|
|
|
|
if (SUCCEEDED(hr) && (x > 0) && (y > 0)) {
|
2016-06-01 15:43:30 +00:00
|
|
|
|
|
|
|
dpiX = (int)x;
|
|
|
|
dpiY = (int)y;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
2016-06-01 15:43:30 +00:00
|
|
|
static int overallX = 0, overallY = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (overallX <= 0 || overallY <= 0) {
|
2016-06-01 15:43:30 +00:00
|
|
|
HDC hdc = GetDC(NULL);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hdc) {
|
2016-06-01 15:43:30 +00:00
|
|
|
overallX = GetDeviceCaps(hdc, LOGPIXELSX);
|
|
|
|
overallY = GetDeviceCaps(hdc, LOGPIXELSY);
|
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (overallX > 0 && overallY > 0) {
|
|
|
|
dpiX = overallX;
|
|
|
|
dpiY = overallY;
|
2016-06-01 15:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (dpiX + dpiY) / 2;
|
2016-06-01 15:43:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 14:18:16 +00:00
|
|
|
typedef enum _SHC_PROCESS_DPI_AWARENESS {
|
2017-09-13 07:13:23 +00:00
|
|
|
SHC_PROCESS_DPI_UNAWARE = 0,
|
|
|
|
SHC_PROCESS_SYSTEM_DPI_AWARE = 1,
|
|
|
|
SHC_PROCESS_PER_MONITOR_DPI_AWARE = 2
|
2017-09-12 14:18:16 +00:00
|
|
|
} SHC_PROCESS_DPI_AWARENESS;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
main_loop = NULL;
|
|
|
|
outside = true;
|
|
|
|
window_has_focus = true;
|
|
|
|
WNDCLASSEXW wc;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-12 14:18:16 +00:00
|
|
|
if (is_hidpi_allowed()) {
|
2017-09-13 07:13:23 +00:00
|
|
|
HMODULE Shcore = LoadLibraryW(L"Shcore.dll");
|
2017-09-12 14:18:16 +00:00
|
|
|
|
|
|
|
if (Shcore != NULL) {
|
2017-09-13 07:13:23 +00:00
|
|
|
typedef HRESULT(WINAPI * SetProcessDpiAwareness_t)(SHC_PROCESS_DPI_AWARENESS);
|
2017-09-12 14:18:16 +00:00
|
|
|
|
2017-09-13 07:13:23 +00:00
|
|
|
SetProcessDpiAwareness_t SetProcessDpiAwareness = (SetProcessDpiAwareness_t)GetProcAddress(Shcore, "SetProcessDpiAwareness");
|
2017-09-12 14:18:16 +00:00
|
|
|
|
|
|
|
if (SetProcessDpiAwareness) {
|
|
|
|
SetProcessDpiAwareness(SHC_PROCESS_SYSTEM_DPI_AWARE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
video_mode = p_desired;
|
2014-02-10 01:10:30 +00:00
|
|
|
//printf("**************** desired %s, mode %s\n", p_desired.fullscreen?"true":"false", video_mode.fullscreen?"true":"false");
|
|
|
|
RECT WindowRect;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
WindowRect.left = 0;
|
|
|
|
WindowRect.right = video_mode.width;
|
|
|
|
WindowRect.top = 0;
|
|
|
|
WindowRect.bottom = video_mode.height;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
memset(&wc, 0, sizeof(WNDCLASSEXW));
|
|
|
|
wc.cbSize = sizeof(WNDCLASSEXW);
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
|
2014-02-10 01:10:30 +00:00
|
|
|
wc.lpfnWndProc = (WNDPROC)::WndProc;
|
|
|
|
wc.cbClsExtra = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
wc.cbWndExtra = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
//wc.hInstance = hInstance;
|
|
|
|
wc.hInstance = godot_hinstance ? godot_hinstance : GetModuleHandle(NULL);
|
2016-03-08 23:00:52 +00:00
|
|
|
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
|
2017-03-05 15:44:50 +00:00
|
|
|
wc.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW);
|
2014-02-10 01:10:30 +00:00
|
|
|
wc.hbrBackground = NULL;
|
2017-03-05 15:44:50 +00:00
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = L"Engine";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!RegisterClassExW(&wc)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
MessageBox(NULL, "Failed To Register The Window Class.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
return; // Return
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pre_fs_valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (video_mode.fullscreen) {
|
|
|
|
|
|
|
|
DEVMODE current;
|
2017-03-05 15:44:50 +00:00
|
|
|
memset(¤t, 0, sizeof(current));
|
2014-02-10 01:10:30 +00:00
|
|
|
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, ¤t);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
WindowRect.right = current.dmPelsWidth;
|
2014-10-28 18:55:12 +00:00
|
|
|
WindowRect.bottom = current.dmPelsHeight;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/* DEVMODE dmScreenSettings;
|
2014-02-10 01:10:30 +00:00
|
|
|
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
|
|
|
|
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
|
|
|
|
dmScreenSettings.dmPelsWidth = video_mode.width;
|
|
|
|
dmScreenSettings.dmPelsHeight = video_mode.height;
|
|
|
|
dmScreenSettings.dmBitsPerPel = current.dmBitsPerPel;
|
|
|
|
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
|
|
|
|
|
|
|
|
LONG err = ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);
|
|
|
|
if (err!=DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
|
|
|
|
video_mode.fullscreen=false;
|
2014-10-28 18:55:12 +00:00
|
|
|
}*/
|
2017-03-05 15:44:50 +00:00
|
|
|
pre_fs_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
DWORD dwExStyle;
|
|
|
|
DWORD dwStyle;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (video_mode.fullscreen || video_mode.borderless_window) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
dwExStyle = WS_EX_APPWINDOW;
|
|
|
|
dwStyle = WS_POPUP;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
|
|
|
|
dwStyle = WS_OVERLAPPEDWINDOW;
|
2014-03-27 12:09:18 +00:00
|
|
|
if (!video_mode.resizable) {
|
|
|
|
dwStyle &= ~WS_THICKFRAME;
|
|
|
|
dwStyle &= ~WS_MAXIMIZEBOX;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
char *windowid = getenv("GODOT_WINDOWID");
|
2014-02-10 01:10:30 +00:00
|
|
|
if (windowid) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
// strtoull on mingw
|
|
|
|
#ifdef MINGW_ENABLED
|
2014-02-10 01:10:30 +00:00
|
|
|
hWnd = (HWND)strtoull(windowid, NULL, 0);
|
2017-03-05 15:44:50 +00:00
|
|
|
#else
|
2014-02-10 01:10:30 +00:00
|
|
|
hWnd = (HWND)_strtoui64(windowid, NULL, 0);
|
2017-03-05 15:44:50 +00:00
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
SetLastError(0);
|
|
|
|
user_proc = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC);
|
|
|
|
SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)(WNDPROC)::WndProc);
|
|
|
|
DWORD le = GetLastError();
|
|
|
|
if (user_proc == 0 && le != 0) {
|
|
|
|
|
|
|
|
printf("Error setting WNDPROC: %li\n", le);
|
|
|
|
};
|
|
|
|
LONG_PTR proc = GetWindowLongPtr(hWnd, GWLP_WNDPROC);
|
|
|
|
|
|
|
|
RECT rect;
|
|
|
|
if (!GetClientRect(hWnd, &rect)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
MessageBoxW(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
return; // Return FALSE
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
video_mode.width = rect.right;
|
|
|
|
video_mode.height = rect.bottom;
|
|
|
|
video_mode.fullscreen = false;
|
|
|
|
} else {
|
|
|
|
|
2017-09-06 21:50:18 +00:00
|
|
|
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);
|
|
|
|
if (!hWnd) {
|
2017-03-05 15:44:50 +00:00
|
|
|
MessageBoxW(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
return; // Return FALSE
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
};
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2016-12-21 05:29:58 +00:00
|
|
|
#if defined(OPENGL_ENABLED)
|
2017-03-05 15:44:50 +00:00
|
|
|
gl_context = memnew(ContextGL_Win(hWnd, true));
|
2014-02-10 01:10:30 +00:00
|
|
|
gl_context->initialize();
|
2016-12-21 05:29:58 +00:00
|
|
|
|
|
|
|
RasterizerGLES3::register_config();
|
|
|
|
|
|
|
|
RasterizerGLES3::make_current();
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
visual_server = memnew(VisualServerRaster);
|
2017-06-10 13:15:33 +00:00
|
|
|
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
|
|
|
|
|
|
|
|
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
|
2017-01-14 11:26:56 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/*
|
2014-02-10 01:10:30 +00:00
|
|
|
DEVMODE dmScreenSettings; // Device Mode
|
|
|
|
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
|
|
|
|
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
|
|
|
|
dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
|
|
|
|
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
|
|
|
|
dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
|
|
|
|
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
|
|
|
|
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2016-03-08 23:00:52 +00:00
|
|
|
visual_server->init();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
input = memnew(InputDefault);
|
|
|
|
joypad = memnew(JoypadWindows(input, &hWnd));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
power_manager = memnew(PowerWindows);
|
2016-07-23 11:15:55 +00:00
|
|
|
|
2017-09-13 16:34:22 +00:00
|
|
|
AudioDriverManager::initialize(p_audio_driver);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
TRACKMOUSEEVENT tme;
|
2017-03-05 15:44:50 +00:00
|
|
|
tme.cbSize = sizeof(TRACKMOUSEEVENT);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = hWnd;
|
|
|
|
tme.dwHoverTime = HOVER_DEFAULT;
|
2014-02-10 01:10:30 +00:00
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
2014-09-22 03:50:48 +00:00
|
|
|
//RegisterTouchWindow(hWnd, 0); // Windows 7
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-17 14:25:22 +00:00
|
|
|
_ensure_user_data_dir();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
DragAcceptFiles(hWnd, true);
|
2016-05-27 17:18:40 +00:00
|
|
|
|
2016-07-01 13:31:37 +00:00
|
|
|
move_timer_id = 1;
|
2017-11-29 00:49:36 +00:00
|
|
|
|
|
|
|
if (!is_no_window_mode_enabled()) {
|
|
|
|
ShowWindow(hWnd, SW_SHOW); // Show The Window
|
|
|
|
SetForegroundWindow(hWnd); // Slightly Higher Priority
|
|
|
|
SetFocus(hWnd); // Sets Keyboard Focus To
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_clipboard(const String &p_text) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!OpenClipboard(hWnd)) {
|
|
|
|
ERR_EXPLAIN("Unable to open clipboard.");
|
|
|
|
ERR_FAIL();
|
|
|
|
};
|
|
|
|
EmptyClipboard();
|
|
|
|
|
|
|
|
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (p_text.length() + 1) * sizeof(CharType));
|
|
|
|
if (mem == NULL) {
|
|
|
|
ERR_EXPLAIN("Unable to allocate memory for clipboard contents.");
|
|
|
|
ERR_FAIL();
|
|
|
|
};
|
|
|
|
LPWSTR lptstrCopy = (LPWSTR)GlobalLock(mem);
|
|
|
|
memcpy(lptstrCopy, p_text.c_str(), (p_text.length() + 1) * sizeof(CharType));
|
|
|
|
//memset((lptstrCopy + p_text.length()), 0, sizeof(CharType));
|
|
|
|
GlobalUnlock(mem);
|
|
|
|
|
|
|
|
SetClipboardData(CF_UNICODETEXT, mem);
|
|
|
|
|
|
|
|
// set the CF_TEXT version (not needed?)
|
|
|
|
CharString utf8 = p_text.utf8();
|
|
|
|
mem = GlobalAlloc(GMEM_MOVEABLE, utf8.length() + 1);
|
|
|
|
if (mem == NULL) {
|
|
|
|
ERR_EXPLAIN("Unable to allocate memory for clipboard contents.");
|
|
|
|
ERR_FAIL();
|
|
|
|
};
|
|
|
|
LPTSTR ptr = (LPTSTR)GlobalLock(mem);
|
|
|
|
memcpy(ptr, utf8.get_data(), utf8.length());
|
|
|
|
ptr[utf8.length()] = 0;
|
|
|
|
GlobalUnlock(mem);
|
|
|
|
|
|
|
|
SetClipboardData(CF_TEXT, mem);
|
|
|
|
|
|
|
|
CloseClipboard();
|
|
|
|
};
|
|
|
|
|
|
|
|
String OS_Windows::get_clipboard() const {
|
|
|
|
|
|
|
|
String ret;
|
|
|
|
if (!OpenClipboard(hWnd)) {
|
|
|
|
ERR_EXPLAIN("Unable to open clipboard.");
|
|
|
|
ERR_FAIL_V("");
|
|
|
|
};
|
|
|
|
|
|
|
|
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
|
|
|
|
|
|
|
|
HGLOBAL mem = GetClipboardData(CF_UNICODETEXT);
|
|
|
|
if (mem != NULL) {
|
|
|
|
|
|
|
|
LPWSTR ptr = (LPWSTR)GlobalLock(mem);
|
|
|
|
if (ptr != NULL) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ret = String((CharType *)ptr);
|
2014-02-10 01:10:30 +00:00
|
|
|
GlobalUnlock(mem);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
} else if (IsClipboardFormatAvailable(CF_TEXT)) {
|
|
|
|
|
|
|
|
HGLOBAL mem = GetClipboardData(CF_UNICODETEXT);
|
|
|
|
if (mem != NULL) {
|
|
|
|
|
|
|
|
LPTSTR ptr = (LPTSTR)GlobalLock(mem);
|
|
|
|
if (ptr != NULL) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ret.parse_utf8((const char *)ptr);
|
2014-02-10 01:10:30 +00:00
|
|
|
GlobalUnlock(mem);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
CloseClipboard();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
void OS_Windows::delete_main_loop() {
|
|
|
|
|
|
|
|
if (main_loop)
|
|
|
|
memdelete(main_loop);
|
2017-03-05 15:44:50 +00:00
|
|
|
main_loop = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_main_loop(MainLoop *p_main_loop) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
input->set_main_loop(p_main_loop);
|
2017-03-05 15:44:50 +00:00
|
|
|
main_loop = p_main_loop;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::finalize() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (main_loop)
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(main_loop);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
main_loop = NULL;
|
2015-11-14 14:14:17 +00:00
|
|
|
|
2017-01-08 20:05:51 +00:00
|
|
|
memdelete(joypad);
|
2015-11-14 14:14:17 +00:00
|
|
|
memdelete(input);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
visual_server->finish();
|
|
|
|
memdelete(visual_server);
|
|
|
|
#ifdef OPENGL_ENABLED
|
|
|
|
if (gl_context)
|
|
|
|
memdelete(gl_context);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (user_proc) {
|
|
|
|
SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)user_proc);
|
|
|
|
};
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
/*
|
|
|
|
if (debugger_connection_console) {
|
|
|
|
memdelete(debugger_connection_console);
|
|
|
|
}
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-02-19 19:42:36 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_Windows::finalize_core() {
|
|
|
|
|
|
|
|
memdelete(process_map);
|
|
|
|
|
|
|
|
TCPServerWinsock::cleanup();
|
|
|
|
StreamPeerWinsock::cleanup();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::alert(const String &p_alert, const String &p_title) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!is_no_window_mode_enabled())
|
2016-07-26 13:16:45 +00:00
|
|
|
MessageBoxW(NULL, p_alert.c_str(), p_title.c_str(), MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL);
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("ALERT: " + p_alert);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::set_mouse_mode(MouseMode p_mode) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == p_mode)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
mouse_mode = p_mode;
|
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
|
2014-02-10 01:10:30 +00:00
|
|
|
RECT clipRect;
|
|
|
|
GetClientRect(hWnd, &clipRect);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClientToScreen(hWnd, (POINT *)&clipRect.left);
|
|
|
|
ClientToScreen(hWnd, (POINT *)&clipRect.right);
|
2014-02-10 01:10:30 +00:00
|
|
|
ClipCursor(&clipRect);
|
2017-03-05 15:44:50 +00:00
|
|
|
center = Point2i(video_mode.width / 2, video_mode.height / 2);
|
|
|
|
POINT pos = { (int)center.x, (int)center.y };
|
2014-02-10 01:10:30 +00:00
|
|
|
ClientToScreen(hWnd, &pos);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED)
|
2017-01-25 18:21:41 +00:00
|
|
|
SetCursorPos(pos.x, pos.y);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
ReleaseCapture();
|
|
|
|
ClipCursor(NULL);
|
|
|
|
}
|
|
|
|
|
2016-10-20 22:01:28 +00:00
|
|
|
if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_HIDDEN) {
|
|
|
|
hCursor = SetCursor(NULL);
|
|
|
|
} else {
|
|
|
|
SetCursor(hCursor);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS_Windows::MouseMode OS_Windows::get_mouse_mode() const {
|
2014-09-20 00:01:41 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return mouse_mode;
|
|
|
|
}
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
void OS_Windows::warp_mouse_position(const Point2 &p_to) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_mode == MOUSE_MODE_CAPTURED) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
old_x = p_to.x;
|
|
|
|
old_y = p_to.y;
|
2014-09-20 00:01:41 +00:00
|
|
|
} else {
|
|
|
|
|
2015-02-14 22:22:06 +00:00
|
|
|
POINT p;
|
2017-03-05 15:44:50 +00:00
|
|
|
p.x = p_to.x;
|
|
|
|
p.y = p_to.y;
|
|
|
|
ClientToScreen(hWnd, &p);
|
2015-02-14 22:22:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
SetCursorPos(p.x, p.y);
|
2014-09-20 00:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
Point2 OS_Windows::get_mouse_position() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return Point2(old_x, old_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_Windows::get_mouse_button_state() const {
|
|
|
|
|
|
|
|
return last_button_state;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_window_title(const String &p_title) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
SetWindowTextW(hWnd, p_title.c_str());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2014-12-17 01:31:57 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::VideoMode OS_Windows::get_video_mode(int p_screen) const {
|
|
|
|
|
|
|
|
return video_mode;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 16:53:53 +00:00
|
|
|
static BOOL CALLBACK _MonitorEnumProcCount(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
|
|
|
|
|
|
|
|
int *data = (int *)dwData;
|
|
|
|
(*data)++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
int OS_Windows::get_screen_count() const {
|
|
|
|
|
2017-08-14 16:53:53 +00:00
|
|
|
int data = 0;
|
|
|
|
EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcCount, (LPARAM)&data);
|
|
|
|
return data;
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 16:53:53 +00:00
|
|
|
typedef struct {
|
|
|
|
int count;
|
|
|
|
int screen;
|
|
|
|
HMONITOR monitor;
|
|
|
|
} EnumScreenData;
|
|
|
|
|
|
|
|
static BOOL CALLBACK _MonitorEnumProcScreen(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
|
|
|
|
|
|
|
|
EnumScreenData *data = (EnumScreenData *)dwData;
|
|
|
|
if (data->monitor == hMonitor) {
|
|
|
|
data->screen = data->count;
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 16:53:53 +00:00
|
|
|
data->count++;
|
|
|
|
return TRUE;
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 16:53:53 +00:00
|
|
|
int OS_Windows::get_current_screen() const {
|
|
|
|
|
|
|
|
EnumScreenData data = { 0, 0, MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST) };
|
|
|
|
EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcScreen, (LPARAM)&data);
|
|
|
|
return data.screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::set_current_screen(int p_screen) {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
Vector2 ofs = get_window_position() - get_screen_position(get_current_screen());
|
2017-03-05 15:44:50 +00:00
|
|
|
set_window_position(ofs + get_screen_position(p_screen));
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 16:53:53 +00:00
|
|
|
typedef struct {
|
|
|
|
int count;
|
|
|
|
int screen;
|
|
|
|
Point2 pos;
|
|
|
|
} EnumPosData;
|
|
|
|
|
|
|
|
static BOOL CALLBACK _MonitorEnumProcPos(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
|
|
|
|
|
|
|
|
EnumPosData *data = (EnumPosData *)dwData;
|
|
|
|
if (data->count == data->screen) {
|
|
|
|
data->pos.x = lprcMonitor->left;
|
|
|
|
data->pos.y = lprcMonitor->top;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->count++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 OS_Windows::get_screen_position(int p_screen) const {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2017-08-20 19:12:29 +00:00
|
|
|
EnumPosData data = { 0, p_screen == -1 ? get_current_screen() : p_screen, Point2() };
|
2017-08-14 16:53:53 +00:00
|
|
|
EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcPos, (LPARAM)&data);
|
|
|
|
return data.pos;
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
2017-08-14 16:53:53 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int count;
|
|
|
|
int screen;
|
|
|
|
Size2 size;
|
|
|
|
} EnumSizeData;
|
|
|
|
|
|
|
|
static BOOL CALLBACK _MonitorEnumProcSize(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
|
|
|
|
|
|
|
|
EnumSizeData *data = (EnumSizeData *)dwData;
|
|
|
|
if (data->count == data->screen) {
|
|
|
|
data->size.x = lprcMonitor->right - lprcMonitor->left;
|
|
|
|
data->size.y = lprcMonitor->bottom - lprcMonitor->top;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->count++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Size2 OS_Windows::get_screen_size(int p_screen) const {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2017-08-20 19:12:29 +00:00
|
|
|
EnumSizeData data = { 0, p_screen == -1 ? get_current_screen() : p_screen, Size2() };
|
2017-08-14 16:53:53 +00:00
|
|
|
EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcSize, (LPARAM)&data);
|
|
|
|
return data.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int count;
|
|
|
|
int screen;
|
|
|
|
int dpi;
|
|
|
|
} EnumDpiData;
|
|
|
|
|
|
|
|
static BOOL CALLBACK _MonitorEnumProcDpi(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
|
|
|
|
|
|
|
|
EnumDpiData *data = (EnumDpiData *)dwData;
|
|
|
|
if (data->count == data->screen) {
|
|
|
|
data->dpi = QueryDpiForMonitor(hMonitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
data->count++;
|
|
|
|
return TRUE;
|
2016-05-29 16:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int OS_Windows::get_screen_dpi(int p_screen) const {
|
|
|
|
|
2017-08-20 19:12:29 +00:00
|
|
|
EnumDpiData data = { 0, p_screen == -1 ? get_current_screen() : p_screen, 72 };
|
2017-08-14 16:53:53 +00:00
|
|
|
EnumDisplayMonitors(NULL, NULL, _MonitorEnumProcDpi, (LPARAM)&data);
|
|
|
|
return data.dpi;
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
2017-08-14 16:53:53 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 OS_Windows::get_window_position() const {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
RECT r;
|
2017-03-05 15:44:50 +00:00
|
|
|
GetWindowRect(hWnd, &r);
|
|
|
|
return Point2(r.left, r.top);
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
2017-08-14 16:53:53 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_window_position(const Point2 &p_position) {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2016-07-24 15:07:59 +00:00
|
|
|
if (video_mode.fullscreen) return;
|
2015-03-22 22:00:50 +00:00
|
|
|
RECT r;
|
2017-03-05 15:44:50 +00:00
|
|
|
GetWindowRect(hWnd, &r);
|
|
|
|
MoveWindow(hWnd, p_position.x, p_position.y, r.right - r.left, r.bottom - r.top, TRUE);
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
Size2 OS_Windows::get_window_size() const {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
RECT r;
|
2017-03-05 15:44:50 +00:00
|
|
|
GetClientRect(hWnd, &r);
|
|
|
|
return Vector2(r.right - r.left, r.bottom - r.top);
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_window_size(const Size2 p_size) {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
video_mode.width = p_size.width;
|
|
|
|
video_mode.height = p_size.height;
|
2015-03-23 23:47:53 +00:00
|
|
|
|
|
|
|
if (video_mode.fullscreen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
int w = p_size.width;
|
|
|
|
int h = p_size.height;
|
2015-03-23 23:47:53 +00:00
|
|
|
|
|
|
|
RECT rect;
|
2017-03-05 15:44:50 +00:00
|
|
|
GetWindowRect(hWnd, &rect);
|
2015-03-23 23:47:53 +00:00
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
if (video_mode.borderless_window == false) {
|
|
|
|
RECT crect;
|
|
|
|
GetClientRect(hWnd, &crect);
|
2015-03-23 23:47:53 +00:00
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
w += (rect.right - rect.left) - (crect.right - crect.left);
|
|
|
|
h += (rect.bottom - rect.top) - (crect.bottom - crect.top);
|
|
|
|
}
|
2015-03-23 23:47:53 +00:00
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
MoveWindow(hWnd, rect.left, rect.top, w, h, TRUE);
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_window_fullscreen(bool p_enabled) {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (video_mode.fullscreen == p_enabled)
|
2015-03-22 22:00:50 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (p_enabled) {
|
|
|
|
|
2015-03-23 23:47:53 +00:00
|
|
|
if (pre_fs_valid) {
|
2017-03-05 15:44:50 +00:00
|
|
|
GetWindowRect(hWnd, &pre_fs_rect);
|
2015-03-23 23:47:53 +00:00
|
|
|
//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));
|
|
|
|
}
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
int cs = get_current_screen();
|
|
|
|
Point2 pos = get_screen_position(cs);
|
|
|
|
Size2 size = get_screen_size(cs);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
video_mode.fullscreen = true;
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
_update_window_style(false);
|
|
|
|
|
|
|
|
MoveWindow(hWnd, pos.x, pos.y, size.width, size.height, TRUE);
|
|
|
|
|
2015-03-22 22:00:50 +00:00
|
|
|
} else {
|
|
|
|
|
2015-03-23 23:47:53 +00:00
|
|
|
RECT rect;
|
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
video_mode.fullscreen = false;
|
|
|
|
|
2015-03-23 23:47:53 +00:00
|
|
|
if (pre_fs_valid) {
|
2017-03-05 15:44:50 +00:00
|
|
|
rect = pre_fs_rect;
|
2015-03-23 23:47:53 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
rect.left = 0;
|
|
|
|
rect.right = video_mode.width;
|
|
|
|
rect.top = 0;
|
|
|
|
rect.bottom = video_mode.height;
|
2015-03-23 23:47:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
_update_window_style(false);
|
2015-03-23 23:47:53 +00:00
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
|
2015-03-23 23:47:53 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pre_fs_valid = true;
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool OS_Windows::is_window_fullscreen() const {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
return video_mode.fullscreen;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_window_resizable(bool p_enabled) {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (video_mode.resizable == p_enabled)
|
2015-03-22 22:00:50 +00:00
|
|
|
return;
|
2015-03-23 23:47:53 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
video_mode.resizable = p_enabled;
|
2017-07-10 00:48:22 +00:00
|
|
|
|
|
|
|
_update_window_style();
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool OS_Windows::is_window_resizable() const {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
return video_mode.resizable;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_window_minimized(bool p_enabled) {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
if (p_enabled) {
|
2017-03-05 15:44:50 +00:00
|
|
|
maximized = false;
|
|
|
|
minimized = true;
|
|
|
|
ShowWindow(hWnd, SW_MINIMIZE);
|
2015-03-22 22:00:50 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
ShowWindow(hWnd, SW_RESTORE);
|
|
|
|
maximized = false;
|
|
|
|
minimized = false;
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool OS_Windows::is_window_minimized() const {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
return minimized;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void OS_Windows::set_window_maximized(bool p_enabled) {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
if (p_enabled) {
|
2017-03-05 15:44:50 +00:00
|
|
|
maximized = true;
|
|
|
|
minimized = false;
|
|
|
|
ShowWindow(hWnd, SW_MAXIMIZE);
|
2015-03-22 22:00:50 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
ShowWindow(hWnd, SW_RESTORE);
|
|
|
|
maximized = false;
|
|
|
|
minimized = false;
|
2015-03-22 22:00:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool OS_Windows::is_window_maximized() const {
|
2015-03-22 22:00:50 +00:00
|
|
|
|
|
|
|
return maximized;
|
|
|
|
}
|
|
|
|
|
2016-01-03 04:18:28 +00:00
|
|
|
void OS_Windows::set_borderless_window(int p_borderless) {
|
2017-07-10 00:48:22 +00:00
|
|
|
if (video_mode.borderless_window == p_borderless)
|
|
|
|
return;
|
|
|
|
|
2016-01-03 04:18:28 +00:00
|
|
|
video_mode.borderless_window = p_borderless;
|
2017-07-10 00:48:22 +00:00
|
|
|
|
|
|
|
_update_window_style();
|
2016-01-03 04:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_Windows::get_borderless_window() {
|
|
|
|
return video_mode.borderless_window;
|
|
|
|
}
|
|
|
|
|
2017-07-10 00:48:22 +00:00
|
|
|
void OS_Windows::_update_window_style(bool repaint) {
|
|
|
|
if (video_mode.fullscreen || video_mode.borderless_window) {
|
|
|
|
SetWindowLongPtr(hWnd, GWL_STYLE, WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE);
|
|
|
|
} else {
|
|
|
|
if (video_mode.resizable) {
|
|
|
|
SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE);
|
|
|
|
} else {
|
|
|
|
SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_MINIMIZEBOX | WS_POPUPWINDOW | WS_VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (repaint) {
|
|
|
|
RECT rect;
|
|
|
|
GetWindowRect(hWnd, &rect);
|
|
|
|
MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:00:10 +00:00
|
|
|
Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
|
|
|
|
|
|
|
|
|
|
|
|
DLL_DIRECTORY_COOKIE cookie;
|
|
|
|
|
|
|
|
if (p_also_set_library_path) {
|
|
|
|
cookie = AddDllDirectory(p_path.get_base_dir().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
p_library_handle = (void *)LoadLibraryExW(p_path.c_str(),NULL,p_also_set_library_path ? LOAD_LIBRARY_SEARCH_USER_DIRS : 0);
|
|
|
|
|
|
|
|
if (p_also_set_library_path) {
|
|
|
|
RemoveDllDirectory(cookie);
|
|
|
|
}
|
|
|
|
|
2017-03-08 01:50:13 +00:00
|
|
|
if (!p_library_handle) {
|
|
|
|
ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + String::num(GetLastError()));
|
|
|
|
ERR_FAIL_V(ERR_CANT_OPEN);
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-04-03 14:11:38 +00:00
|
|
|
Error OS_Windows::close_dynamic_library(void *p_library_handle) {
|
|
|
|
if (!FreeLibrary((HMODULE)p_library_handle)) {
|
2017-03-08 01:50:13 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-07-27 07:23:21 +00:00
|
|
|
Error OS_Windows::get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional) {
|
2017-04-03 14:11:38 +00:00
|
|
|
p_symbol_handle = (void *)GetProcAddress((HMODULE)p_library_handle, p_name.utf8().get_data());
|
2017-03-08 01:50:13 +00:00
|
|
|
if (!p_symbol_handle) {
|
2017-07-27 07:23:21 +00:00
|
|
|
if (!p_optional) {
|
|
|
|
ERR_EXPLAIN("Can't resolve symbol " + p_name + ". Error: " + String::num(GetLastError()));
|
|
|
|
ERR_FAIL_V(ERR_CANT_RESOLVE);
|
|
|
|
} else {
|
|
|
|
return ERR_CANT_RESOLVE;
|
|
|
|
}
|
2017-03-08 01:50:13 +00:00
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2016-07-05 15:29:08 +00:00
|
|
|
void OS_Windows::request_attention() {
|
|
|
|
|
|
|
|
FLASHWINFO info;
|
|
|
|
info.cbSize = sizeof(FLASHWINFO);
|
|
|
|
info.hwnd = hWnd;
|
|
|
|
info.dwFlags = FLASHW_TRAY;
|
|
|
|
info.dwTimeout = 0;
|
|
|
|
info.uCount = 2;
|
|
|
|
FlashWindowEx(&info);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String OS_Windows::get_name() {
|
|
|
|
|
|
|
|
return "Windows";
|
|
|
|
}
|
|
|
|
|
2015-06-07 13:06:13 +00:00
|
|
|
OS::Date OS_Windows::get_date(bool utc) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
SYSTEMTIME systemtime;
|
2015-06-07 13:06:13 +00:00
|
|
|
if (utc)
|
2015-06-06 01:40:56 +00:00
|
|
|
GetSystemTime(&systemtime);
|
|
|
|
else
|
|
|
|
GetLocalTime(&systemtime);
|
2015-06-07 13:06:13 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Date date;
|
2017-03-05 15:44:50 +00:00
|
|
|
date.day = systemtime.wDay;
|
|
|
|
date.month = Month(systemtime.wMonth);
|
|
|
|
date.weekday = Weekday(systemtime.wDayOfWeek);
|
|
|
|
date.year = systemtime.wYear;
|
|
|
|
date.dst = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return date;
|
|
|
|
}
|
2015-06-06 01:40:56 +00:00
|
|
|
OS::Time OS_Windows::get_time(bool utc) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
SYSTEMTIME systemtime;
|
2015-06-06 01:40:56 +00:00
|
|
|
if (utc)
|
|
|
|
GetSystemTime(&systemtime);
|
|
|
|
else
|
|
|
|
GetLocalTime(&systemtime);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Time time;
|
2017-03-05 15:44:50 +00:00
|
|
|
time.hour = systemtime.wHour;
|
|
|
|
time.min = systemtime.wMinute;
|
|
|
|
time.sec = systemtime.wSecond;
|
2014-02-10 01:10:30 +00:00
|
|
|
return time;
|
|
|
|
}
|
2015-06-06 03:35:38 +00:00
|
|
|
|
|
|
|
OS::TimeZoneInfo OS_Windows::get_time_zone_info() const {
|
|
|
|
TIME_ZONE_INFORMATION info;
|
|
|
|
bool daylight = false;
|
2015-06-07 14:10:33 +00:00
|
|
|
if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT)
|
2015-06-06 03:35:38 +00:00
|
|
|
daylight = true;
|
|
|
|
|
2015-06-07 14:10:33 +00:00
|
|
|
TimeZoneInfo ret;
|
2015-06-06 03:35:38 +00:00
|
|
|
if (daylight) {
|
|
|
|
ret.name = info.DaylightName;
|
|
|
|
} else {
|
|
|
|
ret.name = info.StandardName;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.bias = info.Bias;
|
|
|
|
return ret;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-06-07 13:06:13 +00:00
|
|
|
uint64_t OS_Windows::get_unix_time() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
FILETIME ft;
|
|
|
|
SYSTEMTIME st;
|
|
|
|
GetSystemTime(&st);
|
|
|
|
SystemTimeToFileTime(&st, &ft);
|
|
|
|
|
|
|
|
SYSTEMTIME ep;
|
|
|
|
ep.wYear = 1970;
|
|
|
|
ep.wMonth = 1;
|
|
|
|
ep.wDayOfWeek = 4;
|
|
|
|
ep.wDay = 1;
|
|
|
|
ep.wHour = 0;
|
|
|
|
ep.wMinute = 0;
|
|
|
|
ep.wSecond = 0;
|
|
|
|
ep.wMilliseconds = 0;
|
|
|
|
FILETIME fep;
|
|
|
|
SystemTimeToFileTime(&ep, &fep);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2016-01-10 21:24:55 +00:00
|
|
|
uint64_t OS_Windows::get_system_time_secs() const {
|
2016-06-11 17:09:21 +00:00
|
|
|
|
|
|
|
const uint64_t WINDOWS_TICK = 10000000;
|
|
|
|
const uint64_t SEC_TO_UNIX_EPOCH = 11644473600LL;
|
|
|
|
|
2015-08-06 17:29:33 +00:00
|
|
|
SYSTEMTIME st;
|
|
|
|
GetSystemTime(&st);
|
2016-01-10 21:24:55 +00:00
|
|
|
FILETIME ft;
|
2017-03-05 15:44:50 +00:00
|
|
|
SystemTimeToFileTime(&st, &ft);
|
2016-01-10 21:24:55 +00:00
|
|
|
uint64_t ret;
|
2017-03-05 15:44:50 +00:00
|
|
|
ret = ft.dwHighDateTime;
|
|
|
|
ret <<= 32;
|
|
|
|
ret |= ft.dwLowDateTime;
|
2016-06-11 17:09:21 +00:00
|
|
|
|
|
|
|
return (uint64_t)(ret / WINDOWS_TICK - SEC_TO_UNIX_EPOCH);
|
2015-08-06 17:29:33 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_Windows::delay_usec(uint32_t p_usec) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_usec < 1000)
|
|
|
|
Sleep(1);
|
|
|
|
else
|
|
|
|
Sleep(p_usec / 1000);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
uint64_t OS_Windows::get_ticks_usec() const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::process_events() {
|
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
|
2017-03-26 13:59:13 +00:00
|
|
|
joypad->process_joypads();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
process_key_events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::set_cursor_shape(CursorShape p_shape) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (cursor_shape == p_shape)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const LPCTSTR win_cursors[CURSOR_MAX] = {
|
2014-02-10 01:10:30 +00:00
|
|
|
IDC_ARROW,
|
|
|
|
IDC_IBEAM,
|
2017-03-05 15:44:50 +00:00
|
|
|
IDC_HAND, //finger
|
2014-02-10 01:10:30 +00:00
|
|
|
IDC_CROSS,
|
|
|
|
IDC_WAIT,
|
|
|
|
IDC_APPSTARTING,
|
|
|
|
IDC_ARROW,
|
|
|
|
IDC_ARROW,
|
|
|
|
IDC_NO,
|
|
|
|
IDC_SIZENS,
|
|
|
|
IDC_SIZEWE,
|
|
|
|
IDC_SIZENESW,
|
|
|
|
IDC_SIZENWSE,
|
|
|
|
IDC_SIZEALL,
|
|
|
|
IDC_SIZENS,
|
|
|
|
IDC_SIZEWE,
|
|
|
|
IDC_HELP
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
SetCursor(LoadCursor(hInstance, win_cursors[p_shape]));
|
|
|
|
cursor_shape = p_shape;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 18:09:04 +00:00
|
|
|
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, bool read_stderr) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (p_blocking && r_pipe) {
|
|
|
|
|
|
|
|
String argss;
|
2017-03-05 15:44:50 +00:00
|
|
|
argss = "\"\"" + p_path + "\"";
|
|
|
|
|
|
|
|
for (const List<String>::Element *E = p_arguments.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
argss += String(" \"") + E->get() + "\"";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//print_line("ARGS: "+argss);
|
2014-02-10 01:10:30 +00:00
|
|
|
//argss+"\"";
|
|
|
|
//argss+=" 2>nul";
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
FILE *f = _wpopen(argss.c_str(), L"r");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
char buf[65535];
|
2017-03-05 15:44:50 +00:00
|
|
|
while (fgets(buf, 65535, f)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
(*r_pipe) += buf;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int rv = _pclose(f);
|
|
|
|
if (r_exitcode)
|
2017-03-05 15:44:50 +00:00
|
|
|
*r_exitcode = rv;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String cmdline = "\"" + p_path + "\"";
|
|
|
|
const List<String>::Element *I = p_arguments.front();
|
2014-02-10 01:10:30 +00:00
|
|
|
while (I) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cmdline += " \"" + I->get() + "\"";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
I = I->next();
|
|
|
|
};
|
|
|
|
|
|
|
|
//cmdline+="\"";
|
|
|
|
|
|
|
|
ProcessInfo pi;
|
2017-03-05 15:44:50 +00:00
|
|
|
ZeroMemory(&pi.si, sizeof(pi.si));
|
2014-02-10 01:10:30 +00:00
|
|
|
pi.si.cb = sizeof(pi.si);
|
2017-03-05 15:44:50 +00:00
|
|
|
ZeroMemory(&pi.pi, sizeof(pi.pi));
|
|
|
|
LPSTARTUPINFOW si_w = (LPSTARTUPINFOW)&pi.si;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("running cmdline: " + cmdline);
|
2014-02-15 05:01:39 +00:00
|
|
|
Vector<CharType> modstr; //windows wants to change this no idea why
|
|
|
|
modstr.resize(cmdline.size());
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < cmdline.size(); i++)
|
|
|
|
modstr[i] = cmdline[i];
|
2017-11-25 04:12:07 +00:00
|
|
|
int ret = CreateProcessW(NULL, modstr.ptrw(), NULL, NULL, 0, NORMAL_PRIORITY_CLASS, NULL, NULL, si_w, &pi.pi);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND_V(ret == 0, ERR_CANT_FORK);
|
|
|
|
|
|
|
|
if (p_blocking) {
|
|
|
|
|
|
|
|
DWORD ret = WaitForSingleObject(pi.pi.hProcess, INFINITE);
|
|
|
|
if (r_exitcode)
|
2017-03-05 15:44:50 +00:00
|
|
|
*r_exitcode = ret;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ProcessID pid = pi.pi.dwProcessId;
|
|
|
|
if (r_child_id) {
|
|
|
|
*r_child_id = pid;
|
|
|
|
};
|
|
|
|
process_map->insert(pid, pi);
|
|
|
|
};
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error OS_Windows::kill(const ProcessID &p_pid) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
HANDLE h;
|
|
|
|
|
|
|
|
if (process_map->has(p_pid)) {
|
|
|
|
h = (*process_map)[p_pid].pi.hProcess;
|
|
|
|
process_map->erase(p_pid);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!process_map->has(p_pid), FAILED);
|
|
|
|
};
|
|
|
|
|
|
|
|
int ret = TerminateProcess(h, 0);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return ret != 0 ? OK : FAILED;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-08-07 10:17:31 +00:00
|
|
|
int OS_Windows::get_process_id() const {
|
2016-04-29 16:57:57 +00:00
|
|
|
return _getpid();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Error OS_Windows::set_cwd(const String &p_cwd) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (_wchdir(p_cwd.c_str()) != 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return ERR_CANT_OPEN;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2014-02-15 05:01:39 +00:00
|
|
|
String OS_Windows::get_executable_path() const {
|
|
|
|
|
|
|
|
wchar_t bufname[4096];
|
2017-03-05 15:44:50 +00:00
|
|
|
GetModuleFileNameW(NULL, bufname, 4096);
|
|
|
|
String s = bufname;
|
2014-02-15 05:01:39 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
void OS_Windows::set_icon(const Ref<Image> &p_icon) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
ERR_FAIL_COND(!p_icon.is_valid());
|
|
|
|
Ref<Image> icon = p_icon->duplicate();
|
|
|
|
if (icon->get_format() != Image::FORMAT_RGBA8)
|
|
|
|
icon->convert(Image::FORMAT_RGBA8);
|
|
|
|
int w = icon->get_width();
|
|
|
|
int h = icon->get_height();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/* Create temporary bitmap buffer */
|
|
|
|
int icon_len = 40 + h * w * 4;
|
2014-02-13 21:03:28 +00:00
|
|
|
Vector<BYTE> v;
|
|
|
|
v.resize(icon_len);
|
|
|
|
BYTE *icon_bmp = &v[0];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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];
|
2017-05-17 10:36:47 +00:00
|
|
|
PoolVector<uint8_t>::Read r = icon->get_data().read();
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
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];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HICON hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
|
|
|
|
|
|
|
|
/* Set the icon for the window */
|
2017-03-05 15:44:50 +00:00
|
|
|
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hicon);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/* Set the icon in the task manager (should we do this?) */
|
2017-03-05 15:44:50 +00:00
|
|
|
SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hicon);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool OS_Windows::has_environment(const String &p_var) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-30 13:00:10 +00:00
|
|
|
return _wgetenv(p_var.c_str()) != NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String OS_Windows::get_environment(const String &p_var) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-04 16:12:05 +00:00
|
|
|
wchar_t wval[0x7Fff]; // MSDN says 32767 char is the maximum
|
2017-03-05 15:44:50 +00:00
|
|
|
int wlen = GetEnvironmentVariableW(p_var.c_str(), wval, 0x7Fff);
|
|
|
|
if (wlen > 0) {
|
2015-05-04 16:12:05 +00:00
|
|
|
return wval;
|
|
|
|
}
|
2014-02-13 21:03:28 +00:00
|
|
|
return "";
|
2015-05-04 16:12:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String OS_Windows::get_stdin_string(bool p_block) {
|
|
|
|
|
|
|
|
if (p_block) {
|
|
|
|
char buff[1024];
|
2017-03-05 15:44:50 +00:00
|
|
|
return fgets(buff, 1024, stdin);
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2016-09-14 02:02:18 +00:00
|
|
|
void OS_Windows::enable_for_stealing_focus(ProcessID pid) {
|
|
|
|
|
|
|
|
AllowSetForegroundWindow(pid);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_Windows::move_window_to_foreground() {
|
|
|
|
|
|
|
|
SetForegroundWindow(hWnd);
|
|
|
|
}
|
|
|
|
|
2014-04-18 14:43:54 +00:00
|
|
|
Error OS_Windows::shell_open(String p_uri) {
|
|
|
|
|
|
|
|
ShellExecuteW(NULL, L"open", p_uri.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
String OS_Windows::get_locale() const {
|
|
|
|
|
|
|
|
const _WinLocale *wl = &_win_locales[0];
|
|
|
|
|
|
|
|
LANGID langid = GetUserDefaultUILanguage();
|
|
|
|
String neutral;
|
2017-03-05 15:44:50 +00:00
|
|
|
int lang = langid & ((1 << 9) - 1);
|
|
|
|
int sublang = langid & ~((1 << 9) - 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (wl->locale) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (wl->main_lang == lang && wl->sublang == SUBLANG_NEUTRAL)
|
|
|
|
neutral = wl->locale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (lang == wl->main_lang && sublang == wl->sublang)
|
2014-02-10 01:10:30 +00:00
|
|
|
return wl->locale;
|
|
|
|
|
|
|
|
wl++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (neutral != "")
|
2014-02-10 01:10:30 +00:00
|
|
|
return neutral;
|
|
|
|
|
|
|
|
return "en";
|
|
|
|
}
|
|
|
|
|
2016-07-02 18:52:36 +00:00
|
|
|
OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
unsigned long azerty[] = {
|
2016-07-02 18:52:36 +00:00
|
|
|
0x00020401, // Arabic (102) AZERTY
|
|
|
|
0x0001080c, // Belgian (Comma)
|
|
|
|
0x0000080c, // Belgian French
|
|
|
|
0x0000040c, // French
|
|
|
|
0 // <--- STOP MARK
|
|
|
|
};
|
|
|
|
unsigned long qwertz[] = {
|
|
|
|
0x0000041a, // Croation
|
|
|
|
0x00000405, // Czech
|
|
|
|
0x00000407, // German
|
|
|
|
0x00010407, // German (IBM)
|
|
|
|
0x0000040e, // Hungarian
|
|
|
|
0x0000046e, // Luxembourgish
|
|
|
|
0x00010415, // Polish (214)
|
|
|
|
0x00000418, // Romanian (Legacy)
|
|
|
|
0x0000081a, // Serbian (Latin)
|
|
|
|
0x0000041b, // Slovak
|
|
|
|
0x00000424, // Slovenian
|
|
|
|
0x0001042e, // Sorbian Extended
|
|
|
|
0x0002042e, // Sorbian Standard
|
|
|
|
0x0000042e, // Sorbian Standard (Legacy)
|
|
|
|
0x0000100c, // Swiss French
|
|
|
|
0x00000807, // Swiss German
|
|
|
|
0 // <--- STOP MARK
|
|
|
|
};
|
|
|
|
unsigned long dvorak[] = {
|
|
|
|
0x00010409, // US-Dvorak
|
|
|
|
0x00030409, // US-Dvorak for left hand
|
|
|
|
0x00040409, // US-Dvorak for right hand
|
|
|
|
0 // <--- STOP MARK
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
char name[KL_NAMELENGTH + 1];
|
|
|
|
name[0] = 0;
|
|
|
|
GetKeyboardLayoutNameA(name);
|
2016-07-02 18:52:36 +00:00
|
|
|
|
|
|
|
unsigned long hex = strtoul(name, NULL, 16);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int i = 0;
|
|
|
|
while (azerty[i] != 0) {
|
2016-07-02 18:52:36 +00:00
|
|
|
if (azerty[i] == hex) return LATIN_KEYBOARD_AZERTY;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
while (qwertz[i] != 0) {
|
2016-07-02 18:52:36 +00:00
|
|
|
if (qwertz[i] == hex) return LATIN_KEYBOARD_QWERTZ;
|
|
|
|
i++;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2016-07-02 18:52:36 +00:00
|
|
|
i = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
while (dvorak[i] != 0) {
|
2016-07-02 18:52:36 +00:00
|
|
|
if (dvorak[i] == hex) return LATIN_KEYBOARD_DVORAK;
|
2017-03-05 15:44:50 +00:00
|
|
|
i++;
|
2016-07-02 18:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return LATIN_KEYBOARD_QWERTY;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void OS_Windows::release_rendering_thread() {
|
|
|
|
|
|
|
|
gl_context->release_current();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::make_rendering_thread() {
|
|
|
|
|
|
|
|
gl_context->make_current();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::swap_buffers() {
|
|
|
|
|
|
|
|
gl_context->swap_buffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_Windows::run() {
|
|
|
|
|
|
|
|
if (!main_loop)
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
main_loop->init();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint64_t last_ticks = get_ticks_usec();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int frames = 0;
|
|
|
|
uint64_t frame = 0;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
while (!force_quit) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
process_events(); // get rid of pending events
|
2017-03-05 15:44:50 +00:00
|
|
|
if (Main::iteration() == true)
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
};
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
main_loop->finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainLoop *OS_Windows::get_main_loop() const {
|
|
|
|
|
|
|
|
return main_loop;
|
|
|
|
}
|
|
|
|
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
String OS_Windows::get_config_path() const {
|
|
|
|
|
|
|
|
if (has_environment("XDG_CONFIG_HOME")) { // unlikely, but after all why not?
|
|
|
|
return get_environment("XDG_CONFIG_HOME");
|
|
|
|
} else if (has_environment("APPDATA")) {
|
|
|
|
return get_environment("APPDATA");
|
|
|
|
} else {
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_Windows::get_data_path() const {
|
|
|
|
|
|
|
|
if (has_environment("XDG_DATA_HOME")) {
|
|
|
|
return get_environment("XDG_DATA_HOME");
|
|
|
|
} else {
|
|
|
|
return get_config_path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_Windows::get_cache_path() const {
|
|
|
|
|
|
|
|
if (has_environment("XDG_CACHE_HOME")) {
|
|
|
|
return get_environment("XDG_CACHE_HOME");
|
|
|
|
} else if (has_environment("TEMP")) {
|
|
|
|
return get_environment("TEMP");
|
|
|
|
} else {
|
|
|
|
return get_config_path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get properly capitalized engine name for system paths
|
|
|
|
String OS_Windows::get_godot_dir_name() const {
|
|
|
|
|
2017-11-19 20:18:01 +00:00
|
|
|
return String(VERSION_SHORT_NAME).capitalize();
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 17:02:41 +00:00
|
|
|
String OS_Windows::get_system_dir(SystemDir p_dir) const {
|
|
|
|
|
|
|
|
int id;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_dir) {
|
2014-12-02 17:02:41 +00:00
|
|
|
case SYSTEM_DIR_DESKTOP: {
|
2017-03-05 15:44:50 +00:00
|
|
|
id = CSIDL_DESKTOPDIRECTORY;
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DCIM: {
|
2017-03-05 15:44:50 +00:00
|
|
|
id = CSIDL_MYPICTURES;
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DOCUMENTS: {
|
2017-03-05 15:44:50 +00:00
|
|
|
id = CSIDL_PERSONAL;
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DOWNLOADS: {
|
2017-03-05 15:44:50 +00:00
|
|
|
id = 0x000C;
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_MOVIES: {
|
2017-03-05 15:44:50 +00:00
|
|
|
id = CSIDL_MYVIDEO;
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_MUSIC: {
|
2017-03-05 15:44:50 +00:00
|
|
|
id = CSIDL_MYMUSIC;
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_PICTURES: {
|
2017-03-05 15:44:50 +00:00
|
|
|
id = CSIDL_MYPICTURES;
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_RINGTONES: {
|
2017-03-05 15:44:50 +00:00
|
|
|
id = CSIDL_MYMUSIC;
|
2014-12-02 17:02:41 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
WCHAR szPath[MAX_PATH];
|
2017-03-05 15:44:50 +00:00
|
|
|
HRESULT res = SHGetFolderPathW(NULL, id, NULL, 0, szPath);
|
|
|
|
ERR_FAIL_COND_V(res != S_OK, String());
|
2014-12-02 17:02:41 +00:00
|
|
|
return String(szPath);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
String OS_Windows::get_user_data_dir() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-26 18:00:53 +00:00
|
|
|
String appname = get_safe_dir_name(ProjectSettings::get_singleton()->get("application/config/name"));
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
if (appname != "") {
|
2017-11-26 18:00:53 +00:00
|
|
|
bool use_custom_dir = ProjectSettings::get_singleton()->get("application/config/use_custom_user_dir");
|
|
|
|
if (use_custom_dir) {
|
|
|
|
String custom_dir = get_safe_dir_name(ProjectSettings::get_singleton()->get("application/config/custom_user_dir_name"), true);
|
|
|
|
if (custom_dir == "") {
|
|
|
|
custom_dir = appname;
|
|
|
|
}
|
|
|
|
return get_data_path().plus_file(custom_dir).replace("\\", "/");
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
} else {
|
2017-11-26 18:00:53 +00:00
|
|
|
return get_data_path().plus_file(get_godot_dir_name()).plus_file("app_userdata").plus_file(appname).replace("\\", "/");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
return ProjectSettings::get_singleton()->get_resource_path();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 23:40:41 +00:00
|
|
|
bool OS_Windows::is_joy_known(int p_device) {
|
|
|
|
return input->is_joy_mapped(p_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_Windows::get_joy_guid(int p_device) const {
|
|
|
|
return input->get_joy_guid_remapped(p_device);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-05 22:14:33 +00:00
|
|
|
void OS_Windows::set_use_vsync(bool p_enable) {
|
|
|
|
|
|
|
|
if (gl_context)
|
|
|
|
gl_context->set_use_vsync(p_enable);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool OS_Windows::is_vsync_enabled() const {
|
2016-06-05 22:14:33 +00:00
|
|
|
|
|
|
|
if (gl_context)
|
|
|
|
return gl_context->is_using_vsync();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-12 19:09:06 +00:00
|
|
|
OS::PowerState OS_Windows::get_power_state() {
|
2016-07-23 11:15:55 +00:00
|
|
|
return power_manager->get_power_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_Windows::get_power_seconds_left() {
|
|
|
|
return power_manager->get_power_seconds_left();
|
|
|
|
}
|
|
|
|
|
|
|
|
int OS_Windows::get_power_percent_left() {
|
|
|
|
return power_manager->get_power_percent_left();
|
|
|
|
}
|
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
bool OS_Windows::_check_internal_feature_support(const String &p_feature) {
|
2017-02-08 23:07:35 +00:00
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
return p_feature == "pc" || p_feature == "s3tc";
|
2017-02-08 23:07:35 +00:00
|
|
|
}
|
2016-06-05 22:14:33 +00:00
|
|
|
|
2017-09-08 01:01:49 +00:00
|
|
|
void OS_Windows::disable_crash_handler() {
|
|
|
|
crash_handler.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OS_Windows::is_disable_crash_handler() const {
|
|
|
|
return crash_handler.is_disabled();
|
|
|
|
}
|
|
|
|
|
2017-09-25 13:15:11 +00:00
|
|
|
Error OS_Windows::move_to_trash(const String &p_path) {
|
|
|
|
SHFILEOPSTRUCTA sf;
|
|
|
|
TCHAR *from = new TCHAR[p_path.length() + 2];
|
|
|
|
strcpy(from, p_path.utf8().get_data());
|
|
|
|
from[p_path.length()] = 0;
|
|
|
|
from[p_path.length() + 1] = 0;
|
|
|
|
|
|
|
|
sf.hwnd = hWnd;
|
|
|
|
sf.wFunc = FO_DELETE;
|
|
|
|
sf.pFrom = from;
|
|
|
|
sf.pTo = NULL;
|
|
|
|
sf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
|
|
|
|
sf.fAnyOperationsAborted = FALSE;
|
|
|
|
sf.hNameMappings = NULL;
|
|
|
|
sf.lpszProgressTitle = NULL;
|
|
|
|
|
|
|
|
int ret = SHFileOperation(&sf);
|
|
|
|
delete[] from;
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
ERR_PRINTS("SHFileOperation error: " + itos(ret));
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS_Windows::OS_Windows(HINSTANCE _hInstance) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
key_event_pos = 0;
|
|
|
|
force_quit = false;
|
|
|
|
alt_mem = false;
|
|
|
|
gr_mem = false;
|
|
|
|
shift_mem = false;
|
|
|
|
control_mem = false;
|
|
|
|
meta_mem = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
minimized = false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
hInstance = _hInstance;
|
|
|
|
pressrc = 0;
|
|
|
|
old_invalid = true;
|
|
|
|
mouse_mode = MOUSE_MODE_VISIBLE;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef STDOUT_FILE
|
2017-03-05 15:44:50 +00:00
|
|
|
stdo = fopen("stdout.txt", "wb");
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
user_proc = NULL;
|
|
|
|
|
2017-08-27 17:01:34 +00:00
|
|
|
#ifdef WASAPI_ENABLED
|
|
|
|
AudioDriverManager::add_driver(&driver_wasapi);
|
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef RTAUDIO_ENABLED
|
2017-01-16 18:19:45 +00:00
|
|
|
AudioDriverManager::add_driver(&driver_rtaudio);
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
2016-10-17 15:40:45 +00:00
|
|
|
#ifdef XAUDIO2_ENABLED
|
2017-01-16 18:19:45 +00:00
|
|
|
AudioDriverManager::add_driver(&driver_xaudio2);
|
2016-10-17 15:40:45 +00:00
|
|
|
#endif
|
2017-09-22 05:56:02 +00:00
|
|
|
|
2017-11-21 09:35:01 +00:00
|
|
|
Vector<Logger *> loggers;
|
|
|
|
loggers.push_back(memnew(WindowsTerminalLogger));
|
|
|
|
_set_logger(memnew(CompositeLogger(loggers)));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS_Windows::~OS_Windows() {
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef STDOUT_FILE
|
|
|
|
fclose(stdo);
|
|
|
|
#endif
|
|
|
|
}
|