diff --git a/external/ImGui/include/imgui_imhex_extensions.h b/external/ImGui/include/imgui_imhex_extensions.h index 5ea148fa8..e7db14a26 100644 --- a/external/ImGui/include/imgui_imhex_extensions.h +++ b/external/ImGui/include/imgui_imhex_extensions.h @@ -1,9 +1,15 @@ #pragma once +#include + #include namespace ImGui { bool Hyperlink(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); + bool BulletHyperlink(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); + bool DescriptionButton(const char* label, const char* description, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); + + void UnderlinedText(const char* label, ImColor color, const ImVec2& size_arg = ImVec2(0, 0)); } \ No newline at end of file diff --git a/external/ImGui/source/imgui_imhex_extensions.cpp b/external/ImGui/source/imgui_imhex_extensions.cpp index 6bef56d2d..0cbf15715 100644 --- a/external/ImGui/source/imgui_imhex_extensions.cpp +++ b/external/ImGui/source/imgui_imhex_extensions.cpp @@ -1,14 +1,16 @@ #include #include +#include #define IMGUI_DEFINE_MATH_OPERATORS #include #undef IMGUI_DEFINE_MATH_OPERATORS +#include + namespace ImGui { - bool Hyperlink(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags) - { + bool Hyperlink(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; @@ -31,7 +33,7 @@ namespace ImGui { bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); // Render - const ImColor col = (hovered && !pressed) ? ImColor(0.5F, 0.5F, 0.9F, 1.0F) : (pressed ? ImColor(0.6F, 0.6F, 1.0F, 1.0F) : ImColor(0.4F, 0.4F, 0.8F, 1.0F)); + const ImU32 col = hovered ? GetColorU32(ImGuiCol_ButtonHovered) : GetColorU32(ImGuiCol_ButtonActive); PushStyleColor(ImGuiCol_Text, ImU32(col)); TextEx(label, NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting GetOverlayDrawList()->AddLine(ImVec2(pos.x, pos.y + size.y), pos + size, ImU32(col)); @@ -41,4 +43,102 @@ namespace ImGui { return pressed; } + bool BulletHyperlink(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags) { + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + ImVec2 pos = window->DC.CursorPos; + ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y); + + const ImRect bb(pos, pos + size); + if (!ItemAdd(bb, id)) + return false; + + if (window->DC.ItemFlags & ImGuiItemFlags_ButtonRepeat) + flags |= ImGuiButtonFlags_Repeat; + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); + + // Render + const ImU32 col = hovered ? GetColorU32(ImGuiCol_ButtonHovered) : GetColorU32(ImGuiCol_ButtonActive); + PushStyleColor(ImGuiCol_Text, ImU32(col)); + RenderBullet(window->DrawList, bb.Min + ImVec2(style.FramePadding.x + g.FontSize * 0.5f, g.FontSize * 0.5f), col); + RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x * 2, 0.0f), label, nullptr, false); + GetOverlayDrawList()->AddLine(bb.Min + ImVec2(style.FramePadding.x, size.y), pos + size + ImVec2(g.FontSize * 2, 0), ImU32(col)); + ImGui::NewLine(); + PopStyleColor(); + + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags); + return pressed; + } + + bool DescriptionButton(const char* label, const char* description, const ImVec2& size_arg, ImGuiButtonFlags flags) { + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const ImVec2 text_size = CalcTextSize((std::string(label) + "\n " + std::string(description)).c_str(), NULL, true); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + ImVec2 pos = window->DC.CursorPos; + if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrLineTextBaseOffset) // Try to vertically align buttons that are smaller/have no padding so that text baseline matches (bit hacky, since it shouldn't be a flag) + pos.y += window->DC.CurrLineTextBaseOffset - style.FramePadding.y; + ImVec2 size = CalcItemSize(size_arg, text_size.x + style.FramePadding.x * 4.0f, text_size.y + style.FramePadding.y * 4.0f); + + const ImRect bb(pos, pos + size); + ItemSize(size, style.FramePadding.y); + if (!ItemAdd(bb, id)) + return false; + + if (window->DC.ItemFlags & ImGuiItemFlags_ButtonRepeat) + flags |= ImGuiButtonFlags_Repeat; + bool hovered, held; + bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); + + ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0, 0.5)); + + // Render + const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ScrollbarBg : hovered ? ImGuiCol_WindowBg : ImGuiCol_PopupBg); + RenderNavHighlight(bb, id); + RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); + PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_ButtonActive)); + RenderTextClipped(bb.Min + style.FramePadding * 2, bb.Max - style.FramePadding * 2, label, NULL, &text_size, style.ButtonTextAlign, &bb); + PopStyleColor(); + PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_Text)); + RenderTextClipped(bb.Min + style.FramePadding * 2 + ImVec2(style.FramePadding.x * 2, label_size.y), bb.Max - style.FramePadding, description, NULL, &text_size, style.ButtonTextAlign, &bb); + PopStyleColor(); + + ImGui::PopStyleVar(); + + // Automatically close popups + //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup)) + // CloseCurrentPopup(); + + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags); + return pressed; + } + + void UnderlinedText(const char* label, ImColor color, const ImVec2& size_arg) { + ImGuiWindow* window = GetCurrentWindow(); + + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + ImVec2 pos = window->DC.CursorPos; + ImVec2 size = CalcItemSize(size_arg, label_size.x, label_size.y); + + PushStyleColor(ImGuiCol_Text, ImU32(color)); + TextEx(label, NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting + GetOverlayDrawList()->AddLine(ImVec2(pos.x, pos.y + size.y), pos + size, ImU32(color)); + PopStyleColor(); + } + } \ No newline at end of file diff --git a/source/window.cpp b/source/window.cpp index e4ae71874..d17984366 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "helpers/plugin_handler.hpp" @@ -65,8 +66,6 @@ namespace hex { } #endif - printf("Hello\n"); - ContentRegistry::Settings::load(); View::postEvent(Events::SettingsChanged); @@ -257,7 +256,56 @@ namespace hex { } void Window::drawWelcomeScreen() { - ImGui::TextColored(ImGui::GetStyleColorVec4(ImGuiCol_HeaderActive), "Welcome to ImHex!"); + ImGui::UnderlinedText("Welcome to ImHex!", ImGui::GetStyleColorVec4(ImGuiCol_HeaderActive)); + + ImGui::NewLine(); + + auto availableSpace = ImGui::GetContentRegionAvail(); + + ImGui::Indent(); + if (ImGui::BeginTable("Welcome Left", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) { + ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextColumn(); + ImGui::Text("Start"); + { + ImGui::BulletHyperlink("Open file"); + } + ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextColumn(); + ImGui::Text("Recent"); + { + + } + ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextColumn(); + ImGui::Text("Help"); + { + if (ImGui::BulletHyperlink("GitHub Repository")) hex::openWebpage("https://github.com/WerWolv/ImHex"); + if (ImGui::BulletHyperlink("Get help")) hex::openWebpage("https://github.com/WerWolv/ImHex/discussions/categories/get-help"); + } + + ImGui::EndTable(); + } + ImGui::SameLine(); + if (ImGui::BeginTable("Welcome Right", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) { + ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextColumn(); + ImGui::Text("Customize"); + { + ImGui::DescriptionButton("Settings", "Change preferences of ImHex", ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0)); + } + ImGui::TableNextRow(ImGuiTableRowFlags_None, 100); + ImGui::TableNextColumn(); + ImGui::Text("Learn"); + { + if (ImGui::DescriptionButton("Pattern Language Documentation", "Learn how to write ImHex patterns with our extensive documentation", ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0))) + hex::openWebpage("https://github.com/WerWolv/ImHex/wiki/Pattern-Language-Guide"); + if (ImGui::DescriptionButton("Plugins API", "Extend ImHex with additional features using plugins", ImVec2(ImGui::GetContentRegionAvail().x * 0.8, 0))) + hex::openWebpage("https://github.com/WerWolv/ImHex/wiki/Plugins-Development-Guide"); + } + + ImGui::EndTable(); + } } void Window::initGLFW() { @@ -386,17 +434,18 @@ namespace hex { if (this->m_globalScale != 0.0f) style.ScaleAllSizes(this->m_globalScale); -#ifdef __MINGW32__ - std::filesystem::path resourcePath = std::filesystem::path((SharedData::mainArgv)[0]).parent_path(); -#elif defined(__linux__) - std::filesystem::path resourcePath = "/usr/share/ImHex"; -#else - std::filesystem::path resourcePath = ""; -# warning "Unsupported OS for custom font support" -#endif + #if defined(OS_WINDOWS) + std::filesystem::path resourcePath = std::filesystem::path((SharedData::mainArgv)[0]).parent_path(); + #elif defined(OS_LINUX) || defined(OS_MACOS) + std::filesystem::path resourcePath = "/usr/share/ImHex"; + #else + std::filesystem::path resourcePath = ""; + #warning "Unsupported OS for custom font support" + #endif - if (!resourcePath.empty() && this->setFont(resourcePath / "font.ttf")) - ; + if (!resourcePath.empty() && this->setFont(resourcePath / "font.ttf")) { + + } else if ((this->m_fontScale != 0.0f) && (this->m_fontScale != 1.0f)) { io.Fonts->Clear();