Skip to content

Commit

Permalink
New style
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Oct 7, 2023
1 parent 86fd1aa commit 6f26d89
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 29 deletions.
151 changes: 124 additions & 27 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
#include "imgui.h"
#include "imgui-SFML.h"
#include "imgui_markdown.h"
#include "IconsFontAwesome5.h"

// SFML
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/CircleShape.hpp>

//
// STL
Expand All @@ -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<HINSTANCE>(&__ImageBase),
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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<LPARAM>(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())
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/vīcĭus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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"


/////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions vīcĭus.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=autostart/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cmdl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=EPPT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=imgui/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=NOMINMAX/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ocornut/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ruda/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SFML/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unregister/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit 6f26d89

Please sign in to comment.