Skip to content

Commit 38cbcbe

Browse files
committed
Moved GUI classes into a subdir and their own static library
1 parent 7034039 commit 38cbcbe

9 files changed

+55
-45
lines changed

src/CMakeLists.txt

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1+
add_subdirectory(gui)
12

23
set(PROJECTM_CONFIGURATION_FILE "${CMAKE_CURRENT_BINARY_DIR}/projectMSDL.properties")
34
set(PROJECTM_CONFIGURATION_FILE "${PROJECTM_CONFIGURATION_FILE}" PARENT_SCOPE)
45
configure_file(resources/projectMSDL.properties.in "${PROJECTM_CONFIGURATION_FILE}" @ONLY)
56

6-
# Font embedding
7-
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AnonymousProFont.h"
8-
COMMAND $<TARGET_FILE:ImGuiBinaryToCompressedC> "${CMAKE_CURRENT_SOURCE_DIR}/resources/AnonymousPro-Regular.ttf" AnonymousPro > "${CMAKE_CURRENT_BINARY_DIR}/AnonymousProFont.h"
9-
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/resources/AnonymousPro-Regular.ttf"
10-
)
11-
127
add_executable(projectMSDL WIN32
13-
"${CMAKE_CURRENT_BINARY_DIR}/AnonymousProFont.h"
148
AudioCapture.cpp
159
AudioCapture.h
1610
FPSLimiter.cpp
1711
FPSLimiter.h
18-
GuiFileChooserWindow.cpp
19-
GuiFileChooserWindow.h
20-
PresetSelectionGui.cpp
21-
PresetSelectionGui.h
2212
ProjectMSDLApplication.cpp
2313
ProjectMSDLApplication.h
2414
ProjectMWrapper.cpp
@@ -30,11 +20,6 @@ add_executable(projectMSDL WIN32
3020
main.cpp
3121
)
3222

33-
target_include_directories(projectMSDL
34-
PRIVATE
35-
"${CMAKE_CURRENT_BINARY_DIR}"
36-
)
37-
3823
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
3924
target_sources(projectMSDL
4025
PRIVATE
@@ -64,7 +49,7 @@ target_compile_definitions(projectMSDL
6449

6550
target_link_libraries(projectMSDL
6651
PRIVATE
67-
ImGui
52+
ProjectMSDL-GUI
6853
libprojectM::playlist
6954
Poco::Util
7055
SDL2::SDL2$<$<STREQUAL:${SDL2_LINKAGE},static>:-static>

src/ProjectMSDLApplication.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "ProjectMWrapper.h"
99
#include "RenderLoop.h"
1010
#include "SDLRenderingWindow.h"
11-
#include "PresetSelectionGui.h"
11+
#include "gui/PresetSelection.h"
1212

1313
#include <Poco/Environment.h>
1414
#include <Poco/File.h>
@@ -24,7 +24,7 @@ ProjectMSDLApplication::ProjectMSDLApplication()
2424
addSubsystem(new SDLRenderingWindow);
2525
addSubsystem(new ProjectMWrapper);
2626
addSubsystem(new AudioCapture);
27-
addSubsystem(new PresetSelectionGui);
27+
addSubsystem(new PresetSelection);
2828
}
2929

3030
const char* ProjectMSDLApplication::name() const

src/RenderLoop.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RenderLoop::RenderLoop()
1010
: _audioCapture(Poco::Util::Application::instance().getSubsystem<AudioCapture>())
1111
, _projectMWrapper(Poco::Util::Application::instance().getSubsystem<ProjectMWrapper>())
1212
, _sdlRenderingWindow(Poco::Util::Application::instance().getSubsystem<SDLRenderingWindow>())
13-
, _presetSelectionGui(Poco::Util::Application::instance().getSubsystem<PresetSelectionGui>())
13+
, _presetSelectionGui(Poco::Util::Application::instance().getSubsystem<PresetSelection>())
1414
, _projectMHandle(_projectMWrapper.ProjectM())
1515
, _playlistHandle(_projectMWrapper.Playlist())
1616
{

src/RenderLoop.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "AudioCapture.h"
44
#include "ProjectMWrapper.h"
55
#include "SDLRenderingWindow.h"
6-
#include "PresetSelectionGui.h"
6+
#include "gui/PresetSelection.h"
77

88
#include <Poco/Logger.h>
99

@@ -78,7 +78,7 @@ class RenderLoop
7878
AudioCapture& _audioCapture;
7979
ProjectMWrapper& _projectMWrapper;
8080
SDLRenderingWindow& _sdlRenderingWindow;
81-
PresetSelectionGui& _presetSelectionGui;
81+
PresetSelection& _presetSelectionGui;
8282

8383
projectm_handle _projectMHandle{nullptr};
8484
projectm_playlist_handle _playlistHandle{nullptr};

src/gui/CMakeLists.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Font embedding
2+
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/AnonymousProFont.h"
3+
COMMAND $<TARGET_FILE:ImGuiBinaryToCompressedC> "${CMAKE_SOURCE_DIR}/src/resources/AnonymousPro-Regular.ttf" AnonymousPro > "${CMAKE_CURRENT_BINARY_DIR}/AnonymousProFont.h"
4+
MAIN_DEPENDENCY "${CMAKE_SOURCE_DIR}/src/resources/AnonymousPro-Regular.ttf"
5+
)
6+
7+
add_library(ProjectMSDL-GUI STATIC
8+
"${CMAKE_CURRENT_BINARY_DIR}/AnonymousProFont.h"
9+
FileChooser.cpp
10+
FileChooser.h
11+
PresetSelection.cpp
12+
PresetSelection.h
13+
)
14+
15+
target_include_directories(ProjectMSDL-GUI
16+
PRIVATE
17+
"${CMAKE_SOURCE_DIR}/src/"
18+
"${CMAKE_CURRENT_BINARY_DIR}"
19+
)
20+
21+
target_link_libraries(ProjectMSDL-GUI
22+
PUBLIC
23+
ImGui
24+
libprojectM::${PROJECTM_LINKAGE}
25+
)
26+

src/GuiFileChooserWindow.cpp renamed to src/gui/FileChooser.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "GuiFileChooserWindow.h"
1+
#include "FileChooser.h"
22

33
#include "imgui.h"
44

@@ -7,12 +7,12 @@
77

88
#include <algorithm>
99

10-
void GuiFileChooserWindow::Show()
10+
void FileChooser::Show()
1111
{
1212
_visible = true;
1313
}
1414

15-
bool GuiFileChooserWindow::Draw()
15+
bool FileChooser::Draw()
1616
{
1717
if (!_visible)
1818
{
@@ -78,12 +78,12 @@ bool GuiFileChooserWindow::Draw()
7878
return fileSelected;
7979
}
8080

81-
const Poco::File& GuiFileChooserWindow::SelectedFile() const
81+
const Poco::File& FileChooser::SelectedFile() const
8282
{
8383
return _selectedFile;
8484
}
8585

86-
void GuiFileChooserWindow::DrawNavButtons()
86+
void FileChooser::DrawNavButtons()
8787
{
8888
ImGui::Checkbox("Show hidden files", &_showhidden);
8989

@@ -117,7 +117,7 @@ void GuiFileChooserWindow::DrawNavButtons()
117117
}
118118
}
119119

120-
bool GuiFileChooserWindow::PopulateFileList()
120+
bool FileChooser::PopulateFileList()
121121
{
122122
bool fileSelected{false};
123123
bool changeDir{false};
@@ -178,7 +178,7 @@ bool GuiFileChooserWindow::PopulateFileList()
178178
return fileSelected;
179179
}
180180

181-
void GuiFileChooserWindow::ChangeDirectory(const Poco::Path& newDirectory)
181+
void FileChooser::ChangeDirectory(const Poco::Path& newDirectory)
182182
{
183183
_currentDir = newDirectory;
184184
_currentDir.makeDirectory();

src/GuiFileChooserWindow.h renamed to src/gui/FileChooser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Displays a file browser that shows directories and .milk files from which the user can choose one.
1111
*/
12-
class GuiFileChooserWindow
12+
class FileChooser
1313
{
1414
public:
1515

src/PresetSelectionGui.cpp renamed to src/gui/PresetSelection.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include "PresetSelectionGui.h"
1+
#include "PresetSelection.h"
22

3-
#include "AnonymousProFont.h"
43
#include "ProjectMWrapper.h"
54
#include "SDLRenderingWindow.h"
5+
#include "AnonymousProFont.h"
66

77
#include "imgui.h"
88
#include "imgui_impl_opengl3.h"
@@ -12,12 +12,12 @@
1212

1313
#include <cmath>
1414

15-
const char* PresetSelectionGui::name() const
15+
const char* PresetSelection::name() const
1616
{
1717
return "Preset Selection GUI";
1818
}
1919

20-
void PresetSelectionGui::initialize(Poco::Util::Application& app)
20+
void PresetSelection::initialize(Poco::Util::Application& app)
2121
{
2222
IMGUI_CHECKVERSION();
2323
ImGui::CreateContext();
@@ -41,7 +41,7 @@ void PresetSelectionGui::initialize(Poco::Util::Application& app)
4141
UpdateFontSize();
4242
}
4343

44-
void PresetSelectionGui::uninitialize()
44+
void PresetSelection::uninitialize()
4545
{
4646
ImGui_ImplOpenGL3_Shutdown();
4747
ImGui_ImplSDL2_Shutdown();
@@ -53,7 +53,7 @@ void PresetSelectionGui::uninitialize()
5353
_glContext = nullptr;
5454
}
5555

56-
void PresetSelectionGui::UpdateFontSize()
56+
void PresetSelection::UpdateFontSize()
5757
{
5858
ImGuiIO& io = ImGui::GetIO();
5959

@@ -88,7 +88,7 @@ void PresetSelectionGui::UpdateFontSize()
8888
ImGui::GetStyle().ScaleAllSizes(1.0);
8989
}
9090

91-
void PresetSelectionGui::ProcessInput(const SDL_Event& event)
91+
void PresetSelection::ProcessInput(const SDL_Event& event)
9292
{
9393
ImGui_ImplSDL2_ProcessEvent(&event);
9494
unsigned int position;
@@ -97,7 +97,7 @@ void PresetSelectionGui::ProcessInput(const SDL_Event& event)
9797
_playlistSize = projectm_get_playlist_size(_projectMWrapper->ProjectM());
9898
}
9999

100-
void PresetSelectionGui::Draw()
100+
void PresetSelection::Draw()
101101
{
102102
ImGui_ImplSDL2_NewFrame();
103103
ImGui_ImplOpenGL3_NewFrame();
@@ -134,19 +134,19 @@ void PresetSelectionGui::Draw()
134134
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
135135
}
136136

137-
bool PresetSelectionGui::WantsKeyboardInput()
137+
bool PresetSelection::WantsKeyboardInput()
138138
{
139139
auto& io = ImGui::GetIO();
140140
return io.WantCaptureKeyboard;
141141
}
142142

143-
bool PresetSelectionGui::WantsMouseInput()
143+
bool PresetSelection::WantsMouseInput()
144144
{
145145
auto& io = ImGui::GetIO();
146146
return io.WantCaptureMouse;
147147
}
148148

149-
void PresetSelectionGui::DrawSettingsWindow()
149+
void PresetSelection::DrawSettingsWindow()
150150
{
151151
if (ImGui::Begin("projectM Settings", &_settingsVisible))
152152
{
@@ -164,7 +164,6 @@ void PresetSelectionGui::DrawSettingsWindow()
164164
projectm_select_preset(_projectMWrapper->ProjectM(), _playlistPosition, true);
165165
}
166166

167-
168167
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
169168

170169
if (ImGui::Button("Toggle Fullscreen"))

src/PresetSelectionGui.h renamed to src/gui/PresetSelection.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "GuiFileChooserWindow.h"
3+
#include "FileChooser.h"
44

55
#include <SDL2/SDL.h>
66

@@ -13,7 +13,7 @@ struct ImFont;
1313
class ProjectMWrapper;
1414
class SDLRenderingWindow;
1515

16-
class PresetSelectionGui : public Poco::Util::Subsystem
16+
class PresetSelection : public Poco::Util::Subsystem
1717
{
1818
public:
1919
const char* name() const override;
@@ -44,7 +44,7 @@ class PresetSelectionGui : public Poco::Util::Subsystem
4444

4545
float _dpi{ 0.0f }; //!< Last DPI value.
4646

47-
GuiFileChooserWindow _fileChooser; //!< File chooser dialog.
47+
FileChooser _fileChooser; //!< File chooser dialog.
4848

4949
bool _settingsVisible{ true }; //!< Flag for settings window visibility.
5050
float _displayDuration{ 0.0f }; //!< Preset display time

0 commit comments

Comments
 (0)