1// Aseprite
2// Copyright (C) 2018-2022 Igara Studio S.A.
3// Copyright (C) 2001-2018 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_APP_H_INCLUDED
9#define APP_APP_H_INCLUDED
10#pragma once
11
12#ifdef ENABLE_UI
13#include "app/app_brushes.h"
14#endif
15
16#include "base/paths.h"
17#include "doc/pixel_format.h"
18#include "obs/signal.h"
19
20#include <memory>
21#include <string>
22#include <vector>
23
24namespace doc {
25 class Layer;
26}
27
28namespace ui {
29 class UISystem;
30}
31
32namespace app {
33
34#ifdef ENABLE_SCRIPTING
35 namespace script {
36 class Engine;
37 }
38#endif
39
40 class AppMod;
41 class AppOptions;
42 class BackupIndicator;
43 class Context;
44 class ContextBar;
45 class Doc;
46 class Extensions;
47 class INotificationDelegate;
48 class InputChain;
49 class LegacyModules;
50 class LoggerModule;
51 class MainWindow;
52 class Preferences;
53 class RecentFiles;
54 class Timeline;
55 class Workspace;
56
57 namespace crash {
58 class DataRecovery;
59 }
60
61 namespace tools {
62 class ActiveToolManager;
63 class Tool;
64 class ToolBox;
65 }
66
67 using namespace doc;
68
69 class App {
70 public:
71 App(AppMod* mod = nullptr);
72 ~App();
73
74 static App* instance() { return m_instance; }
75
76 Context* context();
77
78 // Returns true if Aseprite is running with GUI available.
79 bool isGui() const { return m_isGui; }
80
81 // Returns true if the application is running in portable mode.
82 bool isPortable();
83
84 // Runs the Aseprite application. In GUI mode it's the top-level
85 // window, in console/scripting it just runs the specified
86 // scripts.
87 int initialize(const AppOptions& options);
88 void run();
89 void close();
90
91 AppMod* mod() const { return m_mod; }
92 tools::ToolBox* toolBox() const;
93 tools::Tool* activeTool() const;
94 tools::ActiveToolManager* activeToolManager() const;
95 RecentFiles* recentFiles() const;
96 MainWindow* mainWindow() const { return m_mainWindow.get(); }
97 Workspace* workspace() const;
98 ContextBar* contextBar() const;
99 Timeline* timeline() const;
100 Preferences& preferences() const;
101 Extensions& extensions() const;
102 crash::DataRecovery* dataRecovery() const;
103
104#ifdef ENABLE_UI
105 AppBrushes& brushes() {
106 ASSERT(m_brushes.get());
107 return *m_brushes;
108 }
109
110 void showNotification(INotificationDelegate* del);
111 void showBackupNotification(bool state);
112 void updateDisplayTitleBar();
113
114 InputChain& inputChain();
115#endif
116
117#ifdef ENABLE_SCRIPTING
118 script::Engine* scriptEngine() { return m_engine.get(); }
119#endif
120
121 const std::string& memoryDumpFilename() const { return m_memoryDumpFilename; }
122 void memoryDumpFilename(const std::string& fn) { m_memoryDumpFilename = fn; }
123
124 // App Signals
125 obs::signal<void()> Exit;
126 obs::signal<void()> PaletteChange;
127 obs::signal<void()> ColorSpaceChange;
128 obs::signal<void()> PalettePresetsChange;
129
130 private:
131 class CoreModules;
132 class LoadLanguage;
133 class Modules;
134
135 static App* m_instance;
136
137 AppMod* m_mod;
138 std::unique_ptr<ui::UISystem> m_uiSystem;
139 std::unique_ptr<CoreModules> m_coreModules;
140 std::unique_ptr<Modules> m_modules;
141 std::unique_ptr<LegacyModules> m_legacy;
142 bool m_isGui;
143 bool m_isShell;
144 std::unique_ptr<MainWindow> m_mainWindow;
145 base::paths m_files;
146#ifdef ENABLE_UI
147 std::unique_ptr<AppBrushes> m_brushes;
148 std::unique_ptr<BackupIndicator> m_backupIndicator;
149#endif // ENABLE_UI
150#ifdef ENABLE_SCRIPTING
151 std::unique_ptr<script::Engine> m_engine;
152#endif
153
154 // Set the memory dump filename to show in the Preferences dialog
155 // or the "send crash" dialog. It's set by the SendCrash class.
156 std::string m_memoryDumpFilename;
157 };
158
159 void app_refresh_screen();
160 void app_rebuild_documents_tabs();
161 PixelFormat app_get_current_pixel_format();
162 int app_get_color_to_clear_layer(doc::Layer* layer);
163 void app_configure_drm();
164
165} // namespace app
166
167#endif
168