From 9b07e46dea388b22f7ba85dd546b589bfd099823 Mon Sep 17 00:00:00 2001 From: stormy <120167078+stowmyy@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:45:38 -0500 Subject: [PATCH] feature: servers selectable with keyboard --- dropship/assets/icons/icon-heart.png | Bin 0 -> 1062 bytes dropship/assets/icons/icon-skull.png | Bin 0 -> 1369 bytes dropship/dropship.rc | Bin 6944 -> 7268 bytes dropship/src/DashboardManager.cpp | 52 ++++++++++++------ dropship/src/_WindowsFirewallUtil.h | 13 +---- dropship/src/theme.cpp | 4 +- dropship/src/util.hpp | 2 + dropship/vendor/imgui-docking/imgui.cpp | 3 + dropship/vendor/imgui-docking/imgui.h | 2 + dropship/vendor/imgui-docking/imgui_demo.cpp | 1 + .../vendor/imgui-docking/imgui_widgets.cpp | 2 +- 11 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 dropship/assets/icons/icon-heart.png create mode 100644 dropship/assets/icons/icon-skull.png diff --git a/dropship/assets/icons/icon-heart.png b/dropship/assets/icons/icon-heart.png new file mode 100644 index 0000000000000000000000000000000000000000..4c4672f04450527986a376d727bdea37df9e39dd GIT binary patch literal 1062 zcmV+>1ljwEP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1G`B?K~#8N?VHPQ z4N)A&dp+79g2V!ecjL{b!a^7INQmbKA^ZaxD;6Y;MKLOV9#UYuy%RQ5r$XkS4XH5?22G)I1Iuj43|UtJ4!TIOE!Ya316CffGHfn!mDq0e zY)HOFQR$3n z6L3GMd&xabz%BIgM5xRE?IEdD>Nyo3S3!ev*9s74tn>+&v-^`6_dj(?sD@KqR3aR+C+hUB4po=PSl zbN8EB0m61{#wOR0ER@rhzmpgLOn~43J=61GtufgAL)HWc4%EvHtMH9$ zh&OL>mF1L0*0aIC;hZpy;s)xCkT~)TH;}w0pV!Z07*qoM6N<$g0|k{BLDyZ literal 0 HcmV?d00001 diff --git a/dropship/assets/icons/icon-skull.png b/dropship/assets/icons/icon-skull.png new file mode 100644 index 0000000000000000000000000000000000000000..333665f6e34b5660846ccc6f8162f78656a07731 GIT binary patch literal 1369 zcmV-f1*ZCmP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1nx;hK~#8N?VHK3 z6h$1z-;690A^`)210k}=LrrjFl>;E41P^i`!5bPqpeHd#PeOpdfdeO&6A%)KA<>X% zq6rDhbBT!pabaH~MhpgU;qmxGzy8E=uh+qx{OYvpU@BJM5$D|LK=j&2LPv^CRu@ALC>Ja zP!{C;_vj${j9~nzgSi5y$D+5;SLk09ivQ5p=xsF4UjF_;BPO5?=p5=a=g~%#wTJn` zMMt3b&_#5=xrElE5w>|@;X(`1F_bq3&_dhHFmQp7(Jfsqr>JckY;)TOM#rH~b%icL zZPhf}l9tmTh8`!`k2Ixq6Iw&8V%j`qij8R+0Gyvr@;RCo9q2xOLn{cv&!$*UVgPV{ z63Lh7iReK0BIjQs2W6`%t$#FXY2M>r)*K0{~mmJd-U1@utitzliGTDC?>jU+I@~+_kDk*{K&zx)b6&{jxeCDSsF)iuNf20Y`3WwEIWrtTZ*b`*AKS02fT&3H6pN zTh+g#W<4&n{WupCfRiTQlSEI0119gp7?foeILi zA?@$6Cff2^{3y~2Op6fB!$PC62BbGo)-ASn+gG<=K=+s3x}BjNBx$$Bv;wOvLNpb* zj>fLE%l=NBSKuPz0qE_mG5d!PO{tK4RPDTIIKX85Ddd%1IA7;eQULTZ!51j&0G1cD z+FeQjuAAaL8U{cRgra;R^9#}^GUrUOmc%KK3i_tzRrG6gpgYk=QY(|37ft7UD(VBH zG+D zb)lq%&Q$LF-=^3a-*x{;o8}p>Hu?sja6AZrO?#G31>lC2E57HarV|191XcF+m2ZXb z`JIDlQ2$HpiY8k}uA?coy6R7{$CB_pKaScq!B%&|w+HC0jL+Vip1!KLs+6yLBCEpp z{5X2o@6$fN0IfG(!#X*G(zw$2H1ezk3z7ioHcf}n9=FFc`#xkW%Ov>}`G00000NkvXXu0mjfgSnKx literal 0 HcmV?d00001 diff --git a/dropship/dropship.rc b/dropship/dropship.rc index 72daa1bfc9f03c768dbdee709d0d05a5f448eb84..e9ed75f479ec7d1420231511c26cc5d84028572c 100644 GIT binary patch delta 68 zcmZ2r_QYa?jWDMNgDZn0Ll8sA4tGk7zEGWam~faQuA TvKdMlau{+za+__0pRfY}ixm?u delta 12 TcmaE2vA}GDjqv6Mktgf`Bx(gD diff --git a/dropship/src/DashboardManager.cpp b/dropship/src/DashboardManager.cpp index f424f53..ec05d03 100644 --- a/dropship/src/DashboardManager.cpp +++ b/dropship/src/DashboardManager.cpp @@ -269,7 +269,7 @@ DashboardManager::DashboardManager() : }, { - .title = "Germany 2", + .title = "Germany", ._ping_ip = "", .heading = "GEW3", ._firewall_rule_address = ips.at("gew3"), @@ -352,6 +352,8 @@ void DashboardManager::loadAssets() { "icon_maple_leaf.png", "icon_chain_slash.png", "icon_bolt.png", + "icon_skull.png", + "icon_heart.png", "icon_outside_window.png", "icon_wifi_slash.png", @@ -431,6 +433,7 @@ void DashboardManager::RenderInline() static auto &style = ImGui::GetStyle(); ImU32 const white = ImGui::ColorConvertFloat4ToU32({ 1, 1, 1, style.Alpha }); + // static ImU32 const transparent = ImGui::ColorConvertFloat4ToU32({ 0, 0, 0, 0 }); ImVec2 const windowPos = ImGui::GetWindowPos(); ImVec2 const windowSize = ImGui::GetWindowSize(); @@ -463,7 +466,8 @@ void DashboardManager::RenderInline() // dashboard copy ImGui::BeginGroup(); { - list->AddText(font_title, font_title->FontSize, widgetPos - ImVec2(1, 0), color_text, appStore.dashboard.title.c_str()); + //list->AddText(font_title, font_title->FontSize, widgetPos - ImVec2(1, 0), color_text, appStore.dashboard.title.c_str()); + list->AddText(font_title, font_title->FontSize, widgetPos - ImVec2(1, 0), ImGui::ColorConvertFloat4ToU32(style.Colors[ImGuiCol_TextDisabled]), appStore.dashboard.title.c_str()); ImGui::Dummy({ 0, font_title->FontSize - 6 }); ImGui::TextWrapped(appStore.dashboard.heading.c_str()); @@ -483,13 +487,13 @@ void DashboardManager::RenderInline() // socials { ImGui::Dummy({ size, size }); - list->AddImage((void*)_get_texture("icon_bolt"), ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), ImVec2(0, 0), ImVec2(1, 1), ImGui::IsItemHovered() ? color_button_hover : color_button); + list->AddImage((void*)_get_texture("icon_heart"), ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), ImVec2(0, 0), ImVec2(1, 1), ImGui::IsItemHovered() ? color_button_hover : color_button); if (ImGui::IsItemClicked()) ImGui::OpenPopup("socials"); } - ImGui::SameLine(NULL, 10); + ImGui::SameLine(NULL, 16); ImGui::SetCursorPos(ImGui::GetCursorPos() + offset); // options @@ -560,6 +564,7 @@ void DashboardManager::RenderInline() { ImGui::BeginChild("endpoints_scrollable", ImVec2(ImGui::GetContentRegionAvail().x, 540), false); + ImGui::Spacing(); { int i = 0; for (auto& endpoint : this->endpoints) @@ -581,21 +586,35 @@ void DashboardManager::RenderInline() ImGui::Dummy({ 0 ,0 }); ImGui::SameLine(NULL, 16); - ImGui::Dummy({ ImGui::GetContentRegionAvail().x - 16, 73 }); + + bool highlighted = false; + + // ImGui::Dummy({ ImGui::GetContentRegionAvail().x - 16, 73 }); + ImGui::PushID(i); + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, selected ? color_secondary : color_secondary_faded); + ImGui::PushStyleColor(ImGuiCol_Header, color); + ImGui::PushStyleColor(ImGuiCol_HeaderActive, selected ? color_secondary : color_secondary_faded); + ImGui::PushStyleColor(ImGuiCol_NavHighlight, NULL); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 16.0f); + ImGui::Selectable("##end", &highlighted, 0, { ImGui::GetContentRegionAvail().x - 16, 73 }); + ImGui::PopStyleColor(4); + ImGui::PopStyleVar(); + ImGui::PopID(); + ImGui::Spacing(); auto hovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup); // background - if (hovered) + if (hovered || highlighted) { if (selected) { w_list->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary, 5, 0, 8); - w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary, 5, NULL); + //w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary, 5, NULL); } else { - w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary_faded, 5, NULL); + //w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary_faded, 5, NULL); } } else @@ -640,13 +659,12 @@ void DashboardManager::RenderInline() if (ImGui::BeginPopupContextItem(key.c_str())) { { - ImGui::MenuItem(endpoint->name.c_str(), NULL, false, false); - if (ImGui::MenuItem("disable")) {} - if (ImGui::MenuItem("block", "wip")) {} - - //ImGui::SeparatorText("xx"); + if (ImGui::MenuItem("all but this one")) { + + } + } - + if (!hovered && !ImGui::IsWindowHovered()) ImGui::CloseCurrentPopup(); @@ -657,7 +675,7 @@ void DashboardManager::RenderInline() }*/ // action - if (ImGui::IsItemClicked()) + if (ImGui::IsItemClicked() || (highlighted && (ImGui::IsKeyPressed(ImGuiKey_Space) || ImGui::IsKeyPressed(ImGuiKey_Enter)))) { int total = 0; for (auto &endpoint : this->endpoints) @@ -735,8 +753,8 @@ void DashboardManager::RenderInline() ImGui::Indent(style.FramePadding.x); { ImGui::Text("Unavailable in this version."); - static bool test; - ToggleButton("test", &test); + // static bool test; + // ToggleButton("test", &test); } ImGui::Unindent(); } diff --git a/dropship/src/_WindowsFirewallUtil.h b/dropship/src/_WindowsFirewallUtil.h index 748fcad..42a36d2 100644 --- a/dropship/src/_WindowsFirewallUtil.h +++ b/dropship/src/_WindowsFirewallUtil.h @@ -549,10 +549,10 @@ class _WindowsFirewallUtil : public failable } } - if (this->networkInfo.connected_networks == 0 && ImGui::GetCurrentContext() != nullptr) + /*if (this->networkInfo.connected_networks == 0 && ImGui::GetCurrentContext() != nullptr) { ImGui::OpenPopup("offline"); - } + }*/ Cleanup: @@ -884,15 +884,6 @@ class _WindowsFirewallUtil : public failable ImGui::OpenPopup("warnings_fixed"); this->modal_warnings_fixed_time = ImGui::GetTime(); } - - - // TODO test - if (ImGui::BeginPopupModal("offline", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground)) - { - ImGui::Text("test"); - ImGui::EndPopup(); - } - //ImGui::Text("debugging %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); diff --git a/dropship/src/theme.cpp b/dropship/src/theme.cpp index 02361f0..ae2f1f0 100644 --- a/dropship/src/theme.cpp +++ b/dropship/src/theme.cpp @@ -45,10 +45,12 @@ void setTheme(THEME theme) style.ItemSpacing = { 8.0f, 8.0f }; style.CellPadding = { 8.0f, 4.0f }; - style.FrameRounding = 4.0f; + style.FrameRounding = 5.0f; //style.FramePadding = { 4.0f, 4.0f }; style.FramePadding = { 10.0f, 8.0f }; + style.SelectableRounding = 5.0f; + style.IndentSpacing = 20; style.GrabMinSize = 8; diff --git a/dropship/src/util.hpp b/dropship/src/util.hpp index 551fffe..82f7064 100644 --- a/dropship/src/util.hpp +++ b/dropship/src/util.hpp @@ -35,6 +35,8 @@ struct Endpoint bool _has_pinged = { false }; // if it has attempted a ping yet ((any point)). bool _has_pinged_successfully = { false }; + // bool highlighted = false; // tab index + bool favorite = { false }; /* 0 (>) = fine diff --git a/dropship/vendor/imgui-docking/imgui.cpp b/dropship/vendor/imgui-docking/imgui.cpp index a87b7cd..00bc3f3 100644 --- a/dropship/vendor/imgui-docking/imgui.cpp +++ b/dropship/vendor/imgui-docking/imgui.cpp @@ -1213,6 +1213,7 @@ ImGuiStyle::ImGuiStyle() TabBarBorderSize = 1.0f; // Thickness of tab-bar separator, which takes on the tab active color to denote focus. ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right. ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text. + SelectableRounding = 0.0f; // Radius of selectable/menuitem corners rounding. Set to 0.0f to have rectangular selection. SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. SeparatorTextBorderSize = 3.0f; // Thickkness of border in SeparatorText() SeparatorTextAlign = ImVec2(0.0f,0.5f);// Alignment of text within the separator. Defaults to (0.0f, 0.5f) (left aligned, center). @@ -1261,6 +1262,7 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor) GrabRounding = ImTrunc(GrabRounding * scale_factor); LogSliderDeadzone = ImTrunc(LogSliderDeadzone * scale_factor); TabRounding = ImTrunc(TabRounding * scale_factor); + SelectableRounding = ImTrunc(SelectableRounding * scale_factor); TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImTrunc(TabMinWidthForCloseButton * scale_factor) : FLT_MAX; SeparatorTextPadding = ImTrunc(SeparatorTextPadding * scale_factor); DockingSeparatorSize = ImTrunc(DockingSeparatorSize * scale_factor); @@ -3203,6 +3205,7 @@ static const ImGuiDataVarInfo GStyleVarInfo[] = { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabMinSize) }, // ImGuiStyleVar_GrabMinSize { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabRounding) }, // ImGuiStyleVar_GrabRounding { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabRounding) }, // ImGuiStyleVar_TabRounding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, SelectableRounding) }, // ImGuiStyleVar_SelectableRounding { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabBarBorderSize) }, // ImGuiStyleVar_TabBarBorderSize { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) }, // ImGuiStyleVar_ButtonTextAlign { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, SelectableTextAlign) }, // ImGuiStyleVar_SelectableTextAlign diff --git a/dropship/vendor/imgui-docking/imgui.h b/dropship/vendor/imgui-docking/imgui.h index 6cd119a..c85d8ff 100644 --- a/dropship/vendor/imgui-docking/imgui.h +++ b/dropship/vendor/imgui-docking/imgui.h @@ -1732,6 +1732,7 @@ enum ImGuiStyleVar_ ImGuiStyleVar_TabRounding, // float TabRounding ImGuiStyleVar_TabBarBorderSize, // float TabBarBorderSize ImGuiStyleVar_ButtonTextAlign, // ImVec2 ButtonTextAlign + ImGuiStyleVar_SelectableRounding, // float SelectableRounding ImGuiStyleVar_SelectableTextAlign, // ImVec2 SelectableTextAlign ImGuiStyleVar_SeparatorTextBorderSize,// float SeparatorTextBorderSize ImGuiStyleVar_SeparatorTextAlign, // ImVec2 SeparatorTextAlign @@ -2002,6 +2003,7 @@ struct ImGuiStyle float TabBarBorderSize; // Thickness of tab-bar separator, which takes on the tab active color to denote focus. ImGuiDir ColorButtonPosition; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right. ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered). + float SelectableRounding; // Radius of selectable/menuitem corners rounding. Set to 0.0f to have rectangular selection. ImVec2 SelectableTextAlign; // Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. float SeparatorTextBorderSize; // Thickkness of border in SeparatorText() ImVec2 SeparatorTextAlign; // Alignment of text within the separator. Defaults to (0.0f, 0.5f) (left aligned, center). diff --git a/dropship/vendor/imgui-docking/imgui_demo.cpp b/dropship/vendor/imgui-docking/imgui_demo.cpp index 7c9cb1e..3f7ca83 100644 --- a/dropship/vendor/imgui-docking/imgui_demo.cpp +++ b/dropship/vendor/imgui-docking/imgui_demo.cpp @@ -6509,6 +6509,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f"); ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f"); ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f"); + ImGui::SliderFloat("SelectableRounding", &style.SelectableRounding, 0.0f, 12.0f, "%.0f"); ImGui::SeparatorText("Widgets"); ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f"); diff --git a/dropship/vendor/imgui-docking/imgui_widgets.cpp b/dropship/vendor/imgui-docking/imgui_widgets.cpp index 1174f09..20ed055 100644 --- a/dropship/vendor/imgui-docking/imgui_widgets.cpp +++ b/dropship/vendor/imgui-docking/imgui_widgets.cpp @@ -6619,7 +6619,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (hovered || selected) { const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); - RenderFrame(bb.Min, bb.Max, col, false, 0.0f); + RenderFrame(bb.Min, bb.Max, col, false, style.SelectableRounding); } if (g.NavId == id) RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding);