2016-09-04 00:25:43 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* app.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2016-09-04 00:25:43 +02:00
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-09-04 00:25:43 +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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
//
|
2015-10-08 20:00:40 +02:00
|
|
|
// This file demonstrates how to initialize EGL in a Windows Store app, using ICoreWindow.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "app.h"
|
|
|
|
|
|
|
|
#include "core/os/dir_access.h"
|
|
|
|
#include "core/os/file_access.h"
|
2016-09-04 00:25:43 +02:00
|
|
|
#include "core/os/keyboard.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "main/main.h"
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
#include "platform/windows/key_mapping_windows.h"
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
#include <collection.h>
|
2015-10-08 20:00:40 +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::Devices::Input;
|
|
|
|
using namespace Windows::UI::Xaml::Input;
|
2015-10-08 20:00:40 +02:00
|
|
|
using namespace Windows::Foundation;
|
|
|
|
using namespace Windows::Graphics::Display;
|
2016-09-04 00:25:43 +02:00
|
|
|
using namespace Windows::System;
|
|
|
|
using namespace Windows::System::Threading::Core;
|
2015-10-08 20:00:40 +02:00
|
|
|
using namespace Microsoft::WRL;
|
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
using namespace GodotUWP;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
// Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
|
2017-03-05 16:44:50 +01:00
|
|
|
inline float ConvertDipsToPixels(float dips, float dpi) {
|
|
|
|
static const float dipsPerInch = 96.0f;
|
|
|
|
return floor(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer.
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation of the IFrameworkViewSource interface, necessary to run our app.
|
2017-03-05 16:44:50 +01:00
|
|
|
ref class GodotUWPViewSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource {
|
2015-10-08 20:00:40 +02:00
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual Windows::ApplicationModel::Core::IFrameworkView ^ CreateView() {
|
|
|
|
return ref new App();
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// The main function creates an IFrameworkViewSource for our app, and runs the app.
|
2017-03-05 16:44:50 +01:00
|
|
|
[Platform::MTAThread] int main(Platform::Array<Platform::String ^> ^) {
|
|
|
|
auto godotApplicationSource = ref new GodotUWPViewSource();
|
|
|
|
CoreApplication::Run(godotApplicationSource);
|
|
|
|
return 0;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The first method called when the IFrameworkView is being created.
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::Initialize(CoreApplicationView ^ applicationView) {
|
|
|
|
// Register event handlers for app lifecycle. This example includes Activated, so that we
|
|
|
|
// can make the CoreWindow active and start rendering on the window.
|
|
|
|
applicationView->Activated +=
|
|
|
|
ref new TypedEventHandler<CoreApplicationView ^, IActivatedEventArgs ^>(this, &App::OnActivated);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
// Logic for other event handlers could go here.
|
|
|
|
// Information about the Suspending and Resuming event handlers can be found here:
|
|
|
|
// http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-02-12 15:43:54 +01:00
|
|
|
os = new OS_UWP;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called when the CoreWindow object is created (or re-created).
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::SetWindow(CoreWindow ^ p_window) {
|
2015-10-08 20:00:40 +02:00
|
|
|
window = p_window;
|
2017-03-05 16:44:50 +01:00
|
|
|
window->VisibilityChanged +=
|
|
|
|
ref new TypedEventHandler<CoreWindow ^, VisibilityChangedEventArgs ^>(this, &App::OnVisibilityChanged);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
window->Closed +=
|
|
|
|
ref new TypedEventHandler<CoreWindow ^, CoreWindowEventArgs ^>(this, &App::OnWindowClosed);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
window->SizeChanged +=
|
|
|
|
ref new TypedEventHandler<CoreWindow ^, WindowSizeChangedEventArgs ^>(this, &App::OnWindowSizeChanged);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
#if !(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
|
2017-03-05 16:44:50 +01:00
|
|
|
// Disable all pointer visual feedback for better performance when touching.
|
|
|
|
// This is not supported on Windows Phone applications.
|
|
|
|
auto pointerVisualizationSettings = PointerVisualizationSettings::GetForCurrentView();
|
|
|
|
pointerVisualizationSettings->IsContactFeedbackEnabled = false;
|
|
|
|
pointerVisualizationSettings->IsBarrelButtonFeedbackEnabled = false;
|
2015-10-08 20:00:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
window->PointerPressed +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>(this, &App::OnPointerPressed);
|
2015-10-08 20:00:40 +02:00
|
|
|
window->PointerMoved +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>(this, &App::OnPointerMoved);
|
2015-10-08 20:00:40 +02:00
|
|
|
window->PointerReleased +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>(this, &App::OnPointerReleased);
|
2016-09-04 00:25:43 +02:00
|
|
|
window->PointerWheelChanged +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>(this, &App::OnPointerWheelChanged);
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
mouseChangedNotifier = SignalNotifier::AttachToEvent(L"os_mouse_mode_changed", ref new SignalHandler(
|
2017-03-05 16:44:50 +01:00
|
|
|
this, &App::OnMouseModeChanged));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
mouseChangedNotifier->Enable();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
window->CharacterReceived +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<CoreWindow ^, CharacterReceivedEventArgs ^>(this, &App::OnCharacterReceived);
|
2016-09-04 00:25:43 +02:00
|
|
|
window->KeyDown +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &App::OnKeyDown);
|
2016-09-04 00:25:43 +02:00
|
|
|
window->KeyUp +=
|
2017-03-05 16:44:50 +01:00
|
|
|
ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &App::OnKeyUp);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-12 21:21:35 +02:00
|
|
|
os->set_window(window);
|
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
unsigned int argc;
|
2017-03-05 16:44:50 +01:00
|
|
|
char **argv = get_command_line(&argc);
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2016-11-02 22:22:49 +01:00
|
|
|
Main::setup("uwp", argc, argv, false);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
UpdateWindowSize(Size(window->Bounds.Width, window->Bounds.Height));
|
|
|
|
|
|
|
|
Main::setup2();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static int _get_button(Windows::UI::Input::PointerPoint ^ pt) {
|
2015-10-08 20:00:40 +02:00
|
|
|
using namespace Windows::UI::Input;
|
|
|
|
|
|
|
|
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
2021-01-08 04:37:37 +01:00
|
|
|
return MOUSE_BUTTON_LEFT;
|
2015-10-08 20:00:40 +02:00
|
|
|
#else
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (pt->Properties->PointerUpdateKind) {
|
2015-10-08 20:00:40 +02:00
|
|
|
case PointerUpdateKind::LeftButtonPressed:
|
|
|
|
case PointerUpdateKind::LeftButtonReleased:
|
2021-01-08 04:37:37 +01:00
|
|
|
return MOUSE_BUTTON_LEFT;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
case PointerUpdateKind::RightButtonPressed:
|
|
|
|
case PointerUpdateKind::RightButtonReleased:
|
2021-01-08 04:37:37 +01:00
|
|
|
return MOUSE_BUTTON_RIGHT;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
case PointerUpdateKind::MiddleButtonPressed:
|
|
|
|
case PointerUpdateKind::MiddleButtonReleased:
|
2021-01-08 04:37:37 +01:00
|
|
|
return MOUSE_BUTTON_MIDDLE;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
case PointerUpdateKind::XButton1Pressed:
|
|
|
|
case PointerUpdateKind::XButton1Released:
|
2021-01-08 04:37:37 +01:00
|
|
|
return MOUSE_BUTTON_WHEEL_UP;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
case PointerUpdateKind::XButton2Pressed:
|
|
|
|
case PointerUpdateKind::XButton2Released:
|
2021-01-08 04:37:37 +01:00
|
|
|
return MOUSE_BUTTON_WHEEL_DOWN;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static bool _is_touch(Windows::UI::Input::PointerPoint ^ pointerPoint) {
|
2015-10-08 20:00:40 +02:00
|
|
|
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
using namespace Windows::Devices::Input;
|
|
|
|
switch (pointerPoint->PointerDevice->PointerDeviceType) {
|
|
|
|
case PointerDeviceType::Touch:
|
|
|
|
case PointerDeviceType::Pen:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static Windows::Foundation::Point _get_pixel_position(CoreWindow ^ window, Windows::Foundation::Point rawPosition, OS *os) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Windows::Foundation::Point outputPosition;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
// Compute coordinates normalized from 0..1.
|
|
|
|
// If the coordinates need to be sized to the SDL window,
|
|
|
|
// we'll do that after.
|
|
|
|
#if 1 || WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
|
2015-10-08 20:00:40 +02:00
|
|
|
outputPosition.X = rawPosition.X / window->Bounds.Width;
|
|
|
|
outputPosition.Y = rawPosition.Y / window->Bounds.Height;
|
2017-03-05 16:44:50 +01:00
|
|
|
#else
|
|
|
|
switch (DisplayProperties::CurrentOrientation) {
|
2015-10-08 20:00:40 +02:00
|
|
|
case DisplayOrientations::Portrait:
|
|
|
|
outputPosition.X = rawPosition.X / window->Bounds.Width;
|
|
|
|
outputPosition.Y = rawPosition.Y / window->Bounds.Height;
|
|
|
|
break;
|
|
|
|
case DisplayOrientations::PortraitFlipped:
|
|
|
|
outputPosition.X = 1.0f - (rawPosition.X / window->Bounds.Width);
|
|
|
|
outputPosition.Y = 1.0f - (rawPosition.Y / window->Bounds.Height);
|
|
|
|
break;
|
|
|
|
case DisplayOrientations::Landscape:
|
|
|
|
outputPosition.X = rawPosition.Y / window->Bounds.Height;
|
|
|
|
outputPosition.Y = 1.0f - (rawPosition.X / window->Bounds.Width);
|
|
|
|
break;
|
|
|
|
case DisplayOrientations::LandscapeFlipped:
|
|
|
|
outputPosition.X = 1.0f - (rawPosition.Y / window->Bounds.Height);
|
|
|
|
outputPosition.Y = rawPosition.X / window->Bounds.Width;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
#endif
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
OS::VideoMode vm = os->get_video_mode();
|
|
|
|
outputPosition.X *= vm.width;
|
|
|
|
outputPosition.Y *= vm.height;
|
|
|
|
|
|
|
|
return outputPosition;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int _get_finger(uint32_t p_touch_id) {
|
|
|
|
return p_touch_id % 31; // for now
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::pointer_event(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::PointerEventArgs ^ args, bool p_pressed, bool p_is_wheel) {
|
|
|
|
Windows::UI::Input::PointerPoint ^ point = args->CurrentPoint;
|
2015-10-08 20:00:40 +02:00
|
|
|
Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os);
|
|
|
|
int but = _get_button(point);
|
|
|
|
if (_is_touch(point)) {
|
2017-05-23 18:50:21 +02:00
|
|
|
Ref<InputEventScreenTouch> screen_touch;
|
|
|
|
screen_touch.instance();
|
|
|
|
screen_touch->set_device(0);
|
|
|
|
screen_touch->set_pressed(p_pressed);
|
2017-06-12 16:47:42 +02:00
|
|
|
screen_touch->set_position(Vector2(pos.X, pos.Y));
|
2017-05-23 18:50:21 +02:00
|
|
|
screen_touch->set_index(_get_finger(point->PointerId));
|
|
|
|
|
|
|
|
last_touch_x[screen_touch->get_index()] = pos.X;
|
|
|
|
last_touch_y[screen_touch->get_index()] = pos.Y;
|
|
|
|
|
|
|
|
os->input_event(screen_touch);
|
2018-02-24 03:04:30 +01:00
|
|
|
} else {
|
|
|
|
Ref<InputEventMouseButton> mouse_button;
|
|
|
|
mouse_button.instance();
|
|
|
|
mouse_button->set_device(0);
|
|
|
|
mouse_button->set_pressed(p_pressed);
|
|
|
|
mouse_button->set_button_index(but);
|
|
|
|
mouse_button->set_position(Vector2(pos.X, pos.Y));
|
|
|
|
mouse_button->set_global_position(Vector2(pos.X, pos.Y));
|
|
|
|
|
|
|
|
if (p_is_wheel) {
|
|
|
|
if (point->Properties->MouseWheelDelta > 0) {
|
2021-01-08 04:37:37 +01:00
|
|
|
mouse_button->set_button_index(point->Properties->IsHorizontalMouseWheel ? MOUSE_BUTTON_WHEEL_RIGHT : MOUSE_BUTTON_WHEEL_UP);
|
2018-02-24 03:04:30 +01:00
|
|
|
} else if (point->Properties->MouseWheelDelta < 0) {
|
2021-01-08 04:37:37 +01:00
|
|
|
mouse_button->set_button_index(point->Properties->IsHorizontalMouseWheel ? MOUSE_BUTTON_WHEEL_LEFT : MOUSE_BUTTON_WHEEL_DOWN);
|
2018-02-24 03:04:30 +01:00
|
|
|
}
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
2018-02-24 03:04:30 +01:00
|
|
|
last_touch_x[31] = pos.X;
|
|
|
|
last_touch_y[31] = pos.Y;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-05-23 18:50:21 +02:00
|
|
|
os->input_event(mouse_button);
|
2018-02-24 03:04:30 +01:00
|
|
|
|
|
|
|
if (p_is_wheel) {
|
|
|
|
// Send release for mouse wheel
|
|
|
|
mouse_button->set_pressed(false);
|
|
|
|
os->input_event(mouse_button);
|
|
|
|
}
|
2017-05-23 18:50:21 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnPointerPressed(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::PointerEventArgs ^ args) {
|
2015-10-08 20:00:40 +02:00
|
|
|
pointer_event(sender, args, true);
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnPointerReleased(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::PointerEventArgs ^ args) {
|
2015-10-08 20:00:40 +02:00
|
|
|
pointer_event(sender, args, false);
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnPointerWheelChanged(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::PointerEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
pointer_event(sender, args, true, true);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnMouseModeChanged(Windows::System::Threading::Core::SignalNotifier ^ signalNotifier, bool timedOut) {
|
2016-09-04 00:25:43 +02:00
|
|
|
OS::MouseMode mode = os->get_mouse_mode();
|
2017-03-05 16:44:50 +01:00
|
|
|
SignalNotifier ^ notifier = mouseChangedNotifier;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
window->Dispatcher->RunAsync(
|
2017-03-05 16:44:50 +01:00
|
|
|
CoreDispatcherPriority::High,
|
|
|
|
ref new DispatchedHandler(
|
|
|
|
[mode, notifier, this]() {
|
|
|
|
if (mode == OS::MOUSE_MODE_CAPTURED) {
|
|
|
|
this->MouseMovedToken = MouseDevice::GetForCurrentView()->MouseMoved +=
|
|
|
|
ref new TypedEventHandler<MouseDevice ^, MouseEventArgs ^>(this, &App::OnMouseMoved);
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
|
|
|
MouseDevice::GetForCurrentView()->MouseMoved -= MouseMovedToken;
|
|
|
|
}
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
notifier->Enable();
|
|
|
|
}));
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
ResetEvent(os->mouse_mode_changed);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::PointerEventArgs ^ args) {
|
|
|
|
Windows::UI::Input::PointerPoint ^ point = args->CurrentPoint;
|
2015-10-08 20:00:40 +02:00
|
|
|
Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os);
|
|
|
|
|
2018-02-24 03:04:30 +01:00
|
|
|
if (_is_touch(point)) {
|
2017-05-23 18:50:21 +02:00
|
|
|
Ref<InputEventScreenDrag> screen_drag;
|
|
|
|
screen_drag.instance();
|
|
|
|
screen_drag->set_device(0);
|
2017-06-12 16:47:42 +02:00
|
|
|
screen_drag->set_position(Vector2(pos.X, pos.Y));
|
2017-05-23 18:50:21 +02:00
|
|
|
screen_drag->set_index(_get_finger(point->PointerId));
|
2017-06-12 16:47:42 +02:00
|
|
|
screen_drag->set_relative(Vector2(screen_drag->get_position().x - last_touch_x[screen_drag->get_index()], screen_drag->get_position().y - last_touch_y[screen_drag->get_index()]));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-05-23 18:50:21 +02:00
|
|
|
os->input_event(screen_drag);
|
2018-02-24 03:04:30 +01:00
|
|
|
} else {
|
|
|
|
// In case the mouse grabbed, MouseMoved will handle this
|
|
|
|
if (os->get_mouse_mode() == OS::MouseMode::MOUSE_MODE_CAPTURED)
|
|
|
|
return;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2018-02-24 03:04:30 +01:00
|
|
|
Ref<InputEventMouseMotion> mouse_motion;
|
|
|
|
mouse_motion.instance();
|
|
|
|
mouse_motion->set_device(0);
|
|
|
|
mouse_motion->set_position(Vector2(pos.X, pos.Y));
|
|
|
|
mouse_motion->set_global_position(Vector2(pos.X, pos.Y));
|
|
|
|
mouse_motion->set_relative(Vector2(pos.X - last_touch_x[31], pos.Y - last_touch_y[31]));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-02-24 03:04:30 +01:00
|
|
|
last_mouse_pos = pos;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2018-02-24 03:04:30 +01:00
|
|
|
os->input_event(mouse_motion);
|
|
|
|
}
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) {
|
|
|
|
// In case the mouse isn't grabbed, PointerMoved will handle this
|
|
|
|
if (os->get_mouse_mode() != OS::MouseMode::MOUSE_MODE_CAPTURED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Windows::Foundation::Point pos;
|
|
|
|
pos.X = last_mouse_pos.X + args->MouseDelta.X;
|
|
|
|
pos.Y = last_mouse_pos.Y + args->MouseDelta.Y;
|
|
|
|
|
2017-05-23 18:50:21 +02:00
|
|
|
Ref<InputEventMouseMotion> mouse_motion;
|
|
|
|
mouse_motion.instance();
|
|
|
|
mouse_motion->set_device(0);
|
2017-06-12 16:47:42 +02:00
|
|
|
mouse_motion->set_position(Vector2(pos.X, pos.Y));
|
|
|
|
mouse_motion->set_global_position(Vector2(pos.X, pos.Y));
|
2017-05-23 18:50:21 +02:00
|
|
|
mouse_motion->set_relative(Vector2(args->MouseDelta.X, args->MouseDelta.Y));
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
last_mouse_pos = pos;
|
|
|
|
|
2017-05-23 18:50:21 +02:00
|
|
|
os->input_event(mouse_motion);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::key_event(Windows::UI::Core::CoreWindow ^ sender, bool p_pressed, Windows::UI::Core::KeyEventArgs ^ key_args, Windows::UI::Core::CharacterReceivedEventArgs ^ char_args) {
|
2019-02-12 15:43:54 +01:00
|
|
|
OS_UWP::KeyEvent ke;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-05-23 18:50:21 +02:00
|
|
|
ke.control = sender->GetAsyncKeyState(VirtualKey::Control) == CoreVirtualKeyStates::Down;
|
|
|
|
ke.alt = sender->GetAsyncKeyState(VirtualKey::Menu) == CoreVirtualKeyStates::Down;
|
|
|
|
ke.shift = sender->GetAsyncKeyState(VirtualKey::Shift) == CoreVirtualKeyStates::Down;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-05-23 18:50:21 +02:00
|
|
|
ke.pressed = p_pressed;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2016-09-04 00:25:43 +02:00
|
|
|
if (key_args != nullptr) {
|
2019-02-12 15:43:54 +01:00
|
|
|
ke.type = OS_UWP::KeyEvent::MessageType::KEY_EVENT_MESSAGE;
|
2016-09-04 00:25:43 +02:00
|
|
|
ke.unicode = 0;
|
2018-04-05 19:59:35 +02:00
|
|
|
ke.keycode = KeyMappingWindows::get_keysym((unsigned int)key_args->VirtualKey);
|
|
|
|
ke.physical_keycode = KeyMappingWindows::get_scansym((unsigned int)key_args->KeyStatus.ScanCode);
|
2016-09-04 00:25:43 +02:00
|
|
|
ke.echo = (!p_pressed && !key_args->KeyStatus.IsKeyReleased) || (p_pressed && key_args->KeyStatus.WasKeyDown);
|
|
|
|
|
|
|
|
} else {
|
2019-02-12 15:43:54 +01:00
|
|
|
ke.type = OS_UWP::KeyEvent::MessageType::CHAR_EVENT_MESSAGE;
|
2016-09-04 00:25:43 +02:00
|
|
|
ke.unicode = char_args->KeyCode;
|
2018-04-05 19:59:35 +02:00
|
|
|
ke.keycode = 0;
|
|
|
|
ke.physical_keycode = 0;
|
2016-09-04 00:25:43 +02:00
|
|
|
ke.echo = (!p_pressed && !char_args->KeyStatus.IsKeyReleased) || (p_pressed && char_args->KeyStatus.WasKeyDown);
|
|
|
|
}
|
|
|
|
|
|
|
|
os->queue_key_event(ke);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnKeyDown(CoreWindow ^ sender, KeyEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
key_event(sender, true, args);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnKeyUp(CoreWindow ^ sender, KeyEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
key_event(sender, false, args);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnCharacterReceived(CoreWindow ^ sender, CharacterReceivedEventArgs ^ args) {
|
2016-09-04 00:25:43 +02:00
|
|
|
key_event(sender, true, nullptr, args);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
// Initializes scene resources
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::Load(Platform::String ^ entryPoint) {
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method is called after the window becomes active.
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::Run() {
|
2015-10-08 20:00:40 +02:00
|
|
|
if (Main::start())
|
|
|
|
os->run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView
|
|
|
|
// class is torn down while the app is in the foreground.
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::Uninitialize() {
|
2015-10-08 20:00:40 +02:00
|
|
|
Main::cleanup();
|
|
|
|
delete os;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Application lifecycle event handler.
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnActivated(CoreApplicationView ^ applicationView, IActivatedEventArgs ^ args) {
|
|
|
|
// Run() won't start until the CoreWindow is activated.
|
|
|
|
CoreWindow::GetForCurrentThread()->Activate();
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Window event handlers.
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnVisibilityChanged(CoreWindow ^ sender, VisibilityChangedEventArgs ^ args) {
|
|
|
|
mWindowVisible = args->Visible;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnWindowClosed(CoreWindow ^ sender, CoreWindowEventArgs ^ args) {
|
|
|
|
mWindowClosed = true;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::OnWindowSizeChanged(CoreWindow ^ sender, WindowSizeChangedEventArgs ^ args) {
|
2015-10-08 20:00:40 +02:00
|
|
|
#if (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP)
|
2017-03-05 16:44:50 +01:00
|
|
|
// On Windows 8.1, apps are resized when they are snapped alongside other apps, or when the device is rotated.
|
|
|
|
// The default framebuffer will be automatically resized when either of these occur.
|
|
|
|
// In particular, on a 90 degree rotation, the default framebuffer's width and height will switch.
|
|
|
|
UpdateWindowSize(args->Size);
|
2015-10-08 20:00:40 +02:00
|
|
|
#else if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
|
2017-03-05 16:44:50 +01:00
|
|
|
// On Windows Phone 8.1, the window size changes when the device is rotated.
|
|
|
|
// The default framebuffer will not be automatically resized when this occurs.
|
|
|
|
// It is therefore up to the app to handle rotation-specific logic in its rendering code.
|
2015-10-08 20:00:40 +02:00
|
|
|
//os->screen_size_changed();
|
|
|
|
UpdateWindowSize(args->Size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void App::UpdateWindowSize(Size size) {
|
2015-10-08 20:00:40 +02:00
|
|
|
float dpi;
|
|
|
|
#if (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP)
|
2017-03-05 16:44:50 +01:00
|
|
|
DisplayInformation ^ currentDisplayInformation = DisplayInformation::GetForCurrentView();
|
2015-10-08 20:00:40 +02:00
|
|
|
dpi = currentDisplayInformation->LogicalDpi;
|
|
|
|
#else if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
|
|
|
|
dpi = DisplayProperties::LogicalDpi;
|
|
|
|
#endif
|
|
|
|
Size pixelSize(ConvertDipsToPixels(size.Width, dpi), ConvertDipsToPixels(size.Height, dpi));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
mWindowWidth = static_cast<GLsizei>(pixelSize.Width);
|
|
|
|
mWindowHeight = static_cast<GLsizei>(pixelSize.Height);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
OS::VideoMode vm;
|
|
|
|
vm.width = mWindowWidth;
|
|
|
|
vm.height = mWindowHeight;
|
|
|
|
vm.fullscreen = true;
|
|
|
|
vm.resizable = false;
|
|
|
|
os->set_video_mode(vm);
|
|
|
|
}
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
char **App::get_command_line(unsigned int *out_argc) {
|
2020-04-02 01:20:12 +02:00
|
|
|
static char *fail_cl[] = { "--path", "game", nullptr };
|
2016-09-04 00:25:43 +02:00
|
|
|
*out_argc = 2;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
FILE *f = _wfopen(L"__cl__.cl", L"rb");
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
if (f == nullptr) {
|
2018-07-12 21:21:35 +02:00
|
|
|
wprintf(L"Couldn't open command line file.\n");
|
2016-09-04 00:25:43 +02:00
|
|
|
return fail_cl;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define READ_LE_4(v) ((int)(##v[3] & 0xFF) << 24) | ((int)(##v[2] & 0xFF) << 16) | ((int)(##v[1] & 0xFF) << 8) | ((int)(##v[0] & 0xFF))
|
|
|
|
#define CMD_MAX_LEN 65535
|
|
|
|
|
|
|
|
uint8_t len[4];
|
|
|
|
int r = fread(len, sizeof(uint8_t), 4, f);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Platform::Collections::Vector<Platform::String ^> cl;
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
if (r < 4) {
|
|
|
|
fclose(f);
|
2018-07-12 21:21:35 +02:00
|
|
|
wprintf(L"Wrong cmdline length.\n");
|
2017-03-05 16:44:50 +01:00
|
|
|
return (fail_cl);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int argc = READ_LE_4(len);
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
r = fread(len, sizeof(uint8_t), 4, f);
|
|
|
|
|
|
|
|
if (r < 4) {
|
|
|
|
fclose(f);
|
2018-07-12 21:21:35 +02:00
|
|
|
wprintf(L"Wrong cmdline param length.\n");
|
2017-03-05 16:44:50 +01:00
|
|
|
return (fail_cl);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int strlen = READ_LE_4(len);
|
|
|
|
|
|
|
|
if (strlen > CMD_MAX_LEN) {
|
|
|
|
fclose(f);
|
2018-07-12 21:21:35 +02:00
|
|
|
wprintf(L"Wrong command length.\n");
|
2017-03-05 16:44:50 +01:00
|
|
|
return (fail_cl);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
char *arg = new char[strlen + 1];
|
2016-09-04 00:25:43 +02:00
|
|
|
r = fread(arg, sizeof(char), strlen, f);
|
|
|
|
arg[strlen] = '\0';
|
|
|
|
|
|
|
|
if (r == strlen) {
|
2020-04-02 01:20:12 +02:00
|
|
|
int warg_size = MultiByteToWideChar(CP_UTF8, 0, arg, -1, nullptr, 0);
|
2017-03-05 16:44:50 +01:00
|
|
|
wchar_t *warg = new wchar_t[warg_size];
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, arg, -1, warg, warg_size);
|
|
|
|
|
|
|
|
cl.Append(ref new Platform::String(warg, warg_size));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
delete[] arg;
|
|
|
|
fclose(f);
|
2018-07-12 21:21:35 +02:00
|
|
|
wprintf(L"Error reading command.\n");
|
2017-03-05 16:44:50 +01:00
|
|
|
return (fail_cl);
|
2016-09-04 00:25:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef READ_LE_4
|
|
|
|
#undef CMD_MAX_LEN
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
char **ret = new char *[cl.Size + 1];
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < cl.Size; i++) {
|
2020-04-02 01:20:12 +02:00
|
|
|
int arg_size = WideCharToMultiByte(CP_UTF8, 0, cl.GetAt(i)->Data(), -1, nullptr, 0, nullptr, nullptr);
|
2017-03-05 16:44:50 +01:00
|
|
|
char *arg = new char[arg_size];
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, cl.GetAt(i)->Data(), -1, arg, arg_size, nullptr, nullptr);
|
2016-09-04 00:25:43 +02:00
|
|
|
|
|
|
|
ret[i] = arg;
|
|
|
|
}
|
2020-04-02 01:20:12 +02:00
|
|
|
ret[cl.Size] = nullptr;
|
2016-09-04 00:25:43 +02:00
|
|
|
*out_argc = cl.Size;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|