Gamp v0.0.7-36-g24b1eb6
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
WinEvent.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2025 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24#ifndef GAMP_WTWINEVENT_HPP_
25#define GAMP_WTWINEVENT_HPP_
26
27#include <jau/bitfield.hpp>
28#include <jau/int_types.hpp>
29#include <jau/enum_util.hpp>
30#include <jau/int_math_ct.hpp>
31#include <jau/fraction_type.hpp>
32#include <jau/cow_darray.hpp>
33#include <jau/math/recti.hpp>
34
36
37namespace gamp::wt::event {
38 /** \addtogroup Gamp_WT
39 *
40 * @{
41 */
42 class WindowEvent : public WTEvent {
43 private:
44
45 std::string getEventTypeString() const noexcept {
46 switch(type()) {
47 case EVENT_WINDOW_RESIZED: return "RESIZED";
48 case EVENT_WINDOW_MOVED: return "MOVED";
49 case EVENT_WINDOW_DESTROY_NOTIFY: return "DESTROY_NOTIFY";
50 case EVENT_WINDOW_FOCUS_CHANGED: return "FOCUS";
51 case EVENT_WINDOW_REPAINT: return "REPAINT";
52 case EVENT_WINDOW_DESTROYED: return "DESTROYED";
53 case EVENT_WINDOW_VISIBILITY_CHANGED: return "VISIBILITY";
54 default: return "unknown (" + std::to_string(type()) + ")";
55 }
56 }
57
58 public:
59 WindowEvent(uint16_t type, const jau::fraction_timespec& when, const WindowRef& source) noexcept
61 { }
62
63 std::string toString() const noexcept {
64 std::string res = "WindowEvent[";
65 res.append(getEventTypeString()).append(", ").append(WTEvent::toString()).append("]");
66 return res;
67 }
68 };
69 inline std::ostream& operator<<(std::ostream& out, const WindowEvent& v) {
70 return out << v.toString();
71 }
72
73 /**
74 * Listener for multiple WindowEvent.
75 *
76 * @see WindowEvent
77 */
79 {
80 public:
81 virtual ~WindowListener() noexcept = default;
82
83 /** Window is resized, your application shall respect the new window-size in window units and surface-size in pixel. A repaint is recommended. */
84 virtual void windowResized(WindowEvent&, const jau::math::Vec2i& /*winSize*/, const jau::math::Vec2i& /*surfSize*/) {}
85
86 /** Window has been moved to given windows-position in window units. */
87 virtual void windowMoved(WindowEvent&, const jau::math::Vec2i& /*winPos*/) {}
88
89 /**
90 * Window destruction has been requested.
91 * <p>
92 * Depending on the {@link WindowClosingProtocol#getDefaultCloseOperation() default close operation},
93 * the window maybe destroyed or not.
94 * </p>
95 * In case the window will be destroyed (see above), release of resources is recommended.
96 **/
98
99 /**
100 * Window has been destroyed.
101 */
102 virtual void windowDestroyed(WindowEvent&) {}
103
104 /** Window gained or lost focus. */
105 virtual void windowFocusChanged(WindowEvent&, bool /*focused*/) {}
106
107 /** Window area shall be repainted. */
108 virtual void windowRepaint(WindowEvent&) {} // FIXME: WindowUpdateEvent
109
110 /** Window visibility changed. */
111 virtual void windowVisibilityChanged(WindowEvent&, bool /*visible*/) {}
112 };
113 typedef std::shared_ptr<WindowListener> WindowListenerRef;
114
115 /**@}*/
116}
117
118#endif /* GAMP_WTWINEVENT_HPP_ */
constexpr const WindowWeakPtr & source() const noexcept
Definition Event.hpp:85
constexpr const jau::fraction_timespec & when() const noexcept
Definition Event.hpp:84
constexpr uint16_t type() const noexcept
Definition Event.hpp:83
std::string toString() const noexcept
Definition Event.hpp:91
WTEvent(uint16_t type, const jau::fraction_timespec &when, const WindowRef &source) noexcept
Definition Event.hpp:80
std::string toString() const noexcept
Definition WinEvent.hpp:63
WindowEvent(uint16_t type, const jau::fraction_timespec &when, const WindowRef &source) noexcept
Definition WinEvent.hpp:59
Listener for multiple WindowEvent.
Definition WinEvent.hpp:79
virtual void windowRepaint(WindowEvent &)
Window area shall be repainted.
Definition WinEvent.hpp:108
virtual ~WindowListener() noexcept=default
virtual void windowFocusChanged(WindowEvent &, bool)
Window gained or lost focus.
Definition WinEvent.hpp:105
virtual void windowVisibilityChanged(WindowEvent &, bool)
Window visibility changed.
Definition WinEvent.hpp:111
virtual void windowResized(WindowEvent &, const jau::math::Vec2i &, const jau::math::Vec2i &)
Window is resized, your application shall respect the new window-size in window units and surface-siz...
Definition WinEvent.hpp:84
virtual void windowDestroyed(WindowEvent &)
Window has been destroyed.
Definition WinEvent.hpp:102
virtual void windowDestroyNotify(WindowEvent &)
Window destruction has been requested.
Definition WinEvent.hpp:97
virtual void windowMoved(WindowEvent &, const jau::math::Vec2i &)
Window has been moved to given windows-position in window units.
Definition WinEvent.hpp:87
std::ostream & operator<<(std::ostream &os, const T v)
static constexpr uint16_t EVENT_WINDOW_RESIZED
Definition Event.hpp:48
std::shared_ptr< WindowListener > WindowListenerRef
Definition WinEvent.hpp:113
static constexpr uint16_t EVENT_WINDOW_MOVED
Definition Event.hpp:49
static constexpr uint16_t EVENT_WINDOW_DESTROY_NOTIFY
Definition Event.hpp:50
static constexpr uint16_t EVENT_WINDOW_DESTROYED
Definition Event.hpp:53
static constexpr uint16_t EVENT_WINDOW_REPAINT
Definition Event.hpp:52
std::shared_ptr< Window > WindowRef
Definition Event.hpp:36
static constexpr uint16_t EVENT_WINDOW_FOCUS_CHANGED
Definition Event.hpp:51
static constexpr uint16_t EVENT_WINDOW_VISIBILITY_CHANGED
Definition Event.hpp:54
Vector2I< int > Vec2i
Definition vec2i.hpp:328
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition backtrace.hpp:32
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...