1.10
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 void paint(Painter& painter) override;
166
167 /*
168 * Damage rectangles propagate up the widget tree and stop at a top level
169 * widget, which can only be a window. As it propagates up, the damage
170 * rectangle origin changes value to respect the current frame. When
171 * drawing those rectangles, as they propagate down the widget hierarchy
172 * the opposite change happens to the rectangle origin.
173 */
174 void begin_draw() override;
175 using Frame::begin_draw;
176
180 EGT_NODISCARD PixelFormat format() const
181 {
182 auto frame = find_screen();
183 if (frame)
184 return frame->screen()->format();
185
186 return PixelFormat::invalid;
187 }
188
195 void format_hint(PixelFormat format_hint)
196 {
197 m_format_hint = format_hint;
198 }
199
207 EGT_NODISCARD PixelFormat format_hint() const { return m_format_hint; }
208
216 {
217 m_hint = hint;
218 }
219
226 EGT_NODISCARD WindowHint window_hint() const { return m_hint; }
227
228 void serialize(Serializer& serializer) const override;
229
230 ~Window() noexcept override;
231
232protected:
233
238 virtual void do_draw();
239
241 virtual void allocate_screen();
242
246 void create_impl(const Rect& rect,
247 PixelFormat format_hint,
248 WindowHint hint);
249
251 virtual void default_damage(const Rect& rect)
252 {
253 Frame::damage(rect);
254 }
255
257 virtual void default_resize(const Size& size)
258 {
259 Frame::resize(size);
260 }
261
263 virtual void default_scale(float scalex, float scaley)
264 {
265 Frame::scale(scalex, scaley);
266 }
267
269 virtual void default_move(const Point& point)
270 {
271 Frame::move(point);
272 }
273
275 virtual void default_begin_draw()
276 {
277 if (m_parent)
278 {
279 begin_draw(m_parent);
280 return;
281 }
282
283 do_draw();
284 }
285
287 virtual void default_show()
288 {
289 Frame::show();
290 }
291
293 virtual void default_hide()
294 {
295 Frame::hide();
296 }
297
299 virtual void default_paint(Painter& painter)
300 {
301 Frame::paint(painter);
302 }
303
305 std::unique_ptr<detail::WindowImpl> m_impl;
306
309
311 PixelFormat m_format_hint;
312
314 WindowHint m_hint;
315
317 float m_hscale{1.0};
318
320 float m_vscale{1.0};
321
322 friend class detail::WindowImpl;
323 friend class detail::PlaneWindow;
324};
325
333// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
334class EGT_API TopWindow : public Window
335{
336public:
337
338 using Window::Window;
339
340 TopWindow& operator=(const TopWindow&) = delete;
342
344 void show_cursor(const Image& image = Image("res:internal_cursor"));
345
348
349 ~TopWindow() noexcept override;
350
351protected:
352
354 void handle_mouse(Event& event);
355
357 std::unique_ptr<Window> m_cursor;
358
359private:
360
362 Object::RegisterHandle m_handle{0};
363};
364
365}
366}
367
368#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:39
Base object class with fundamental properties.
Definition object.h:32
uint64_t RegisterHandle
Handle type.
Definition object.h:61
Drawing interface for 2D graphics.
Definition painter.h:45
Manages one of more buffers that make up a Screen.
Definition screen.h:34
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:335
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:207
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:195
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:215
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:226
void paint(Painter &painter) override
Paint the Widget using a Painter.
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:180
~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:683
PixelFormat
Supported pixel formats.
Definition types.h:94
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