Skip to content

Commit

Permalink
Work on the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Zang3th committed Sep 24, 2023
1 parent 73e6314 commit f41767a
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 23 deletions.
100 changes: 86 additions & 14 deletions Apps/CellSim/src/CellSimInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@ namespace CS
: _windowFlags(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_NoMove),
_windowAlphaValue(0.65f),
_windowAlphaValue(0.85f),
_showOverlay(true)
{
//Load custom font
// --- Load custom font
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("../Res/Assets/Fonts/JetBrainsMono-Medium.ttf", 19);

//Set style
// --- Set style
ImGui::StyleColorsDark();
SetDarkThemeColors();

//Calculate and set overlay parameters
// --- Calculate and set overlay parameters
SetOverlayParameters();
}

void CellSimInterface::AddElements()
{
//Discard old plotting data every 120 frames
// --- Discard old plotting data every 120 frames
if(Engine::Window::GetFrameCounter() > 120)
{
ImGui::PlotVarFlushOldEntries();
}

//Menu bar
// --- Menu bar
if(ImGui::BeginMainMenuBar())
{
if(ImGui::BeginMenu("Settings"))
Expand All @@ -71,24 +73,24 @@ namespace CS
}
ImGui::EndMainMenuBar();

//Overlay
// --- Overlay
if(_showOverlay)
{
SetOverlayParameters();

//Sidebar
// --- Sidebar
{
ImGui::SetNextWindowBgAlpha(_windowAlphaValue);
ImGui::SetNextWindowPos(_sidebarPos, ImGuiCond_Always, _overlayPivot);
ImGui::SetNextWindowSize(_sidebarSize);

if(ImGui::Begin("Sidebar", &_showOverlay, _windowFlags))
{
//Application stats
// --- Application stats
ImGui::Text("Application average %.2f ms/frame (%.1f FPS)", Engine::Window::GetDeltaTime() * 1000.0f, Engine::Window::GetFps());
ImGui::PlotVar("", (float)Engine::Window::GetDeltaTime() * 1000.0f, 0.0f, 30.0f);

//Render stats
// --- Render stats
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("DrawCalls: %d", Engine::AppSettings::renderStats.drawCalls);
Expand All @@ -97,24 +99,94 @@ namespace CS

ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Model passes: %d", Engine::AppSettings::renderStats.modelPasses);
ImGui::Text("Model passes: %d", Engine::AppSettings::renderStats.modelPasses);
ImGui::Text("Sprite passes: %d", Engine::AppSettings::renderStats.spritePasses);
ImGui::Text("Cell passes: %d", Engine::AppSettings::renderStats.cellPasses);
ImGui::Text("Cell passes: %d", Engine::AppSettings::renderStats.cellPasses);
ImGui::Separator();

//Camera stats
// --- Camera stats
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Camera-Position: ( %.1f, %.1f, %.1f )", Engine::Camera3D::GetPosition().x, Engine::Camera3D::GetPosition().y, Engine::Camera3D::GetPosition().z);
ImGui::Text("Camera-Front: ( %.1f, %.1f, %.1f )", Engine::Camera3D::GetFront().x, Engine::Camera3D::GetFront().y, Engine::Camera3D::GetFront().z);
ImGui::Text("Camera-Yaw, Pitch: ( %.2f, %.2f )", Engine::Camera3D::GetYaw(), Engine::Camera3D::GetPitch());
ImGui::Separator();

//Profiling/Timing-Results
// --- Profiling/Timing-Results
ImGui::NewLine();
ImGui::Separator();
for(auto const& entry : Engine::Profiler::_results)
{
ImGui::Text("%.3fms - %s", entry.second, entry.first);
}
ImGui::Separator();

// --- Cell spawn menu
ImGui::NewLine();
ImGui::Separator();
TextCentered("Cell spawn menu");
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 10));
ImGui::Separator();
ImGui::Text("Frame dimensions: (%d, %d, %d)", Engine::AppSettings::CELL_FRAME_SIZE, Engine::AppSettings::CELL_FRAME_SIZE, Engine::AppSettings::CELL_FRAME_SIZE);

// --- Drop down menu
std::string cellTypeString = std::string("Cell type: ") + Engine::CellTypeStrings[Engine::AppSettings::selectedCellType];
if(ImGui::BeginMenu(cellTypeString.c_str()))
{
if(ImGui::MenuItem("None"))
{
Engine::AppSettings::selectedCellType = Engine::CellTypes::None;
}

if(ImGui::MenuItem("Water"))
{
Engine::AppSettings::selectedCellType = Engine::CellTypes::Water;
}

if(ImGui::MenuItem("Magma"))
{
Engine::AppSettings::selectedCellType = Engine::CellTypes::Magma;
}

if(ImGui::MenuItem("Stone"))
{
Engine::AppSettings::selectedCellType = Engine::CellTypes::Stone;
}
ImGui::EndMenu();

Engine::CameraController3D::DeFocusWindow(Engine::Window::GetWindow());
}

// --- Coordinate input
float width = ImGui::CalcItemWidth();
ImGui::PushItemWidth(width / 1.5f);

ImGui::Text("X Coordinate:\t");
ImGui::SameLine();
ImGui::InputInt("##1", &Engine::AppSettings::selectedXCoord, 10, 0, ImGuiInputTextFlags_CharsDecimal);

ImGui::Text("Y Coordinate:\t");
ImGui::SameLine();
ImGui::InputInt("##2", &Engine::AppSettings::selectedYCoord, 10, 0, ImGuiInputTextFlags_CharsDecimal);

ImGui::Text("Z Coordinate:\t");
ImGui::SameLine();
ImGui::InputInt("##3", &Engine::AppSettings::selectedZCoord, 10, 0, ImGuiInputTextFlags_CharsDecimal);

//ToDo: Implement boundary checks

// --- Spawn button
//ToDo: Integrate in base class
ImGui::PopItemWidth();
auto windowWidth = ImGui::GetWindowSize().x;
auto textWidth = ImGui::CalcTextSize("Spawn").x;

ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
if (ImGui::Button("Spawn"))
{
//ToDo: Implement spawn logic
}
ImGui::PopStyleVar();
ImGui::Separator();
}
ImGui::End();
Expand Down
6 changes: 5 additions & 1 deletion Engine/Application/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Engine

void Interface::SetDarkThemeColors()
{
auto& colors = ImGui::GetStyle().Colors;
auto& colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_WindowBg] = ImVec4{0.1f, 0.105f, 0.11f, 1.0f};

// Headers
Expand Down Expand Up @@ -35,6 +35,10 @@ namespace Engine
colors[ImGuiCol_TitleBg] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f};
colors[ImGuiCol_TitleBgActive] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f};
colors[ImGuiCol_TitleBgCollapsed] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f};

// Slider
colors[ImGuiCol_SliderGrab] = ImVec4{0.20f, 0.25f, 0.55f, 1.0f};
colors[ImGuiCol_SliderGrabActive] = ImVec4{0.45f, 0.50f, 0.80f, 1.0f};
}

void Interface::TextCentered(const char* text)
Expand Down
4 changes: 4 additions & 0 deletions Engine/Core/CellTypes.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
X(None)
X(Water)
X(Magma)
X(Stone)
32 changes: 28 additions & 4 deletions Engine/Core/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,43 @@ namespace Engine
}
};

// --- Read in of cell types via X-Macro
enum CellTypes
{
# define X(a) a,
# include "CellTypes.def"
# undef X
};

inline static const char* const CellTypeStrings[] =
{
# define X(a) #a,
# include "CellTypes.def"
# undef X
};

// --- Application settings
struct AppSettings
struct AppSettings //ToDo: Separate all application settings from another
{
// --- General
inline static constexpr int32 WINDOW_WIDTH = 1920;
inline static constexpr int32 WINDOW_HEIGHT = 1080;
inline static constexpr uint32 CELL_CUBE_SIZE = 64;
inline static uint32 planeSize = 64;
inline static constexpr float GRAVITY = -20.0f;
inline static bool wireframeRendering = false;
inline static bool debugSprites = false;
inline static bool resetCamera = false;
inline static RenderStats renderStats;

// --- GreenWorld
inline static constexpr float GRAVITY = -20.0f;

// --- CellSim
inline static constexpr uint32 CELL_FRAME_SIZE = 64;
inline static bool resetCamera = false;
inline static CellTypes selectedCellType = None;
inline static int32 selectedXCoord = 0;
inline static int32 selectedYCoord = 0;
inline static int32 selectedZCoord = 0;

AppSettings() = delete;
};
}
3 changes: 2 additions & 1 deletion Engine/Rendering/Camera/CameraController3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace Engine
void CameraController3D::MouseButtonCallback(GLFWwindow* window, int32 button, int32 action, int32 mods)
{
//_lastY needs to be greater than 27 to not trigger on the titlebar
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS && _lastY > 27)
//_lastX needs to be less than 1505 to not trigger on the sidebar
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS && _lastY > 27 && _lastX < 1505)
{
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
_windowInFocus = true;
Expand Down
2 changes: 1 addition & 1 deletion Engine/Rendering/Renderer/CellRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Engine

CellRenderer::~CellRenderer()
{
//TODO: Iterate over all cells and delete them
//ToDo: Iterate over all cells and delete them
}

void CellRenderer::InitGpuStorage()
Expand Down
2 changes: 1 addition & 1 deletion Engine/Rendering/Renderer/CellRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Engine
Shader* _shader;
glm::vec3 _worldPos;

std::array<glm::mat4, AppSettings::CELL_CUBE_SIZE * 3> _modelViewStorage;
std::array<glm::mat4, AppSettings::CELL_FRAME_SIZE * 3> _modelViewStorage;

CellRenderer
(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@

### CellSim

![CellSim](Res/Screenshots/CellSim/Screenshot_CS_003.png)
![CellSim](Res/Screenshots/CellSim/Screenshot_CS_004.png)
Binary file added Res/Screenshots/CellSim/Screenshot_CS_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f41767a

Please sign in to comment.