Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions editor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# Frame Editor.

add_executable(FrameEditor
WIN32
# Frame Editor.
add_executable(FrameEditor
WIN32
main.cpp
menubar.cpp
menubar.h
menubar_view.cpp
menubar_view.h
menubar_file.cpp
menubar_file.h
window_start.cpp
window_start.h
${CMAKE_CURRENT_SOURCE_DIR}/../asset/json/new_project_template.json
)

target_include_directories(FrameEditor
PUBLIC
editor/
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_CURRENT_BINARY_DIR}
)

target_link_libraries(FrameEditor
PUBLIC
Frame
FrameCommon
FrameGui
FrameOpenGL
FrameOpenGLGui
FrameOpenGLFile
FrameProto
imgui::imgui
ImGuiColorTextEdit
)

set_property(TARGET FrameEditor PROPERTY FOLDER "FrameEditor")
menubar_file.h
window_start.cpp
window_start.h
window_level.cpp
window_level.h
${CMAKE_CURRENT_SOURCE_DIR}/../asset/json/new_project_template.json
)

target_include_directories(FrameEditor
PUBLIC
editor/
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_CURRENT_BINARY_DIR}
)

target_link_libraries(FrameEditor
PUBLIC
Frame
FrameCommon
FrameGui
FrameOpenGL
FrameOpenGLGui
FrameOpenGLFile
FrameProto
imgui::imgui
ImGuiColorTextEdit
)

set_property(TARGET FrameEditor PROPERTY FOLDER "FrameEditor")
6 changes: 6 additions & 0 deletions editor/menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "frame/gui/window_logger.h"
#include "frame/gui/window_resolution.h"
#include "frame/logger.h"
#include "window_level.h"
#include <imgui.h>
#include <set>

Expand Down Expand Up @@ -77,6 +78,11 @@ void Menubar::MenuEdit()
std::make_unique<WindowJsonFile>(
menubar_file_.GetFileName(), device_));
}
if (ImGui::MenuItem("Level Editor"))
{
menubar_view_.GetDrawGui().AddWindow(
std::make_unique<WindowLevel>(device_));
}
if (ImGui::BeginMenu("Shader"))
{
std::set<std::string> shader_names;
Expand Down
93 changes: 93 additions & 0 deletions editor/window_level.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "window_level.h"

#include <imgui.h>

namespace frame::gui
{

WindowLevel::WindowLevel(DeviceInterface& device) : device_(device)
{
}

void WindowLevel::DisplayNode(LevelInterface& level, EntityId id)
{
auto& node = level.GetSceneNodeFromId(id);
std::string name = level.GetNameFromId(id);
auto children = level.GetChildList(id);
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow;
if (children.empty())
flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen;
bool open = ImGui::TreeNodeEx(
(void*)(static_cast<intptr_t>(id)), flags, "%s", name.c_str());
if (open && !children.empty())
{
for (auto child : children)
{
DisplayNode(level, child);
}
ImGui::TreePop();
}
}

bool WindowLevel::DrawCallback()
{
auto& level = device_.GetLevel();
if (ImGui::BeginTabBar("##level_tabs"))
{
if (ImGui::BeginTabItem("Textures"))
{
for (auto id : level.GetTextures())
{
auto& tex = level.GetTextureFromId(id);
ImGui::BulletText("%s", tex.GetName().c_str());
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Programs"))
{
for (auto id : level.GetPrograms())
{
auto& prog = level.GetProgramFromId(id);
ImGui::BulletText("%s", prog.GetName().c_str());
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Materials"))
{
for (auto id : level.GetMaterials())
{
auto& mat = level.GetMaterialFromId(id);
ImGui::BulletText("%s", mat.GetName().c_str());
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Scene"))
{
auto root = level.GetDefaultRootSceneNodeId();
if (root)
{
DisplayNode(level, root);
}
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
return true;
}

bool WindowLevel::End() const
{
return end_;
}

std::string WindowLevel::GetName() const
{
return name_;
}

void WindowLevel::SetName(const std::string& name)
{
name_ = name;
}

} // namespace frame::gui
28 changes: 28 additions & 0 deletions editor/window_level.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "frame/device_interface.h"
#include "frame/gui/gui_window_interface.h"

namespace frame::gui
{

class WindowLevel : public GuiWindowInterface
{
public:
explicit WindowLevel(DeviceInterface& device);
~WindowLevel() override = default;

bool DrawCallback() override;
bool End() const override;
std::string GetName() const override;
void SetName(const std::string& name) override;

private:
void DisplayNode(LevelInterface& level, EntityId id);

DeviceInterface& device_;
std::string name_ = "Level Editor";
bool end_ = false;
};

} // namespace frame::gui
Loading