2023-03-11 22:10:18 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __AX_EGLVIEWIMPL_WINRT_H__
|
|
|
|
#define __AX_EGLVIEWIMPL_WINRT_H__
|
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/winrt/StdC-winrt.h"
|
|
|
|
#include "platform/Common.h"
|
2023-03-11 22:10:18 +08:00
|
|
|
#include "platform/winrt/Keyboard-winrt.h"
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/GLView.h"
|
|
|
|
#include "base/EventKeyboard.h"
|
|
|
|
#include "base/EventMouse.h"
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
#include <concurrent_queue.h>
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2023-09-26 00:11:33 +08:00
|
|
|
|
|
|
|
#include <winrt/Windows.Foundation.h>
|
|
|
|
#include <winrt/Windows.Graphics.Display.h>
|
|
|
|
|
|
|
|
using namespace winrt;
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
NS_AX_BEGIN
|
|
|
|
|
|
|
|
class GLViewImpl;
|
|
|
|
|
|
|
|
class AX_DLL GLViewImpl : public GLView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static GLViewImpl* create(std::string_view viewName);
|
2023-03-25 16:08:48 +08:00
|
|
|
static GLViewImpl* createWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor = 1.0f, bool resizable = false);
|
2023-03-11 23:19:52 +08:00
|
|
|
static GLViewImpl* createWithFullScreen(std::string_view viewName);
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
/* override functions */
|
|
|
|
virtual bool isOpenGLReady();
|
|
|
|
virtual void end();
|
|
|
|
virtual void swapBuffers();
|
|
|
|
|
|
|
|
Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() { return m_orientation; };
|
|
|
|
Size getRenerTargetSize() const { return Size(m_width, m_height); }
|
|
|
|
|
|
|
|
virtual void setIMEKeyboardState(bool bOpen) override;
|
|
|
|
virtual void setIMEKeyboardState(bool bOpen, std::string_view str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide or Show the mouse cursor if there is one.
|
|
|
|
*
|
|
|
|
* @param isVisible Hide or Show the mouse cursor if there is one.
|
|
|
|
*/
|
|
|
|
virtual void setCursorVisible(bool isVisible) override;
|
|
|
|
|
|
|
|
bool isCursorVisible() { return _isCursorVisible; }
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
void setDispatcher(winrt::agile_ref<Windows::UI::Core::CoreDispatcher> dispatcher);
|
|
|
|
winrt::agile_ref<Windows::UI::Core::CoreDispatcher> getDispatcher() const { return m_dispatcher; }
|
|
|
|
|
|
|
|
void setPanel(winrt::agile_ref<Windows::UI::Xaml::Controls::Panel> panel);
|
|
|
|
winrt::agile_ref<Windows::UI::Xaml::Controls::Panel> getPanel() { return m_panel; }
|
|
|
|
|
|
|
|
void OnPointerPressed(Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnPointerMoved(Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnPointerReleased(Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
|
|
|
|
void OnMousePressed(Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnMouseMoved(Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnMouseReleased(Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnMouseWheelChanged(Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
|
|
|
|
void OnWinRTKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs const& args);
|
|
|
|
|
|
|
|
void OnPointerPressed(Windows::UI::Core::CoreWindow const& sender, Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnPointerWheelChanged(Windows::UI::Core::CoreWindow const&, Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnPointerMoved(Windows::UI::Core::CoreWindow const&, Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnPointerReleased(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void OnVisibilityChanged(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::VisibilityChangedEventArgs const& args);
|
|
|
|
void OnWindowClosed(Windows::UI::Core::CoreWindow const& sender,
|
|
|
|
Windows::UI::Core::CoreWindowEventArgs const& args);
|
|
|
|
void OnResuming(Windows::Foundation::IInspectable const& sender);
|
|
|
|
void OnSuspending(Windows::Foundation::IInspectable const& sender,
|
|
|
|
Windows::ApplicationModel::SuspendingEventArgs const& args);
|
2023-03-11 22:10:18 +08:00
|
|
|
void OnBackKeyPress();
|
|
|
|
bool AppShouldExit();
|
|
|
|
void BackButtonListener(ax::EventKeyboard::KeyCode keyCode, ax::Event* event);
|
|
|
|
|
|
|
|
void QueueBackKeyPress();
|
2023-09-26 00:11:33 +08:00
|
|
|
void QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
void QueueWinRTKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs const& args);
|
2023-03-11 22:10:18 +08:00
|
|
|
void QueueEvent(std::shared_ptr<InputEvent>& event);
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
bool ShowMessageBox(const winrt::hstring& title, const winrt::hstring& message);
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
int Run();
|
|
|
|
void Render();
|
|
|
|
|
|
|
|
void resize(int width, int height);
|
|
|
|
|
|
|
|
float getFrameZoomFactor();
|
|
|
|
void centerWindow();
|
|
|
|
|
|
|
|
void UpdateOrientation(Windows::Graphics::Display::DisplayOrientations orientation);
|
|
|
|
void UpdateForWindowSizeChange(float width, float height);
|
|
|
|
|
|
|
|
void SetDPI(float dpi) { m_dpi = dpi; }
|
|
|
|
float GetDPI() { return m_dpi; }
|
|
|
|
// static function
|
|
|
|
/**
|
|
|
|
@brief get the shared main open gl window
|
|
|
|
*/
|
2023-12-01 09:04:51 +08:00
|
|
|
static GLViewImpl* sharedGLView();
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
void ProcessEvents();
|
|
|
|
|
2023-05-31 20:42:39 +08:00
|
|
|
void queueOperation(AsyncOperation op, void* param) override;
|
|
|
|
|
|
|
|
void SetQueueOperationCb(std::function<void(AsyncOperation, void*)> cb);
|
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
protected:
|
|
|
|
GLViewImpl();
|
|
|
|
virtual ~GLViewImpl();
|
|
|
|
|
2023-03-11 22:53:55 +08:00
|
|
|
bool initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor);
|
2023-03-11 22:10:18 +08:00
|
|
|
bool initWithFullScreen(std::string_view viewName);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
|
|
|
|
*/
|
|
|
|
void setFrameZoomFactor(float zoomFactor);
|
|
|
|
|
|
|
|
inline bool isRetina() { return _isRetina; };
|
|
|
|
|
|
|
|
float _frameZoomFactor;
|
|
|
|
bool _supportTouch;
|
|
|
|
bool _isRetina;
|
|
|
|
bool _isCursorVisible;
|
|
|
|
|
|
|
|
private:
|
|
|
|
AX_DISALLOW_COPY_AND_ASSIGN(GLViewImpl);
|
|
|
|
|
|
|
|
void OnRendering();
|
|
|
|
void UpdateWindowSize();
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
ax::Vec2 TransformToOrientation(Windows::Foundation::Point const& point);
|
|
|
|
ax::Vec2 GetPoint(Windows::UI::Core::PointerEventArgs const& args);
|
|
|
|
ax::Vec2 GetPointMouse(Windows::UI::Core::PointerEventArgs const& args);
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
Windows::Foundation::Rect m_windowBounds;
|
2023-09-26 00:11:33 +08:00
|
|
|
winrt::event_token m_eventToken;
|
2023-03-11 22:10:18 +08:00
|
|
|
Windows::Foundation::Point m_lastPoint;
|
|
|
|
|
|
|
|
float m_width;
|
|
|
|
float m_height;
|
|
|
|
float m_dpi;
|
|
|
|
Windows::Graphics::Display::DisplayOrientations m_orientation;
|
|
|
|
Windows::Foundation::Rect m_keyboardRect;
|
|
|
|
|
|
|
|
bool m_lastPointValid;
|
|
|
|
bool m_windowClosed;
|
|
|
|
bool m_windowVisible;
|
|
|
|
// PointerReleased for mouse not send button id, need save in PointerPressed last button
|
|
|
|
EventMouse::MouseButton _lastMouseButtonPressed;
|
|
|
|
|
|
|
|
bool m_running;
|
|
|
|
bool m_initialized;
|
|
|
|
bool m_appShouldExit;
|
|
|
|
|
|
|
|
Concurrency::concurrent_queue<std::shared_ptr<InputEvent>> mInputEvents;
|
|
|
|
|
2023-05-31 20:42:39 +08:00
|
|
|
std::function<void(AsyncOperation, void*)> mQueueOperationCb;
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
winrt::agile_ref<Windows::UI::Core::CoreDispatcher> m_dispatcher;
|
|
|
|
winrt::agile_ref<Windows::UI::Xaml::Controls::Panel> m_panel;
|
2023-03-11 22:10:18 +08:00
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
KeyBoardWinRT m_keyboard;
|
2023-03-11 22:10:18 +08:00
|
|
|
|
|
|
|
ax::EventListenerKeyboard* m_backButtonListener;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_AX_END
|
|
|
|
|
|
|
|
#endif // end of __AX_EGLVIEWIMPL_WINRT_H__
|