1.10
app.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_APP_H
7#define EGT_APP_H
8
9#include <clocale>
10#include <egt/asio.hpp>
11#include <egt/detail/meta.h>
12#include <egt/eventloop.h>
13#include <egt/object.h>
14#include <iosfwd>
15#include <memory>
16#include <ostream>
17#include <string>
18#include <vector>
19
28namespace egt
29{
33inline namespace v1
34{
35
36class Screen;
37class Input;
38class Window;
39class Timer;
40
48class EGT_API Application
49{
50public:
58 explicit Application(int argc = 0, char** argv = nullptr,
59 const std::string& name = {}, bool primary = true);
60
61 Application(const Application&) = delete;
65
72
76 static bool check_instance();
77
89 static void setup_search_paths(const std::vector<std::string>& extra_paths = {});
90
94 EGT_NODISCARD bool is_composer() const;
95
103 virtual int run();
104
109 virtual void quit(int exit_value = 0);
110
114 EventLoop& event() { return m_event; }
115
119 EGT_NODISCARD Screen* screen() const { return m_screen.get(); }
120
124 EGT_NODISCARD Window* main_window() const { return m_main_window; }
125
132 EGT_NODISCARD Window* modal_window() const { return m_modal_window; }
133
135 void set_modal_window(Window* window)
136 {
137 m_modal_window = window;
138 }
139
143 EGT_NODISCARD const std::vector<Window*>& windows() const { return m_windows; }
144
148 void paint_to_file(const std::string& filename = {});
149
158 void dump(std::ostream& out) const;
159
168 void dump_timers(std::ostream& out) const;
169
174 const std::vector<std::pair<std::string, std::string>>& get_input_devices();
175
179 EGT_NODISCARD inline int argc() const { return m_argc; }
180
184 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
185 EGT_NODISCARD inline const char** argv() const { return const_cast<const char**>(m_argv); }
186
187 virtual ~Application() noexcept;
188
189protected:
190
192 static void setup_info();
194 static void setup_logging();
196 static void setup_locale(const std::string& name);
198 void setup_backend(bool primary, const std::string& name);
200 void setup_inputs();
202 void setup_events();
203
207 EventLoop m_event;
208
212 int m_argc{0};
213
217 char** m_argv{nullptr};
218
222 asio::signal_set m_signals;
223
227 std::vector<std::pair<std::string, std::string>> m_input_devices;
228
229private:
230
232 void signal_handler(const asio::error_code& error, int signum);
233
235 std::unique_ptr<Screen> m_screen;
236
238 std::vector<std::unique_ptr<Input>> m_inputs;
239
241 Object::RegisterHandle m_handle{0};
242
244 std::vector<Window*> m_windows;
245
247 Window* m_main_window{nullptr};
248
250 Window* m_modal_window{nullptr};
251
253 std::vector<Timer*> m_timers;
254
255 friend class Window;
256 friend class Timer;
257};
258
259}
260}
261
262#endif
Application definition.
Definition app.h:49
Application(const Application &)=delete
EGT_NODISCARD int argc() const
Get the argc value passed in.
Definition app.h:179
virtual void quit(int exit_value=0)
Calls EventLoop::quit(exit_value) by default.
virtual ~Application() noexcept
void dump(std::ostream &out) const
Dump the widget hierarchy and properties to the specified std::ostream.
static bool check_instance()
Check if there is an available instance.
EGT_NODISCARD Screen * screen() const
Get a pointer to the Screen instance.
Definition app.h:119
EventLoop & event()
Get a reference to the application event loop instance.
Definition app.h:114
EGT_NODISCARD const char ** argv() const
Get the argv value passed in.
Definition app.h:185
const std::vector< std::pair< std::string, std::string > > & get_input_devices()
Get a list of input devices configured with the EGT_INPUT_DEVICES environment variable.
Application(Application &&)=delete
void paint_to_file(const std::string &filename={})
Paint the entire Screen to a file.
Application & operator=(Application &&)=delete
std::vector< std::pair< std::string, std::string > > m_input_devices
List of configured input devices.
Definition app.h:227
virtual int run()
Run the application.
Application & operator=(const Application &)=delete
EGT_NODISCARD bool is_composer() const
Check whether the application runs under the Microchip Graphic Composer.
EGT_NODISCARD Window * main_window() const
Get a pointer to the main Window.
Definition app.h:124
static Application & instance()
Reference to the main Application instance.
EGT_NODISCARD Window * modal_window() const
Get a pointer to the modal Window.
Definition app.h:132
asio::signal_set m_signals
Signal instance for registered signal handles by the Application.
Definition app.h:222
void dump_timers(std::ostream &out) const
Dump all allocated timers to the specified std::ostream.
static void setup_search_paths(const std::vector< std::string > &extra_paths={})
Reset the resources search paths optionally adding extra paths.
EGT_NODISCARD const std::vector< Window * > & windows() const
Get the list of all currently allocated Windows.
Definition app.h:143
Application(int argc=0, char **argv=nullptr, const std::string &name={}, bool primary=true)
Event loop interface.
Definition eventloop.h:39
uint64_t RegisterHandle
Handle type.
Definition object.h:61
Manages one of more buffers that make up a Screen.
Definition screen.h:34
Basic one shot timer.
Definition timer.h:70
A Window is a Widget that handles drawing to a Screen.
Definition window.h:47
EGT framework namespace.
Definition animation.h:24