2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* os_uwp.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2016-11-02 21:26:42 +01:00
|
|
|
#include "os_uwp.h"
|
2017-11-17 15:25:22 +01:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/config/project_settings.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/io/marshalls.h"
|
2017-04-29 16:48:23 +02:00
|
|
|
#include "drivers/unix/ip_unix.h"
|
2021-09-23 08:56:12 +02:00
|
|
|
#include "drivers/unix/net_socket_posix.h"
|
2016-11-02 21:26:42 +01:00
|
|
|
#include "drivers/windows/dir_access_windows.h"
|
2016-09-04 00:25:43 +02:00
|
|
|
#include "drivers/windows/file_access_windows.h"
|
2014-09-15 16:33:30 +02:00
|
|
|
#include "drivers/windows/mutex_windows.h"
|
|
|
|
#include "drivers/windows/semaphore_windows.h"
|
2017-04-29 16:48:23 +02:00
|
|
|
#include "main/main.h"
|
2017-09-22 07:56:02 +02:00
|
|
|
#include "platform/windows/windows_terminal_logger.h"
|
2017-04-29 16:48:23 +02:00
|
|
|
#include "servers/audio_server.h"
|
2020-12-03 22:09:47 +01:00
|
|
|
#include "servers/rendering/rendering_server_default.h"
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
#include <ppltasks.h>
|
2014-10-03 05:10:51 +02:00
|
|
|
#include <wrl.h>
|
|
|
|
|
|
|
|
using namespace Windows::ApplicationModel::Core;
|
|
|
|
using namespace Windows::ApplicationModel::Activation;
|
|
|
|
using namespace Windows::UI::Core;
|
|
|
|
using namespace Windows::UI::Input;
|
2016-09-04 00:25:43 +02:00
|
|
|
using namespace Windows::UI::Popups;
|
2014-10-03 05:10:51 +02:00
|
|
|
using namespace Windows::Foundation;
|
|
|
|
using namespace Windows::Graphics::Display;
|
|
|
|
using namespace Microsoft::WRL;
|
2016-09-04 00:25:43 +02:00
|
|
|
using namespace Windows::UI::ViewManagement;
|
|
|
|
using namespace Windows::Devices::Input;
|
|
|
|
using namespace Windows::Devices::Sensors;
|
|
|
|
using namespace Windows::ApplicationModel::DataTransfer;
|
|
|
|
using namespace concurrency;
|
2014-10-03 05:10:51 +02:00
|
|
|
|
2021-03-16 21:08:55 +01:00
|
|
|
static const float earth_gravity = 9.80665;
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
int OS_UWP::get_video_driver_count() const {
|
2018-07-12 21:21:35 +02:00
|
|
|
return 2;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
Size2 OS_UWP::get_window_size() const {
|
2016-09-04 00:25:43 +02:00
|
|
|
Size2 size;
|
|
|
|
size.width = video_mode.width;
|
|
|
|
size.height = video_mode.height;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
int OS_UWP::get_current_video_driver() const {
|
2018-07-20 11:56:18 +02:00
|
|
|
return video_driver_index;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_window_size(const Size2 p_size) {
|
2016-09-04 00:25:43 +02:00
|
|
|
Windows::Foundation::Size new_size;
|
|
|
|
new_size.Width = p_size.width;
|
|
|
|
new_size.Height = p_size.height;
|
|
|
|
|
|
|
|
ApplicationView ^ view = ApplicationView::GetForCurrentView();
|
|
|
|
|
|
|
|
if (view->TryResizeView(new_size)) {
|
|
|
|
video_mode.width = p_size.width;
|
|
|
|
video_mode.height = p_size.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_window_fullscreen(bool p_enabled) {
|
2016-09-04 00:25:43 +02:00
|
|
|
ApplicationView ^ view = ApplicationView::GetForCurrentView();
|
|
|
|
|
|
|
|
video_mode.fullscreen = view->IsFullScreenMode;
|
|
|
|
|
2022-02-16 13:56:32 +01:00
|
|
|
if (video_mode.fullscreen == p_enabled) {
|
2016-09-04 00:25:43 +02:00
|
|
|
return;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
if (p_enabled) {
|
|
|
|
video_mode.fullscreen = view->TryEnterFullScreenMode();
|
|
|
|
} else {
|
|
|
|
view->ExitFullScreenMode();
|
|
|
|
video_mode.fullscreen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
bool OS_UWP::is_window_fullscreen() const {
|
2016-09-04 00:25:43 +02:00
|
|
|
return ApplicationView::GetForCurrentView()->IsFullScreenMode;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_keep_screen_on(bool p_enabled) {
|
2022-02-16 13:56:32 +01:00
|
|
|
if (is_keep_screen_on() == p_enabled) {
|
2016-09-04 00:25:43 +02:00
|
|
|
return;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2022-02-16 13:56:32 +01:00
|
|
|
if (p_enabled) {
|
2016-09-04 00:25:43 +02:00
|
|
|
display_request->RequestActive();
|
2022-02-16 13:56:32 +01:00
|
|
|
} else {
|
2016-09-04 00:25:43 +02:00
|
|
|
display_request->RequestRelease();
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
OS::set_keep_screen_on(p_enabled);
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::initialize_core() {
|
2014-09-15 16:33:30 +02:00
|
|
|
//RedirectIOToConsole();
|
|
|
|
|
|
|
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
|
|
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
|
|
|
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_FILESYSTEM);
|
|
|
|
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_RESOURCES);
|
|
|
|
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_USERDATA);
|
|
|
|
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
|
2018-09-02 05:32:12 +02:00
|
|
|
NetSocketPosix::make_default();
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
// We need to know how often the clock is updated
|
2022-01-08 13:10:27 +01:00
|
|
|
QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second);
|
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&ticks_start);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2021-05-06 02:48:18 +02:00
|
|
|
IPUnix::make_default();
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
cursor_shape = CURSOR_ARROW;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_window(Windows::UI::Core::CoreWindow ^ p_window) {
|
2018-07-12 21:21:35 +02:00
|
|
|
window = p_window;
|
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::screen_size_changed() {
|
2014-12-20 19:30:06 +01:00
|
|
|
gl_context->reset();
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-12-20 19:30:06 +01:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
2020-04-02 01:20:12 +02:00
|
|
|
main_loop = nullptr;
|
2014-09-15 16:33:30 +02:00
|
|
|
outside = true;
|
|
|
|
|
2020-02-13 10:08:52 +01:00
|
|
|
// FIXME: Hardcoded for now, add Vulkan support.
|
2022-10-11 10:32:13 +02:00
|
|
|
p_video_driver = RENDERING_DRIVER_OPENGL3;
|
2019-02-12 15:43:54 +01:00
|
|
|
ContextEGL_UWP::Driver opengl_api_type = ContextEGL_UWP::GLES_2_0;
|
2018-08-25 00:04:25 +02:00
|
|
|
|
|
|
|
bool gl_initialization_error = false;
|
|
|
|
|
2020-02-13 10:08:52 +01:00
|
|
|
gl_context = memnew(ContextEGL_UWP(window, opengl_api_type));
|
2018-08-25 00:04:25 +02:00
|
|
|
|
2020-02-13 10:08:52 +01:00
|
|
|
if (gl_context->initialize() != OK) {
|
|
|
|
memdelete(gl_context);
|
2020-04-02 01:20:12 +02:00
|
|
|
gl_context = nullptr;
|
2020-02-13 10:08:52 +01:00
|
|
|
gl_initialization_error = true;
|
|
|
|
}
|
2018-08-25 00:04:25 +02:00
|
|
|
|
2020-02-13 10:08:52 +01:00
|
|
|
if (opengl_api_type == ContextEGL_UWP::GLES_2_0) {
|
2021-10-26 17:18:39 +02:00
|
|
|
if (RasterizerGLES3::is_viable() == OK) {
|
|
|
|
RasterizerGLES3::register_config();
|
|
|
|
RasterizerGLES3::make_current();
|
2020-02-13 10:08:52 +01:00
|
|
|
} else {
|
|
|
|
gl_initialization_error = true;
|
2018-08-25 00:04:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_initialization_error) {
|
|
|
|
OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
|
|
|
|
"Please update your drivers or if you have a very old or integrated GPU upgrade it.",
|
2020-02-13 10:08:52 +01:00
|
|
|
"Unable to initialize video driver");
|
2018-08-25 00:04:25 +02:00
|
|
|
return ERR_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
video_driver_index = p_video_driver;
|
|
|
|
gl_context->make_current();
|
|
|
|
gl_context->set_use_vsync(video_mode.use_vsync);
|
|
|
|
|
2014-12-15 19:42:58 +01:00
|
|
|
VideoMode vm;
|
|
|
|
vm.width = gl_context->get_window_width();
|
|
|
|
vm.height = gl_context->get_window_height();
|
|
|
|
vm.resizable = false;
|
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
ApplicationView ^ view = ApplicationView::GetForCurrentView();
|
|
|
|
vm.fullscreen = view->IsFullScreenMode;
|
|
|
|
|
|
|
|
view->SetDesiredBoundsMode(ApplicationViewBoundsMode::UseVisible);
|
|
|
|
view->PreferredLaunchWindowingMode = ApplicationViewWindowingMode::PreferredLaunchViewSize;
|
|
|
|
|
|
|
|
if (p_desired.fullscreen != view->IsFullScreenMode) {
|
|
|
|
if (p_desired.fullscreen) {
|
|
|
|
vm.fullscreen = view->TryEnterFullScreenMode();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
view->ExitFullScreenMode();
|
|
|
|
vm.fullscreen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Windows::Foundation::Size desired;
|
|
|
|
desired.Width = p_desired.width;
|
|
|
|
desired.Height = p_desired.height;
|
|
|
|
|
|
|
|
view->PreferredLaunchViewSize = desired;
|
|
|
|
|
|
|
|
if (view->TryResizeView(desired)) {
|
|
|
|
vm.width = view->VisibleBounds.Width;
|
|
|
|
vm.height = view->VisibleBounds.Height;
|
|
|
|
}
|
|
|
|
|
2014-12-15 19:42:58 +01:00
|
|
|
set_video_mode(vm);
|
|
|
|
|
2020-12-03 22:09:47 +01:00
|
|
|
rendering_server = memnew(RenderingServerDefault);
|
2018-11-01 19:22:15 +01:00
|
|
|
// FIXME: Reimplement threaded rendering
|
2014-09-15 16:33:30 +02:00
|
|
|
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
|
2020-03-27 19:21:27 +01:00
|
|
|
rendering_server = memnew(RenderingServerWrapMT(rendering_server, false));
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
rendering_server->init();
|
2017-08-20 16:17:24 +02:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
input = memnew(InputDefault);
|
|
|
|
|
2017-01-08 21:05:51 +01:00
|
|
|
joypad = ref new JoypadUWP(input);
|
|
|
|
joypad->register_events();
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-09-13 18:34:22 +02:00
|
|
|
AudioDriverManager::initialize(p_audio_driver);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
managed_object->update_clipboard();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
Clipboard::ContentChanged += ref new EventHandler<Platform::Object ^>(managed_object, &ManagedType::on_clipboard_changed);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
accelerometer = Accelerometer::GetDefault();
|
|
|
|
if (accelerometer != nullptr) {
|
|
|
|
// 60 FPS
|
|
|
|
accelerometer->ReportInterval = (1.0f / 60.0f) * 1000;
|
|
|
|
accelerometer->ReadingChanged +=
|
|
|
|
ref new TypedEventHandler<Accelerometer ^, AccelerometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_accelerometer_reading_changed);
|
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
magnetometer = Magnetometer::GetDefault();
|
|
|
|
if (magnetometer != nullptr) {
|
|
|
|
// 60 FPS
|
|
|
|
magnetometer->ReportInterval = (1.0f / 60.0f) * 1000;
|
|
|
|
magnetometer->ReadingChanged +=
|
|
|
|
ref new TypedEventHandler<Magnetometer ^, MagnetometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_magnetometer_reading_changed);
|
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
gyrometer = Gyrometer::GetDefault();
|
|
|
|
if (gyrometer != nullptr) {
|
|
|
|
// 60 FPS
|
|
|
|
gyrometer->ReportInterval = (1.0f / 60.0f) * 1000;
|
|
|
|
gyrometer->ReadingChanged +=
|
|
|
|
ref new TypedEventHandler<Gyrometer ^, GyrometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_gyroscope_reading_changed);
|
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-11-17 15:25:22 +01:00
|
|
|
_ensure_user_data_dir();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-02-16 13:56:32 +01:00
|
|
|
if (is_keep_screen_on()) {
|
2016-09-04 00:25:43 +02:00
|
|
|
display_request->RequestActive();
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-08-06 22:10:24 +02:00
|
|
|
set_keep_screen_on(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));
|
2018-01-03 18:26:44 +01:00
|
|
|
|
|
|
|
return OK;
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_clipboard(const String &p_text) {
|
2016-09-04 00:25:43 +02:00
|
|
|
DataPackage ^ clip = ref new DataPackage();
|
|
|
|
clip->RequestedOperation = DataPackageOperation::Copy;
|
2020-07-27 12:43:20 +02:00
|
|
|
clip->SetText(ref new Platform::String((LPCWSTR)(p_text.utf16().get_data())));
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
Clipboard::SetContent(clip);
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
String OS_UWP::get_clipboard() const {
|
2022-02-16 13:56:32 +01:00
|
|
|
if (managed_object->clipboard != nullptr) {
|
2016-09-04 00:25:43 +02:00
|
|
|
return managed_object->clipboard->Data();
|
2022-02-16 13:56:32 +01:00
|
|
|
} else {
|
2016-09-04 00:25:43 +02:00
|
|
|
return "";
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::input_event(const Ref<InputEvent> &p_event) {
|
2014-12-15 19:42:58 +01:00
|
|
|
input->parse_input_event(p_event);
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-12-15 19:42:58 +01:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::delete_main_loop() {
|
2022-02-16 13:56:32 +01:00
|
|
|
if (main_loop) {
|
2014-09-15 16:33:30 +02:00
|
|
|
memdelete(main_loop);
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2020-04-02 01:20:12 +02:00
|
|
|
main_loop = nullptr;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_main_loop(MainLoop *p_main_loop) {
|
2014-09-15 16:33:30 +02:00
|
|
|
input->set_main_loop(p_main_loop);
|
|
|
|
main_loop = p_main_loop;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::finalize() {
|
2022-02-16 13:56:32 +01:00
|
|
|
if (main_loop) {
|
2014-09-15 16:33:30 +02:00
|
|
|
memdelete(main_loop);
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
main_loop = nullptr;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
rendering_server->finish();
|
|
|
|
memdelete(rendering_server);
|
2021-10-26 17:18:39 +02:00
|
|
|
#ifdef GLES3_ENABLED
|
2022-02-16 13:56:32 +01:00
|
|
|
if (gl_context) {
|
2014-09-15 16:33:30 +02:00
|
|
|
memdelete(gl_context);
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
#endif
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
memdelete(input);
|
|
|
|
|
2017-01-08 21:05:51 +01:00
|
|
|
joypad = nullptr;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::finalize_core() {
|
2018-09-13 15:47:00 +02:00
|
|
|
NetSocketPosix::cleanup();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::alert(const String &p_alert, const String &p_title) {
|
2020-07-27 12:43:20 +02:00
|
|
|
Platform::String ^ alert = ref new Platform::String((LPCWSTR)(p_alert.utf16().get_data()));
|
|
|
|
Platform::String ^ title = ref new Platform::String((LPCWSTR)(p_title.utf16().get_data()));
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
MessageDialog ^ msg = ref new MessageDialog(alert, title);
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
UICommand ^ close = ref new UICommand("Close", ref new UICommandInvokedHandler(managed_object, &OS_UWP::ManagedType::alert_close));
|
2016-09-04 00:25:43 +02:00
|
|
|
msg->Commands->Append(close);
|
|
|
|
msg->DefaultCommandIndex = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
managed_object->alert_close_handle = true;
|
|
|
|
|
|
|
|
msg->ShowAsync();
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::ManagedType::alert_close(IUICommand ^ command) {
|
2016-09-04 00:25:43 +02:00
|
|
|
alert_close_handle = false;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) {
|
2016-09-04 00:25:43 +02:00
|
|
|
update_clipboard();
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::ManagedType::update_clipboard() {
|
2016-09-04 00:25:43 +02:00
|
|
|
DataPackageView ^ data = Clipboard::GetContent();
|
|
|
|
|
|
|
|
if (data->Contains(StandardDataFormats::Text)) {
|
|
|
|
create_task(data->GetTextAsync()).then([this](Platform::String ^ clipboard_content) {
|
|
|
|
this->clipboard = clipboard_content;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
AccelerometerReading ^ reading = args->Reading;
|
|
|
|
|
|
|
|
os->input->set_accelerometer(Vector3(
|
2021-03-16 21:08:55 +01:00
|
|
|
reading->AccelerationX * earth_gravity,
|
|
|
|
reading->AccelerationY * earth_gravity,
|
|
|
|
reading->AccelerationZ * earth_gravity));
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
MagnetometerReading ^ reading = args->Reading;
|
|
|
|
|
|
|
|
os->input->set_magnetometer(Vector3(
|
|
|
|
reading->MagneticFieldX,
|
|
|
|
reading->MagneticFieldY,
|
|
|
|
reading->MagneticFieldZ));
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
GyrometerReading ^ reading = args->Reading;
|
|
|
|
|
|
|
|
os->input->set_magnetometer(Vector3(
|
|
|
|
reading->AngularVelocityX,
|
|
|
|
reading->AngularVelocityY,
|
|
|
|
reading->AngularVelocityZ));
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_mouse_mode(MouseMode p_mode) {
|
2016-09-04 00:25:43 +02:00
|
|
|
if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) {
|
|
|
|
CoreWindow::GetForCurrentThread()->SetPointerCapture();
|
|
|
|
} else {
|
|
|
|
CoreWindow::GetForCurrentThread()->ReleasePointerCapture();
|
|
|
|
}
|
|
|
|
|
2021-03-31 00:35:08 +02:00
|
|
|
if (p_mode == MouseMode::MOUSE_MODE_HIDDEN || p_mode == MouseMode::MOUSE_MODE_CAPTURED || p_mode == MouseMode::MOUSE_MODE_CONFINED_HIDDEN) {
|
2016-09-04 00:25:43 +02:00
|
|
|
CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
|
|
|
|
} else {
|
|
|
|
CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
mouse_mode = p_mode;
|
|
|
|
|
|
|
|
SetEvent(mouse_mode_changed);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
OS_UWP::MouseMode OS_UWP::get_mouse_mode() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
return mouse_mode;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
Point2 OS_UWP::get_mouse_position() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
return Point2(old_x, old_y);
|
|
|
|
}
|
|
|
|
|
2021-03-25 21:56:12 +01:00
|
|
|
MouseButton OS_UWP::get_mouse_button_state() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
return last_button_state;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_window_title(const String &p_title) {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
|
2014-12-15 19:42:58 +01:00
|
|
|
video_mode = p_video_mode;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
OS::VideoMode OS_UWP::get_video_mode(int p_screen) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
return video_mode;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 19:36:24 +02:00
|
|
|
String OS_UWP::get_name() const {
|
2016-11-02 22:22:49 +01:00
|
|
|
return "UWP";
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2022-09-16 11:14:14 +02:00
|
|
|
String OS_UWP::get_distribution_name() const {
|
|
|
|
return get_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_UWP::get_version() const {
|
|
|
|
winrt::hstring df_version = VersionInfo().DeviceFamilyVersion();
|
2023-05-27 18:21:23 +02:00
|
|
|
return String(winrt::to_string(df_version).c_str());
|
2022-09-16 11:14:14 +02:00
|
|
|
}
|
|
|
|
|
2022-09-08 07:36:10 +02:00
|
|
|
OS::DateTime OS_UWP::get_datetime(bool p_utc) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
SYSTEMTIME systemtime;
|
2022-01-06 19:49:41 +01:00
|
|
|
if (p_utc) {
|
2015-06-07 15:06:13 +02:00
|
|
|
GetSystemTime(&systemtime);
|
2021-10-28 17:16:47 +02:00
|
|
|
} else {
|
2015-06-07 15:06:13 +02:00
|
|
|
GetLocalTime(&systemtime);
|
2021-10-28 17:16:47 +02:00
|
|
|
}
|
2015-06-07 15:06:13 +02:00
|
|
|
|
2022-09-08 07:36:10 +02:00
|
|
|
//Get DST information from Windows, but only if p_utc is false.
|
|
|
|
TIME_ZONE_INFORMATION info;
|
|
|
|
bool daylight = false;
|
|
|
|
if (!p_utc && GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) {
|
|
|
|
daylight = true;
|
2022-01-06 19:49:41 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-09-08 07:36:10 +02:00
|
|
|
DateTime dt;
|
|
|
|
dt.year = systemtime.wYear;
|
|
|
|
dt.month = Month(systemtime.wMonth);
|
|
|
|
dt.day = systemtime.wDay;
|
|
|
|
dt.weekday = Weekday(systemtime.wDayOfWeek);
|
|
|
|
dt.hour = systemtime.wHour;
|
|
|
|
dt.minute = systemtime.wMinute;
|
|
|
|
dt.second = systemtime.wSecond;
|
|
|
|
dt.dst = daylight;
|
|
|
|
return dt;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
OS::TimeZoneInfo OS_UWP::get_time_zone_info() const {
|
2015-06-06 05:35:38 +02:00
|
|
|
TIME_ZONE_INFORMATION info;
|
|
|
|
bool daylight = false;
|
2022-02-16 13:56:32 +01:00
|
|
|
if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) {
|
2015-06-06 05:35:38 +02:00
|
|
|
daylight = true;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2015-06-06 05:35:38 +02:00
|
|
|
|
2015-06-07 16:10:33 +02:00
|
|
|
TimeZoneInfo ret;
|
2015-06-06 05:35:38 +02:00
|
|
|
if (daylight) {
|
|
|
|
ret.name = info.DaylightName;
|
|
|
|
} else {
|
|
|
|
ret.name = info.StandardName;
|
|
|
|
}
|
|
|
|
|
2019-02-13 01:41:19 +01:00
|
|
|
// Bias value returned by GetTimeZoneInformation is inverted of what we expect
|
|
|
|
// For example on GMT-3 GetTimeZoneInformation return a Bias of 180, so invert the value to get -180
|
|
|
|
ret.bias = -info.Bias;
|
2015-06-06 05:35:38 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
uint64_t OS_UWP::get_unix_time() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
FILETIME ft;
|
|
|
|
SYSTEMTIME st;
|
2016-09-04 00:25:43 +02:00
|
|
|
GetSystemTime(&st);
|
2014-09-15 16:33:30 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::delay_usec(uint32_t p_usec) const {
|
2014-10-03 05:10:51 +02:00
|
|
|
int msec = p_usec < 1000 ? 1 : p_usec / 1000;
|
|
|
|
|
|
|
|
// no Sleep()
|
|
|
|
WaitForSingleObjectEx(GetCurrentThread(), msec, false);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
uint64_t OS_UWP::get_ticks_usec() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
uint64_t ticks;
|
2020-05-22 13:20:19 +02:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
// This is the number of clock ticks since start
|
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
|
2022-01-08 13:10:27 +01:00
|
|
|
// Subtract the ticks at game start to get
|
|
|
|
// the ticks since the game started
|
|
|
|
ticks -= ticks_start;
|
2020-05-22 13:20:19 +02:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
// Divide by frequency to get the time in seconds
|
2020-05-22 13:20:19 +02:00
|
|
|
// original calculation shown below is subject to overflow
|
|
|
|
// with high ticks_per_second and a number of days since the last reboot.
|
|
|
|
// time = ticks * 1000000L / ticks_per_second;
|
|
|
|
|
|
|
|
// we can prevent this by either using 128 bit math
|
|
|
|
// or separating into a calculation for seconds, and the fraction
|
|
|
|
uint64_t seconds = ticks / ticks_per_second;
|
|
|
|
|
|
|
|
// compiler will optimize these two into one divide
|
|
|
|
uint64_t leftover = ticks % ticks_per_second;
|
|
|
|
|
|
|
|
// remainder
|
|
|
|
uint64_t time = (leftover * 1000000L) / ticks_per_second;
|
|
|
|
|
|
|
|
// seconds
|
|
|
|
time += seconds * 1000000L;
|
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::process_events() {
|
2017-03-26 15:59:13 +02:00
|
|
|
joypad->process_controllers();
|
2016-09-04 00:25:43 +02:00
|
|
|
process_key_events();
|
2022-07-23 12:02:07 +02:00
|
|
|
input->flush_buffered_events();
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::process_key_events() {
|
2016-09-04 00:25:43 +02:00
|
|
|
for (int i = 0; i < key_event_pos; i++) {
|
|
|
|
KeyEvent &kev = key_event_buffer[i];
|
|
|
|
|
2017-05-23 18:50:21 +02:00
|
|
|
Ref<InputEventKey> key_event;
|
2021-06-18 00:03:09 +02:00
|
|
|
key_event.instantiate();
|
2021-04-24 22:33:50 +02:00
|
|
|
key_event->set_alt_pressed(kev.alt);
|
|
|
|
key_event->set_shift_pressed(kev.shift);
|
|
|
|
key_event->set_ctrl_pressed(kev.control);
|
2017-05-23 18:50:21 +02:00
|
|
|
key_event->set_echo(kev.echo);
|
2018-04-05 19:59:35 +02:00
|
|
|
key_event->set_keycode(kev.keycode);
|
2021-06-20 19:12:33 +02:00
|
|
|
key_event->set_physical_keycode((Key)kev.physical_keycode);
|
2017-05-23 18:50:21 +02:00
|
|
|
key_event->set_unicode(kev.unicode);
|
|
|
|
key_event->set_pressed(kev.pressed);
|
|
|
|
|
|
|
|
input_event(key_event);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
key_event_pos = 0;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::queue_key_event(KeyEvent &p_event) {
|
2016-09-04 00:25:43 +02:00
|
|
|
// This merges Char events with the previous Key event, so
|
|
|
|
// the unicode can be retrieved without sending duplicate events.
|
|
|
|
if (p_event.type == KeyEvent::MessageType::CHAR_EVENT_MESSAGE && key_event_pos > 0) {
|
|
|
|
KeyEvent &old = key_event_buffer[key_event_pos - 1];
|
|
|
|
ERR_FAIL_COND(old.type != KeyEvent::MessageType::KEY_EVENT_MESSAGE);
|
|
|
|
|
|
|
|
key_event_buffer[key_event_pos - 1].unicode = p_event.unicode;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND(key_event_pos >= KEY_EVENT_BUFFER_SIZE);
|
|
|
|
|
|
|
|
key_event_buffer[key_event_pos++] = p_event;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_cursor_shape(CursorShape p_shape) {
|
2016-09-04 00:25:43 +02:00
|
|
|
ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
|
|
|
|
|
2022-02-16 13:56:32 +01:00
|
|
|
if (cursor_shape == p_shape) {
|
2016-09-04 00:25:43 +02:00
|
|
|
return;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
static const CoreCursorType uwp_cursors[CURSOR_MAX] = {
|
|
|
|
CoreCursorType::Arrow,
|
|
|
|
CoreCursorType::IBeam,
|
|
|
|
CoreCursorType::Hand,
|
|
|
|
CoreCursorType::Cross,
|
|
|
|
CoreCursorType::Wait,
|
|
|
|
CoreCursorType::Wait,
|
|
|
|
CoreCursorType::Arrow,
|
|
|
|
CoreCursorType::Arrow,
|
|
|
|
CoreCursorType::UniversalNo,
|
|
|
|
CoreCursorType::SizeNorthSouth,
|
|
|
|
CoreCursorType::SizeWestEast,
|
|
|
|
CoreCursorType::SizeNortheastSouthwest,
|
|
|
|
CoreCursorType::SizeNorthwestSoutheast,
|
|
|
|
CoreCursorType::SizeAll,
|
|
|
|
CoreCursorType::SizeNorthSouth,
|
|
|
|
CoreCursorType::SizeWestEast,
|
|
|
|
CoreCursorType::Help
|
|
|
|
};
|
|
|
|
|
|
|
|
CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(uwp_cursors[p_shape], 0);
|
|
|
|
|
|
|
|
cursor_shape = p_shape;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-04-15 17:30:20 +02:00
|
|
|
OS::CursorShape OS_UWP::get_cursor_shape() const {
|
|
|
|
return cursor_shape;
|
|
|
|
}
|
|
|
|
|
2022-05-03 01:43:50 +02:00
|
|
|
void OS_UWP::set_custom_mouse_cursor(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
|
2017-11-10 11:50:11 +01:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2021-12-16 14:00:55 +01:00
|
|
|
Error OS_UWP::execute(const String &p_path, const List<String> &p_arguments, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex, bool p_open_console) {
|
2020-12-18 19:49:13 +01:00
|
|
|
return FAILED;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2020-12-18 19:49:13 +01:00
|
|
|
|
2021-12-16 14:00:55 +01:00
|
|
|
Error OS_UWP::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id, bool p_open_console) {
|
2014-09-15 16:33:30 +02:00
|
|
|
return FAILED;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
Error OS_UWP::kill(const ProcessID &p_pid) {
|
2014-09-15 16:33:30 +02:00
|
|
|
return FAILED;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2021-08-13 05:36:23 +02:00
|
|
|
bool OS_UWP::is_process_running(const ProcessID &p_pid) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
Error OS_UWP::set_cwd(const String &p_cwd) {
|
2014-12-15 19:42:58 +01:00
|
|
|
return FAILED;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
String OS_UWP::get_executable_path() const {
|
2014-10-03 05:10:51 +02:00
|
|
|
return "";
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::set_icon(const Ref<Image> &p_icon) {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
bool OS_UWP::has_environment(const String &p_var) const {
|
2014-10-03 05:10:51 +02:00
|
|
|
return false;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
String OS_UWP::get_environment(const String &p_var) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
return "";
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
bool OS_UWP::set_environment(const String &p_var, const String &p_value) const {
|
2019-01-29 22:59:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-29 21:06:11 +01:00
|
|
|
String OS_UWP::get_stdin_string() {
|
2014-09-15 16:33:30 +02:00
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::move_window_to_foreground() {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
Error OS_UWP::shell_open(String p_uri) {
|
2014-09-15 16:33:30 +02:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
String OS_UWP::get_locale() const {
|
2014-12-20 19:30:06 +01:00
|
|
|
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // this should work on phone 8.1, but it doesn't
|
|
|
|
return "en";
|
|
|
|
#else
|
2014-09-15 16:33:30 +02:00
|
|
|
Platform::String ^ language = Windows::Globalization::Language::CurrentInputMethodLanguageTag;
|
2016-09-04 00:25:43 +02:00
|
|
|
return String(language->Data()).replace("-", "_");
|
2014-12-20 19:30:06 +01:00
|
|
|
#endif
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::release_rendering_thread() {
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context->release_current();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::make_rendering_thread() {
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context->make_current();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::swap_buffers() {
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context->swap_buffers();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
bool OS_UWP::has_touchscreen_ui_hint() const {
|
2016-09-04 00:25:43 +02:00
|
|
|
TouchCapabilities ^ tc = ref new TouchCapabilities();
|
|
|
|
return tc->TouchPresent != 0 || UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
bool OS_UWP::has_virtual_keyboard() const {
|
2016-09-04 00:25:43 +02:00
|
|
|
return UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch;
|
|
|
|
}
|
|
|
|
|
2022-07-07 20:20:10 +02:00
|
|
|
void OS_UWP::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
2016-09-04 00:25:43 +02:00
|
|
|
InputPane ^ pane = InputPane::GetForCurrentView();
|
|
|
|
pane->TryShow();
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::hide_virtual_keyboard() {
|
2016-09-04 00:25:43 +02:00
|
|
|
InputPane ^ pane = InputPane::GetForCurrentView();
|
|
|
|
pane->TryHide();
|
|
|
|
}
|
|
|
|
|
2018-01-01 16:59:13 +01:00
|
|
|
static String format_error_message(DWORD id) {
|
2020-04-02 01:20:12 +02:00
|
|
|
LPWSTR messageBuffer = nullptr;
|
2018-01-01 16:59:13 +01:00
|
|
|
size_t size = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
2020-04-02 01:20:12 +02:00
|
|
|
nullptr, id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, nullptr);
|
2018-01-01 16:59:13 +01:00
|
|
|
|
|
|
|
String msg = "Error " + itos(id) + ": " + String(messageBuffer, size);
|
|
|
|
|
|
|
|
LocalFree(messageBuffer);
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2022-04-29 00:51:04 +02:00
|
|
|
Error OS_UWP::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) {
|
2018-01-01 16:59:13 +01:00
|
|
|
String full_path = "game/" + p_path;
|
2020-07-27 12:43:20 +02:00
|
|
|
p_library_handle = (void *)LoadPackagedLibrary((LPCWSTR)(full_path.utf16().get_data()), 0);
|
2019-08-09 06:49:33 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + full_path + ", error: " + format_error_message(GetLastError()) + ".");
|
2022-04-29 00:51:04 +02:00
|
|
|
|
|
|
|
if (r_resolved_path != nullptr) {
|
|
|
|
*r_resolved_path = full_path;
|
|
|
|
}
|
|
|
|
|
2018-01-01 16:59:13 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
Error OS_UWP::close_dynamic_library(void *p_library_handle) {
|
2018-01-01 16:59:13 +01:00
|
|
|
if (!FreeLibrary((HMODULE)p_library_handle)) {
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
Error OS_UWP::get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional) {
|
2018-01-01 16:59:13 +01:00
|
|
|
p_symbol_handle = (void *)GetProcAddress((HMODULE)p_library_handle, p_name.utf8().get_data());
|
|
|
|
if (!p_symbol_handle) {
|
|
|
|
if (!p_optional) {
|
2019-08-09 06:49:33 +02:00
|
|
|
ERR_FAIL_V_MSG(ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ", error: " + String::num(GetLastError()) + ".");
|
2018-01-01 16:59:13 +01:00
|
|
|
} else {
|
|
|
|
return ERR_CANT_RESOLVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
void OS_UWP::run() {
|
2022-02-16 13:56:32 +01:00
|
|
|
if (!main_loop) {
|
2014-09-15 16:33:30 +02:00
|
|
|
return;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
main_loop->init();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
uint64_t last_ticks = get_ticks_usec();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
int frames = 0;
|
|
|
|
uint64_t frame = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-08-16 20:29:55 +02:00
|
|
|
while (true) {
|
2014-10-03 05:10:51 +02:00
|
|
|
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
|
2022-02-16 13:56:32 +01:00
|
|
|
if (managed_object->alert_close_handle) {
|
2016-09-04 00:25:43 +02:00
|
|
|
continue;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
process_events(); // get rid of pending events
|
2022-02-16 13:56:32 +01:00
|
|
|
if (Main::iteration()) {
|
2014-09-15 16:33:30 +02:00
|
|
|
break;
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
main_loop->finish();
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
MainLoop *OS_UWP::get_main_loop() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
return main_loop;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
String OS_UWP::get_user_data_dir() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
Windows::Storage::StorageFolder ^ data_folder = Windows::Storage::ApplicationData::Current->LocalFolder;
|
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
return String(data_folder->Path->Data()).replace("\\", "/");
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
bool OS_UWP::_check_internal_feature_support(const String &p_feature) {
|
2019-02-26 15:58:47 +01:00
|
|
|
return p_feature == "pc";
|
2017-04-29 16:48:23 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
OS_UWP::OS_UWP() {
|
2014-09-15 16:33:30 +02:00
|
|
|
key_event_pos = 0;
|
|
|
|
alt_mem = false;
|
|
|
|
gr_mem = false;
|
|
|
|
shift_mem = false;
|
|
|
|
control_mem = false;
|
|
|
|
meta_mem = false;
|
|
|
|
minimized = false;
|
|
|
|
|
|
|
|
pressrc = 0;
|
|
|
|
old_invalid = true;
|
|
|
|
mouse_mode = MOUSE_MODE_VISIBLE;
|
2020-04-02 01:20:12 +02:00
|
|
|
gl_context = nullptr;
|
2014-10-03 05:10:51 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
display_request = ref new Windows::System::Display::DisplayRequest();
|
|
|
|
|
|
|
|
managed_object = ref new ManagedType;
|
|
|
|
managed_object->os = this;
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
mouse_mode_changed = CreateEvent(nullptr, TRUE, FALSE, L"os_mouse_mode_changed");
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
AudioDriverManager::add_driver(&audio_driver);
|
2017-09-22 07:56:02 +02:00
|
|
|
|
2017-11-21 10:35:01 +01:00
|
|
|
Vector<Logger *> loggers;
|
|
|
|
loggers.push_back(memnew(WindowsTerminalLogger));
|
|
|
|
_set_logger(memnew(CompositeLogger(loggers)));
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
OS_UWP::~OS_UWP() {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|