Skip to content

Commit 61630ee

Browse files
committed
Reduce includes by using unique_ptr and fwd declarations
1 parent a9b4b6c commit 61630ee

6 files changed

Lines changed: 64 additions & 27 deletions

File tree

src/RenderLoop.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "gui/ProjectMGUI.h"
66

7+
#include <Poco/File.h>
78
#include <Poco/NotificationCenter.h>
89

910
#include <Poco/Util/Application.h>

src/gui/ProjectMGUI.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
#include "ProjectMWrapper.h"
44
#include "SDLRenderingWindow.h"
55

6+
#include "AboutWindow.h"
67
#include "AnonymousProFont.h"
78
#include "FontAwesomeIconsRegular7.h"
89
#include "FontAwesomeIconsSolid7.h"
10+
#include "HelpWindow.h"
911
#include "LiberationSansFont.h"
12+
#include "MainMenu.h"
13+
#include "PresetEditorGUI.h"
14+
#include "SettingsWindow.h"
15+
#include "ToastMessage.h"
1016

1117
#include "imgui.h"
1218
#include "imgui_impl_opengl3.h"
@@ -18,6 +24,17 @@
1824

1925
#include <utility>
2026

27+
ProjectMGUI::ProjectMGUI()
28+
: _mainMenu(std::make_unique<MainMenu>(*this))
29+
, _presetEditorGUI(std::make_unique<Editor::PresetEditorGUI>(*this))
30+
, _settingsWindow(std::make_unique<SettingsWindow>(*this))
31+
, _aboutWindow(std::make_unique<AboutWindow>(*this))
32+
, _helpWindow(std::make_unique<HelpWindow>())
33+
{
34+
}
35+
36+
ProjectMGUI::~ProjectMGUI() = default;
37+
2138
const char* ProjectMGUI::name() const
2239
{
2340
return "Preset Selection GUI";
@@ -171,12 +188,12 @@ void ProjectMGUI::Draw()
171188

172189
if (_visible)
173190
{
174-
if (!_presetEditorGUI.Draw())
191+
if (!_presetEditorGUI->Draw())
175192
{
176-
_mainMenu.Draw();
177-
_settingsWindow.Draw();
178-
_aboutWindow.Draw();
179-
_helpWindow.Draw();
193+
_mainMenu->Draw();
194+
_settingsWindow->Draw();
195+
_aboutWindow->Draw();
196+
_helpWindow->Draw();
180197
}
181198
}
182199

@@ -223,22 +240,22 @@ void ProjectMGUI::PopFont()
223240

224241
void ProjectMGUI::ShowPresetEditor(const std::string& presetFileName)
225242
{
226-
_presetEditorGUI.Show(presetFileName);
243+
_presetEditorGUI->Show(presetFileName);
227244
}
228245

229246
void ProjectMGUI::ShowSettingsWindow()
230247
{
231-
_settingsWindow.Show();
248+
_settingsWindow->Show();
232249
}
233250

234251
void ProjectMGUI::ShowAboutWindow()
235252
{
236-
_aboutWindow.Show();
253+
_aboutWindow->Show();
237254
}
238255

239256
void ProjectMGUI::ShowHelpWindow()
240257
{
241-
_helpWindow.Show();
258+
_helpWindow->Show();
242259
}
243260

244261
float ProjectMGUI::GetScalingFactor()

src/gui/ProjectMGUI.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
#pragma once
22

3-
#include "AboutWindow.h"
4-
#include "HelpWindow.h"
5-
#include "MainMenu.h"
6-
#include "PresetEditorGUI.h"
7-
#include "SettingsWindow.h"
8-
#include "ToastMessage.h"
9-
103
#include "notifications/DisplayToastNotification.h"
114

125
#include <SDL2/SDL.h>
@@ -16,13 +9,28 @@
169

1710
#include <Poco/Util/Subsystem.h>
1811

12+
#include <memory>
13+
14+
namespace Editor {
15+
class PresetEditorGUI;
16+
}
17+
1918
struct ImFont;
2019
class ProjectMWrapper;
2120
class SDLRenderingWindow;
21+
class MainMenu;
22+
class SettingsWindow;
23+
class AboutWindow;
24+
class HelpWindow;
25+
class ToastMessage;
2226

2327
class ProjectMGUI : public Poco::Util::Subsystem
2428
{
2529
public:
30+
ProjectMGUI();
31+
32+
~ProjectMGUI() override;
33+
2634
const char* name() const override;
2735

2836
void initialize(Poco::Util::Application& app) override;
@@ -146,11 +154,11 @@ class ProjectMGUI : public Poco::Util::Subsystem
146154
float _userScalingFactor{1.0f}; //!< The user-defined UI scaling factor.
147155
float _textScalingFactor{0.0f}; //!< The text scaling factor.
148156

149-
MainMenu _mainMenu{*this};
150-
Editor::PresetEditorGUI _presetEditorGUI{*this}; //!< The preset editor GUI.
151-
SettingsWindow _settingsWindow{*this}; //!< The settings window.
152-
AboutWindow _aboutWindow{*this}; //!< The about window.
153-
HelpWindow _helpWindow; //!< Help window with shortcuts and tips.
157+
std::unique_ptr<MainMenu> _mainMenu;
158+
std::unique_ptr<Editor::PresetEditorGUI> _presetEditorGUI; //!< The preset editor GUI.
159+
std::unique_ptr<SettingsWindow> _settingsWindow; //!< The settings window.
160+
std::unique_ptr<AboutWindow> _aboutWindow; //!< The about window.
161+
std::unique_ptr<HelpWindow> _helpWindow; //!< Help window with shortcuts and tips.
154162

155163
std::unique_ptr<ToastMessage> _toast; //!< Current toast to be displayed.
156164

src/gui/preset_editor/EditorMenu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "notifications/QuitNotification.h"
99

10+
#include "imgui.h"
11+
1012
#include <Poco/NotificationCenter.h>
1113

1214
namespace Editor {

src/gui/preset_editor/PresetEditorGUI.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "PresetEditorGUI.h"
22

33
#include "CodeContextInformation.h"
4+
#include "CodeEditorWindow.h"
45
#include "IconsFontAwesome7.h"
5-
#include "ProjectMGUI.h"
66

77
#include "ProjectMSDLApplication.h"
88
#include "ProjectMWrapper.h"
@@ -27,6 +27,10 @@ PresetEditorGUI::PresetEditorGUI(ProjectMGUI& gui)
2727
{
2828
}
2929

30+
PresetEditorGUI::~PresetEditorGUI()
31+
{
32+
}
33+
3034
void PresetEditorGUI::Show(const std::string& presetFile)
3135
{
3236
if (presetFile.empty())
@@ -55,6 +59,7 @@ void PresetEditorGUI::Show(const std::string& presetFile)
5559
}
5660

5761
_editorPreset.FromParsedFile(_presetFile);
62+
_codeEditorWindow = std::make_unique<CodeEditorWindow>();
5863

5964
_visible = true;
6065
}
@@ -86,7 +91,7 @@ bool PresetEditorGUI::Draw()
8691

8792
ImGui::SameLine();
8893

89-
_codeEditorWindow.Draw();
94+
_codeEditorWindow->Draw();
9095
}
9196
ImGui::End();
9297

@@ -100,6 +105,8 @@ bool PresetEditorGUI::Draw()
100105

101106
_visible = false;
102107
_wantClose = false;
108+
109+
_codeEditorWindow.reset();
103110
}
104111

105112
return true;
@@ -164,7 +171,7 @@ void PresetEditorGUI::ReleaseProjectMControl()
164171

165172
void PresetEditorGUI::EditCode(ExpressionCodeTypes type, std::string& code, int index)
166173
{
167-
_codeEditorWindow.OpenCodeInTab(type, code, index);
174+
_codeEditorWindow->OpenCodeInTab(type, code, index);
168175
}
169176

170177
unsigned long PresetEditorGUI::GetLoC(const std::string& code)

src/gui/preset_editor/PresetEditorGUI.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#pragma once
22

3-
#include "CodeEditorWindow.h"
43
#include "EditorMenu.h"
54
#include "EditorPreset.h"
65
#include "ExpressionCodeTypes.h"
76
#include "PresetFile.h"
87

8+
#include <memory>
99
#include <string>
1010

1111
class ProjectMGUI;
@@ -14,12 +14,14 @@ class ProjectMWrapper;
1414

1515
namespace Editor {
1616

17+
class CodeEditorWindow;
18+
1719
class PresetEditorGUI
1820
{
1921
public:
2022
explicit PresetEditorGUI(ProjectMGUI& gui);
2123

22-
~PresetEditorGUI() = default;
24+
~PresetEditorGUI();
2325

2426
/**
2527
* @brief Displays the preset editor screen and associated windows.
@@ -84,7 +86,7 @@ class PresetEditorGUI
8486
PresetFile _presetFile; //!< The raw preset data.
8587
EditorPreset _editorPreset; //!< The preset data in a parsed, strongly-typed container.
8688

87-
CodeEditorWindow _codeEditorWindow; //!< The code editor window.
89+
std::unique_ptr<CodeEditorWindow> _codeEditorWindow; //!< The code editor window.
8890

8991
};
9092

0 commit comments

Comments
 (0)