From 05fa363ca5de377cd5839dc6453d1b1ddad23ac3 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Thu, 21 Sep 2023 11:22:38 -0400 Subject: [PATCH] Clean up main and argument parsing --- Editor/Editor.cpp | 198 ++++++++++++------------- Editor/src/Misc/WindowTheming.cpp | 16 ++ Editor/src/Misc/WindowTheming.h | 8 + Editor/src/Windows/EditorInterface.cpp | 30 +--- Editor/src/Windows/WelcomeWindow.cpp | 4 +- Nuake/src/Core/OS.cpp | 134 ++++++++--------- Nuake/src/Rendering/Renderer.cpp | 7 +- Nuake/src/Rendering/Renderer.h | 1 + Nuake/src/UI/ImUI.cpp | 141 ++++++++++++++++++ Nuake/src/UI/ImUI.h | 134 +---------------- Runtime/Runtime.cpp | 25 +++- premake5.lua | 4 + 12 files changed, 373 insertions(+), 329 deletions(-) create mode 100644 Editor/src/Misc/WindowTheming.cpp create mode 100644 Editor/src/Misc/WindowTheming.h create mode 100644 Nuake/src/UI/ImUI.cpp diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 8d7a7b89..4993cfd1 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -34,143 +34,133 @@ #include "src/Misc/WindowTheming.h" -std::string WindowTitle = "Nuake Editor "; -int ApplicationMain(int argc, char* argv[]) +struct LaunchSettings { - using namespace Nuake; + int32_t monitor = -1; + Vector2 resolution = { 1920, 1080 }; + std::string windowTitle = "Nuake Editor "; + std::string projectPath; +}; - std::string projectPath = ""; - - Vector2 editorResolution = Vector2(1280, 720); - int monitorIdx = -1; +std::vector ParseArguments(int argc, char* argv[]) +{ + std::vector args; for (uint32_t i = 0; i < argc; i++) { - char* arg = argv[i]; - std::string args = std::string(arg); + args.push_back(std::string(argv[i])); + } + return args; +} - if (args == "--resolution") +LaunchSettings ParseLaunchSettings(const std::vector& arguments) +{ + LaunchSettings launchSettings; + + const auto argumentSize = arguments.size(); + size_t i = 0; + for (const auto& arg : arguments) + { + if (arg == "--project") { - if (argc >= i + 1) + if (i + 1 <= argumentSize) { - std::string resString = std::string(argv[i + 1]); + std::string projectPath = arguments[i + 1]; + launchSettings.projectPath = projectPath; + } + } + else if (arg == "--resolution") + { + if (i + 1 <= argumentSize) + { + std::string resString = arguments[i + 1]; const auto& resSplits = String::Split(resString, 'x'); if (resSplits.size() == 2) { int width = stoi(resSplits[0]); int height = stoi(resSplits[1]); - editorResolution = Vector2(width, height); + launchSettings.resolution = Vector2(width, height); } } } - - if (args == "--monitor") + else if (arg == "--monitor") { - if (argc >= i + 1) + if (i + 1 <= argumentSize) { - std::string monitorIdxString = std::string(argv[i + 1]); - monitorIdx = stoi(monitorIdxString); - + launchSettings.monitor = stoi(arguments[i + 1]); } } + + i++; } - bool shouldLoadProject = false; - if (argc > 1) + return launchSettings; +} + +int ApplicationMain(int argc, char* argv[]) +{ + using namespace Nuake; + + // Parse launch arguments + const auto arguments = ParseArguments(argc, argv); + LaunchSettings launchSettings = ParseLaunchSettings(arguments); + +#ifdef NK_DEBUG + launchSettings.windowTitle += "(DEBUG BUILD)"; +#endif // NK_DEBUG + + // Initialize Engine & Window + Engine::Init(); + auto& window = Engine::GetCurrentWindow(); + window->SetSize(launchSettings.resolution); + window->SetTitle(launchSettings.windowTitle); + + if (launchSettings.monitor >= 0) { - shouldLoadProject = true; - projectPath = std::string(argv[1]); + window->SetMonitor(launchSettings.monitor); } + WindowTheming::SetWindowDarkMode(window); - if (playMode) - { - Nuake::Engine::Init(); - Nuake::EditorInterface editor; - editor.BuildFonts(); - - Ref project = Nuake::Project::New(); - FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); - - project->FullPath = projectPath; - project->Deserialize(FileSystem::ReadFile(projectPath, true)); - - Ref window = Nuake::Engine::GetCurrentWindow(); - window->SetTitle(project->Name); - - Nuake::Engine::LoadProject(project); - - Nuake::Engine::EnterPlayMode(); - auto shader = Nuake::ShaderManager::GetShader("resources/Shaders/copy.shader"); - while (!window->ShouldClose()) - { - Nuake::Vector2 WindowSize = window->GetSize(); - glViewport(0, 0, WindowSize.x, WindowSize.y); - Nuake::Renderer2D::BeginDraw(WindowSize); - Nuake::Engine::Tick(); - Nuake::Engine::Draw(); - - shader->Bind(); - - window->GetFrameBuffer()->GetTexture()->Bind(0); - shader->SetUniform1i("u_Source", 0); - Nuake::Renderer::DrawQuad(Nuake::Matrix4(1)); - - Nuake::Engine::EndDraw(); - } - } - else - { - Nuake::Engine::Init(); - - auto& window = Engine::GetCurrentWindow(); - window->SetSize(editorResolution); - window->SetTitle(WindowTitle); - - WindowTheming::SetWindowDarkMode(window); - + // Initialize Editor Nuake::EditorInterface editor; editor.BuildFonts(); + + // Load project in argument + if (!launchSettings.projectPath.empty()) + { + FileSystem::SetRootDirectory(FileSystem::GetParentPath(launchSettings.projectPath)); - if (monitorIdx != -1) + auto project = Project::New(); + auto projectFileData = FileSystem::ReadFile(launchSettings.projectPath, true); + try { - window->SetMonitor(monitorIdx); + project->Deserialize(json::parse(projectFileData)); + project->FullPath = launchSettings.projectPath; + + Engine::LoadProject(project); + + editor.filesystem->m_CurrentDirectory = Nuake::FileSystem::RootDirectory; } - - GizmoDrawer gizmoDrawer = GizmoDrawer(); - - if (shouldLoadProject) + catch (std::exception exception) { - FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); - - auto project = Project::New(); - auto projectFileData = FileSystem::ReadFile(projectPath, true); - try - { - project->Deserialize(json::parse(projectFileData)); - project->FullPath = projectPath; - - Engine::LoadProject(project); - - editor.filesystem->m_CurrentDirectory = Nuake::FileSystem::RootDirectory; - } - catch (std::exception exception) - { - Logger::Log("Error loading project: " + projectPath, "editor", CRITICAL); - Logger::Log(exception.what()); - } + Logger::Log("Error loading project: " + launchSettings.projectPath, "editor", CRITICAL); + Logger::Log(exception.what()); } + } - while (!window->ShouldClose()) - { - Nuake::Engine::Tick(); - Nuake::Engine::Draw(); - - Timestep ts = Nuake::Engine::GetTimestep(); - + // Start application main loop + GizmoDrawer gizmoDrawer = GizmoDrawer(); + while (!window->ShouldClose()) + { + Nuake::Engine::Tick(); // Update + Nuake::Engine::Draw(); // Render + + // Render editor Nuake::Vector2 WindowSize = window->GetSize(); glViewport(0, 0, WindowSize.x, WindowSize.y); Nuake::Renderer2D::BeginDraw(WindowSize); + // Draw gizmos auto sceneFramebuffer = window->GetFrameBuffer(); sceneFramebuffer->Bind(); { @@ -198,15 +188,15 @@ int ApplicationMain(int argc, char* argv[]) } sceneFramebuffer->Unbind(); - editor.Update(ts); + // Update & Draw editor + editor.Update(Nuake::Engine::GetTimestep()); editor.Draw(); Nuake::Engine::EndDraw(); } - + // Shutdown Nuake::Engine::Close(); - return 0; } @@ -221,7 +211,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cdmline, int cmds #else -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) { return ApplicationMain(argc, argv); } diff --git a/Editor/src/Misc/WindowTheming.cpp b/Editor/src/Misc/WindowTheming.cpp new file mode 100644 index 00000000..ff461abc --- /dev/null +++ b/Editor/src/Misc/WindowTheming.cpp @@ -0,0 +1,16 @@ +#include "WindowTheming.h" + +#include + +#define GLFW_EXPOSE_NATIVE_WIN32 +#include + +#include + +namespace WindowTheming +{ + void SetWindowDarkMode(Ref window) + { + + } +} \ No newline at end of file diff --git a/Editor/src/Misc/WindowTheming.h b/Editor/src/Misc/WindowTheming.h new file mode 100644 index 00000000..d26d2612 --- /dev/null +++ b/Editor/src/Misc/WindowTheming.h @@ -0,0 +1,8 @@ +#pragma once + +#include "src/Window.h" + +namespace WindowTheming +{ + void SetWindowDarkMode(Ref window); +} \ No newline at end of file diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 399f0f8c..4a835397 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -48,6 +48,8 @@ #include #include "UIDemoWindow.h" +#include + namespace Nuake { Ref userInterface; ImFont* normalFont; @@ -1045,39 +1047,19 @@ namespace Nuake { ImGui::End(); std::string title = ICON_FA_TREE + std::string(" Hierarchy"); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(4, 0)); if (ImGui::Begin(title.c_str())) { - // Buttons to add and remove entity. - if(ImGui::BeginChild("Buttons", ImVec2(ImGui::GetContentRegionAvail().x, 30), false)) - { - // Add entity. - if (ImGui::Button(ICON_FA_PLUS, ImVec2(30, 30))) - Engine::GetCurrentScene()->CreateEntity("Entity"); - - //// Remove Entity - //if (ImGui::Button("Remove")) - //{ - // scene->DestroyEntity(m_SelectedEntity); - // - // // Unselect delted entity. - // m_SelectedEntity = scene->GetAllEntities().at(0); - //} - } - ImGui::EndChild(); // Draw a tree of entities. ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(26.f / 255.0f, 26.f / 255.0f, 26.f / 255.0f, 1)); - if (ImGui::BeginChild("Scene tree", ImGui::GetContentRegionAvail(), false)) { - if (ImGui::BeginTable("entity_table", 3, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_SizingStretchProp)) + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, { 8, 4 }); + if (ImGui::BeginTable("entity_table", 3, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_NoPadInnerX | ImGuiTableFlags_NoPadOuterX)) { ImGui::TableSetupColumn("Label", ImGuiTableColumnFlags_IndentEnable); ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_IndentEnable); ImGui::TableSetupColumn("Visibility", ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_IndentDisable | ImGuiTableColumnFlags_WidthFixed); ImGui::TableHeadersRow(); - ImGui::TableNextRow(); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0, 0)); std::vector entities = scene->GetAllEntities(); @@ -1108,8 +1090,8 @@ namespace Nuake { } ImGui::PopStyleVar(); } - ImGui::EndTable(); + ImGui::PopStyleVar(); } ImGui::EndChild(); @@ -1139,8 +1121,6 @@ namespace Nuake { } } ImGui::End(); - ImGui::PopStyleVar(); - ImGui::PopStyleVar(); } bool EditorInterface::EntityContainsItself(Entity source, Entity target) diff --git a/Editor/src/Windows/WelcomeWindow.cpp b/Editor/src/Windows/WelcomeWindow.cpp index d81eb63c..c96cc33e 100644 --- a/Editor/src/Windows/WelcomeWindow.cpp +++ b/Editor/src/Windows/WelcomeWindow.cpp @@ -131,10 +131,8 @@ namespace Nuake ImGui::SameLine(); DrawRecentProjectsSection(); } - ImGui::End(); - ImGui::PopStyleVar(); - ImGui::PopStyleVar(); + ImGui::PopStyleVar(2); } void WelcomeWindow::DrawRecentProjectsSection() diff --git a/Nuake/src/Core/OS.cpp b/Nuake/src/Core/OS.cpp index 823b1634..a9210672 100644 --- a/Nuake/src/Core/OS.cpp +++ b/Nuake/src/Core/OS.cpp @@ -10,72 +10,72 @@ #include #include -using namespace Nuake; +namespace Nuake { + void OS::CopyToClipboard(const std::string& value) + { + auto glob = GlobalAlloc(GMEM_FIXED, 512); + memcpy(glob, value.data(), value.size()); + OpenClipboard(glfwGetWin32Window(Window::Get()->GetHandle())); + EmptyClipboard(); + SetClipboardData(CF_TEXT, glob); + CloseClipboard(); + } -void OS::CopyToClipboard(const std::string& value) -{ - auto glob = GlobalAlloc(GMEM_FIXED, 512); - memcpy(glob, value.data(), value.size()); - OpenClipboard(glfwGetWin32Window(Window::Get()->GetHandle())); - EmptyClipboard(); - SetClipboardData(CF_TEXT, glob); - CloseClipboard(); + std::string OS::GetFromClipboard() + { + OpenClipboard(nullptr); + HANDLE hData = GetClipboardData(CF_TEXT); + + char* pszText = static_cast(GlobalLock(hData)); + std::string text(pszText); + + GlobalUnlock(hData); + CloseClipboard(); + + return text; + } + + int OS::GetTime() + { + return static_cast(std::chrono::system_clock::now().time_since_epoch().count()); + } + + void OS::OpenIn(const std::string& filePath) + { + ShellExecuteA(nullptr, "open", filePath.c_str(), nullptr, nullptr, SW_SHOWDEFAULT); + } + + int OS::RenameFile(const Ref& file, const std::string& newName) + { + std::string extension = !String::EndsWith(newName, file->GetExtension().c_str()) ? file->GetExtension() : ""; + std::string newFilePath = file->GetParent()->fullPath + newName + extension; + + std::error_code resultError; + std::filesystem::rename(file->GetAbsolutePath().c_str(), newFilePath.c_str(), resultError); + return resultError.value() == 0; + } + + int OS::RenameDirectory(const Ref& dir, const std::string& newName) + { + std::string newDirPath = dir->Parent->fullPath + newName; + + std::error_code resultError; + std::filesystem::rename(dir->fullPath.c_str(), newDirPath.c_str(), resultError); + return resultError.value() == 0; + } + + void OS::ShowInFileExplorer(const std::string& filePath) + { + ShellExecuteA(nullptr, "open", "explorer.exe", ("/select," + std::string(filePath)).c_str(), nullptr, SW_SHOWDEFAULT); + } + + void OS::OpenTrenchbroomMap(const std::string& filePath) + { + ShellExecuteA(nullptr, nullptr, Engine::GetProject()->TrenchbroomPath.c_str(), filePath.c_str(), nullptr, SW_SHOW); + } + + void OS::OpenURL(const std::string& url) + { + ShellExecute(nullptr, nullptr, std::wstring(url.begin(), url.end()).c_str(), 0, 0, SW_SHOW); + } } - -std::string OS::GetFromClipboard() -{ - OpenClipboard(nullptr); - HANDLE hData = GetClipboardData(CF_TEXT); - - char* pszText = static_cast(GlobalLock(hData)); - std::string text(pszText); - - GlobalUnlock(hData); - CloseClipboard(); - - return text; -} - -int OS::GetTime() -{ - return static_cast(std::chrono::system_clock::now().time_since_epoch().count()); -} - -void OS::OpenIn(const std::string& filePath) -{ - ShellExecuteA(nullptr, "open", filePath.c_str(), nullptr, nullptr, SW_SHOWDEFAULT); -} - -int OS::RenameFile(const Ref& file, const std::string& newName) -{ - std::string extension = !String::EndsWith(newName, file->GetExtension().c_str()) ? file->GetExtension() : ""; - std::string newFilePath = file->GetParent()->fullPath + newName + extension; - - std::error_code resultError; - std::filesystem::rename(file->GetAbsolutePath().c_str(), newFilePath.c_str(), resultError); - return resultError.value() == 0; -} - -int OS::RenameDirectory(const Ref& dir, const std::string& newName) -{ - std::string newDirPath = dir->Parent->fullPath + newName; - - std::error_code resultError; - std::filesystem::rename(dir->fullPath.c_str(), newDirPath.c_str(), resultError); - return resultError.value() == 0; -} - -void OS::ShowInFileExplorer(const std::string& filePath) -{ - ShellExecuteA(nullptr, "open", "explorer.exe", ("/select," + std::string(filePath)).c_str(), nullptr, SW_SHOWDEFAULT); -} - -void OS::OpenTrenchbroomMap(const std::string& filePath) -{ - ShellExecuteA(nullptr, nullptr, Engine::GetProject()->TrenchbroomPath.c_str(), filePath.c_str(), nullptr, SW_SHOW); -} - -void OS::OpenURL(const std::string& url) -{ - ShellExecute(nullptr, nullptr, std::wstring(url.begin(), url.end()).c_str(), 0, 0, SW_SHOW); -} \ No newline at end of file diff --git a/Nuake/src/Rendering/Renderer.cpp b/Nuake/src/Rendering/Renderer.cpp index c6490846..63da102e 100644 --- a/Nuake/src/Rendering/Renderer.cpp +++ b/Nuake/src/Rendering/Renderer.cpp @@ -18,6 +18,8 @@ namespace Nuake { + uint32_t Renderer::MAX_LIGHT = 32; + unsigned int depthTexture; unsigned int depthFBO; @@ -137,8 +139,10 @@ namespace Nuake void Renderer::RegisterDeferredLight(TransformComponent transform, LightComponent light) { - if (m_Lights.size() == 20) + if (m_Lights.size() == MAX_LIGHT) + { return; + } Shader* deferredShader = ShaderManager::GetShader("resources/Shaders/deferred.shader"); deferredShader->Bind(); @@ -173,7 +177,6 @@ namespace Nuake deferredShader->SetUniform1i("Lights[" + std::to_string(idx - 1) + "].Volumetric", light.IsVolumetric); m_LightsUniformBuffer->Bind(); - //m_LightsUniformBuffer->UpdateData() } void Renderer::DrawLine(Vector3 start, Vector3 end, Color color, Matrix4 transform) diff --git a/Nuake/src/Rendering/Renderer.h b/Nuake/src/Rendering/Renderer.h index 76c86b28..5f8508f9 100644 --- a/Nuake/src/Rendering/Renderer.h +++ b/Nuake/src/Rendering/Renderer.h @@ -33,6 +33,7 @@ namespace Nuake { private: static RenderList m_RenderList; + static uint32_t MAX_LIGHT; public: static VertexArray* QuadVertexArray; diff --git a/Nuake/src/UI/ImUI.cpp b/Nuake/src/UI/ImUI.cpp new file mode 100644 index 00000000..2a872b21 --- /dev/null +++ b/Nuake/src/UI/ImUI.cpp @@ -0,0 +1,141 @@ +#include "ImUI.h" + +namespace Nuake { + + namespace UI { + + void BeginWindow(const std::string& name) + { + ImGui::Begin(name.c_str()); + } + + void EndWindow() + { + ImGui::End(); + } + + bool PrimaryButton(const std::string& name) + { + ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(97, 0, 255, 255)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(97, 0, 255, 255)); + + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); + + UIFont boldFont(Bold); + const bool buttonPressed = ImGui::Button(name.c_str()); + + ImGui::PopStyleColor(3); + + ImGui::PopStyleVar(2); + + return buttonPressed; + } + + bool SecondaryButton(const std::string& name) + { + ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(97, 0, 255, 255)); + ImGui::PushStyleColor(ImGuiCol_Border, PrimaryCol); + + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); + + UIFont boldFont(Bold); + const bool buttonPressed = ImGui::Button(name.c_str()); + + ImGui::PopStyleVar(3); + + ImGui::PopStyleColor(4); + + return buttonPressed; + } + + bool IconButton(const std::string& icon) + { + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, IconButtonPadding); + + const float height = ImGui::GetTextLineHeight() + ButtonPadding.y * 2.0; + const bool isPressed = ImGui::Button(icon.c_str(), ImVec2(height, height)); + + ImGui::PopStyleVar(2); + + return isPressed; + } + + bool FloatSlider(const std::string& name, float& input, float min, float max, float speed) + { + //ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 0, ImGui::GetStyle().ItemSpacing.y }); + //IconButton(ICON_FA_ANGLE_UP); + // + //ImGui::SameLine(); + + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); + + const bool isUsing = ImGui::DragFloat(("##" + name).c_str(), &input, speed, min, max); + + ImGui::PopStyleVar(2); + + //ImGui::PopStyleColor(); + + return isUsing; + } + + bool CheckBox(const std::string& name, bool& value) + { + const float height = ImGui::GetTextLineHeight() + ButtonPadding.y * 2.0; + + if (value) + { + ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, PrimaryCol); + ImGui::PushStyleColor(ImGuiCol_Border, PrimaryCol); + + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); + + const bool buttonPressed = ImGui::Button(("##" + name).c_str(), ImVec2(height, height)); + + ImGui::PopStyleVar(3); + + ImGui::PopStyleColor(4); + + if (buttonPressed) + { + value = false; + } + } + else + { + ImGui::PushStyleColor(ImGuiCol_Button, PrimaryCol); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, PrimaryCol); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, PrimaryCol); + ImGui::PushStyleColor(ImGuiCol_Border, IM_COL32(97, 0, 255, 200)); + + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); + + const bool buttonPressed = ImGui::Button(("##" + name).c_str(), ImVec2(height, height)); + + ImGui::PopStyleVar(3); + + ImGui::PopStyleColor(4); + + if (buttonPressed) + { + value = true; + } + } + + return value; + } + } +} \ No newline at end of file diff --git a/Nuake/src/UI/ImUI.h b/Nuake/src/UI/ImUI.h index b65a4f24..cf993aa8 100644 --- a/Nuake/src/UI/ImUI.h +++ b/Nuake/src/UI/ImUI.h @@ -17,138 +17,18 @@ namespace Nuake static ImVec2 ButtonPadding = ImVec2(16.0f, 8.0f); static ImVec2 IconButtonPadding = ImVec2(8.0f, 8.0f); - void BeginWindow(const std::string& name) - { - ImGui::Begin(name.c_str()); - } + void BeginWindow(const std::string& name); - void EndWindow() - { - ImGui::End(); - } + void EndWindow(); - bool PrimaryButton(const std::string& name) - { - ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(97, 0, 255, 255)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(97, 0, 255, 255)); + bool PrimaryButton(const std::string& name); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); + bool SecondaryButton(const std::string& name); - UIFont boldFont(Bold); - const bool buttonPressed = ImGui::Button(name.c_str()); + bool IconButton(const std::string& icon); - ImGui::PopStyleColor(3); + bool FloatSlider(const std::string& name, float& input, float min = 0.0f, float max = 1.0f, float speed = 0.01f); - ImGui::PopStyleVar(2); - - return buttonPressed; - } - - bool SecondaryButton(const std::string& name) - { - ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(97, 0, 255, 255)); - ImGui::PushStyleColor(ImGuiCol_Border, PrimaryCol); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); - - UIFont boldFont(Bold); - const bool buttonPressed = ImGui::Button(name.c_str()); - - ImGui::PopStyleVar(3); - - ImGui::PopStyleColor(4); - - return buttonPressed; - } - - bool IconButton(const std::string& icon) - { - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, IconButtonPadding); - - const float height = ImGui::GetTextLineHeight() + ButtonPadding.y * 2.0; - const bool isPressed = ImGui::Button(icon.c_str(), ImVec2(height, height)); - - ImGui::PopStyleVar(2); - - return isPressed; - } - - bool FloatSlider(const std::string& name, float& input, float min = 0.0f, float max = 1.0f, float speed = 0.01f) - { - //ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 0, ImGui::GetStyle().ItemSpacing.y }); - //IconButton(ICON_FA_ANGLE_UP); - // - //ImGui::SameLine(); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); - - const bool isUsing = ImGui::DragFloat(("##" + name).c_str(), &input, speed, min, max); - - ImGui::PopStyleVar(2); - - //ImGui::PopStyleColor(); - - return isUsing; - } - - bool CheckBox(const std::string& name, bool& value) - { - const float height = ImGui::GetTextLineHeight() + ButtonPadding.y * 2.0; - - if (value) - { - ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, PrimaryCol); - ImGui::PushStyleColor(ImGuiCol_Border, PrimaryCol); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); - - const bool buttonPressed = ImGui::Button(("##" + name).c_str(), ImVec2(height, height)); - - ImGui::PopStyleVar(3); - - ImGui::PopStyleColor(4); - - if (buttonPressed) - { - value = false; - } - } - else - { - ImGui::PushStyleColor(ImGuiCol_Button, PrimaryCol); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, PrimaryCol); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, PrimaryCol); - ImGui::PushStyleColor(ImGuiCol_Border, IM_COL32(97, 0, 255, 200)); - - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding); - - const bool buttonPressed = ImGui::Button(("##" + name).c_str(), ImVec2(height, height)); - - ImGui::PopStyleVar(3); - - ImGui::PopStyleColor(4); - - if (buttonPressed) - { - value = true; - } - } - - return value; - } + bool CheckBox(const std::string& name, bool& value); } } \ No newline at end of file diff --git a/Runtime/Runtime.cpp b/Runtime/Runtime.cpp index c1dee184..f8674e7c 100644 --- a/Runtime/Runtime.cpp +++ b/Runtime/Runtime.cpp @@ -5,7 +5,7 @@ #include -void main(int argc, char* argv[]) +int ApplicationMain(int argc, char* argv[]) { using namespace Nuake; @@ -73,3 +73,26 @@ void main(int argc, char* argv[]) Engine::EndDraw(); } } + +#ifdef NK_DIST + +#include "windows.h" + +int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cdmline, int cmdshow) +{ + BOOL USE_DARK_MODE = true; + BOOL SET_IMMERSIVE_DARK_MODE_SUCCESS = SUCCEEDED(DwmSetWindowAttribute( + WINhWnd, DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE, + &USE_DARK_MODE, sizeof(USE_DARK_MODE))); + + return ApplicationMain(__argc, __argv); +} + +#else + +void main(int argc, char* argv[]) +{ + return ApplicationMain(argc, argv); +} + +#endif diff --git a/premake5.lua b/premake5.lua index cbf046e0..ad7e8a8f 100644 --- a/premake5.lua +++ b/premake5.lua @@ -249,6 +249,10 @@ project "Editor" filter "configurations:Debug" runtime "Debug" symbols "on" + defines { + "NK_DEBUG", + "WIN32_LEAN_AND_MEAN" + } filter "configurations:Release" runtime "Release"