os_uwp.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. /*************************************************************************/
  2. /* os_uwp.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "os_uwp.h"
  31. #include "drivers/gles3/rasterizer_gles3.h"
  32. #include "drivers/unix/ip_unix.h"
  33. #include "drivers/windows/dir_access_windows.h"
  34. #include "drivers/windows/file_access_windows.h"
  35. #include "drivers/windows/mutex_windows.h"
  36. #include "drivers/windows/rw_lock_windows.h"
  37. #include "drivers/windows/semaphore_windows.h"
  38. #include "io/marshalls.h"
  39. #include "main/main.h"
  40. #include "platform/windows/packet_peer_udp_winsock.h"
  41. #include "platform/windows/stream_peer_winsock.h"
  42. #include "platform/windows/tcp_server_winsock.h"
  43. #include "platform/windows/windows_terminal_logger.h"
  44. #include "project_settings.h"
  45. #include "servers/audio_server.h"
  46. #include "servers/visual/visual_server_raster.h"
  47. #include "thread_uwp.h"
  48. #include <ppltasks.h>
  49. #include <wrl.h>
  50. using namespace Windows::ApplicationModel::Core;
  51. using namespace Windows::ApplicationModel::Activation;
  52. using namespace Windows::UI::Core;
  53. using namespace Windows::UI::Input;
  54. using namespace Windows::UI::Popups;
  55. using namespace Windows::Foundation;
  56. using namespace Windows::Graphics::Display;
  57. using namespace Microsoft::WRL;
  58. using namespace Windows::UI::ViewManagement;
  59. using namespace Windows::Devices::Input;
  60. using namespace Windows::Devices::Sensors;
  61. using namespace Windows::ApplicationModel::DataTransfer;
  62. using namespace concurrency;
  63. int OSUWP::get_video_driver_count() const {
  64. return 1;
  65. }
  66. const char *OSUWP::get_video_driver_name(int p_driver) const {
  67. return "GLES3";
  68. }
  69. Size2 OSUWP::get_window_size() const {
  70. Size2 size;
  71. size.width = video_mode.width;
  72. size.height = video_mode.height;
  73. return size;
  74. }
  75. void OSUWP::set_window_size(const Size2 p_size) {
  76. Windows::Foundation::Size new_size;
  77. new_size.Width = p_size.width;
  78. new_size.Height = p_size.height;
  79. ApplicationView ^ view = ApplicationView::GetForCurrentView();
  80. if (view->TryResizeView(new_size)) {
  81. video_mode.width = p_size.width;
  82. video_mode.height = p_size.height;
  83. }
  84. }
  85. void OSUWP::set_window_fullscreen(bool p_enabled) {
  86. ApplicationView ^ view = ApplicationView::GetForCurrentView();
  87. video_mode.fullscreen = view->IsFullScreenMode;
  88. if (video_mode.fullscreen == p_enabled)
  89. return;
  90. if (p_enabled) {
  91. video_mode.fullscreen = view->TryEnterFullScreenMode();
  92. } else {
  93. view->ExitFullScreenMode();
  94. video_mode.fullscreen = false;
  95. }
  96. }
  97. bool OSUWP::is_window_fullscreen() const {
  98. return ApplicationView::GetForCurrentView()->IsFullScreenMode;
  99. }
  100. void OSUWP::set_keep_screen_on(bool p_enabled) {
  101. if (is_keep_screen_on() == p_enabled) return;
  102. if (p_enabled)
  103. display_request->RequestActive();
  104. else
  105. display_request->RequestRelease();
  106. OS::set_keep_screen_on(p_enabled);
  107. }
  108. int OSUWP::get_audio_driver_count() const {
  109. return AudioDriverManager::get_driver_count();
  110. }
  111. const char *OSUWP::get_audio_driver_name(int p_driver) const {
  112. AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
  113. ERR_FAIL_COND_V(!driver, "");
  114. return AudioDriverManager::get_driver(p_driver)->get_name();
  115. }
  116. void OSUWP::initialize_core() {
  117. last_button_state = 0;
  118. //RedirectIOToConsole();
  119. ThreadUWP::make_default();
  120. SemaphoreWindows::make_default();
  121. MutexWindows::make_default();
  122. RWLockWindows::make_default();
  123. FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
  124. FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
  125. FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_FILESYSTEM);
  126. DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_RESOURCES);
  127. DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_USERDATA);
  128. DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_FILESYSTEM);
  129. TCPServerWinsock::make_default();
  130. StreamPeerWinsock::make_default();
  131. PacketPeerUDPWinsock::make_default();
  132. // We need to know how often the clock is updated
  133. if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second))
  134. ticks_per_second = 1000;
  135. // If timeAtGameStart is 0 then we get the time since
  136. // the start of the computer when we call GetGameTime()
  137. ticks_start = 0;
  138. ticks_start = get_ticks_usec();
  139. IP_Unix::make_default();
  140. cursor_shape = CURSOR_ARROW;
  141. }
  142. void OSUWP::initialize_logger() {
  143. Vector<Logger *> loggers;
  144. loggers.push_back(memnew(WindowsTerminalLogger));
  145. // FIXME: Reenable once we figure out how to get this properly in user://
  146. // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277)
  147. //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
  148. _set_logger(memnew(CompositeLogger(loggers)));
  149. }
  150. bool OSUWP::can_draw() const {
  151. return !minimized;
  152. };
  153. void OSUWP::set_gl_context(ContextEGL *p_context) {
  154. gl_context = p_context;
  155. };
  156. void OSUWP::screen_size_changed() {
  157. gl_context->reset();
  158. };
  159. void OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
  160. main_loop = NULL;
  161. outside = true;
  162. gl_context->initialize();
  163. VideoMode vm;
  164. vm.width = gl_context->get_window_width();
  165. vm.height = gl_context->get_window_height();
  166. vm.resizable = false;
  167. ApplicationView ^ view = ApplicationView::GetForCurrentView();
  168. vm.fullscreen = view->IsFullScreenMode;
  169. view->SetDesiredBoundsMode(ApplicationViewBoundsMode::UseVisible);
  170. view->PreferredLaunchWindowingMode = ApplicationViewWindowingMode::PreferredLaunchViewSize;
  171. if (p_desired.fullscreen != view->IsFullScreenMode) {
  172. if (p_desired.fullscreen) {
  173. vm.fullscreen = view->TryEnterFullScreenMode();
  174. } else {
  175. view->ExitFullScreenMode();
  176. vm.fullscreen = false;
  177. }
  178. }
  179. Windows::Foundation::Size desired;
  180. desired.Width = p_desired.width;
  181. desired.Height = p_desired.height;
  182. view->PreferredLaunchViewSize = desired;
  183. if (view->TryResizeView(desired)) {
  184. vm.width = view->VisibleBounds.Width;
  185. vm.height = view->VisibleBounds.Height;
  186. }
  187. set_video_mode(vm);
  188. gl_context->make_current();
  189. RasterizerGLES3::register_config();
  190. RasterizerGLES3::make_current();
  191. visual_server = memnew(VisualServerRaster);
  192. // FIXME: Reimplement threaded rendering? Or remove?
  193. /*
  194. if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
  195. visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
  196. }
  197. */
  198. visual_server->init();
  199. input = memnew(InputDefault);
  200. joypad = ref new JoypadUWP(input);
  201. joypad->register_events();
  202. AudioDriverManager::initialize(p_audio_driver);
  203. power_manager = memnew(PowerUWP);
  204. managed_object->update_clipboard();
  205. Clipboard::ContentChanged += ref new EventHandler<Platform::Object ^>(managed_object, &ManagedType::on_clipboard_changed);
  206. accelerometer = Accelerometer::GetDefault();
  207. if (accelerometer != nullptr) {
  208. // 60 FPS
  209. accelerometer->ReportInterval = (1.0f / 60.0f) * 1000;
  210. accelerometer->ReadingChanged +=
  211. ref new TypedEventHandler<Accelerometer ^, AccelerometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_accelerometer_reading_changed);
  212. }
  213. magnetometer = Magnetometer::GetDefault();
  214. if (magnetometer != nullptr) {
  215. // 60 FPS
  216. magnetometer->ReportInterval = (1.0f / 60.0f) * 1000;
  217. magnetometer->ReadingChanged +=
  218. ref new TypedEventHandler<Magnetometer ^, MagnetometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_magnetometer_reading_changed);
  219. }
  220. gyrometer = Gyrometer::GetDefault();
  221. if (gyrometer != nullptr) {
  222. // 60 FPS
  223. gyrometer->ReportInterval = (1.0f / 60.0f) * 1000;
  224. gyrometer->ReadingChanged +=
  225. ref new TypedEventHandler<Gyrometer ^, GyrometerReadingChangedEventArgs ^>(managed_object, &ManagedType::on_gyroscope_reading_changed);
  226. }
  227. _ensure_data_dir();
  228. if (is_keep_screen_on())
  229. display_request->RequestActive();
  230. set_keep_screen_on(GLOBAL_DEF("display/window/keep_screen_on", true));
  231. }
  232. void OSUWP::set_clipboard(const String &p_text) {
  233. DataPackage ^ clip = ref new DataPackage();
  234. clip->RequestedOperation = DataPackageOperation::Copy;
  235. clip->SetText(ref new Platform::String((const wchar_t *)p_text.c_str()));
  236. Clipboard::SetContent(clip);
  237. };
  238. String OSUWP::get_clipboard() const {
  239. if (managed_object->clipboard != nullptr)
  240. return managed_object->clipboard->Data();
  241. else
  242. return "";
  243. };
  244. void OSUWP::input_event(const Ref<InputEvent> &p_event) {
  245. input->parse_input_event(p_event);
  246. };
  247. void OSUWP::delete_main_loop() {
  248. if (main_loop)
  249. memdelete(main_loop);
  250. main_loop = NULL;
  251. }
  252. void OSUWP::set_main_loop(MainLoop *p_main_loop) {
  253. input->set_main_loop(p_main_loop);
  254. main_loop = p_main_loop;
  255. }
  256. void OSUWP::finalize() {
  257. if (main_loop)
  258. memdelete(main_loop);
  259. main_loop = NULL;
  260. visual_server->finish();
  261. memdelete(visual_server);
  262. #ifdef OPENGL_ENABLED
  263. if (gl_context)
  264. memdelete(gl_context);
  265. #endif
  266. memdelete(input);
  267. joypad = nullptr;
  268. }
  269. void OSUWP::finalize_core() {
  270. }
  271. void OSUWP::alert(const String &p_alert, const String &p_title) {
  272. Platform::String ^ alert = ref new Platform::String(p_alert.c_str());
  273. Platform::String ^ title = ref new Platform::String(p_title.c_str());
  274. MessageDialog ^ msg = ref new MessageDialog(alert, title);
  275. UICommand ^ close = ref new UICommand("Close", ref new UICommandInvokedHandler(managed_object, &OSUWP::ManagedType::alert_close));
  276. msg->Commands->Append(close);
  277. msg->DefaultCommandIndex = 0;
  278. managed_object->alert_close_handle = true;
  279. msg->ShowAsync();
  280. }
  281. void OSUWP::ManagedType::alert_close(IUICommand ^ command) {
  282. alert_close_handle = false;
  283. }
  284. void OSUWP::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) {
  285. update_clipboard();
  286. }
  287. void OSUWP::ManagedType::update_clipboard() {
  288. DataPackageView ^ data = Clipboard::GetContent();
  289. if (data->Contains(StandardDataFormats::Text)) {
  290. create_task(data->GetTextAsync()).then([this](Platform::String ^ clipboard_content) {
  291. this->clipboard = clipboard_content;
  292. });
  293. }
  294. }
  295. void OSUWP::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) {
  296. AccelerometerReading ^ reading = args->Reading;
  297. os->input->set_accelerometer(Vector3(
  298. reading->AccelerationX,
  299. reading->AccelerationY,
  300. reading->AccelerationZ));
  301. }
  302. void OSUWP::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) {
  303. MagnetometerReading ^ reading = args->Reading;
  304. os->input->set_magnetometer(Vector3(
  305. reading->MagneticFieldX,
  306. reading->MagneticFieldY,
  307. reading->MagneticFieldZ));
  308. }
  309. void OSUWP::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) {
  310. GyrometerReading ^ reading = args->Reading;
  311. os->input->set_magnetometer(Vector3(
  312. reading->AngularVelocityX,
  313. reading->AngularVelocityY,
  314. reading->AngularVelocityZ));
  315. }
  316. void OSUWP::set_mouse_mode(MouseMode p_mode) {
  317. if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) {
  318. CoreWindow::GetForCurrentThread()->SetPointerCapture();
  319. } else {
  320. CoreWindow::GetForCurrentThread()->ReleasePointerCapture();
  321. }
  322. if (p_mode == MouseMode::MOUSE_MODE_CAPTURED || p_mode == MouseMode::MOUSE_MODE_HIDDEN) {
  323. CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;
  324. } else {
  325. CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
  326. }
  327. mouse_mode = p_mode;
  328. SetEvent(mouse_mode_changed);
  329. }
  330. OSUWP::MouseMode OSUWP::get_mouse_mode() const {
  331. return mouse_mode;
  332. }
  333. Point2 OSUWP::get_mouse_position() const {
  334. return Point2(old_x, old_y);
  335. }
  336. int OSUWP::get_mouse_button_state() const {
  337. return last_button_state;
  338. }
  339. void OSUWP::set_window_title(const String &p_title) {
  340. }
  341. void OSUWP::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
  342. video_mode = p_video_mode;
  343. }
  344. OS::VideoMode OSUWP::get_video_mode(int p_screen) const {
  345. return video_mode;
  346. }
  347. void OSUWP::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
  348. }
  349. String OSUWP::get_name() {
  350. return "UWP";
  351. }
  352. OS::Date OSUWP::get_date(bool utc) const {
  353. SYSTEMTIME systemtime;
  354. if (utc)
  355. GetSystemTime(&systemtime);
  356. else
  357. GetLocalTime(&systemtime);
  358. Date date;
  359. date.day = systemtime.wDay;
  360. date.month = Month(systemtime.wMonth);
  361. date.weekday = Weekday(systemtime.wDayOfWeek);
  362. date.year = systemtime.wYear;
  363. date.dst = false;
  364. return date;
  365. }
  366. OS::Time OSUWP::get_time(bool utc) const {
  367. SYSTEMTIME systemtime;
  368. if (utc)
  369. GetSystemTime(&systemtime);
  370. else
  371. GetLocalTime(&systemtime);
  372. Time time;
  373. time.hour = systemtime.wHour;
  374. time.min = systemtime.wMinute;
  375. time.sec = systemtime.wSecond;
  376. return time;
  377. }
  378. OS::TimeZoneInfo OSUWP::get_time_zone_info() const {
  379. TIME_ZONE_INFORMATION info;
  380. bool daylight = false;
  381. if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT)
  382. daylight = true;
  383. TimeZoneInfo ret;
  384. if (daylight) {
  385. ret.name = info.DaylightName;
  386. } else {
  387. ret.name = info.StandardName;
  388. }
  389. ret.bias = info.Bias;
  390. return ret;
  391. }
  392. uint64_t OSUWP::get_unix_time() const {
  393. FILETIME ft;
  394. SYSTEMTIME st;
  395. GetSystemTime(&st);
  396. SystemTimeToFileTime(&st, &ft);
  397. SYSTEMTIME ep;
  398. ep.wYear = 1970;
  399. ep.wMonth = 1;
  400. ep.wDayOfWeek = 4;
  401. ep.wDay = 1;
  402. ep.wHour = 0;
  403. ep.wMinute = 0;
  404. ep.wSecond = 0;
  405. ep.wMilliseconds = 0;
  406. FILETIME fep;
  407. SystemTimeToFileTime(&ep, &fep);
  408. return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000;
  409. };
  410. void OSUWP::delay_usec(uint32_t p_usec) const {
  411. int msec = p_usec < 1000 ? 1 : p_usec / 1000;
  412. // no Sleep()
  413. WaitForSingleObjectEx(GetCurrentThread(), msec, false);
  414. }
  415. uint64_t OSUWP::get_ticks_usec() const {
  416. uint64_t ticks;
  417. uint64_t time;
  418. // This is the number of clock ticks since start
  419. QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
  420. // Divide by frequency to get the time in seconds
  421. time = ticks * 1000000L / ticks_per_second;
  422. // Subtract the time at game start to get
  423. // the time since the game started
  424. time -= ticks_start;
  425. return time;
  426. }
  427. void OSUWP::process_events() {
  428. joypad->process_controllers();
  429. process_key_events();
  430. }
  431. void OSUWP::process_key_events() {
  432. for (int i = 0; i < key_event_pos; i++) {
  433. KeyEvent &kev = key_event_buffer[i];
  434. Ref<InputEventKey> key_event;
  435. key_event.instance();
  436. key_event->set_alt(kev.alt);
  437. key_event->set_shift(kev.shift);
  438. key_event->set_control(kev.control);
  439. key_event->set_echo(kev.echo);
  440. key_event->set_scancode(kev.scancode);
  441. key_event->set_unicode(kev.unicode);
  442. key_event->set_pressed(kev.pressed);
  443. input_event(key_event);
  444. }
  445. key_event_pos = 0;
  446. }
  447. void OSUWP::queue_key_event(KeyEvent &p_event) {
  448. // This merges Char events with the previous Key event, so
  449. // the unicode can be retrieved without sending duplicate events.
  450. if (p_event.type == KeyEvent::MessageType::CHAR_EVENT_MESSAGE && key_event_pos > 0) {
  451. KeyEvent &old = key_event_buffer[key_event_pos - 1];
  452. ERR_FAIL_COND(old.type != KeyEvent::MessageType::KEY_EVENT_MESSAGE);
  453. key_event_buffer[key_event_pos - 1].unicode = p_event.unicode;
  454. return;
  455. }
  456. ERR_FAIL_COND(key_event_pos >= KEY_EVENT_BUFFER_SIZE);
  457. key_event_buffer[key_event_pos++] = p_event;
  458. }
  459. void OSUWP::set_cursor_shape(CursorShape p_shape) {
  460. ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
  461. if (cursor_shape == p_shape)
  462. return;
  463. static const CoreCursorType uwp_cursors[CURSOR_MAX] = {
  464. CoreCursorType::Arrow,
  465. CoreCursorType::IBeam,
  466. CoreCursorType::Hand,
  467. CoreCursorType::Cross,
  468. CoreCursorType::Wait,
  469. CoreCursorType::Wait,
  470. CoreCursorType::Arrow,
  471. CoreCursorType::Arrow,
  472. CoreCursorType::UniversalNo,
  473. CoreCursorType::SizeNorthSouth,
  474. CoreCursorType::SizeWestEast,
  475. CoreCursorType::SizeNortheastSouthwest,
  476. CoreCursorType::SizeNorthwestSoutheast,
  477. CoreCursorType::SizeAll,
  478. CoreCursorType::SizeNorthSouth,
  479. CoreCursorType::SizeWestEast,
  480. CoreCursorType::Help
  481. };
  482. CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(uwp_cursors[p_shape], 0);
  483. cursor_shape = p_shape;
  484. }
  485. 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, bool read_stderr) {
  486. return FAILED;
  487. };
  488. Error OSUWP::kill(const ProcessID &p_pid) {
  489. return FAILED;
  490. };
  491. Error OSUWP::set_cwd(const String &p_cwd) {
  492. return FAILED;
  493. }
  494. String OSUWP::get_executable_path() const {
  495. return "";
  496. }
  497. void OSUWP::set_icon(const Ref<Image> &p_icon) {
  498. }
  499. bool OSUWP::has_environment(const String &p_var) const {
  500. return false;
  501. };
  502. String OSUWP::get_environment(const String &p_var) const {
  503. return "";
  504. };
  505. String OSUWP::get_stdin_string(bool p_block) {
  506. return String();
  507. }
  508. void OSUWP::move_window_to_foreground() {
  509. }
  510. Error OSUWP::shell_open(String p_uri) {
  511. return FAILED;
  512. }
  513. String OSUWP::get_locale() const {
  514. #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // this should work on phone 8.1, but it doesn't
  515. return "en";
  516. #else
  517. Platform::String ^ language = Windows::Globalization::Language::CurrentInputMethodLanguageTag;
  518. return String(language->Data()).replace("-", "_");
  519. #endif
  520. }
  521. void OSUWP::release_rendering_thread() {
  522. gl_context->release_current();
  523. }
  524. void OSUWP::make_rendering_thread() {
  525. gl_context->make_current();
  526. }
  527. void OSUWP::swap_buffers() {
  528. gl_context->swap_buffers();
  529. }
  530. bool OSUWP::has_touchscreen_ui_hint() const {
  531. TouchCapabilities ^ tc = ref new TouchCapabilities();
  532. return tc->TouchPresent != 0 || UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch;
  533. }
  534. bool OSUWP::has_virtual_keyboard() const {
  535. return UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch;
  536. }
  537. void OSUWP::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) {
  538. InputPane ^ pane = InputPane::GetForCurrentView();
  539. pane->TryShow();
  540. }
  541. void OSUWP::hide_virtual_keyboard() {
  542. InputPane ^ pane = InputPane::GetForCurrentView();
  543. pane->TryHide();
  544. }
  545. void OSUWP::run() {
  546. if (!main_loop)
  547. return;
  548. main_loop->init();
  549. uint64_t last_ticks = get_ticks_usec();
  550. int frames = 0;
  551. uint64_t frame = 0;
  552. while (!force_quit) {
  553. CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
  554. if (managed_object->alert_close_handle) continue;
  555. process_events(); // get rid of pending events
  556. if (Main::iteration() == true)
  557. break;
  558. };
  559. main_loop->finish();
  560. }
  561. MainLoop *OSUWP::get_main_loop() const {
  562. return main_loop;
  563. }
  564. String OSUWP::get_data_dir() const {
  565. Windows::Storage::StorageFolder ^ data_folder = Windows::Storage::ApplicationData::Current->LocalFolder;
  566. return String(data_folder->Path->Data()).replace("\\", "/");
  567. }
  568. bool OSUWP::_check_internal_feature_support(const String &p_feature) {
  569. return p_feature == "pc" || p_feature == "s3tc";
  570. }
  571. OS::PowerState OSUWP::get_power_state() {
  572. return power_manager->get_power_state();
  573. }
  574. int OSUWP::get_power_seconds_left() {
  575. return power_manager->get_power_seconds_left();
  576. }
  577. int OSUWP::get_power_percent_left() {
  578. return power_manager->get_power_percent_left();
  579. }
  580. OSUWP::OSUWP() {
  581. key_event_pos = 0;
  582. force_quit = false;
  583. alt_mem = false;
  584. gr_mem = false;
  585. shift_mem = false;
  586. control_mem = false;
  587. meta_mem = false;
  588. minimized = false;
  589. pressrc = 0;
  590. old_invalid = true;
  591. mouse_mode = MOUSE_MODE_VISIBLE;
  592. #ifdef STDOUT_FILE
  593. stdo = fopen("stdout.txt", "wb");
  594. #endif
  595. gl_context = NULL;
  596. display_request = ref new Windows::System::Display::DisplayRequest();
  597. managed_object = ref new ManagedType;
  598. managed_object->os = this;
  599. mouse_mode_changed = CreateEvent(NULL, TRUE, FALSE, L"os_mouse_mode_changed");
  600. AudioDriverManager::add_driver(&audio_driver);
  601. _set_logger(memnew(WindowsTerminalLogger));
  602. }
  603. OSUWP::~OSUWP() {
  604. #ifdef STDOUT_FILE
  605. fclose(stdo);
  606. #endif
  607. }