2023-03-11 22:10:18 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
Copyright (c) Microsoft Open Technologies, Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2023-03-12 01:44:55 +08:00
|
|
|
https://axmolengine.github.io/
|
2023-03-11 22:10:18 +08: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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/winrt/GLViewImpl-winrt.h"
|
|
|
|
#include "base/Macros.h"
|
|
|
|
#include "base/Director.h"
|
|
|
|
#include "base/Touch.h"
|
|
|
|
#include "base/IMEDispatcher.h"
|
|
|
|
#include "base/EventListenerKeyboard.h"
|
|
|
|
#include "platform/winrt/Application-winrt.h"
|
|
|
|
#include "platform/winrt/WinRTUtils.h"
|
|
|
|
#include "base/EventDispatcher.h"
|
|
|
|
#include "base/EventMouse.h"
|
2023-03-11 22:10:18 +08:00
|
|
|
#include <map>
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
#include <winrt/Windows.UI.Xaml.Controls.h>
|
|
|
|
#include <winrt/Windows.UI.Popups.h>
|
|
|
|
#include <winrt/Windows.UI.Input.h>
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
NS_AX_BEGIN
|
|
|
|
|
|
|
|
static GLViewImpl* s_pEglView = nullptr;
|
|
|
|
|
|
|
|
GLViewImpl* GLViewImpl::create(std::string_view viewName)
|
|
|
|
{
|
|
|
|
auto ret = new GLViewImpl;
|
|
|
|
if (ret && ret->initWithFullScreen(viewName))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-03-11 22:53:55 +08:00
|
|
|
GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName,
|
2023-03-25 16:08:48 +08:00
|
|
|
const Rect& rect, float frameZoomFactor, bool /*resizable*/)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
auto ret = new GLViewImpl;
|
2023-03-11 22:53:55 +08:00
|
|
|
if (ret && ret->initWithRect(viewName, rect, frameZoomFactor))
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-03-11 23:19:52 +08:00
|
|
|
GLViewImpl* GLViewImpl::createWithFullScreen(std::string_view viewName)
|
|
|
|
{
|
|
|
|
auto ret = new GLViewImpl();
|
|
|
|
if (ret->initWithFullScreen(viewName))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
AX_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
GLViewImpl::GLViewImpl()
|
|
|
|
: _frameZoomFactor(1.0f)
|
|
|
|
, _supportTouch(true)
|
|
|
|
, _isRetina(false)
|
|
|
|
, _isCursorVisible(true)
|
|
|
|
, m_lastPointValid(false)
|
|
|
|
, m_running(false)
|
|
|
|
, m_initialized(false)
|
|
|
|
, m_windowClosed(false)
|
|
|
|
, m_windowVisible(true)
|
|
|
|
, m_width(0)
|
|
|
|
, m_height(0)
|
2023-09-26 00:11:33 +08:00
|
|
|
, m_orientation(Windows::Graphics::Display::DisplayOrientations::Landscape)
|
2023-03-11 22:10:18 +08:00
|
|
|
, m_appShouldExit(false)
|
|
|
|
, _lastMouseButtonPressed(EventMouse::MouseButton::BUTTON_UNSET)
|
|
|
|
{
|
|
|
|
s_pEglView = this;
|
2023-09-26 00:11:33 +08:00
|
|
|
_viewName = "axmol2";
|
|
|
|
m_keyboard = KeyBoardWinRT();
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
m_backButtonListener = EventListenerKeyboard::create();
|
|
|
|
m_backButtonListener->onKeyReleased = AX_CALLBACK_2(GLViewImpl::BackButtonListener, this);
|
|
|
|
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(m_backButtonListener, INT_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLViewImpl::~GLViewImpl()
|
|
|
|
{
|
|
|
|
AX_ASSERT(this == s_pEglView);
|
|
|
|
s_pEglView = nullptr;
|
|
|
|
}
|
|
|
|
|
2023-03-11 22:53:55 +08:00
|
|
|
bool GLViewImpl::initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
setViewName(viewName);
|
|
|
|
setFrameSize(rect.size.width, rect.size.height);
|
|
|
|
setFrameZoomFactor(frameZoomFactor);
|
2023-03-11 22:53:55 +08:00
|
|
|
UpdateForWindowSizeChange(rect.size.width, rect.size.height);
|
2023-03-11 22:10:18 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLViewImpl::initWithFullScreen(std::string_view viewName)
|
|
|
|
{
|
|
|
|
return initWithRect(viewName, Rect(0, 0, m_width, m_height), 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ax::GLViewImpl::setCursorVisible(bool isVisible)
|
|
|
|
{
|
|
|
|
_isCursorVisible = isVisible;
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::setDispatcher(winrt::agile_ref<Windows::UI::Core::CoreDispatcher> dispatcher)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
m_dispatcher = dispatcher;
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::setPanel(winrt::agile_ref<Windows::UI::Xaml::Controls::Panel> panel)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
m_panel = panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::setIMEKeyboardState(bool bOpen)
|
|
|
|
{
|
|
|
|
std::string str;
|
|
|
|
setIMEKeyboardState(bOpen, str);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
bool GLViewImpl::ShowMessageBox(const winrt::hstring& title, const winrt::hstring& message)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
if (m_dispatcher)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
m_dispatcher.get().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal,
|
|
|
|
Windows::UI::Core::DispatchedHandler([title, message]() {
|
2023-03-11 22:10:18 +08:00
|
|
|
// Show the message dialog
|
2023-09-26 00:11:33 +08:00
|
|
|
auto msg = Windows::UI::Popups::MessageDialog(message, title);
|
2023-03-11 22:10:18 +08:00
|
|
|
// Set the command to be invoked when a user presses 'ESC'
|
2023-09-26 00:11:33 +08:00
|
|
|
msg.CancelCommandIndex(1);
|
|
|
|
msg.ShowAsync();
|
2023-03-11 22:10:18 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::setIMEKeyboardState(bool bOpen, std::string_view str)
|
|
|
|
{
|
|
|
|
if (bOpen)
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
m_keyboard.ShowKeyboard(PlatformStringFromString(str));
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
m_keyboard.HideKeyboard(PlatformStringFromString(str));
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::swapBuffers() {}
|
|
|
|
|
|
|
|
bool GLViewImpl::isOpenGLReady()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::end()
|
|
|
|
{
|
|
|
|
m_windowClosed = true;
|
|
|
|
m_appShouldExit = true;
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnSuspending(Windows::Foundation::IInspectable const& sender,
|
|
|
|
Windows::ApplicationModel::SuspendingEventArgs const& args)
|
|
|
|
{}
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnResuming(Windows::Foundation::IInspectable const& sender) {}
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
// user pressed the Back Key on the phone
|
|
|
|
void GLViewImpl::OnBackKeyPress()
|
|
|
|
{
|
|
|
|
ax::EventKeyboard::KeyCode cocos2dKey = EventKeyboard::KeyCode::KEY_ESCAPE;
|
|
|
|
ax::EventKeyboard event(cocos2dKey, false);
|
|
|
|
ax::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::BackButtonListener(EventKeyboard::KeyCode keyCode, Event* event)
|
|
|
|
{
|
|
|
|
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
|
|
|
|
{
|
|
|
|
AXLOG("*********************************************************************");
|
|
|
|
AXLOG("GLViewImpl::BackButtonListener: Exiting application!");
|
|
|
|
AXLOG("");
|
|
|
|
AXLOG("If you want to listen for Windows Phone back button events,");
|
|
|
|
AXLOG("add a listener for EventKeyboard::KeyCode::KEY_ESCAPE");
|
|
|
|
AXLOG("Make sure you call stopPropagation() on the Event if you don't");
|
|
|
|
AXLOG("want your app to exit when the back button is pressed.");
|
|
|
|
AXLOG("");
|
|
|
|
AXLOG("For example, add the following to your scene...");
|
|
|
|
AXLOG("auto listener = EventListenerKeyboard::create();");
|
|
|
|
AXLOG("listener->onKeyReleased = AX_CALLBACK_2(HelloWorld::onKeyReleased, this);");
|
|
|
|
AXLOG("getEventDispatcher()->addEventListenerWithFixedPriority(listener, 1);");
|
|
|
|
AXLOG("");
|
|
|
|
AXLOG("void HelloWorld::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)");
|
|
|
|
AXLOG("{");
|
|
|
|
AXLOG(" if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)");
|
|
|
|
AXLOG(" {");
|
|
|
|
AXLOG(" if (myAppShouldNotQuit) // or whatever logic you want...");
|
|
|
|
AXLOG(" {");
|
|
|
|
AXLOG(" event->stopPropagation();");
|
|
|
|
AXLOG(" }");
|
|
|
|
AXLOG(" }");
|
|
|
|
AXLOG("}");
|
|
|
|
AXLOG("");
|
|
|
|
AXLOG("You MUST call event->stopPropagation() if you don't want your app to quit!");
|
|
|
|
AXLOG("*********************************************************************");
|
|
|
|
|
|
|
|
Director::getInstance()->end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLViewImpl::AppShouldExit()
|
|
|
|
{
|
|
|
|
return m_appShouldExit;
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnPointerPressed(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
OnPointerPressed(args);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnPointerPressed(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
intptr_t id = args.CurrentPoint().PointerId();
|
2023-03-11 22:10:18 +08:00
|
|
|
Vec2 pt = GetPoint(args);
|
|
|
|
handleTouchesBegin(1, &id, &pt.x, &pt.y);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnPointerWheelChanged(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
float direction = (float)args.CurrentPoint().Properties().MouseWheelDelta();
|
2023-03-11 22:10:18 +08:00
|
|
|
intptr_t id = 0;
|
|
|
|
Vec2 p(0.0f, 0.0f);
|
|
|
|
handleTouchesBegin(1, &id, &p.x, &p.y);
|
|
|
|
p.y += direction;
|
|
|
|
handleTouchesMove(1, &id, &p.x, &p.y);
|
|
|
|
handleTouchesEnd(1, &id, &p.x, &p.y);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnVisibilityChanged(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::VisibilityChangedEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
m_windowVisible = args.Visible();
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnWindowClosed(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::CoreWindowEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
m_windowClosed = true;
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnPointerMoved(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
OnPointerMoved(args);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnPointerMoved(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
auto currentPoint = args.CurrentPoint();
|
|
|
|
if (currentPoint.IsInContact())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
if (m_lastPointValid)
|
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
intptr_t id = args.CurrentPoint().PointerId();
|
2023-03-11 22:10:18 +08:00
|
|
|
Vec2 p = GetPoint(args);
|
|
|
|
handleTouchesMove(1, &id, &p.x, &p.y);
|
|
|
|
}
|
2023-09-26 00:11:33 +08:00
|
|
|
m_lastPoint = currentPoint.Position();
|
2023-03-11 22:10:18 +08:00
|
|
|
m_lastPointValid = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lastPointValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnPointerReleased(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
OnPointerReleased(args);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnPointerReleased(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
intptr_t id = args.CurrentPoint().PointerId();
|
2023-03-11 22:10:18 +08:00
|
|
|
Vec2 pt = GetPoint(args);
|
|
|
|
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void ax::GLViewImpl::OnMousePressed(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
Vec2 mousePosition = GetPointMouse(args);
|
|
|
|
|
|
|
|
// Emulated touch, if left mouse button
|
2023-09-26 00:11:33 +08:00
|
|
|
if (args.CurrentPoint().Properties().IsLeftButtonPressed())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
intptr_t id = 0;
|
|
|
|
Vec2 pt = GetPoint(args);
|
|
|
|
handleTouchesBegin(1, &id, &pt.x, &pt.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_lastMouseButtonPressed != EventMouse::MouseButton::BUTTON_UNSET)
|
|
|
|
{
|
|
|
|
EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
|
|
|
|
|
|
|
|
event.setMouseButton(_lastMouseButtonPressed);
|
|
|
|
event.setCursorPosition(mousePosition.x, mousePosition.y);
|
|
|
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventMouse event(EventMouse::MouseEventType::MOUSE_DOWN);
|
|
|
|
// Set current button
|
2023-09-26 00:11:33 +08:00
|
|
|
if (args.CurrentPoint().Properties().IsLeftButtonPressed())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
_lastMouseButtonPressed = EventMouse::MouseButton::BUTTON_LEFT;
|
|
|
|
}
|
2023-09-26 00:11:33 +08:00
|
|
|
else if (args.CurrentPoint().Properties().IsRightButtonPressed())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
_lastMouseButtonPressed = EventMouse::MouseButton::BUTTON_RIGHT;
|
|
|
|
}
|
2023-09-26 00:11:33 +08:00
|
|
|
else if (args.CurrentPoint().Properties().IsMiddleButtonPressed())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
_lastMouseButtonPressed = EventMouse::MouseButton::BUTTON_MIDDLE;
|
|
|
|
}
|
|
|
|
event.setMouseButton(_lastMouseButtonPressed);
|
|
|
|
event.setCursorPosition(mousePosition.x, mousePosition.y);
|
|
|
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void ax::GLViewImpl::OnMouseMoved(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
Vec2 mousePosition = GetPointMouse(args);
|
|
|
|
|
|
|
|
// Emulated touch, if left mouse button
|
2023-09-26 00:11:33 +08:00
|
|
|
if (args.CurrentPoint().Properties().IsLeftButtonPressed())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
intptr_t id = 0;
|
|
|
|
Vec2 pt = GetPoint(args);
|
|
|
|
handleTouchesMove(1, &id, &pt.x, &pt.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventMouse event(EventMouse::MouseEventType::MOUSE_MOVE);
|
|
|
|
// Set current button
|
2023-09-26 00:11:33 +08:00
|
|
|
if (args.CurrentPoint().Properties().IsLeftButtonPressed())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
event.setMouseButton(EventMouse::MouseButton::BUTTON_LEFT);
|
|
|
|
}
|
2023-09-26 00:11:33 +08:00
|
|
|
else if (args.CurrentPoint().Properties().IsRightButtonPressed())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
event.setMouseButton(EventMouse::MouseButton::BUTTON_RIGHT);
|
|
|
|
}
|
2023-09-26 00:11:33 +08:00
|
|
|
else if (args.CurrentPoint().Properties().IsMiddleButtonPressed())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
event.setMouseButton(EventMouse::MouseButton::BUTTON_MIDDLE);
|
|
|
|
}
|
|
|
|
event.setCursorPosition(mousePosition.x, mousePosition.y);
|
|
|
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void ax::GLViewImpl::OnMouseReleased(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
Vec2 mousePosition = GetPointMouse(args);
|
|
|
|
|
|
|
|
// Emulated touch, if left mouse button
|
|
|
|
if (_lastMouseButtonPressed == EventMouse::MouseButton::BUTTON_LEFT)
|
|
|
|
{
|
|
|
|
intptr_t id = 0;
|
|
|
|
Vec2 pt = GetPoint(args);
|
|
|
|
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventMouse event(EventMouse::MouseEventType::MOUSE_UP);
|
|
|
|
|
|
|
|
event.setMouseButton(_lastMouseButtonPressed);
|
|
|
|
event.setCursorPosition(mousePosition.x, mousePosition.y);
|
|
|
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
|
|
|
|
|
|
|
_lastMouseButtonPressed = EventMouse::MouseButton::BUTTON_UNSET;
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void ax::GLViewImpl::OnMouseWheelChanged(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
Vec2 mousePosition = GetPointMouse(args);
|
|
|
|
EventMouse event(EventMouse::MouseEventType::MOUSE_SCROLL);
|
2023-04-02 14:31:51 +08:00
|
|
|
// Because OpenGL and axmol uses different Y axis, we need to convert the coordinate here
|
|
|
|
float cursorX = (mousePosition.x - _viewPortRect.origin.x) / _scaleX;
|
|
|
|
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - mousePosition.y) / _scaleY;
|
2023-09-26 00:11:33 +08:00
|
|
|
float delta = args.CurrentPoint().Properties().MouseWheelDelta();
|
|
|
|
if (args.CurrentPoint().Properties().IsHorizontalMouseWheel())
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-04-02 14:31:51 +08:00
|
|
|
event.setScrollData(delta / WHEEL_DELTA, 0.0f);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-02 14:31:51 +08:00
|
|
|
event.setScrollData(0.0f, -delta / WHEEL_DELTA);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
2023-04-02 14:31:51 +08:00
|
|
|
event.setCursorPosition(cursorX, cursorY);
|
2023-03-11 22:10:18 +08:00
|
|
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::resize(int width, int height) {}
|
|
|
|
|
|
|
|
void GLViewImpl::setFrameZoomFactor(float fZoomFactor)
|
|
|
|
{
|
|
|
|
_frameZoomFactor = fZoomFactor;
|
|
|
|
Director::getInstance()->setProjection(Director::getInstance()->getProjection());
|
|
|
|
// resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
float GLViewImpl::getFrameZoomFactor()
|
|
|
|
{
|
|
|
|
return _frameZoomFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::centerWindow()
|
|
|
|
{
|
|
|
|
// not implemented in WinRT. Window is always full screen
|
|
|
|
}
|
|
|
|
|
2023-12-01 09:04:51 +08:00
|
|
|
GLViewImpl* GLViewImpl::sharedGLView()
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
return s_pEglView;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GLViewImpl::Run()
|
|
|
|
{
|
|
|
|
// XAML version does not have a run loop
|
|
|
|
m_running = true;
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void GLViewImpl::Render()
|
|
|
|
{
|
|
|
|
OnRendering();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::OnRendering()
|
|
|
|
{
|
|
|
|
if (m_running && m_initialized)
|
|
|
|
{
|
|
|
|
Director::getInstance()->mainLoop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// called by orientation change from WP8 XAML
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::UpdateOrientation(Windows::Graphics::Display::DisplayOrientations orientation)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
if (m_orientation != orientation)
|
|
|
|
{
|
|
|
|
m_orientation = orientation;
|
|
|
|
UpdateWindowSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// called by size change from WP8 XAML
|
|
|
|
void GLViewImpl::UpdateForWindowSizeChange(float width, float height)
|
|
|
|
{
|
|
|
|
if (width != m_width || height != m_height)
|
|
|
|
{
|
|
|
|
m_width = width;
|
|
|
|
m_height = height;
|
|
|
|
UpdateWindowSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::UpdateWindowSize()
|
|
|
|
{
|
|
|
|
float width, height;
|
|
|
|
|
|
|
|
width = m_width;
|
|
|
|
height = m_height;
|
|
|
|
|
|
|
|
// CCSize designSize = getDesignResolutionSize();
|
|
|
|
if (!m_initialized)
|
|
|
|
{
|
|
|
|
m_initialized = true;
|
|
|
|
GLView::setFrameSize(width, height);
|
|
|
|
}
|
|
|
|
|
2023-12-01 09:04:51 +08:00
|
|
|
auto view = Director::getInstance()->getGLView();
|
2023-03-11 22:10:18 +08:00
|
|
|
if (view && view->getResolutionPolicy() != ResolutionPolicy::UNKNOWN)
|
|
|
|
{
|
|
|
|
Size resSize = view->getDesignResolutionSize();
|
|
|
|
ResolutionPolicy resPolicy = view->getResolutionPolicy();
|
|
|
|
view->setFrameSize(width, height);
|
|
|
|
view->setDesignResolutionSize(resSize.width, resSize.height, resPolicy);
|
|
|
|
auto director = Director::getInstance();
|
|
|
|
director->setViewport();
|
|
|
|
director->setProjection(director->getProjection());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
ax::Vec2 GLViewImpl::TransformToOrientation(Windows::Foundation::Point const& p)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
ax::Vec2 returnValue;
|
|
|
|
|
|
|
|
float x = p.X;
|
|
|
|
float y = p.Y;
|
|
|
|
returnValue = Vec2(x, y);
|
|
|
|
|
2023-12-01 09:04:51 +08:00
|
|
|
float zoomFactor = GLViewImpl::sharedGLView()->getFrameZoomFactor();
|
2023-03-11 22:10:18 +08:00
|
|
|
if (zoomFactor > 0.0f)
|
|
|
|
{
|
|
|
|
returnValue.x /= zoomFactor;
|
|
|
|
returnValue.y /= zoomFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// AXLOG("%.2f %.2f : %.2f %.2f", p.X, p.Y,returnValue.x, returnValue.y);
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
Vec2 GLViewImpl::GetPoint(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
return TransformToOrientation(args.CurrentPoint().Position());
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
Vec2 GLViewImpl::GetPointMouse(Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
Vec2 position = TransformToOrientation(args.CurrentPoint().Position());
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
// Because Windows and axmol uses different Y axis, we need to convert the coordinate here
|
2023-03-11 22:10:18 +08:00
|
|
|
position.x = (position.x - _viewPortRect.origin.x) / _scaleX;
|
|
|
|
position.y = (_viewPortRect.origin.y + _viewPortRect.size.height - position.y) / _scaleY;
|
|
|
|
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::QueueBackKeyPress()
|
|
|
|
{
|
|
|
|
std::shared_ptr<BackButtonEvent> e(new BackButtonEvent());
|
|
|
|
mInputEvents.push(e);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
std::shared_ptr<PointerEvent> e(new PointerEvent(type, args));
|
|
|
|
mInputEvents.push(e);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::QueueWinRTKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
|
|
|
std::shared_ptr<WinRTKeyboardEvent> e(new WinRTKeyboardEvent(type, args));
|
|
|
|
mInputEvents.push(e);
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void GLViewImpl::OnWinRTKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs const& args)
|
2023-03-11 22:10:18 +08:00
|
|
|
{
|
2023-09-26 00:11:33 +08:00
|
|
|
m_keyboard.OnWinRTKeyboardEvent(type, args);
|
2023-03-11 22:10:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::QueueEvent(std::shared_ptr<InputEvent>& event)
|
|
|
|
{
|
|
|
|
mInputEvents.push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::ProcessEvents()
|
|
|
|
{
|
|
|
|
std::shared_ptr<InputEvent> e;
|
|
|
|
while (mInputEvents.try_pop(e))
|
|
|
|
{
|
|
|
|
e->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-31 20:42:39 +08:00
|
|
|
void GLViewImpl::SetQueueOperationCb(std::function<void(AsyncOperation, void*)> cb)
|
|
|
|
{
|
|
|
|
mQueueOperationCb = std::move(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLViewImpl::queueOperation(AsyncOperation op, void* param)
|
|
|
|
{
|
|
|
|
if (mQueueOperationCb)
|
|
|
|
mQueueOperationCb(std::move(op), param);
|
|
|
|
}
|
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
NS_AX_END
|