Skip to content

Commit

Permalink
Add track list window
Browse files Browse the repository at this point in the history
  • Loading branch information
superctr committed Apr 6, 2021
1 parent 946d59e commit 17d1c51
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ MMLGUI_OBJS = \
$(OBJ)/song_manager.o \
$(OBJ)/track_info.o \
$(OBJ)/track_view_window.o \
$(OBJ)/track_list_window.o \
$(OBJ)/audio_manager.o \
$(OBJ)/emu_player.o \
$(OBJ)/config_window.o \
Expand Down
5 changes: 5 additions & 0 deletions src/editor_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "main_window.h"
#include "editor_window.h"
#include "track_view_window.h"
#include "track_list_window.h"

#include "imgui.h"

Expand Down Expand Up @@ -161,6 +162,10 @@ void Editor_Window::display()
{
children.push_back(std::make_shared<Track_View_Window>(song_manager));
}
if (ImGui::MenuItem("Track list..."))
{
children.push_back(std::make_shared<Track_List_Window>(song_manager));
}
ImGui::Separator();
if (ImGui::BeginMenu("Editor style"))
{
Expand Down
48 changes: 48 additions & 0 deletions src/track_list_window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "track_list_window.h"
#include "track_info.h"
#include "song.h"

Track_List_Window::Track_List_Window(std::shared_ptr<Song_Manager> song_mgr)
: song_manager(song_mgr)
{
}

void Track_List_Window::display()
{
// Draw window
std::string window_id;
window_id = "Track List##" + std::to_string(id);

ImGui::Begin(window_id.c_str(), &active);
ImGui::SetWindowSize(ImVec2(200, 300), ImGuiCond_Once);

ImGui::Columns(3, "tracklist");
ImGui::Separator();
ImGui::Text("Name"); ImGui::NextColumn();
ImGui::Text("Length"); ImGui::NextColumn();
ImGui::Text("Loop"); ImGui::NextColumn();
ImGui::Separator();

Song_Manager::Track_Map& map = *song_manager->get_tracks();

for(auto&& i : map)
{
int id = i.first;
std::string str = "";
if(id < 'Z'-'A')
str.push_back(id + 'A');
else
str = std::to_string(id);

ImGui::Selectable(str.c_str(), false, ImGuiSelectableFlags_SpanAllColumns);
ImGui::NextColumn();
ImGui::Text("%5d", i.second.length);
ImGui::NextColumn();
ImGui::Text("%5d", i.second.loop_length);
ImGui::NextColumn();
}
ImGui::Columns(1);
ImGui::Separator();

ImGui::End();
}
27 changes: 27 additions & 0 deletions src/track_list_window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef TRACK_LIST_WINDOW_H
#define TRACK_LIST_WINDOW_H

#include <memory>
#include <string>

#include "imgui.h"

#include "window.h"
#include "song_manager.h"

// todo: just get the Track_Info struct.
// I don't want to bring all of ctrmml in the global namespace here
#include "track_info.h"

class Track_List_Window : public Window
{
public:
Track_List_Window(std::shared_ptr<Song_Manager> song_mgr);

void display() override;

private:
std::shared_ptr<Song_Manager> song_manager;
};

#endif

0 comments on commit 17d1c51

Please sign in to comment.