2014-09-15 16:33:30 +02:00
|
|
|
/*************************************************************************/
|
2016-11-02 21:26:42 +01:00
|
|
|
/* os_uwp.cpp */
|
2014-09-15 16:33:30 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-09-15 16:33:30 +02: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. */
|
|
|
|
/*************************************************************************/
|
2016-11-02 21:26:42 +01:00
|
|
|
#include "os_uwp.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "drivers/gles2/rasterizer_gles2.h"
|
|
|
|
#include "drivers/windows/dir_access_windows.h"
|
|
|
|
#include "drivers/windows/file_access_windows.h"
|
2014-09-15 16:33:30 +02:00
|
|
|
#include "drivers/windows/mutex_windows.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "drivers/windows/semaphore_windows.h"
|
2014-09-15 16:33:30 +02:00
|
|
|
#include "main/main.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "os/memory_pool_dynamic_static.h"
|
2017-01-16 19:19:45 +01:00
|
|
|
#include "servers/audio_server.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "servers/visual/visual_server_raster.h"
|
|
|
|
#include "thread_uwp.h"
|
2017-01-16 19:19:45 +01:00
|
|
|
//#include "servers/visual/visual_server_wrap_mt.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "drivers/unix/ip_unix.h"
|
2017-02-21 04:05:15 +01:00
|
|
|
#include "global_config.h"
|
2014-09-15 16:33:30 +02:00
|
|
|
#include "io/marshalls.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "os/memory_pool_dynamic_prealloc.h"
|
2016-09-04 00:25:43 +02:00
|
|
|
#include "platform/windows/packet_peer_udp_winsock.h"
|
|
|
|
#include "platform/windows/stream_peer_winsock.h"
|
|
|
|
#include "platform/windows/tcp_server_winsock.h"
|
|
|
|
|
|
|
|
#include <ppltasks.h>
|
2017-03-05 16:44:50 +01:00
|
|
|
#include <wrl.h>
|
2014-10-03 05:10:51 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
int OSUWP::get_video_driver_count() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2015-02-18 23:39:44 +01:00
|
|
|
return 1;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *OSUWP::get_video_driver_name(int p_driver) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2015-02-18 23:39:44 +01:00
|
|
|
return "GLES2";
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
OS::VideoMode OSUWP::get_default_video_mode() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-12-15 19:42:58 +01:00
|
|
|
return video_mode;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
Size2 OSUWP::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;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::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;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ApplicationView ^ view = ApplicationView::GetForCurrentView();
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
if (view->TryResizeView(new_size)) {
|
|
|
|
|
|
|
|
video_mode.width = p_size.width;
|
|
|
|
video_mode.height = p_size.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::set_window_fullscreen(bool p_enabled) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ApplicationView ^ view = ApplicationView::GetForCurrentView();
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
video_mode.fullscreen = view->IsFullScreenMode;
|
|
|
|
|
|
|
|
if (video_mode.fullscreen == p_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (p_enabled) {
|
|
|
|
|
|
|
|
video_mode.fullscreen = view->TryEnterFullScreenMode();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
view->ExitFullScreenMode();
|
|
|
|
video_mode.fullscreen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
bool OSUWP::is_window_fullscreen() const {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
return ApplicationView::GetForCurrentView()->IsFullScreenMode;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::set_keep_screen_on(bool p_enabled) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
if (is_keep_screen_on() == p_enabled) return;
|
|
|
|
|
|
|
|
if (p_enabled)
|
|
|
|
display_request->RequestActive();
|
|
|
|
else
|
|
|
|
display_request->RequestRelease();
|
|
|
|
|
|
|
|
OS::set_keep_screen_on(p_enabled);
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
int OSUWP::get_audio_driver_count() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
return AudioDriverManager::get_driver_count();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-01-16 19:19:45 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *OSUWP::get_audio_driver_name(int p_driver) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
|
|
|
|
ERR_FAIL_COND_V(!driver, "");
|
2017-01-15 20:06:14 +01:00
|
|
|
return AudioDriverManager::get_driver(p_driver)->get_name();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static MemoryPoolStatic *mempool_static = NULL;
|
|
|
|
static MemoryPoolDynamic *mempool_dynamic = NULL;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::initialize_core() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
last_button_state = 0;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
//RedirectIOToConsole();
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
ThreadUWP::make_default();
|
2016-09-04 00:25:43 +02:00
|
|
|
SemaphoreWindows::make_default();
|
2016-03-09 00:00:52 +01:00
|
|
|
MutexWindows::make_default();
|
2014-09-15 16:33:30 +02: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();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
TCPServerWinsock::make_default();
|
|
|
|
StreamPeerWinsock::make_default();
|
|
|
|
PacketPeerUDPWinsock::make_default();
|
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
mempool_static = new MemoryPoolStaticMalloc;
|
|
|
|
#if 1
|
2017-03-05 16:44:50 +01:00
|
|
|
mempool_dynamic = memnew(MemoryPoolDynamicStatic);
|
2014-09-15 16:33:30 +02:00
|
|
|
#else
|
2017-03-05 16:44:50 +01:00
|
|
|
#define DYNPOOL_SIZE 4 * 1024 * 1024
|
|
|
|
void *buffer = malloc(DYNPOOL_SIZE);
|
|
|
|
mempool_dynamic = memnew(MemoryPoolDynamicPrealloc(buffer, DYNPOOL_SIZE));
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
#endif
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
// We need to know how often the clock is updated
|
|
|
|
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second))
|
2014-09-15 16:33:30 +02: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();
|
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
IP_Unix::make_default();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor_shape = CURSOR_ARROW;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
bool OSUWP::can_draw() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return !minimized;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::set_gl_context(ContextEGL *p_context) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context = p_context;
|
2014-09-15 16:33:30 +02:00
|
|
|
};
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::screen_size_changed() {
|
2014-12-20 19:30:06 +01:00
|
|
|
|
|
|
|
gl_context->reset();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
main_loop = NULL;
|
|
|
|
outside = true;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context->initialize();
|
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;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ApplicationView ^ view = ApplicationView::GetForCurrentView();
|
2016-09-04 00:25:43 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
gl_context->make_current();
|
2017-03-05 16:44:50 +01:00
|
|
|
rasterizer = memnew(RasterizerGLES2);
|
2014-10-03 05:10:51 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
visual_server = memnew(VisualServerRaster(rasterizer));
|
|
|
|
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2017-03-05 16:44:50 +01:00
|
|
|
physics_server = memnew(PhysicsServerSW);
|
2014-09-15 16:33:30 +02:00
|
|
|
physics_server->init();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
physics_2d_server = memnew(Physics2DServerSW);
|
2014-09-15 16:33:30 +02:00
|
|
|
physics_2d_server->init();
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
visual_server->init();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
input = memnew(InputDefault);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
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-01-15 20:06:14 +01:00
|
|
|
AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
ERR_PRINT("Initializing audio failed.");
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
power_manager = memnew(PowerWinRT);
|
2016-07-23 13:15:55 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
managed_object->update_clipboard();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01: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 +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<Accelerometer ^, AccelerometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_accelerometer_reading_changed);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
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 +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<Magnetometer ^, MagnetometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_magnetometer_reading_changed);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
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 +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<Gyrometer ^, GyrometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_gyroscope_reading_changed);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
_ensure_data_dir();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
if (is_keep_screen_on())
|
|
|
|
display_request->RequestActive();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
set_keep_screen_on(GLOBAL_DEF("display/keep_screen_on", true));
|
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::set_clipboard(const String &p_text) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
DataPackage ^ clip = ref new DataPackage();
|
2016-09-04 00:25:43 +02:00
|
|
|
clip->RequestedOperation = DataPackageOperation::Copy;
|
2017-03-05 16:44:50 +01:00
|
|
|
clip->SetText(ref new Platform::String((const wchar_t *)p_text.c_str()));
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
Clipboard::SetContent(clip);
|
|
|
|
};
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
String OSUWP::get_clipboard() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
if (managed_object->clipboard != nullptr)
|
|
|
|
return managed_object->clipboard->Data();
|
|
|
|
else
|
|
|
|
return "";
|
2014-09-15 16:33:30 +02:00
|
|
|
};
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::input_event(InputEvent &p_event) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2014-12-15 19:42:58 +01:00
|
|
|
input->parse_input_event(p_event);
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index > 3) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
//send release for mouse wheel
|
|
|
|
p_event.mouse_button.pressed = false;
|
|
|
|
input->parse_input_event(p_event);
|
|
|
|
}
|
2014-12-15 19:42:58 +01:00
|
|
|
};
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::delete_main_loop() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (main_loop)
|
|
|
|
memdelete(main_loop);
|
2017-03-05 16:44:50 +01:00
|
|
|
main_loop = NULL;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::set_main_loop(MainLoop *p_main_loop) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
input->set_main_loop(p_main_loop);
|
2017-03-05 16:44:50 +01:00
|
|
|
main_loop = p_main_loop;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::finalize() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (main_loop)
|
2014-09-15 16:33:30 +02:00
|
|
|
memdelete(main_loop);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
main_loop = NULL;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
visual_server->finish();
|
|
|
|
memdelete(visual_server);
|
|
|
|
#ifdef OPENGL_ENABLED
|
|
|
|
if (gl_context)
|
|
|
|
memdelete(gl_context);
|
|
|
|
#endif
|
|
|
|
if (rasterizer)
|
|
|
|
memdelete(rasterizer);
|
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
/*
|
|
|
|
if (debugger_connection_console) {
|
|
|
|
memdelete(debugger_connection_console);
|
|
|
|
}
|
|
|
|
*/
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
memdelete(input);
|
|
|
|
|
|
|
|
physics_server->finish();
|
|
|
|
memdelete(physics_server);
|
|
|
|
|
|
|
|
physics_2d_server->finish();
|
|
|
|
memdelete(physics_2d_server);
|
|
|
|
|
2017-01-08 21:05:51 +01:00
|
|
|
joypad = nullptr;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::finalize_core() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (mempool_dynamic)
|
2017-03-05 16:44:50 +01:00
|
|
|
memdelete(mempool_dynamic);
|
2016-01-04 11:46:16 +01:00
|
|
|
delete mempool_static;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::vprint(const char *p_format, va_list p_list, bool p_stderr) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
char buf[16384 + 1];
|
|
|
|
int len = vsnprintf(buf, 16384, p_format, p_list);
|
|
|
|
if (len <= 0)
|
2014-09-15 16:33:30 +02:00
|
|
|
return;
|
2017-03-05 16:44:50 +01:00
|
|
|
buf[len] = 0;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int wlen = MultiByteToWideChar(CP_UTF8, 0, buf, len, NULL, 0);
|
|
|
|
if (wlen < 0)
|
2014-09-15 16:33:30 +02:00
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
wchar_t *wbuf = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, buf, len, wbuf, wlen);
|
|
|
|
wbuf[wlen] = 0;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (p_stderr)
|
2017-03-05 16:44:50 +01:00
|
|
|
fwprintf(stderr, L"%s", wbuf);
|
2014-09-15 16:33:30 +02:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
wprintf(L"%s", wbuf);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
free(wbuf);
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::alert(const String &p_alert, const String &p_title) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Platform::String ^ alert = ref new Platform::String(p_alert.c_str());
|
|
|
|
Platform::String ^ title = ref new Platform::String(p_title.c_str());
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MessageDialog ^ msg = ref new MessageDialog(alert, title);
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
UICommand ^ close = ref new UICommand("Close", ref new UICommandInvokedHandler(managed_object, &OSUWP::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();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::ManagedType::alert_close(IUICommand ^ command) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
alert_close_handle = false;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
update_clipboard();
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::ManagedType::update_clipboard() {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
DataPackageView ^ data = Clipboard::GetContent();
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
if (data->Contains(StandardDataFormats::Text)) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
create_task(data->GetTextAsync()).then([this](Platform::String ^ clipboard_content) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
this->clipboard = clipboard_content;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) {
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
AccelerometerReading ^ reading = args->Reading;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
os->input->set_accelerometer(Vector3(
|
2017-03-05 16:44:50 +01:00
|
|
|
reading->AccelerationX,
|
|
|
|
reading->AccelerationY,
|
|
|
|
reading->AccelerationZ));
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MagnetometerReading ^ reading = args->Reading;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
os->input->set_magnetometer(Vector3(
|
2017-03-05 16:44:50 +01:00
|
|
|
reading->MagneticFieldX,
|
|
|
|
reading->MagneticFieldY,
|
|
|
|
reading->MagneticFieldZ));
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GyrometerReading ^ reading = args->Reading;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
os->input->set_magnetometer(Vector3(
|
2017-03-05 16:44:50 +01:00
|
|
|
reading->AngularVelocityX,
|
|
|
|
reading->AngularVelocityY,
|
|
|
|
reading->AngularVelocityZ));
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::set_mouse_mode(MouseMode p_mode) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) {
|
|
|
|
|
|
|
|
CoreWindow::GetForCurrentThread()->SetPointerCapture();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
CoreWindow::GetForCurrentThread()->ReleasePointerCapture();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_mode == MouseMode::MOUSE_MODE_CAPTURED || p_mode == MouseMode::MOUSE_MODE_HIDDEN) {
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
OSUWP::MouseMode OSUWP::get_mouse_mode() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return mouse_mode;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
Point2 OSUWP::get_mouse_pos() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return Point2(old_x, old_y);
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
int OSUWP::get_mouse_button_state() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return last_button_state;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::set_window_title(const String &p_title) {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-12-15 19:42:58 +01:00
|
|
|
video_mode = p_video_mode;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2016-11-02 22:22:49 +01:00
|
|
|
OS::VideoMode OSUWP::get_video_mode(int p_screen) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return video_mode;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *err_details;
|
2015-11-05 20:13:05 +01:00
|
|
|
if (p_rationale && p_rationale[0])
|
2015-11-19 14:23:05 +01:00
|
|
|
err_details = p_rationale;
|
2015-11-05 20:13:05 +01:00
|
|
|
else
|
2015-11-19 14:23:05 +01:00
|
|
|
err_details = p_code;
|
2015-11-05 20:13:05 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_type) {
|
2015-11-05 20:13:05 +01:00
|
|
|
case ERR_ERROR:
|
2015-11-19 14:26:42 +01:00
|
|
|
print("ERROR: %s: %s\n", p_function, err_details);
|
2015-11-19 14:36:31 +01:00
|
|
|
print(" At: %s:%i\n", p_file, p_line);
|
2015-11-05 20:13:05 +01:00
|
|
|
break;
|
|
|
|
case ERR_WARNING:
|
2015-11-19 14:26:42 +01:00
|
|
|
print("WARNING: %s: %s\n", p_function, err_details);
|
2015-11-19 14:36:31 +01:00
|
|
|
print(" At: %s:%i\n", p_file, p_line);
|
2015-11-05 20:13:05 +01:00
|
|
|
break;
|
|
|
|
case ERR_SCRIPT:
|
2015-11-19 15:35:18 +01:00
|
|
|
print("SCRIPT ERROR: %s: %s\n", p_function, err_details);
|
2015-11-19 14:36:31 +01:00
|
|
|
print(" At: %s:%i\n", p_file, p_line);
|
2015-11-05 20:13:05 +01:00
|
|
|
break;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
String OSUWP::get_name() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
return "UWP";
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
OS::Date OSUWP::get_date(bool utc) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
SYSTEMTIME systemtime;
|
2015-06-07 15:06:13 +02:00
|
|
|
if (utc)
|
|
|
|
GetSystemTime(&systemtime);
|
|
|
|
else
|
|
|
|
GetLocalTime(&systemtime);
|
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
Date date;
|
2017-03-05 16:44:50 +01:00
|
|
|
date.day = systemtime.wDay;
|
|
|
|
date.month = Month(systemtime.wMonth);
|
|
|
|
date.weekday = Weekday(systemtime.wDayOfWeek);
|
|
|
|
date.year = systemtime.wYear;
|
|
|
|
date.dst = false;
|
2014-09-15 16:33:30 +02:00
|
|
|
return date;
|
|
|
|
}
|
2016-11-02 22:22:49 +01:00
|
|
|
OS::Time OSUWP::get_time(bool utc) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
SYSTEMTIME systemtime;
|
2015-06-06 03:40:56 +02:00
|
|
|
if (utc)
|
|
|
|
GetSystemTime(&systemtime);
|
|
|
|
else
|
|
|
|
GetLocalTime(&systemtime);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
Time time;
|
2017-03-05 16:44:50 +01:00
|
|
|
time.hour = systemtime.wHour;
|
|
|
|
time.min = systemtime.wMinute;
|
|
|
|
time.sec = systemtime.wSecond;
|
2014-09-15 16:33:30 +02:00
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
OS::TimeZoneInfo OSUWP::get_time_zone_info() const {
|
2015-06-06 05:35:38 +02:00
|
|
|
TIME_ZONE_INFORMATION info;
|
|
|
|
bool daylight = false;
|
2015-06-07 16:10:33 +02:00
|
|
|
if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT)
|
2015-06-06 05:35:38 +02:00
|
|
|
daylight = true;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.bias = info.Bias;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
uint64_t OSUWP::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);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000;
|
2014-09-15 16:33:30 +02:00
|
|
|
};
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::delay_usec(uint32_t p_usec) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
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
|
|
|
}
|
2016-11-02 22:22:49 +01:00
|
|
|
uint64_t OSUWP::get_ticks_usec() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
uint64_t ticks;
|
|
|
|
uint64_t time;
|
|
|
|
// This is the number of clock ticks since start
|
|
|
|
QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::process_events() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-26 15:59:13 +02:00
|
|
|
joypad->process_controllers();
|
2016-09-04 00:25:43 +02:00
|
|
|
process_key_events();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::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];
|
|
|
|
InputEvent iev;
|
|
|
|
|
|
|
|
iev.type = InputEvent::KEY;
|
|
|
|
iev.key.mod = kev.mod_state;
|
|
|
|
iev.key.echo = kev.echo;
|
|
|
|
iev.key.scancode = kev.scancode;
|
|
|
|
iev.key.unicode = kev.unicode;
|
|
|
|
iev.key.pressed = kev.pressed;
|
|
|
|
|
|
|
|
input_event(iev);
|
|
|
|
}
|
|
|
|
key_event_pos = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::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
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::set_cursor_shape(CursorShape p_shape) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
|
|
|
|
|
|
|
|
if (cursor_shape == p_shape)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error OSUWP::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return FAILED;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error OSUWP::kill(const ProcessID &p_pid) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return FAILED;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error OSUWP::set_cwd(const String &p_cwd) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-12-15 19:42:58 +01:00
|
|
|
return FAILED;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
String OSUWP::get_executable_path() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
return "";
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::set_icon(const Image &p_icon) {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool OSUWP::has_environment(const String &p_var) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
return false;
|
2014-09-15 16:33:30 +02:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String OSUWP::get_environment(const String &p_var) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return "";
|
|
|
|
};
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
String OSUWP::get_stdin_string(bool p_block) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::move_window_to_foreground() {
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
Error OSUWP::shell_open(String p_uri) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
String OSUWP::get_locale() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
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
|
2017-03-05 16:44:50 +01: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
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::release_rendering_thread() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context->release_current();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::make_rendering_thread() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context->make_current();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::swap_buffers() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context->swap_buffers();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
bool OSUWP::has_touchscreen_ui_hint() const {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
TouchCapabilities ^ tc = ref new TouchCapabilities();
|
2016-09-04 00:25:43 +02:00
|
|
|
return tc->TouchPresent != 0 || UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
bool OSUWP::has_virtual_keyboard() const {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
return UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void OSUWP::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
InputPane ^ pane = InputPane::GetForCurrentView();
|
2016-09-04 00:25:43 +02:00
|
|
|
pane->TryShow();
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::hide_virtual_keyboard() {
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
InputPane ^ pane = InputPane::GetForCurrentView();
|
2016-09-04 00:25:43 +02:00
|
|
|
pane->TryHide();
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
void OSUWP::run() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (!main_loop)
|
|
|
|
return;
|
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
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint64_t last_ticks = get_ticks_usec();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int frames = 0;
|
|
|
|
uint64_t frame = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
while (!force_quit) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
|
2016-09-04 00:25:43 +02:00
|
|
|
if (managed_object->alert_close_handle) continue;
|
2014-09-15 16:33:30 +02:00
|
|
|
process_events(); // get rid of pending events
|
2017-03-05 16:44:50 +01:00
|
|
|
if (Main::iteration() == true)
|
2014-09-15 16:33:30 +02:00
|
|
|
break;
|
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
main_loop->finish();
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
MainLoop *OSUWP::get_main_loop() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return main_loop;
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
String OSUWP::get_data_dir() const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Windows::Storage::StorageFolder ^ data_folder = Windows::Storage::ApplicationData::Current->LocalFolder;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
return String(data_folder->Path->Data()).replace("\\", "/");
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 13:15:55 +02:00
|
|
|
PowerState OSWinrt::get_power_state() {
|
|
|
|
return power_manager->get_power_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
int OSWinrt::get_power_seconds_left() {
|
|
|
|
return power_manager->get_power_seconds_left();
|
|
|
|
}
|
|
|
|
|
|
|
|
int OSWinrt::get_power_percent_left() {
|
|
|
|
return power_manager->get_power_percent_left();
|
|
|
|
}
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
OSUWP::OSUWP() {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
key_event_pos = 0;
|
|
|
|
force_quit = false;
|
|
|
|
alt_mem = false;
|
|
|
|
gr_mem = false;
|
|
|
|
shift_mem = false;
|
|
|
|
control_mem = false;
|
|
|
|
meta_mem = false;
|
2014-09-15 16:33:30 +02:00
|
|
|
minimized = false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pressrc = 0;
|
|
|
|
old_invalid = true;
|
|
|
|
mouse_mode = MOUSE_MODE_VISIBLE;
|
2014-09-15 16:33:30 +02:00
|
|
|
#ifdef STDOUT_FILE
|
2017-03-05 16:44:50 +01:00
|
|
|
stdo = fopen("stdout.txt", "wb");
|
2014-09-15 16:33:30 +02:00
|
|
|
#endif
|
|
|
|
|
2014-10-03 05:10:51 +02:00
|
|
|
gl_context = NULL;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
mouse_mode_changed = CreateEvent(NULL, TRUE, FALSE, L"os_mouse_mode_changed");
|
|
|
|
|
2017-01-15 20:06:14 +01:00
|
|
|
AudioDriverManager::add_driver(&audio_driver);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
OSUWP::~OSUWP() {
|
2014-09-15 16:33:30 +02:00
|
|
|
#ifdef STDOUT_FILE
|
|
|
|
fclose(stdo);
|
|
|
|
#endif
|
|
|
|
}
|