From 6f26d8986b2f8b85281c6334fd6b3bd5c3b536d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Sat, 7 Oct 2023 15:48:34 +0200 Subject: [PATCH] New style --- src/main.cpp | 151 ++++++++++++++++++++----- src/resource.h | 2 +- "src/v\304\253c\304\255us.rc" | 2 +- "v\304\253c\304\255us.sln.DotSettings" | 2 + 4 files changed, 128 insertions(+), 29 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4bfa216..7fadb06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,13 +9,11 @@ #include "imgui.h" #include "imgui-SFML.h" #include "imgui_markdown.h" -#include "IconsFontAwesome5.h" // SFML #include #include #include -#include // // STL @@ -42,7 +40,7 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase; static std::wstring GetImageBasePathW() { - wchar_t myPath[MAX_PATH + 1] = {0}; + wchar_t myPath[MAX_PATH + 1] = { 0 }; GetModuleFileNameW( reinterpret_cast(&__ImageBase), @@ -53,6 +51,124 @@ static std::wstring GetImageBasePathW() return std::wstring(myPath); } +/** + * \brief https://github.com/ocornut/imgui/issues/707#issuecomment-1372640066 + */ +inline void ApplyImGuiStyleDark() +{ + auto& colors = ImGui::GetStyle().Colors; + colors[ImGuiCol_WindowBg] = ImVec4{ 0.1f, 0.1f, 0.13f, 1.0f }; + colors[ImGuiCol_MenuBarBg] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + + // Border + colors[ImGuiCol_Border] = ImVec4{ 0.44f, 0.37f, 0.61f, 0.29f }; + colors[ImGuiCol_BorderShadow] = ImVec4{ 0.0f, 0.0f, 0.0f, 0.24f }; + + // Text + colors[ImGuiCol_Text] = ImVec4{ 1.0f, 1.0f, 1.0f, 1.0f }; + colors[ImGuiCol_TextDisabled] = ImVec4{ 0.5f, 0.5f, 0.5f, 1.0f }; + + // Headers + colors[ImGuiCol_Header] = ImVec4{ 0.13f, 0.13f, 0.17f, 1.0f }; + colors[ImGuiCol_HeaderHovered] = ImVec4{ 0.19f, 0.2f, 0.25f, 1.0f }; + colors[ImGuiCol_HeaderActive] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + + // Buttons + colors[ImGuiCol_Button] = ImVec4{ 0.13f, 0.13f, 0.17f, 1.0f }; + colors[ImGuiCol_ButtonHovered] = ImVec4{ 0.19f, 0.2f, 0.25f, 1.0f }; + colors[ImGuiCol_ButtonActive] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + colors[ImGuiCol_CheckMark] = ImVec4{ 0.74f, 0.58f, 0.98f, 1.0f }; + + // Popups + colors[ImGuiCol_PopupBg] = ImVec4{ 0.1f, 0.1f, 0.13f, 0.92f }; + + // Slider + colors[ImGuiCol_SliderGrab] = ImVec4{ 0.44f, 0.37f, 0.61f, 0.54f }; + colors[ImGuiCol_SliderGrabActive] = ImVec4{ 0.74f, 0.58f, 0.98f, 0.54f }; + + // Frame BG + colors[ImGuiCol_FrameBg] = ImVec4{ 0.13f, 0.13f, 0.17f, 1.0f }; + colors[ImGuiCol_FrameBgHovered] = ImVec4{ 0.19f, 0.2f, 0.25f, 1.0f }; + colors[ImGuiCol_FrameBgActive] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + + // Tabs + colors[ImGuiCol_Tab] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + colors[ImGuiCol_TabHovered] = ImVec4{ 0.24f, 0.24f, 0.32f, 1.0f }; + colors[ImGuiCol_TabActive] = ImVec4{ 0.2f, 0.22f, 0.27f, 1.0f }; + colors[ImGuiCol_TabUnfocused] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + colors[ImGuiCol_TabUnfocusedActive] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + + // Title + colors[ImGuiCol_TitleBg] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + colors[ImGuiCol_TitleBgActive] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + colors[ImGuiCol_TitleBgCollapsed] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + + // Scrollbar + colors[ImGuiCol_ScrollbarBg] = ImVec4{ 0.1f, 0.1f, 0.13f, 1.0f }; + colors[ImGuiCol_ScrollbarGrab] = ImVec4{ 0.16f, 0.16f, 0.21f, 1.0f }; + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4{ 0.19f, 0.2f, 0.25f, 1.0f }; + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4{ 0.24f, 0.24f, 0.32f, 1.0f }; + + // Separator + colors[ImGuiCol_Separator] = ImVec4{ 0.44f, 0.37f, 0.61f, 1.0f }; + colors[ImGuiCol_SeparatorHovered] = ImVec4{ 0.74f, 0.58f, 0.98f, 1.0f }; + colors[ImGuiCol_SeparatorActive] = ImVec4{ 0.84f, 0.58f, 1.0f, 1.0f }; + + // Resize Grip + colors[ImGuiCol_ResizeGrip] = ImVec4{ 0.44f, 0.37f, 0.61f, 0.29f }; + colors[ImGuiCol_ResizeGripHovered] = ImVec4{ 0.74f, 0.58f, 0.98f, 0.29f }; + colors[ImGuiCol_ResizeGripActive] = ImVec4{ 0.84f, 0.58f, 1.0f, 0.29f }; + + auto& style = ImGui::GetStyle(); + style.TabRounding = 4; + style.ScrollbarRounding = 9; + style.WindowRounding = 7; + style.GrabRounding = 3; + style.FrameRounding = 3; + style.PopupRounding = 4; + style.ChildRounding = 4; +} + +void LinkCallback( ImGui::MarkdownLinkCallbackData data_ ); +inline ImGui::MarkdownImageData ImageCallback( ImGui::MarkdownLinkCallbackData data_ ); + +static ImFont* H1 = NULL; +static ImFont* H2 = NULL; +static ImFont* H3 = NULL; + +static ImGui::MarkdownConfig mdConfig; + +void LinkCallback( ImGui::MarkdownLinkCallbackData data_ ) +{ + std::string url( data_.link, data_.linkLength ); + if( !data_.isImage ) + { + ShellExecuteA( NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL ); + } +} + + +void LoadFonts(HINSTANCE hInstance) +{ + ImFontConfig font_cfg; + font_cfg.FontDataOwnedByAtlas = false; + + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->Clear(); + + // get embedded fonts + HRSRC ruda_bold_res = FindResource(hInstance, MAKEINTRESOURCE(IDR_FONT_RUDA_BOLD), RT_FONT); + int ruda_bold_size = (int)SizeofResource(hInstance, ruda_bold_res); + LPVOID ruda_bold_data = LockResource(LoadResource(hInstance, ruda_bold_res)); + + io.Fonts->AddFontFromMemoryTTF(ruda_bold_data, ruda_bold_size, 12, &font_cfg); + io.Fonts->AddFontFromMemoryTTF(ruda_bold_data, ruda_bold_size, 10, &font_cfg); + io.Fonts->AddFontFromMemoryTTF(ruda_bold_data, ruda_bold_size, 14, &font_cfg); + io.Fonts->AddFontFromMemoryTTF(ruda_bold_data, ruda_bold_size, 18, &font_cfg); + + ImGui::SFML::UpdateFontTexture(); +} + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); @@ -82,7 +198,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, } argv.resize(nArgs); - std::transform(narrow.begin(), narrow.end(), argv.begin(), [](const std::string& arg) { return arg.c_str(); }); + std::ranges::transform(narrow, argv.begin(), [](const std::string& arg) { return arg.c_str(); }); argv.push_back(nullptr); @@ -102,32 +218,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, ImGui::SFML::Init(window, false); // Set window icon - auto hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); - if (hIcon) + if (auto hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_MAIN))) { SendMessage(window.getSystemHandle(), WM_SETICON, ICON_BIG, reinterpret_cast(hIcon)); } - - ImFontConfig font_cfg; - font_cfg.FontDataOwnedByAtlas = false; - - ImGuiIO& io = ImGui::GetIO(); - io.Fonts->Clear(); - // get embedded fonts - HRSRC ruda_bold_res = FindResource(hInstance, MAKEINTRESOURCE(IDR_FONT_RUDA_BOLD), RT_FONT); - int ruda_bold_size = (int)SizeofResource(hInstance, ruda_bold_res); - LPVOID ruda_bold_data = LockResource(LoadResource(hInstance, ruda_bold_res)); - - io.Fonts->AddFontFromMemoryTTF(ruda_bold_data, ruda_bold_size, 12, &font_cfg); - io.Fonts->AddFontFromMemoryTTF(ruda_bold_data, ruda_bold_size, 10, &font_cfg); - io.Fonts->AddFontFromMemoryTTF(ruda_bold_data, ruda_bold_size, 14, &font_cfg); - io.Fonts->AddFontFromMemoryTTF(ruda_bold_data, ruda_bold_size, 18, &font_cfg); - - ImGui::SFML::UpdateFontTexture(); + LoadFonts(hInstance); - sf::CircleShape shape(100.f); - shape.setFillColor(sf::Color::Green); + ApplyImGuiStyleDark(); sf::Clock deltaClock; while (window.isOpen()) @@ -145,14 +243,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, ImGui::SFML::Update(window, deltaClock.restart()); - ImGui::ShowDemoWindow(); + //ImGui::ShowDemoWindow(); ImGui::Begin("Hello, world!"); ImGui::Button("Look at this pretty button"); ImGui::End(); window.clear(); - window.draw(shape); ImGui::SFML::Render(window); window.display(); } diff --git a/src/resource.h b/src/resource.h index 7f88c4f..3ab46ea 100644 --- a/src/resource.h +++ b/src/resource.h @@ -2,7 +2,7 @@ // Microsoft Visual C++ generated include file. // Used by vicius.rc // -#define IDI_ICON1 101 +#define IDI_ICON_MAIN 101 #define IDR_FONT_RUDA_BOLD 102 // Next default values for new objects diff --git "a/src/v\304\253c\304\255us.rc" "b/src/v\304\253c\304\255us.rc" index e652e7f..00fd817 100644 --- "a/src/v\304\253c\304\255us.rc" +++ "b/src/v\304\253c\304\255us.rc" @@ -70,7 +70,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. -IDI_ICON1 ICON "favicon.ico" +IDI_ICON_MAIN ICON "favicon.ico" ///////////////////////////////////////////////////////////////////////////// diff --git "a/v\304\253c\304\255us.sln.DotSettings" "b/v\304\253c\304\255us.sln.DotSettings" index e6fefda..b84b84c 100644 --- "a/v\304\253c\304\255us.sln.DotSettings" +++ "b/v\304\253c\304\255us.sln.DotSettings" @@ -4,7 +4,9 @@ True True True + True True + True True True True \ No newline at end of file