Skip to content

Commit

Permalink
Clean up window creation
Browse files Browse the repository at this point in the history
- check if the windows are visible before rendering it's content
  • Loading branch information
dvsku committed Jun 18, 2024
1 parent 57de40d commit 152283a
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 145 deletions.
97 changes: 41 additions & 56 deletions source/devue_app/src/gui/components/dv_comp_hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,51 @@ dv_comp_hierarchy::dv_comp_hierarchy(dv_systems* systems, dv_components* compone
: dv_comp(systems, components) {}

void dv_comp_hierarchy::render() {
// Just create the window if there's no
// active scene
if (!m_systems->scene.current_scene) {
ImGui::Begin("Hierarchy##Window");
ImGui::End();
return;
}

bool is_selected = false;
core::dv_scene* scene = m_systems->scene.current_scene;
bool is_selected = false;
auto scene = m_systems->scene.current_scene;

ImGui::PushStyleVar(ImGuiStyleVar_DisabledAlpha, 0.8f);

ImGui::Begin("Hierarchy##Window");

ImGui::PushID("Hierarchy");

ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (dv_util_imgui::collapsible("Cameras##Cameras")) {
is_selected = m_systems->properties.is_inspected(scene->camera);
if (dv_util_imgui::selectable("Camera 1##Camera1", is_selected)) {
m_systems->properties.set_inspected(scene->camera);
}
}

ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (dv_util_imgui::collapsible("Lighting##Lighting")) {
is_selected = m_systems->properties.is_inspected(scene->lighting.ambient_light);
if (dv_util_imgui::selectable("Ambient Light##AmbientLight1", is_selected)) {
m_systems->properties.set_inspected(scene->lighting.ambient_light);
}

is_selected = m_systems->properties.is_inspected(scene->lighting.directional_light);
if (dv_util_imgui::selectable("Directional Light##DirectionalLight1", is_selected)) {
m_systems->properties.set_inspected(scene->lighting.directional_light);
}
}

ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (dv_util_imgui::collapsible("Objects##Objects")) {
if (m_systems->scene.current_scene) {
for (auto& kvp : m_systems->scene.current_scene->models) {
dv_scene_model& smodel = kvp.second;

ImGui::PushID(DV_FORMAT("{}", smodel.uuid).c_str());

is_selected = m_systems->properties.is_inspected(smodel);
if (dv_util_imgui::selectable(DV_FORMAT("{}##Object", smodel.name).c_str(), is_selected)) {
m_systems->properties.set_inspected(smodel);
}

render_scene_model_context_menu(smodel);

ImGui::PopID();
}
}
if (ImGui::Begin("Hierarchy##Window")) {
if (scene) {
ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (dv_util_imgui::collapsible("Cameras##Cameras")) {
is_selected = m_systems->properties.is_inspected(scene->camera);
if (dv_util_imgui::selectable("Camera 1##Camera1", is_selected)) {
m_systems->properties.set_inspected(scene->camera);
}
}

ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (dv_util_imgui::collapsible("Lighting##Lighting")) {
is_selected = m_systems->properties.is_inspected(scene->lighting.ambient_light);
if (dv_util_imgui::selectable("Ambient Light##AmbientLight1", is_selected)) {
m_systems->properties.set_inspected(scene->lighting.ambient_light);
}

is_selected = m_systems->properties.is_inspected(scene->lighting.directional_light);
if (dv_util_imgui::selectable("Directional Light##DirectionalLight1", is_selected)) {
m_systems->properties.set_inspected(scene->lighting.directional_light);
}
}

ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (dv_util_imgui::collapsible("Objects##Objects")) {
for (auto& [smodel_id, smodel] : scene->models) {
ImGui::PushID(DV_FORMAT("{}", smodel_id).c_str());

is_selected = m_systems->properties.is_inspected(smodel);
if (dv_util_imgui::selectable(DV_FORMAT("{}##Object", smodel.name).c_str(), is_selected)) {
m_systems->properties.set_inspected(smodel);
}

render_scene_model_context_menu(smodel);

ImGui::PopID();
}
}
}
}

ImGui::PopID();

ImGui::End();

ImGui::PopStyleVar();
Expand Down
55 changes: 27 additions & 28 deletions source/devue_app/src/gui/components/dv_comp_meshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,42 @@ dv_comp_meshes::dv_comp_meshes(dv_systems* systems, dv_components* components)

void dv_comp_meshes::render() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0.0f, 0.0f });
ImGui::Begin("Meshes##Window");

ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.12157f, 0.12157f, 0.12157f, 1.00f));
ImGui::BeginChild("##Head", { 0.0f, 19.0f});
{
ImGui::Indent(4.0f);

const bool is_disabled = m_current_mesh_id == 0U;
if (ImGui::Begin("Meshes##Window")) {
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.12157f, 0.12157f, 0.12157f, 1.00f));
if (ImGui::BeginChild("##Head", { 0.0f, 19.0f })) {
ImGui::Indent(4.0f);

if (is_disabled)
ImGui::BeginDisabled();
const bool is_disabled = m_current_mesh_id == 0U;

if (libgui::imgui::icon_button(ICON_FA_CHEVRON_LEFT"##BackToMeshes", {19.0f, 19.0f})) {
m_current_mesh_id = 0U;
}
if (is_disabled)
ImGui::BeginDisabled();

if (is_disabled)
ImGui::EndDisabled();
if (libgui::imgui::icon_button(ICON_FA_CHEVRON_LEFT"##BackToMeshes", { 19.0f, 19.0f })) {
m_current_mesh_id = 0U;
}

ImGui::Unindent(2.0f);
}
ImGui::EndChild();
ImGui::PopStyleColor(1);
if (is_disabled)
ImGui::EndDisabled();

ImGui::Indent(4.0f);
ImGui::BeginChild("##Content", { ImGui::GetContentRegionAvail().x - 4.0f, ImGui::GetContentRegionAvail().y });
{
switch (m_systems->properties.get_inspected().inspected_type) {
case inspectable::type::model: render_model(); break;
case inspectable::type::scene_model: render_scene_model(); break;
default: m_current_mesh_id = 0U; break;
ImGui::Unindent(2.0f);
}
}
ImGui::EndChild();
ImGui::Unindent(4.0f);
ImGui::EndChild();
ImGui::PopStyleColor(1);

ImGui::Indent(4.0f);
if(ImGui::BeginChild("##Content", { ImGui::GetContentRegionAvail().x - 4.0f, ImGui::GetContentRegionAvail().y })) {
switch (m_systems->properties.get_inspected().inspected_type) {
case inspectable::type::model: render_model(); break;
case inspectable::type::scene_model: render_scene_model(); break;
default: m_current_mesh_id = 0U; break;
}
}
ImGui::EndChild();
ImGui::Unindent(4.0f);
}
ImGui::End();

ImGui::PopStyleVar(1);
}

Expand Down
19 changes: 9 additions & 10 deletions source/devue_app/src/gui/components/dv_comp_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ dv_comp_properties::dv_comp_properties(dv_systems* systems, dv_components* compo
: dv_comp(systems, components) {}

void dv_comp_properties::render() {
ImGui::Begin("Properties##Window");

switch (m_systems->properties.get_inspected().inspected_type) {
case inspectable::type::model: render_model(); break;
case inspectable::type::scene_model: render_scene_model(); break;
case inspectable::type::camera: render_camera(); break;
case inspectable::type::ambient_light: render_ambient_light(); break;
case inspectable::type::directional_light: render_directional_light(); break;
default: break;
if (ImGui::Begin("Properties##Window")) {
switch (m_systems->properties.get_inspected().inspected_type) {
case inspectable::type::model: render_model(); break;
case inspectable::type::scene_model: render_scene_model(); break;
case inspectable::type::camera: render_camera(); break;
case inspectable::type::ambient_light: render_ambient_light(); break;
case inspectable::type::directional_light: render_directional_light(); break;
default: break;
}
}

ImGui::End();
}

Expand Down
98 changes: 47 additions & 51 deletions source/devue_app/src/gui/components/dv_comp_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,57 @@ dv_comp_scene::dv_comp_scene(dv_systems* systems, dv_components* components)
: dv_comp(systems, components) {}

void dv_comp_scene::render(core::dv_render_target* render_target) {
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoCollapse
| ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
ImGuiWindowFlags flags = 0;
flags |= ImGuiWindowFlags_NoCollapse;
flags |= ImGuiWindowFlags_NoResize;
flags |= ImGuiWindowFlags_NoMove;

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));

ImGui::Begin("Scene##Window", 0, window_flags);

ImGui::PushID("Scene");

is_hovered = ImGui::IsWindowHovered();

if (render_target) {
ImVec2 available_size = ImGui::GetContentRegionAvail();

ImVec2 clipped_top_left = { 0.0f, 1.0f };
ImVec2 clipped_bottom_right = { 1.0f, 0.0f };

if (available_size.x < render_target->width || available_size.y < render_target->height) {
clipped_top_left = {
(0.5f - (available_size.x / 2.0f) / render_target->width),
1.0f - (0.5f - (available_size.y / 2.0f) / render_target->height)
};

clipped_bottom_right = {
(0.5f + (available_size.x / 2.0f) / render_target->width),
1.0f - (0.5f + (available_size.y / 2.0f) / render_target->height)
};
}

ImGui::Image(
(ImTextureID)render_target->get_frame_texture(),
ImGui::GetContentRegionAvail(),
clipped_top_left,
clipped_bottom_right
);
if (ImGui::Begin("Scene##Window", 0, flags)) {
is_hovered = ImGui::IsWindowHovered();

if (render_target) {
ImVec2 available_size = ImGui::GetContentRegionAvail();

ImVec2 clipped_top_left = { 0.0f, 1.0f };
ImVec2 clipped_bottom_right = { 1.0f, 0.0f };

if (available_size.x < render_target->width || available_size.y < render_target->height) {
clipped_top_left = {
( 0.5f - (available_size.x / 2.0f) / render_target->width ),
1.0f - ( 0.5f - (available_size.y / 2.0f) / render_target->height )
};

clipped_bottom_right = {
( 0.5f + (available_size.x / 2.0f) / render_target->width ),
1.0f - ( 0.5f + (available_size.y / 2.0f) / render_target->height )
};
}

ImGui::Image(
(ImTextureID)render_target->get_frame_texture(),
ImGui::GetContentRegionAvail(),
clipped_top_left,
clipped_bottom_right
);
}

ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(5, 5));
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.0f, 0.0f, 0.0f, 0.5f));

ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 28);

if (ImGui::BeginChild("Info", ImVec2(-1, 23))) {
ImGui::AlignTextToFramePadding();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10);
ImGui::Text("FPS: %d", core::dv_util_diag::fps);
}
ImGui::EndChild();

ImGui::PopStyleColor();
ImGui::PopStyleVar();
}

ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(5, 5));
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.0f, 0.0f, 0.0f, 0.5f));

ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 28);

ImGui::BeginChild("Info", ImVec2(-1, 23));

ImGui::AlignTextToFramePadding();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10);
ImGui::Text("FPS: %d", core::dv_util_diag::fps);

ImGui::EndChild();

ImGui::PopStyleColor();
ImGui::PopStyleVar();

ImGui::PopID();

ImGui::End();

ImGui::PopStyleVar();
Expand Down

0 comments on commit 152283a

Please sign in to comment.