1.11
window.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_WINDOW_H
7#define EGT_WINDOW_H
8
14#include <egt/detail/meta.h>
15#include <egt/frame.h>
16#include <egt/image.h>
17#include <egt/label.h>
18#include <egt/screen.h>
19#include <egt/widgetflags.h>
20#include <memory>
21
22namespace egt
23{
24inline namespace v1
25{
26
27namespace detail
28{
29class WindowImpl;
30class PlaneWindow;
31}
32
46class EGT_API Window : public Frame
47{
48public:
49
54
66 explicit Window(PixelFormat format_hint = DEFAULT_FORMAT,
67 WindowHint hint = WindowHint::automatic)
68 : Window({}, format_hint, hint)
69 {}
70
83 explicit Window(const Rect& rect,
84 PixelFormat format_hint = DEFAULT_FORMAT,
85 WindowHint hint = WindowHint::automatic);
86
100 Window(Frame& parent,
101 const Rect& rect,
102 PixelFormat format_hint = DEFAULT_FORMAT,
103 WindowHint hint = WindowHint::automatic);
110 : Window(props, false)
111 {
112 }
113
114protected:
115
116 explicit Window(Serializer::Properties& props, bool is_derived);
117
118public:
119
120 Window(const Window&) = delete;
121 Window& operator=(const Window&) = delete;
122 Window(Window&&) noexcept;
123 Window& operator=(Window&&) noexcept;
124
125 using Frame::damage;
126
127 void damage(const Rect& rect) override;
128
133 EGT_NODISCARD Screen* screen() const override;
134
135 EGT_NODISCARD bool has_screen() const override;
136
137 void move(const Point& point) override;
138
139 void show() override;
140
141 void hide() override;
142
143 void resize(const Size& size) override;
144
145 using Frame::scale;
146
147 void scale(float hscale, float vscale) override;
148
152 EGT_NODISCARD float hscale() const
153 {
154 return m_hscale;
155 }
156
160 EGT_NODISCARD float vscale() const
161 {
162 return m_vscale;
163 }
164
165 /*
166 * Damage rectangles propagate up the widget tree and stop at a top level
167 * widget, which can only be a window. As it propagates up, the damage
168 * rectangle origin changes value to respect the current frame. When
169 * drawing those rectangles, as they propagate down the widget hierarchy
170 * the opposite change happens to the rectangle origin.
171 */
172 void begin_draw() override;
173 using Frame::begin_draw;
174
178 EGT_NODISCARD PixelFormat format() const
179 {
180 auto frame = find_screen();
181 if (frame)
182 return frame->screen()->format();
183
184 return PixelFormat::invalid;
185 }
186
193 void format_hint(PixelFormat format_hint)
194 {
195 m_format_hint = format_hint;
196 }
197
205 EGT_NODISCARD PixelFormat format_hint() const { return m_format_hint; }
206
214 {
215 m_hint = hint;
216 }
217
224 EGT_NODISCARD WindowHint window_hint() const { return m_hint; }
225
226 void serialize(Serializer& serializer) const override;
227
228 ~Window() noexcept override;
229
230protected:
231
236 virtual void do_draw();
237
239 virtual void allocate_screen();
240
244 void create_impl(const Rect& rect,
245 PixelFormat format_hint,
246 WindowHint hint);
247
249 virtual void default_damage(const Rect& rect)
250 {
251 Frame::damage(rect);
252 }
253
255 virtual void default_resize(const Size& size)
256 {
257 Frame::resize(size);
258 }
259
261 virtual void default_scale(float scalex, float scaley)
262 {
263 Frame::scale(scalex, scaley);
264 }
265
267 virtual void default_move(const Point& point)
268 {
269 Frame::move(point);
270 }
271
273 virtual void default_begin_draw()
274 {
275 if (m_parent)
276 {
277 begin_draw(m_parent);
278 return;
279 }
280
281 do_draw();
282 }
283
285 virtual void default_show()
286 {
287 Frame::show();
288 }
289
291 virtual void default_hide()
292 {
293 Frame::hide();
294 }
295
297 std::unique_ptr<detail::WindowImpl> m_impl;
298
301
303 PixelFormat m_format_hint;
304
306 WindowHint m_hint;
307
309 float m_hscale{1.0};
310
312 float m_vscale{1.0};
313
314 friend class detail::WindowImpl;
315 friend class detail::PlaneWindow;
316};
317
325// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
326class EGT_API TopWindow : public Window
327{
328public:
329
330 using Window::Window;
331
332 TopWindow& operator=(const TopWindow&) = delete;
334
336 void show_cursor(const Image& image = Image("res:internal_cursor"));
337
340
341 ~TopWindow() noexcept override;
342
343protected:
344
346 void handle_mouse(Event& event);
347
349 std::unique_ptr<Window> m_cursor;
350
351private:
352
354 Object::RegisterHandle m_handle{0};
355};
356
357}
358}
359
360#endif
A Frame is a Widget that has children widgets.
Definition frame.h:45
Raster image resource used for drawing or displaying.
Definition image.h:38
Base object class with fundamental properties.
Definition object.h:32
uint64_t RegisterHandle
Handle type.
Definition object.h:61
Manages one of more buffers that make up a Screen.
Definition screen.h:39
Abstract base serializer class.
Definition serialize.h:34
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
Top level Window.
Definition window.h:327
TopWindow & operator=(TopWindow &&)=default
void hide_cursor()
Hide the cursor.
~TopWindow() noexcept override
TopWindow & operator=(const TopWindow &)=delete
void show_cursor(const Image &image=Image("res:internal_cursor"))
Show the cursor.
A Window is a Widget that handles drawing to a Screen.
Definition window.h:47
EGT_NODISCARD PixelFormat format_hint() const
Get the pixel format hint of the window.
Definition window.h:205
Window(Serializer::Properties &props, bool is_derived)
void main_window()
Set this window as the main window.
void format_hint(PixelFormat format_hint)
Set the pixel format hint of the window.
Definition window.h:193
Window(Serializer::Properties &props)
Construct a window.
Definition window.h:109
Window(const Rect &rect, PixelFormat format_hint=DEFAULT_FORMAT, WindowHint hint=WindowHint::automatic)
Construct a window.
Window(Frame &parent, const Rect &rect, PixelFormat format_hint=DEFAULT_FORMAT, WindowHint hint=WindowHint::automatic)
Construct a window.
EGT_NODISCARD float vscale() const
Get vertical scale value.
Definition window.h:160
void window_hint(WindowHint hint)
Set the window hint.
Definition window.h:213
Window(const Window &)=delete
static const PixelFormat DEFAULT_FORMAT
Default pixel format used for Window.
Definition window.h:53
EGT_NODISCARD WindowHint window_hint() const
Get the window hint.
Definition window.h:224
void serialize(Serializer &serializer) const override
Serialize the widget to the specified serializer.
Window(Window &&) noexcept
Window & operator=(const Window &)=delete
EGT_NODISCARD PixelFormat format() const
Get the pixel format of the window.
Definition window.h:178
~Window() noexcept override
Window(PixelFormat format_hint=DEFAULT_FORMAT, WindowHint hint=WindowHint::automatic)
Construct a window.
Definition window.h:66
void begin_draw() override
Cause the widget to draw itself and all of its children.
WindowHint
Hint used for configuring Window backends.
Definition widgetflags.h:710
PixelFormat
Supported pixel formats.
Definition types.h:30
EGT framework namespace.
Definition animation.h:24
A single event that has information about the event and state for the event.
Definition event.h:255