1
0
mirror of synced 2025-01-30 19:43:43 +01:00

impr: Added simplified welcome screen

This commit is contained in:
WerWolv 2023-12-07 11:18:49 +01:00
parent 60ff62d018
commit 9ba6d7ee1e
4 changed files with 405 additions and 317 deletions

View File

@ -289,6 +289,9 @@ namespace ImGuiExt {
bool InputFilePicker(const char *label, std::fs::path &path, const std::vector<hex::fs::ItemFilter> &validExtensions); bool InputFilePicker(const char *label, std::fs::path &path, const std::vector<hex::fs::ItemFilter> &validExtensions);
bool ToggleSwitch(const char *label, bool *v);
bool ToggleSwitch(const char *label, bool v);
template<typename T> template<typename T>
constexpr ImGuiDataType getImGuiDataType() { constexpr ImGuiDataType getImGuiDataType() {
if constexpr (std::same_as<T, u8>) return ImGuiDataType_U8; if constexpr (std::same_as<T, u8>) return ImGuiDataType_U8;

View File

@ -41,8 +41,8 @@ namespace ImGuiExt {
glGenTextures(1, &texture); glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
#if defined(GL_UNPACK_ROW_LENGTH) #if defined(GL_UNPACK_ROW_LENGTH)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
@ -1003,6 +1003,57 @@ namespace ImGuiExt {
return picked; return picked;
} }
bool ToggleSwitch(const char *label, bool *v) {
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);
const ImVec2 size = ImVec2(GetFrameHeight() * 2.0F, GetFrameHeight());
const ImVec2 pos = window->DC.CursorPos;
const ImRect total_bb(pos, pos + ImVec2(size.x + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), label_size.y + style.FramePadding.y * 2.0f));
ItemSize(total_bb, style.FramePadding.y);
if (!ItemAdd(total_bb, id))
{
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
return false;
}
bool hovered, held;
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
if (pressed)
{
*v = !(*v);
MarkItemEdited(id);
}
const ImRect knob_bb(pos, pos + size);
window->DrawList->AddRectFilled(knob_bb.Min, knob_bb.Max, GetColorU32(held ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : *v ? ImGuiCol_ButtonActive : ImGuiCol_Button), size.y / 2);
if (*v)
window->DrawList->AddCircleFilled(knob_bb.Max - ImVec2(size.y / 2, size.y / 2), (size.y - style.ItemInnerSpacing.y) / 2, GetColorU32(ImGuiCol_Text), 16);
else
window->DrawList->AddCircleFilled(knob_bb.Min + ImVec2(size.y / 2, size.y / 2), (size.y - style.ItemInnerSpacing.y) / 2, GetColorU32(ImGuiCol_Text), 16);
ImVec2 label_pos = ImVec2(knob_bb.Max.x + style.ItemInnerSpacing.x, knob_bb.Min.y + style.FramePadding.y);
if (g.LogEnabled)
LogRenderedText(&label_pos, *v ? "((*) )" : "( (*))");
if (label_size.x > 0.0f)
RenderText(label_pos, label);
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
return pressed;
}
bool ToggleSwitch(const char *label, bool v) {
return ToggleSwitch(label, &v);
}
} }
namespace ImGui { namespace ImGui {

View File

@ -335,7 +335,7 @@ namespace hex::plugin::builtin {
namespace Widgets = ContentRegistry::Settings::Widgets; namespace Widgets = ContentRegistry::Settings::Widgets;
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.show_tips", true); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.show_tips", false);
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.save_recent_providers", true); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.save_recent_providers", true);
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.patterns", "hex.builtin.setting.general.auto_load_patterns", true); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.patterns", "hex.builtin.setting.general.auto_load_patterns", true);
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.patterns", "hex.builtin.setting.general.sync_pattern_source", false); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "hex.builtin.setting.general.patterns", "hex.builtin.setting.general.sync_pattern_source", false);
@ -392,6 +392,7 @@ namespace hex::plugin::builtin {
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.multi_windows", MultiWindowSupportEnabledDefault).requiresRestart(); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.multi_windows", MultiWindowSupportEnabledDefault).requiresRestart();
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.restore_window_pos", false); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.restore_window_pos", false);
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.simplified_welcome_screen", false);
ContentRegistry::Settings::add<Widgets::ColorPicker>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.highlight_color", ImColor(0x80, 0x80, 0xC0, 0x60)); ContentRegistry::Settings::add<Widgets::ColorPicker>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.highlight_color", ImColor(0x80, 0x80, 0xC0, 0x60));
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.sync_scrolling", false); ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.sync_scrolling", false);

View File

@ -33,9 +33,12 @@
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
static ImGuiExt::Texture s_bannerTexture, s_backdropTexture, s_infoBannerTexture; namespace {
ImGuiExt::Texture s_bannerTexture, s_backdropTexture, s_infoBannerTexture;
static std::string s_tipOfTheDay; std::string s_tipOfTheDay;
bool s_simplifiedWelcomeScreen = false;
class PopupRestoreBackup : public Popup<PopupRestoreBackup> { class PopupRestoreBackup : public Popup<PopupRestoreBackup> {
private: private:
@ -132,11 +135,11 @@ namespace hex::plugin::builtin {
} }
}; };
static void loadDefaultLayout() { void loadDefaultLayout() {
LayoutManager::loadString(std::string(romfs::get("layouts/default.hexlyt").string())); LayoutManager::loadString(std::string(romfs::get("layouts/default.hexlyt").string()));
} }
static bool isAnyViewOpen() { bool isAnyViewOpen() {
const auto &views = ContentRegistry::Views::impl::getEntries(); const auto &views = ContentRegistry::Views::impl::getEntries();
return std::any_of(views.begin(), views.end(), return std::any_of(views.begin(), views.end(),
[](const auto &entry) { [](const auto &entry) {
@ -144,7 +147,15 @@ namespace hex::plugin::builtin {
}); });
} }
static void drawWelcomeScreenContent() { void drawWelcomeScreenContentSimplified() {
const ImVec2 backdropSize = scaled({ 350, 350 });
ImGui::SetCursorPos((ImGui::GetContentRegionAvail() - backdropSize) / 2);
ImGui::Image(s_backdropTexture, backdropSize);
ImGuiExt::TextFormattedCentered("Drop file here to get started");
}
void drawWelcomeScreenContentFull() {
const auto availableSpace = ImGui::GetContentRegionAvail(); const auto availableSpace = ImGui::GetContentRegionAvail();
ImGui::Image(s_bannerTexture, s_bannerTexture.getSize() / (2 * (1.0F / ImHexApi::System::getGlobalScale()))); ImGui::Image(s_bannerTexture, s_bannerTexture.getSize() / (2 * (1.0F / ImHexApi::System::getGlobalScale())));
@ -355,7 +366,7 @@ namespace hex::plugin::builtin {
} }
} }
static void drawWelcomeScreen() { void drawWelcomeScreen() {
ImGui::PushStyleColor(ImGuiCol_WindowShadow, 0x00); ImGui::PushStyleColor(ImGuiCol_WindowShadow, 0x00);
if (ImGui::Begin("ImHexDockSpace")) { if (ImGui::Begin("ImHexDockSpace")) {
if (!ImHexApi::Provider::isValid()) { if (!ImHexApi::Provider::isValid()) {
@ -369,7 +380,26 @@ namespace hex::plugin::builtin {
ImGui::SetNextWindowSize(ImGui::GetContentRegionAvail() + scaled({ 0, 10 })); ImGui::SetNextWindowSize(ImGui::GetContentRegionAvail() + scaled({ 0, 10 }));
ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos() - ImVec2(0, ImGui::GetStyle().FramePadding.y + 2_scaled)); ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos() - ImVec2(0, ImGui::GetStyle().FramePadding.y + 2_scaled));
if (ImGui::Begin("Welcome Screen", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { if (ImGui::Begin("Welcome Screen", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
drawWelcomeScreenContent(); if (s_simplifiedWelcomeScreen)
drawWelcomeScreenContentSimplified();
else
drawWelcomeScreenContentFull();
static bool hovered = false;
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, hovered ? 1.0F : 0.3F);
{
const ImVec2 windowSize = scaled({ 150, 60 });
ImGui::SetCursorPos(ImGui::GetWindowSize() - windowSize - ImGui::GetStyle().WindowPadding);
ImGuiExt::BeginSubWindow("Quick Settings", windowSize);
{
if (ImGuiExt::ToggleSwitch("Simplified", &s_simplifiedWelcomeScreen))
ContentRegistry::Settings::write("hex.builtin.setting.interface", "hex.builtin.setting.interface.simplified_welcome_screen", s_simplifiedWelcomeScreen);
}
ImGuiExt::EndSubWindow();
hovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByItem | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
}
ImGui::PopStyleVar();
} }
ImGui::End(); ImGui::End();
ImGui::PopStyleVar(); ImGui::PopStyleVar();
@ -383,7 +413,7 @@ namespace hex::plugin::builtin {
/** /**
* @brief Draw some default background if there are no views available in the current layout * @brief Draw some default background if there are no views available in the current layout
*/ */
static void drawNoViewsBackground() { void drawNoViewsBackground() {
if (ImGui::Begin("ImHexDockSpace")) { if (ImGui::Begin("ImHexDockSpace")) {
static std::array<char, 256> title; static std::array<char, 256> title;
ImFormatString(title.data(), title.size(), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("ImHexMainDock")); ImFormatString(title.data(), title.size(), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("ImHexMainDock"));
@ -422,6 +452,7 @@ namespace hex::plugin::builtin {
} }
ImGui::End(); ImGui::End();
} }
}
/** /**
* @brief Registers the event handlers related to the welcome screen * @brief Registers the event handlers related to the welcome screen
@ -451,6 +482,8 @@ namespace hex::plugin::builtin {
lastTheme = theme; lastTheme = theme;
} }
} }
s_simplifiedWelcomeScreen = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.simplified_welcome_screen", false);
} }
{ {
@ -579,7 +612,7 @@ namespace hex::plugin::builtin {
auto chosenTip = chosenCategory[random()%chosenCategory.size()]; auto chosenTip = chosenCategory[random()%chosenCategory.size()];
s_tipOfTheDay = chosenTip.get<std::string>(); s_tipOfTheDay = chosenTip.get<std::string>();
bool showTipOfTheDay = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", true); bool showTipOfTheDay = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", false);
if (showTipOfTheDay) if (showTipOfTheDay)
PopupTipOfTheDay::open(); PopupTipOfTheDay::open();
} }