3#include <Covellite/Os/Window.hpp>
4#include <alicorn/platform/environment.hpp>
5#include <Covellite/Events.hpp>
6#include <Covellite/App/IApplication.hpp>
7#include <Covellite/Os/Events.hpp>
9using AppInfo_t = ::alicorn::system::platform::AppInfo;
17Window::Window(const ::covellite::app::IApplication & _Application) :
18 m_Events(_Application),
20 m_LastTypeSizeMessage(0)
22 ActivateResizeEvents();
23 ActivateMouseEvents();
27Window::~Window(
void) =
default;
49Rect Window::GetClientRect(
void)
const
54 ::alicorn::system::platform::Environment{}.GetStatusBarHeight(),
55 ANativeWindow_getWidth(::covellite::any_cast<ANativeWindow *>(m_Handle)),
56 ANativeWindow_getHeight(::covellite::any_cast<ANativeWindow *>(m_Handle))
60void Window::ActivateApplicationEvents(
void)
65void Window::ActivateResizeEvents(
void)
67 m_Events[(int32_t)APP_CMD_WINDOW_REDRAW_NEEDED].Connect([=](
void)
69 m_Events[events::Window.Resize]();
73void Window::ActivateMouseEvents(
void)
75 using AInputEvent_t = AInputEvent *;
77 auto BuildMessage = [](int32_t _Type, int32_t _Value) -> int32_t
79 return (_Type << 8) | _Value;
83 BuildMessage(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_MOVE);
85 m_Events[Motion].Connect([=](
const AInputEvent_t & _pEvent)
87 const auto X =
static_cast<int32_t
>(AMotionEvent_getX(_pEvent, 0));
88 const auto Y =
static_cast<int32_t
>(AMotionEvent_getY(_pEvent, 0));
90 m_Events[events::Cursor.Motion](events::Cursor_t::Position{ X, Y });
94 BuildMessage(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN);
96 m_Events[Touch].Connect([=](
const AInputEvent_t & _pEvent)
98 const auto X =
static_cast<int32_t
>(AMotionEvent_getX(_pEvent, 0));
99 const auto Y =
static_cast<int32_t
>(AMotionEvent_getY(_pEvent, 0));
103 m_Events[events::Cursor.Motion](events::Cursor_t::Position{ X, Y });
104 m_Events[events::Cursor.Touch]();
108 BuildMessage(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_UP);
110 m_Events[Release].Connect([=](
const AInputEvent_t & _pEvent)
112 const auto X =
static_cast<int32_t
>(AMotionEvent_getX(_pEvent, 0));
113 const auto Y =
static_cast<int32_t
>(AMotionEvent_getY(_pEvent, 0));
117 m_Events[events::Cursor.Motion](events::Cursor_t::Position{ X, Y });
118 m_Events[events::Cursor.Release]();
122void Window::ActivateKeyEvents(
void)
124 using AInputEvent_t = AInputEvent *;
126 auto BuildMessage = [](int32_t _Type, int32_t _Value) -> int32_t
128 return (_Type << 8) | _Value;
132 BuildMessage(AINPUT_EVENT_TYPE_KEY, events::Key_t::APP_CMD_KEY_PRESSED);
134 m_Events[Pressed].Connect([=](
const AInputEvent_t & _pEvent)
136 const events::Key_t::Code Code = AKeyEvent_getKeyCode(_pEvent);
138 m_Events[events::Key.Pressed](Code);
142 BuildMessage(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_DOWN);
144 m_Events[Down].Connect([=](
const AInputEvent_t & _pEvent)
146 const events::Key_t::Code Code = AKeyEvent_getKeyCode(_pEvent);
148 m_Events[events::Key.Down](Code);
152 BuildMessage(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP);
154 m_Events[Up].Connect([=](
const AInputEvent_t & _pEvent)
156 const events::Key_t::Code Code = AKeyEvent_getKeyCode(_pEvent);
158 if (Code == AKEYCODE_BACK)
160 m_Events[events::Key.Back]();
162 else if (Code == AKEYCODE_MENU)
164 m_Events[events::Key.Menu]();
168 m_Events[events::Key.Up](Code);
Definition android_native_app_glue.h:111