content browser and textures on entity sprites

This commit is contained in:
Erris
2026-02-27 10:45:44 +01:00
parent cee0f42164
commit 9de9609dee
23 changed files with 809 additions and 213 deletions

View File

@@ -0,0 +1,88 @@
#include "imgui_internal.h"
#include <cstdint>
#include <cstring>
#include <panels/content_browser.hpp>
#include <open_engine/renderer/texture.hpp>
#include <open_engine/logging.hpp>
#include <filesystem>
#include <imgui.h>
namespace OpenEngine {
const std::filesystem::path assets_directory = "assets";
ContentBrowserPanel::ContentBrowserPanel()
: current_directory(assets_directory)
{
// TODO: Add file texture. Get free icons and add license
folder_icon = Texture2D::Create("resources/textures/folder.png");
}
void ContentBrowserPanel::OnImGuiRender()
{
ImGui::Begin("Assets");
ImGui::Text("%s", current_directory.c_str());
if (current_directory != assets_directory)
if (ImGui::Button(".."))
current_directory = current_directory.parent_path();
auto directory_it = std::filesystem::directory_iterator(current_directory);
ImVec2 button_size = { 100, 100 };
auto panel_width = ImGui::GetContentRegionAvail().x;
uint32_t table_columns = (int)(panel_width / button_size.x) - 1;
if (table_columns <= 0)
table_columns = 1;
ImVec2 padding( 9, 9 );
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, padding);
if (ImGui::BeginTable("table1", table_columns, ImGuiTableFlags_SizingFixedSame))
{
for (auto& entry : directory_it) {
auto file_name = entry.path().filename().string();
ImGui::PushID(file_name.c_str());
ImGui::TableNextColumn();
ImGui::PushStyleColor(ImGuiCol_Button, { 0.0f, 0.0f, 0.0f, 0.0f });
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, { 0.192f, 0.196f, 0.266f, 1.0f });
ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.270f, 0.278f, 0.352f, 1.0f });
ImGui::BeginGroup();
ImGui::ImageButton("##X", (ImTextureID)folder_icon->GetID(), button_size, { 0, 1 }, { 1, 0 });
if (entry.is_regular_file() && ImGui::BeginDragDropSource()) {
const char* source = entry.path().c_str();
ImGui::SetDragDropPayload("CONTENT_BROWSER_PAYLOAD", source, (strlen(source) + 1) * sizeof(char), ImGuiCond_Once);
ImGui::EndDragDropSource();
}
float columnWidth = ImGui::GetColumnWidth();
float textWidth = ImGui::CalcTextSize(file_name.c_str()).x;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (columnWidth - textWidth) * 0.5f);
ImGui::TextWrapped("%s", file_name.c_str());
ImGui::EndGroup();
if (entry.is_directory()) {
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
current_directory = entry.path().c_str();
}
ImGui::PopStyleColor(3);
ImGui::PopID();
}
ImGui::EndTable();
}
ImGui::PopStyleVar();
ImGui::End();
}
}