28 Shown, Hidden, Exposed, SizeChanged, Minimized, Maximized, FullScreen, Restored, Enter, Leave, Focus, UnFocus,
29 Close, Moved, Resized,
32 using WindowStateChangeCallback = std::function<void(Application&, WindowEventType)>;
33 using WindowPositionChangeCallback = std::function<void(Application&, WindowEventType, Position<int>&)>;
34 using WindowSizeChangeCallback = std::function<void(Application&, WindowEventType, Size)>;
35 using KeyboardEventCallback = std::function<bool(Application&, const SDL_KeyboardEvent&)>;
36 using MouseMotionEventCallback = std::function<bool(Application&, const SDL_MouseMotionEvent&)>;
37 using MouseButtonEventCallback = std::function<bool(Application&, const SDL_MouseButtonEvent&)>;
38 using MouseWheelEventCallback = std::function<bool(Application&, const SDL_MouseWheelEvent&)>;
39 using FingerTouchEventCallback = std::function<bool(Application&, const SDL_TouchFingerEvent&)>;
40 using TextInputEventCallback = std::function<bool(Application&, const SDL_TextInputEvent&)>;
45 WindowSizeChangeCallback windowSizeChangeCallback;
46 WindowPositionChangeCallback windowPositionChangeCallback;
47 WindowStateChangeCallback windowStateChangeCallback;
48 KeyboardEventCallback keyboardEventCallback;
49 MouseMotionEventCallback mouseMotionEventCallback;
50 MouseButtonEventCallback mouseButtonEventCallback;
51 MouseWheelEventCallback mouseWheelEventCallback;
52 FingerTouchEventCallback fingerTouchEventCallback;
53 TextInputEventCallback textInputEventCallback;
56 if (windowStateChangeCallback)
57 windowStateChangeCallback(mApplication, type);
61 if (windowSizeChangeCallback)
62 windowSizeChangeCallback(mApplication, type, size);
66 if (windowPositionChangeCallback)
67 windowPositionChangeCallback(mApplication, type, position);
75 void onEvent(SDL_Event &e);
77 void windowEvent(SDL_WindowEvent &e);
79 void keyboardEvent(SDL_KeyboardEvent &e);
81 void mouseMotionEvent(SDL_MouseMotionEvent &e);
83 void mouseButtonEvent(SDL_MouseButtonEvent &e);
85 void mouseWheelEvent(SDL_MouseWheelEvent &e);
87 void fingerTouchEvent(SDL_TouchFingerEvent &e);
89 void textInputEvent(SDL_TextInputEvent &e);
91 void setWindowStateChangeCallback(WindowStateChangeCallback callback) {
92 windowStateChangeCallback = std::move(callback);
95 void setWindowPositionChangeCallback(WindowPositionChangeCallback callback) {
96 windowPositionChangeCallback = std::move(callback);
99 void setWindowSizeChangeCallback(WindowSizeChangeCallback callback) {
100 windowSizeChangeCallback = std::move(callback);
103 void setKeyboardEventCallback(KeyboardEventCallback callback) {
104 keyboardEventCallback = std::move(callback);
107 void setMouseMotionEventCallback(MouseMotionEventCallback callback) {
108 mouseMotionEventCallback = std::move(callback);
111 void setMouseButtonEventCallback(MouseButtonEventCallback callback) {
112 mouseButtonEventCallback = std::move(callback);
115 void setMouseWheelEventCallback(MouseWheelEventCallback callback) {
116 mouseWheelEventCallback = std::move(callback);
119 void setFingerTouchEventCallback(FingerTouchEventCallback callback) {
120 fingerTouchEventCallback = std::move(callback);
123 void setTextInputEventCallback(TextInputEventCallback callback) {
124 textInputEventCallback = std::move(callback);
140 for (
int i = 1; i < argc; ++i)
141 this->tokens.emplace_back(argv[i]);
145 [[nodiscard]]
const std::string &
getCmdOption(
const std::string_view &option)
const {
146 std::vector<std::string>::const_iterator itr;
147 itr = std::find(this->tokens.begin(), this->tokens.end(), option);
148 if (itr != this->tokens.end() && ++itr != this->tokens.end()) {
151 static const std::string empty_string;
157 return std::find(this->tokens.begin(), this->tokens.end(), option)
158 != this->tokens.end();
162 std::vector<std::string> tokens;
171 static constexpr std::string_view UsbDeviceByPath{
"/dev/input/by-path/"};
172 static constexpr std::string_view KeyboardPathRegEx{
".*-kbd"};
174 std::shared_ptr<Screen> mScreen{};
180 std::shared_ptr<Widget> mPointerWidget{};
181 std::shared_ptr<Widget> mClickFocusWidget{};
182 std::shared_ptr<Widget> mDragFocusWidget{};
183 std::shared_ptr<Widget> mScrollFocusWidget{};
184 std::shared_ptr<Widget> mKeyFocusWidget{};
186 std::map<SDL_Keycode, std::pair<uint32_t,std::weak_ptr<Widget>>> mKeyboardShortcuts{};
188 bool mMouseButtonPressed{
false};
189 uint mMouseButtonId{0};
199 virtual void initialize(
const std::string &title,
Size defaultSize);
207 virtual bool keyboardEventCallback(
const SDL_KeyboardEvent& keyboardEvent);
209 virtual bool mouseMotionEventCallback(
const SDL_MouseMotionEvent& mouseMotionEvent);
211 virtual bool mouseButtonEventCallback(
const SDL_MouseButtonEvent& mouseButtonEvent);
213 virtual bool mouseWheelEventCallback(
const SDL_MouseWheelEvent& mouseWheelEvent);
215 virtual bool fingerTouchEventCallback(
const SDL_TouchFingerEvent& fingerTouchEvent);
217 virtual bool textInputEventCallback(
const SDL_TextInputEvent& textInputEvent);
219 gm::Context& context() {
return mGraphicsModel.context(); }
221 std::shared_ptr<Screen>& screen() {
return mScreen; }
225 std::shared_ptr<Widget> pointerWidget(
const Position<int>& position);
227 [[nodiscard]]
Padding windowBorders()
const noexcept {
228 return mGraphicsModel.windowBorders();
232 return mGraphicsModel.getSdlWindow();
235 void capturePointerWidget(std::shared_ptr<Widget> widget) {
237 mPointerWidget->leaveEvent();
238 mPointerWidget = std::move(widget);
241 void captureScrollWheelWidget(std::shared_ptr<Widget> widget) {
243 mPointerWidget->leaveEvent();
244 mPointerWidget = std::move(widget);
248 registerKeyboardShortcut(SDL_Keycode keycode,
const std::shared_ptr<Widget> &widget, uint32_t shortcutCode) {
249 std::cout << __PRETTY_FUNCTION__ <<
" keycode: " << keycode <<
'\n';
250 mKeyboardShortcuts[keycode] = std::make_pair(shortcutCode, widget);
253 void redrawBackground() {
254 mGraphicsModel.redrawBackground();
257 [[nodiscard]]
bool keyboardFound()
const noexcept {
258 return mKeyboardFound;
Definition: Application.h:169
WindowEventType
The type of window event.
Definition: Application.h:27
A class to process event semantics.
Definition: Application.h:21
Application & mApplication
The Application the EventSemantics are processed for.
Definition: Application.h:44
Abstraction of space consumed around an object for space, borders, etc.
Definition: Types.h:454
Context
Definition: GraphicsModel.h:76
Abstraction of the graphics model.
std::unique_ptr< SDL_Window, SdlWindowDestroy > SdlWindow
An SDL_Window unique pointer.
Definition: GraphicsModel.h:44
A size in integer dimensions.
Definition: Types.h:230
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
Definition: GraphicsModel.h:461
User Interface Visual types.