1.10
sdlscreen.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_DETAIL_SCREEN_SDLSCREEN_H
7#define EGT_DETAIL_SCREEN_SDLSCREEN_H
8
14#include <atomic>
15#include <egt/asio.hpp>
16#include <egt/detail/meta.h>
17#include <egt/input.h>
18#include <egt/screen.h>
19#include <memory>
20#include <string>
21#include <thread>
22
23namespace egt
24{
25inline namespace v1
26{
27namespace detail
28{
29struct SDLData;
30
34class SDLScreen : public Screen
35{
36public:
37
42 explicit SDLScreen(Application& app, const Size& size = Size(800, 480), const std::string& name = {});
43
44 SDLScreen(const SDLScreen&) = delete;
45 SDLScreen& operator=(const SDLScreen&) = delete;
46 SDLScreen(SDLScreen&&) = delete;
48
49 void schedule_flip() override
50 {}
51
52 void flip(const DamageArray& damage) override;
53
54 void quit()
55 {
56 m_quit = true;
57 }
58
59 ~SDLScreen() override;
60
61protected:
62
63 void pointer_event(EventId e, const Pointer& pointer);
64 void key_event(EventId e, const Key& key);
65 void sdl_draw(const DamageArray& damage);
67
69 std::unique_ptr<detail::SDLData> m_priv;
70
72 std::thread m_thread;
73
75 std::atomic<bool> m_quit{false};
76
78 asio::io_context m_io;
79
85 struct SDLInput : public Input
86 {
87 using Input::Input;
88 friend class SDLScreen;
89 };
90
92 SDLInput m_in;
93
96};
97
98}
99}
100}
101
102#endif
Application definition.
Definition app.h:49
Base Input device class.
Definition input.h:39
Manages one of more buffers that make up a Screen.
Definition screen.h:34
std::vector< Rect > DamageArray
Type used for damage arrays.
Definition screen.h:40
EGT_NODISCARD Size size() const
Size of the screen.
Definition screen.h:75
Screen in an SDL window.
Definition sdlscreen.h:35
SDLScreen(Application &app, const Size &size=Size(800, 480), const std::string &name={})
void key_event(EventId e, const Key &key)
std::thread m_thread
Internal thread for event processing.
Definition sdlscreen.h:72
void quit()
Definition sdlscreen.h:54
SDLScreen(SDLScreen &&)=delete
SDLScreen & operator=(SDLScreen &&)=delete
Application & m_app
Application reference.
Definition sdlscreen.h:95
void flip(const DamageArray &damage) override
Perform a flip of the buffers.
SDLInput m_in
Custom input for dispatching events.
Definition sdlscreen.h:92
std::atomic< bool > m_quit
Flag to quit thread.
Definition sdlscreen.h:75
SDLScreen(const SDLScreen &)=delete
void schedule_flip() override
Schedule a flip to occur later.
Definition sdlscreen.h:49
void pointer_event(EventId e, const Pointer &pointer)
void sdl_draw(const DamageArray &damage)
SDLScreen & operator=(const SDLScreen &)=delete
asio::io_context m_io
Internal io context.
Definition sdlscreen.h:78
static KeyboardCode sdl_to_egtkeys(int key)
EventId
Event identifiers.
Definition event.h:36
SizeType< DefaultDim, detail::Compatible::normal > Size
Helper type alias.
Definition geometry.h:573
KeyboardCode
Key codes that represent a physical key.
Definition keycode.h:26
EGT framework namespace.
Definition animation.h:24
Keyboard event data.
Definition event.h:165
Pointer event data.
Definition event.h:79