mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-03 14:09:46 +03:00
Clean up main and argument parsing
This commit is contained in:
@@ -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<std::string> ParseArguments(int argc, char* argv[])
|
||||
{
|
||||
std::vector<std::string> 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<std::string>& 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<Nuake::Project> project = Nuake::Project::New();
|
||||
FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath));
|
||||
|
||||
project->FullPath = projectPath;
|
||||
project->Deserialize(FileSystem::ReadFile(projectPath, true));
|
||||
|
||||
Ref<Nuake::Window> 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);
|
||||
}
|
||||
|
||||
16
Editor/src/Misc/WindowTheming.cpp
Normal file
16
Editor/src/Misc/WindowTheming.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "WindowTheming.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3native.h>
|
||||
|
||||
#include <dwmapi.h>
|
||||
|
||||
namespace WindowTheming
|
||||
{
|
||||
void SetWindowDarkMode(Ref<Nuake::Window> window)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
8
Editor/src/Misc/WindowTheming.h
Normal file
8
Editor/src/Misc/WindowTheming.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/Window.h"
|
||||
|
||||
namespace WindowTheming
|
||||
{
|
||||
void SetWindowDarkMode(Ref<Nuake::Window> window);
|
||||
}
|
||||
@@ -48,6 +48,8 @@
|
||||
#include <src/Rendering/Buffers/Framebuffer.h>
|
||||
#include "UIDemoWindow.h"
|
||||
|
||||
#include <src/UI/ImUI.h>
|
||||
|
||||
namespace Nuake {
|
||||
Ref<UI::UserInterface> 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<Entity> 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)
|
||||
|
||||
@@ -131,10 +131,8 @@ namespace Nuake
|
||||
ImGui::SameLine();
|
||||
DrawRecentProjectsSection();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
|
||||
void WelcomeWindow::DrawRecentProjectsSection()
|
||||
|
||||
@@ -10,72 +10,72 @@
|
||||
#include <chrono>
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
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<char*>(GlobalLock(hData));
|
||||
std::string text(pszText);
|
||||
|
||||
GlobalUnlock(hData);
|
||||
CloseClipboard();
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
int OS::GetTime()
|
||||
{
|
||||
return static_cast<int>(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>& 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<Directory>& 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<char*>(GlobalLock(hData));
|
||||
std::string text(pszText);
|
||||
|
||||
GlobalUnlock(hData);
|
||||
CloseClipboard();
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
int OS::GetTime()
|
||||
{
|
||||
return static_cast<int>(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>& 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<Directory>& 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);
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Nuake
|
||||
{
|
||||
private:
|
||||
static RenderList m_RenderList;
|
||||
static uint32_t MAX_LIGHT;
|
||||
|
||||
public:
|
||||
static VertexArray* QuadVertexArray;
|
||||
|
||||
141
Nuake/src/UI/ImUI.cpp
Normal file
141
Nuake/src/UI/ImUI.cpp
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user