Skip to content

Commit

Permalink
Split parsing code into separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Sep 10, 2022
1 parent 1ddc249 commit 5f7bd07
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 221 deletions.
2 changes: 1 addition & 1 deletion include/ui/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void Ui::Renderer::ApplyDarkTheme()
style->Colors[ImGuiCol_Tab] = ImVec4(0.15f, 0.15f, 0.15f, 0.95f);
style->Colors[ImGuiCol_TabHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style->Colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_Header] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
style->Colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style->Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style->Colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
style->Colors[ImGuiCol_ResizeGrip] = ImVec4(0.12f, 0.12f, 0.12f, 0.00f);
Expand Down
Binary file modified resource/icon.ico
Binary file not shown.
28 changes: 14 additions & 14 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Editor::WelcomePopup()
ImGui::Spacing();
ImGui::TextWrapped("Directly open archives in IMG Editor by windows modifying file association.");
ImGui::Spacing();
if (ImGui::Button("File association help", Widget::CalcSize(1)))
if (ImGui::Button("Help with file association", Widget::CalcSize(1)))
{
ShellExecute(nullptr, "open", "https://www.google.com/search?q=windows+set+file+associations", nullptr, nullptr, SW_SHOWNORMAL);
}
Expand All @@ -74,7 +74,7 @@ void Editor::WelcomePopup()

bool Editor::DoesArchiveExist(const std::string &name)
{
for (IMGArchive &arc : ArchiveList)
for (IMGMgr &arc : ArchiveList)
{
if (std::string(arc.FileName) == name)
{
Expand Down Expand Up @@ -114,9 +114,9 @@ void Editor::ProcessMenuBar()

if (path != "")
{
if (IMGArchive::IsSupported(path))
if (IMGMgr::IsSupported(path))
{
AddArchiveEntry(std::move(IMGArchive(std::move(path))));
AddArchiveEntry(std::move(IMGMgr(std::move(path))));
}
else
{
Expand All @@ -139,14 +139,14 @@ void Editor::ProcessMenuBar()
pSelectedArchive->Path = WinDialogs::SaveFile(pSelectedArchive->FileName + ".img");
}
ArchiveInfo *info = new ArchiveInfo{pSelectedArchive, pSelectedArchive->Path};
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGArchive::Rebuild, info, NULL, NULL);
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGMgr::Rebuild, info, NULL, NULL);
pSelectedArchive->AddLogMessage("Archive saved");
}
if (ImGui::MenuItem("Save as...") && !pSelectedArchive->ProgressBar.bInUse)
{
std::string path = WinDialogs::SaveFile(pSelectedArchive->FileName + ".img");
ArchiveInfo *info = new ArchiveInfo{pSelectedArchive, path};
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGArchive::Rebuild, info, NULL, NULL);
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGMgr::Rebuild, info, NULL, NULL);
pSelectedArchive->AddLogMessage("Archive saved");
}
ImGui::EndMenu();
Expand All @@ -167,13 +167,13 @@ void Editor::ProcessMenuBar()
{
std::string path = WinDialogs::SaveFolder();
ArchiveInfo *info = new ArchiveInfo{pSelectedArchive, path};
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGArchive::ExportAll, info, NULL, NULL);
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGMgr::ExportAll, info, NULL, NULL);
}
if (ImGui::MenuItem("Export selected", NULL, false, !pSelectedArchive->ProgressBar.bInUse))
{
std::string path = WinDialogs::SaveFolder();
ArchiveInfo *info = new ArchiveInfo{pSelectedArchive, path};
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGArchive::ExportSelected, info, NULL, NULL);
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGMgr::ExportSelected, info, NULL, NULL);
}
ImGui::EndMenu();
}
Expand Down Expand Up @@ -306,7 +306,7 @@ void Editor::ProcessWindow()
pSelectedArchive = nullptr;
if (ImGui::BeginTabBar("Archives", tabFlags))
{
for (IMGArchive &archive : ArchiveList)
for (IMGMgr &archive : ArchiveList)
{
if (ImGui::BeginTabItem(archive.FileName.c_str(), &archive.bOpen))
{
Expand Down Expand Up @@ -457,7 +457,7 @@ void Editor::ProcessWindow()
{
std::string path = WinDialogs::SaveFolder();
ArchiveInfo *info = new ArchiveInfo{pSelectedArchive, path};
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGArchive::ExportAll, info, NULL, NULL);
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)&IMGMgr::ExportAll, info, NULL, NULL);
}
if (ImGui::Button("Select all", sz))
{
Expand Down Expand Up @@ -541,7 +541,7 @@ void Editor::ProcessWindow()
ArchiveList.begin(),
ArchiveList.end(),

[&archive](IMGArchive const& obj) {
[&archive](IMGMgr const& obj) {
return obj.bCreateNew ? obj.FileName == archive.FileName : obj.Path == archive.Path;
}
),
Expand All @@ -554,9 +554,9 @@ void Editor::ProcessWindow()
}
}

void Editor::AddArchiveEntry(IMGArchive &&archive)
void Editor::AddArchiveEntry(IMGMgr &&archive)
{
for (IMGArchive &arc : ArchiveList)
for (IMGMgr &arc : ArchiveList)
{
if (arc.Path == archive.Path)
{
Expand Down Expand Up @@ -629,7 +629,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
}

bool exists = std::filesystem::exists(&lpCmdLine[1]);
Editor::AddArchiveEntry(exists ? IMGArchive(&lpCmdLine[1]) : IMGArchive("Untitled", true));
Editor::AddArchiveEntry(exists ? IMGMgr(&lpCmdLine[1]) : IMGMgr("Untitled", true));
Editor::Run();
return 0;
}
6 changes: 3 additions & 3 deletions src/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class Editor
{
private:
static inline std::vector<IMGArchive> ArchiveList;
static inline IMGArchive* pSelectedArchive; // pointer to the selected archive in editor
static inline std::vector<IMGMgr> ArchiveList;
static inline IMGMgr* pSelectedArchive; // pointer to the selected archive in editor
static inline EntryInfo *pContextEntry = nullptr; // pointer to the selected archive entry in editor
static inline Ui::Application *pApp = nullptr;
static inline CSimpleIniA Config;
Expand All @@ -25,7 +25,7 @@ class Editor
public:

// Adds a new archive to the list
static void AddArchiveEntry(IMGArchive &&archive);
static void AddArchiveEntry(IMGMgr &&archive);

// Returns true if archive with the given name already exists
static bool DoesArchiveExist(const std::string &name);
Expand Down
Loading

0 comments on commit 5f7bd07

Please sign in to comment.