|
@@ -1,34 +1,31 @@
|
|
|
|
|
|
#include "BaseWindow.h"
|
|
#include "BaseWindow.h"
|
|
-#include <imfilebrowser.h>
|
|
|
|
|
|
|
|
|
|
+#include <imfilebrowser.h>
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
|
|
-void window_resize_callback(GLFWwindow *window, int width, int height)
|
|
|
|
-{
|
|
|
|
|
|
+void window_resize_callback(GLFWwindow * /*unused*/, int width, int height) {
|
|
glViewport(0, 0, width, height);
|
|
glViewport(0, 0, width, height);
|
|
}
|
|
}
|
|
|
|
|
|
-BaseWindow::BaseWindow(int width, int height, const char *title, Color clear_color, Audio audio_handler)
|
|
|
|
- : m_window_height(height),
|
|
|
|
|
|
+BaseWindow::BaseWindow(int width, int height, const char *title,
|
|
|
|
+ Color clear_color, Audio *audio_handler)
|
|
|
|
+ : m_clear_color(clear_color),
|
|
m_window_width(width),
|
|
m_window_width(width),
|
|
|
|
+ m_window_height(height),
|
|
m_window_title(title),
|
|
m_window_title(title),
|
|
- m_clear_color(clear_color),
|
|
|
|
m_audio_handler(audio_handler) {}
|
|
m_audio_handler(audio_handler) {}
|
|
|
|
|
|
-BaseWindow::~BaseWindow()
|
|
|
|
-{
|
|
|
|
-
|
|
|
|
- //ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
- //ImGui_ImplGlfw_Shutdown();
|
|
|
|
- //ImGui::DestroyContext();
|
|
|
|
|
|
+BaseWindow::~BaseWindow() {
|
|
|
|
+ ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
+ ImGui_ImplGlfw_Shutdown();
|
|
|
|
+ ImGui::DestroyContext();
|
|
glfwDestroyWindow(m_window);
|
|
glfwDestroyWindow(m_window);
|
|
glfwTerminate();
|
|
glfwTerminate();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-int BaseWindow::run()
|
|
|
|
-{
|
|
|
|
|
|
+auto BaseWindow::run() -> int {
|
|
glfwInit();
|
|
glfwInit();
|
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
@@ -36,9 +33,9 @@ int BaseWindow::run()
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
|
|
|
|
- m_window = glfwCreateWindow(m_window_width, m_window_height, m_window_title, NULL, NULL);
|
|
|
|
- if (m_window == NULL)
|
|
|
|
- {
|
|
|
|
|
|
+ m_window = glfwCreateWindow(m_window_width, m_window_height, m_window_title,
|
|
|
|
+ nullptr, nullptr);
|
|
|
|
+ if (m_window == nullptr) {
|
|
std::cout << "could not intialize GLFW Window"
|
|
std::cout << "could not intialize GLFW Window"
|
|
<< "\n";
|
|
<< "\n";
|
|
glfwTerminate();
|
|
glfwTerminate();
|
|
@@ -47,8 +44,7 @@ int BaseWindow::run()
|
|
|
|
|
|
glfwMakeContextCurrent(m_window);
|
|
glfwMakeContextCurrent(m_window);
|
|
|
|
|
|
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
|
|
|
- {
|
|
|
|
|
|
+ if (gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress)) == 0) {
|
|
std::cout << "Failed to initialize GLAD" << std::endl;
|
|
std::cout << "Failed to initialize GLAD" << std::endl;
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
@@ -56,7 +52,7 @@ int BaseWindow::run()
|
|
glfwSetFramebufferSizeCallback(m_window, window_resize_callback);
|
|
glfwSetFramebufferSizeCallback(m_window, window_resize_callback);
|
|
IMGUI_CHECKVERSION();
|
|
IMGUI_CHECKVERSION();
|
|
ImGui::CreateContext();
|
|
ImGui::CreateContext();
|
|
- ImGuiIO &io = ImGui::GetIO();
|
|
|
|
|
|
+ ImGuiIO const&io = ImGui::GetIO();
|
|
(void)io;
|
|
(void)io;
|
|
ImGui::StyleColorsDark();
|
|
ImGui::StyleColorsDark();
|
|
ImGui_ImplGlfw_InitForOpenGL(m_window, true);
|
|
ImGui_ImplGlfw_InitForOpenGL(m_window, true);
|
|
@@ -67,9 +63,7 @@ int BaseWindow::run()
|
|
fileDialog.SetTypeFilters({".mp3"});
|
|
fileDialog.SetTypeFilters({".mp3"});
|
|
|
|
|
|
// Main game loop
|
|
// Main game loop
|
|
- while (!glfwWindowShouldClose(m_window))
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
|
|
+ while (glfwWindowShouldClose(m_window) == 0) {
|
|
// Create new imgui frames
|
|
// Create new imgui frames
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
@@ -78,29 +72,25 @@ int BaseWindow::run()
|
|
// Draw IMGUI
|
|
// Draw IMGUI
|
|
ImGui::Begin("Hello!");
|
|
ImGui::Begin("Hello!");
|
|
{
|
|
{
|
|
- static int clicked = 0;
|
|
|
|
- if (ImGui::Button("Add Music"))
|
|
|
|
- {
|
|
|
|
|
|
+ if (ImGui::Button("Add Music")) {
|
|
fileDialog.Open();
|
|
fileDialog.Open();
|
|
}
|
|
}
|
|
|
|
|
|
static std::filesystem::path selected;
|
|
static std::filesystem::path selected;
|
|
- if (m_audio_handler.loaded_files().size() > 0)
|
|
|
|
- {
|
|
|
|
- if (ImGui::BeginListBox("##", ImVec2(-FLT_MIN, 5 * ImGui::GetTextLineHeightWithSpacing())))
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- for (auto file : m_audio_handler.loaded_files())
|
|
|
|
- {
|
|
|
|
- bool is_selected = selected.compare(file);
|
|
|
|
- if (ImGui::Selectable(file.string().c_str(), is_selected))
|
|
|
|
- {
|
|
|
|
|
|
+ if (!m_audio_handler->loaded_files().empty()) {
|
|
|
|
+ if (ImGui::BeginListBox(
|
|
|
|
+ "##",
|
|
|
|
+ ImVec2(-FLT_MIN,
|
|
|
|
+ 5 * ImGui::GetTextLineHeightWithSpacing()))) {
|
|
|
|
+ for (const auto& file : m_audio_handler->loaded_files()) {
|
|
|
|
+ bool const is_selected = selected.compare(file) != 0;
|
|
|
|
+ if (ImGui::Selectable(file.string().c_str(),
|
|
|
|
+ is_selected)) {
|
|
selected = file;
|
|
selected = file;
|
|
- m_audio_handler.select_file(file);
|
|
|
|
|
|
+ m_audio_handler->select_file(file);
|
|
}
|
|
}
|
|
|
|
|
|
- if (is_selected)
|
|
|
|
- {
|
|
|
|
|
|
+ if (is_selected) {
|
|
ImGui::SetItemDefaultFocus();
|
|
ImGui::SetItemDefaultFocus();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -110,41 +100,36 @@ int BaseWindow::run()
|
|
}
|
|
}
|
|
ImGui::End();
|
|
ImGui::End();
|
|
fileDialog.Display();
|
|
fileDialog.Display();
|
|
- if (fileDialog.HasSelected())
|
|
|
|
- {
|
|
|
|
- m_audio_handler.load_file(fileDialog.GetSelected());
|
|
|
|
- m_audio_handler.select_file(fileDialog.GetSelected());
|
|
|
|
|
|
+ if (fileDialog.HasSelected()) {
|
|
|
|
+ m_audio_handler->load_file(fileDialog.GetSelected());
|
|
|
|
+ m_audio_handler->select_file(fileDialog.GetSelected());
|
|
fileDialog.ClearSelected();
|
|
fileDialog.ClearSelected();
|
|
}
|
|
}
|
|
|
|
|
|
ImGui::Begin("Player controls");
|
|
ImGui::Begin("Player controls");
|
|
{
|
|
{
|
|
- if (ImGui::Button("Play"))
|
|
|
|
- {
|
|
|
|
- m_audio_handler.play();
|
|
|
|
|
|
+ if (ImGui::Button("Play")) {
|
|
|
|
+ m_audio_handler->play();
|
|
}
|
|
}
|
|
- if (ImGui::Button("Stop"))
|
|
|
|
- {
|
|
|
|
- m_audio_handler.stop();
|
|
|
|
|
|
+ if (ImGui::Button("Stop")) {
|
|
|
|
+ m_audio_handler->stop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ImGui::End();
|
|
ImGui::End();
|
|
|
|
|
|
- if (m_audio_handler.decoder().is_finished)
|
|
|
|
- {
|
|
|
|
- m_audio_handler.next_music();
|
|
|
|
|
|
+ if (m_audio_handler->decoder().is_finished) {
|
|
|
|
+ m_audio_handler->next_music();
|
|
}
|
|
}
|
|
|
|
|
|
ImGui::Render();
|
|
ImGui::Render();
|
|
|
|
|
|
- glClearColor(m_clear_color.r, m_clear_color.g, m_clear_color.b, m_clear_color.a);
|
|
|
|
|
|
+ glClearColor(m_clear_color.r, m_clear_color.g, m_clear_color.b,
|
|
|
|
+ m_clear_color.a);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
glfwSwapBuffers(m_window);
|
|
glfwSwapBuffers(m_window);
|
|
glfwPollEvents();
|
|
glfwPollEvents();
|
|
}
|
|
}
|
|
|
|
|
|
- // Unload and destroy
|
|
|
|
-
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|