os_uwp.cpp 21 KB

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