Skip to content

Commit

Permalink
Content Browser Implementation (JeanPhilippeKernel#419)
Browse files Browse the repository at this point in the history
* raw patch

* made some crazy changes

* remove comments

* remove assets from build

* add margin to thumbnail
  • Loading branch information
jnyfah authored Jan 23, 2025
1 parent baa9bd4 commit adb990c
Show file tree
Hide file tree
Showing 8 changed files with 830 additions and 4 deletions.
Binary file added Resources/Editor/Settings/Icons/DirectoryIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Editor/Settings/Icons/FileIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
693 changes: 692 additions & 1 deletion Tetragrama/Components/ProjectViewUIComponent.cpp

Large diffs are not rendered by default.

56 changes: 54 additions & 2 deletions Tetragrama/Components/ProjectViewUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,66 @@

namespace Tetragrama::Components
{
enum class ContextMenuType
{
RightPane,
LeftPane,
File,
Folder
};

enum class PopupType
{
None,
CreateFolder,
CreateFile,
RenameFolder,
RenameFile,
DeleteFolder,
DeleteFile,
};

class ProjectViewUIComponent : public UIComponent
{
public:
ProjectViewUIComponent(Layers::ImguiLayer* parent = nullptr, std::string_view name = "Project", bool visibility = true);
virtual ~ProjectViewUIComponent();

void Update(ZEngine::Core::TimeStep dt) override;
void Update(ZEngine::Core::TimeStep dt) override;

virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override;

// Render Panes
void RenderContentBrowser(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer);
void RenderFilteredContent(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, std::string_view searchTerm);
void RenderDirectoryNode(const std::filesystem::path& directory);
void RenderContentTile(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, const std::filesystem::directory_entry& entry);
void RenderBackButton();
void RenderTreeBrowser();

// Popup helpers
void RenderContextMenu(ContextMenuType type, const std::filesystem::path& targetPath);
void RenderPopUpMenu();
void HandleCreateFolderPopup(const std::filesystem::path& path);
void HandleCreateFilePopup(const std::filesystem::path& path);

void HandleRenameFolderPopup(const std::filesystem::path& path);
void HandleDeleteFolderPopup(const std::filesystem::path& path);
void HandleRenameFilePopup(const std::filesystem::path& path);
void HandleDeleteFilePopup(const std::filesystem::path& path);

std::filesystem::path MakeRelative(const std::filesystem::path& path, const std::filesystem::path& base);

private:
std::filesystem::path m_assets_directory;
std::filesystem::path m_current_directory;
PopupType m_active_popup = PopupType::None;
std::filesystem::path m_popup_target_path;

virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override;
ZEngine::Rendering::Textures::TextureHandle m_directory_icon;
ZEngine::Rendering::Textures::TextureHandle m_file_icon;
bool m_textures_loaded = false;
static constexpr float m_thumbnail_size = 128.0f;
char m_search_buffer[MAX_FILE_PATH_COUNT] = "";
};
} // namespace Tetragrama::Components
24 changes: 24 additions & 0 deletions ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,30 @@ namespace ZEngine::Rendering::Renderers
Helpers::ThreadPoolHelper::Submit([this] { Run(); });
}

Textures::TextureHandle AsyncResourceLoader::LoadTextureFileSync(std::string_view filename)
{
int width = 0, height = 0, channel = 0;
stbi_uc* image_data = stbi_load(filename.data(), &width, &height, &channel, STBI_rgb_alpha);
if (!image_data)
{
ZENGINE_CORE_ERROR("Failed to load texture file synchronously: {}", filename.data());
return Textures::TextureHandle{};
}

Specifications::TextureSpecification spec = {
.Width = static_cast<uint32_t>(width),
.Height = static_cast<uint32_t>(height),
.BytePerPixel = 4, // RGBA
.Format = Specifications::ImageFormat::R8G8B8A8_SRGB,
.Data = image_data,
};

Textures::TextureHandle handle = Renderer->Device->GlobalTextures->Add(Renderer->CreateTexture(spec));
stbi_image_free(image_data);

return handle;
}

Textures::TextureHandle AsyncResourceLoader::LoadTextureFile(std::string_view filename)
{
auto abs_filename = std::filesystem::absolute(filename).string();
Expand Down
1 change: 1 addition & 0 deletions ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace ZEngine::Rendering::Renderers

void EnqueueTextureRequest(std::string_view file, const Textures::TextureHandle& handle);
Textures::TextureHandle LoadTextureFile(std::string_view filename);
Textures::TextureHandle LoadTextureFileSync(std::string_view filename);

private:
std::atomic_bool m_cancellation_token{false};
Expand Down
56 changes: 55 additions & 1 deletion ZEngine/ZEngine/Rendering/Renderers/ImGUIRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace ZEngine::Rendering::Renderers

.UseShader("imgui")
.SetShaderOverloadMaxSet(2000)
.SetOverloadPoolSize(2)
.SetOverloadPoolSize(4)

.UseSwapchainAsRenderTarget();

Expand Down Expand Up @@ -134,6 +134,20 @@ namespace ZEngine::Rendering::Renderers
frame_alloc_info.descriptorSetCount = 1;
frame_alloc_info.pSetLayouts = &descriptor_setlayout;
ZENGINE_VALIDATE_ASSERT(vkAllocateDescriptorSets(m_renderer->Device->LogicalDevice, &frame_alloc_info, &m_frame_output) == VK_SUCCESS, "Failed to create descriptor set")

VkDescriptorSetAllocateInfo image_alloc_info = {};
image_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
image_alloc_info.descriptorPool = shader->GetDescriptorPool();
image_alloc_info.descriptorSetCount = 1;
image_alloc_info.pSetLayouts = &descriptor_setlayout;
ZENGINE_VALIDATE_ASSERT(vkAllocateDescriptorSets(m_renderer->Device->LogicalDevice, &image_alloc_info, &m_folder_output) == VK_SUCCESS, "Failed to create descriptor set")

VkDescriptorSetAllocateInfo image2_alloc_info = {};
image2_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
image2_alloc_info.descriptorPool = shader->GetDescriptorPool();
image2_alloc_info.descriptorSetCount = 1;
image2_alloc_info.pSetLayouts = &descriptor_setlayout;
ZENGINE_VALIDATE_ASSERT(vkAllocateDescriptorSets(m_renderer->Device->LogicalDevice, &image2_alloc_info, &m_file_output) == VK_SUCCESS, "Failed to create descriptor set")
}

void ImGUIRenderer::Deinitialize()
Expand Down Expand Up @@ -344,4 +358,44 @@ namespace ZEngine::Rendering::Renderers

return m_frame_output;
}

VkDescriptorSet ImGUIRenderer::UpdateFileIconOutput(const Textures::TextureHandle& handle)
{
auto& texture = m_renderer->Device->GlobalTextures->Access(handle);
auto& buffer = texture->ImageBuffer->GetBuffer();

VkDescriptorImageInfo desc_image[1] = {};
desc_image[0].sampler = buffer.Sampler;
desc_image[0].imageView = buffer.ViewHandle;
desc_image[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
VkWriteDescriptorSet write_desc[1] = {};
write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write_desc[0].dstSet = m_file_output;
write_desc[0].descriptorCount = 1;
write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
write_desc[0].pImageInfo = desc_image;
vkUpdateDescriptorSets(m_renderer->Device->LogicalDevice, 1, write_desc, 0, nullptr);

return m_file_output;
}

VkDescriptorSet ImGUIRenderer::UpdateDirIconOutput(const Textures::TextureHandle& handle)
{
auto& texture = m_renderer->Device->GlobalTextures->Access(handle);
auto& buffer = texture->ImageBuffer->GetBuffer();

VkDescriptorImageInfo desc_image[1] = {};
desc_image[0].sampler = buffer.Sampler;
desc_image[0].imageView = buffer.ViewHandle;
desc_image[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
VkWriteDescriptorSet write_desc[1] = {};
write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write_desc[0].dstSet = m_folder_output;
write_desc[0].descriptorCount = 1;
write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
write_desc[0].pImageInfo = desc_image;
vkUpdateDescriptorSets(m_renderer->Device->LogicalDevice, 1, write_desc, 0, nullptr);

return m_folder_output;
}
} // namespace ZEngine::Rendering::Renderers
4 changes: 4 additions & 0 deletions ZEngine/ZEngine/Rendering/Renderers/ImGUIRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ namespace ZEngine::Rendering::Renderers
void DrawFrame(uint32_t frame_index, Hardwares::CommandBuffer* const command_buffer);

VkDescriptorSet UpdateFrameOutput(const Textures::TextureHandle& handle);
VkDescriptorSet UpdateFileIconOutput(const Textures::TextureHandle& handle);
VkDescriptorSet UpdateDirIconOutput(const Textures::TextureHandle& handle);

private:
VkDescriptorSet m_frame_output{VK_NULL_HANDLE};
VkDescriptorSet m_font_descriptor_set{VK_NULL_HANDLE};
VkDescriptorSet m_folder_output{VK_NULL_HANDLE};
VkDescriptorSet m_file_output{VK_NULL_HANDLE};
GraphicRenderer* m_renderer;
Hardwares::VertexBufferSetHandle m_vertex_buffer_handle;
Hardwares::IndexBufferSetHandle m_index_buffer_handle;
Expand Down

0 comments on commit adb990c

Please sign in to comment.