diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 1940591..4b87cb7 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -59,7 +59,8 @@ namespace lunarium // NOTE: Generating a font file for now. Late might look into loading directly from memory DataManager::GenerateFontFileAt(Font::F_ROBOTO, "robo.ttf"); //io.Fonts->AddFontFromFileTTF("open.ttf", 16.0f); - io.Fonts->AddFontFromFileTTF("robo.ttf", 18.0f); + mFonts[GuiFont::FONT_ROBO] = io.Fonts->AddFontFromFileTTF("robo.ttf", 18.0f); + mFonts[GuiFont::FONT_ROBO_SMALL] = io.Fonts->AddFontFromFileTTF("robo.ttf", 12.0f); //io.Fonts->AddFontFromFileTTF("Karla-Regular.ttf", 16.0f); // Setup Dear ImGui style @@ -139,6 +140,12 @@ namespace lunarium } + ImFont* GUI::GetFont(GuiFont font) + { + return mFonts[font]; + } + + void GUI::SetStyle(GuiStyle style) { // Reset the style diff --git a/src/gui/gui.h b/src/gui/gui.h index cc908d2..8d7d413 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -10,9 +10,11 @@ #define GUI_H_ #include +#include struct GLFWwindow; struct ImGuiStyle; +struct ImFont; namespace lunarium { @@ -30,6 +32,12 @@ namespace lunarium STYLE_CORPORATE_GRAY_3D, }; + enum GuiFont + { + FONT_ROBO, + FONT_ROBO_SMALL, + }; + class GUI { public: @@ -45,6 +53,7 @@ namespace lunarium bool WantCaptureKeyboard() const; void SetStyle(GuiStyle style); + ImFont* GetFont(GuiFont font); private: GUI(); @@ -55,6 +64,7 @@ namespace lunarium static GUI* mpInstance; bool mbIsInit; ImGuiStyle* mpBaseStyle; + std::map mFonts; //bool mbShowDemo; private: // STYLES diff --git a/src/run_modes/editor/panels/asset_browser.cpp b/src/run_modes/editor/panels/asset_browser.cpp index 6942e74..250c69e 100644 --- a/src/run_modes/editor/panels/asset_browser.cpp +++ b/src/run_modes/editor/panels/asset_browser.cpp @@ -7,11 +7,14 @@ ******************************************************************************/ #include "asset_browser.h" +#include #include #include #include #include #include +#include +#include namespace lunarium { @@ -19,10 +22,8 @@ namespace editor { AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor) : Panel("Asset Browser", gui::PanelDockZone::DDZ_BOTTOM, true), - mAssetDirectory(dir), mTreeRoot(nullptr), mSelectedNode(nullptr), mpEditor(pEditor), mNewFolder(false), mSyncTree(false) + mAssetDirectory(dir), mpEditor(pEditor), mNewFolder(false), mSyncTree(false) { - mTreeRoot = ReloadAssets(mAssetDirectory); - mSelectedNode = mTreeRoot; } void AssetBrowser::SetAssetDirectory(std::filesystem::path dir) @@ -66,6 +67,63 @@ namespace editor ImGui::SetCursorPosX(ImGui::GetCursorPosX() + wind_size.x * 0.15f); // Contents + DoContentArea(wind_size); + + ImGui::End(); + return true; + } + + void AssetBrowser::DoDirTree(std::filesystem::path dir) + { + if ("" == dir) + return; + + if (!std::filesystem::is_directory(dir)) + return; + + std::string next_node_name = dir.filename().string(); + if (mSyncTree) + { + if (mSelectedDir.string().find(next_node_name) != std::string::npos) + { + ImGui::SetNextItemOpen(true); + } + else + { + ImGui::SetNextItemOpen(false); + } + } + + if (ImGui::TreeNode(next_node_name.c_str())) + { + if (!mSyncTree) + { + if (ImGui::IsItemClicked()) + { + mSelectedDir = dir; + ImGui::SetNextItemOpen(false); + } + HandleAssetDrop(mSelectedDir); + } + + for(auto const& dir_entry: std::filesystem::directory_iterator{dir}) + { + DoDirTree(dir_entry); + } + ImGui::TreePop(); + } + else + { + if (ImGui::IsItemClicked()) + { + mSelectedDir = dir; + ImGui::SetNextItemOpen(false); + } + } + } + + void AssetBrowser::DoContentArea(ImVec2 wind_size) + { if (ImGui::BeginChild("Contents", ImVec2(wind_size.x * 0.85f, wind_size.y), true, ImGuiWindowFlags_NoCollapse)) { if (std::filesystem::exists(mSelectedDir)) @@ -74,7 +132,11 @@ namespace editor float xPos = ImGui::GetCursorPosX(); float left = xPos; - ImGui::BeginChild("ToolBar", ImVec2(0, ImGui::GetFrameHeightWithSpacing())); + + ImGui::BeginChild("ToolBar", ImVec2(0, ImGui::GetFrameHeightWithSpacing() * 1.5f)); + ImGui::PushFont(GUI::GetInstance().GetFont(GuiFont::FONT_ROBO_SMALL)); + ImGui::TextUnformatted(mpEditor->GetProject()->MakeRelativeToAssets(mSelectedDir, true).string().c_str()); + ImGui::PopFont(); if (ImGui::Button("Back")) { mSelectedDir = mSelectedDir.parent_path(); @@ -83,29 +145,33 @@ namespace editor ImGui::EndChild(); + ImGui::Separator(); ImGui::BeginChild("Files"); // List directories - for(auto const& dir_entry: std::filesystem::directory_iterator{mSelectedDir}) + for (auto const &dir_entry : std::filesystem::directory_iterator{mSelectedDir}) { if (dir_entry.is_directory()) { - ImGui::Text("DIRECTORY: %s", dir_entry.path().filename().string().c_str()); + ImGui::Image((ImTextureID)DataManager::mFolderIcon->GetGLTextureID64(), + ImVec2(DataManager::mFolderIcon->GetWidth(), DataManager::mFolderIcon->GetHeight())); + ImGui::SameLine(); + ImGui::Selectable(dir_entry.path().filename().string().c_str()); HandleAssetDrop(dir_entry.path()); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { // TODO: Open relevant editor Logger::Info(Editor::LogCat, "Directory double clicked on. Open Folder"); - + // This will force open the tree nodes on the next update so the tree is synced with the content window mSelectedDir = dir_entry.path(); - mSyncTree = true; + mSyncTree = true; } } } std::filesystem::path selected_final = mpEditor->GetProject()->MakeRelativeToAssets(mSelectedDir); - std::vector assets; + std::vector assets; ContentManager::GetInstance().GetAllAssetsInDirectory(assets, selected_final); for (auto iter = assets.begin(); iter != assets.end(); iter++) @@ -119,7 +185,7 @@ namespace editor { // Need to pass a pointer to the payload data. This means we need to pass a // pointer to the EditorAsset pointer (EditorAsset**) which &(*iter) becomes - ImGui::SetDragDropPayload("EditorAsset", (void*)&(*iter), sizeof(EditorAsset*)); + ImGui::SetDragDropPayload("EditorAsset", (void *)&(*iter), sizeof(EditorAsset *)); ImGui::Text("%s", (*iter)->GetFileLocation().stem().string().c_str()); ImGui::EndDragDropSource(); } @@ -130,52 +196,12 @@ namespace editor } } - DoContextMenu(); - + DoContextMenu(); + ImGui::EndChild(); } } ImGui::EndChild(); - - ImGui::End(); - return true; - } - - void AssetBrowser::DoDirTree(std::filesystem::path dir) - { - if ("" == dir) - return; - - if (!std::filesystem::is_directory(dir)) - return; - - std::string next_node_name = dir.filename().string(); - if (mSyncTree) - { - if (mSelectedDir.string().find(next_node_name) != std::string::npos) - { - ImGui::SetNextItemOpen(true); - } - else - { - ImGui::SetNextItemOpen(false); - } - } - - if (ImGui::TreeNode(next_node_name.c_str())) - { - if (!mSyncTree) - { - mSelectedDir = dir; - HandleAssetDrop(mSelectedDir); - } - - for(auto const& dir_entry: std::filesystem::directory_iterator{dir}) - { - DoDirTree(dir_entry); - } - ImGui::TreePop(); - } } void AssetBrowser::DoContextMenu() @@ -208,29 +234,6 @@ namespace editor if (mNewFolder) ImGui::OpenPopup("New Folder Name"); } - - AssetBrowser::Node* AssetBrowser::ReloadAssets(std::filesystem::path dir) - { - if ("" == dir) - return nullptr; - - Node* pNode = new Node; - pNode->Myself = dir; - for(auto const& dir_entry: std::filesystem::directory_iterator{dir}) - { - if (std::filesystem::is_directory(dir_entry)) - { - pNode->Children.push_back(ReloadAssets(dir_entry)); - } - else - { - pNode->Files.push_back(dir_entry); - } - } - - return pNode; - } - void AssetBrowser::HandleAssetDrop(std::filesystem::path dir) { @@ -252,25 +255,3 @@ namespace editor } } } - -// void treeChildren(ImGuiTreeNodeFlags node_flags, bool isOpen, int index) -// { -// if (isOpen) -// { -// for (int p = 0; p < meshList[index].children.size(); p++) -// { -// if (meshList[index].children[p].children.empty()) -// { -// node_flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; // ImGuiTreeNodeFlags_Bullet -// ImGui::TreeNodeEx((void *)(intptr_t)p, node_flags, meshList[index].children[p].name.c_str()); -// } -// else -// { -// bool o = ImGui::TreeNodeEx((void *)(intptr_t)p, node_flags, meshList[index].children[p].name.c_str()); -// ImGui::TreePop(); -// treeChildren(node_flags, o, p); -// } -// } -// ImGui::TreePop(); -// } -// } \ No newline at end of file diff --git a/src/run_modes/editor/panels/asset_browser.h b/src/run_modes/editor/panels/asset_browser.h index c9b25f5..8a5023f 100644 --- a/src/run_modes/editor/panels/asset_browser.h +++ b/src/run_modes/editor/panels/asset_browser.h @@ -41,19 +41,16 @@ namespace editor private: std::filesystem::path mAssetDirectory; std::filesystem::path mSelectedDir; - Node* mTreeRoot; - Node* mSelectedNode; Editor* mpEditor; bool mNewFolder; bool mSyncTree; private: - Node* ReloadAssets(std::filesystem::path dir); - Node* FindNodeAt(std::filesystem::path dir); void HandleAssetDrop(std::filesystem::path dir); void DoDirTree(std::filesystem::path dir); + void DoContentArea(ImVec2 wind_size); void DoContextMenu(); }; }