From 4916dfe85a8e19a4a8877643c7709be144b5048c Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 9 Oct 2023 22:01:58 -0500 Subject: [PATCH] Add drop shadow to placefile text --- .../source/scwx/qt/gl/draw/placefile_text.cpp | 36 ++++++++++++++----- .../source/scwx/qt/settings/text_settings.cpp | 15 +++++++- .../source/scwx/qt/settings/text_settings.hpp | 1 + scwx-qt/source/scwx/qt/ui/settings_dialog.cpp | 9 ++++- scwx-qt/source/scwx/qt/ui/settings_dialog.ui | 25 ++++++++----- test/data | 2 +- 6 files changed, 68 insertions(+), 20 deletions(-) diff --git a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp index b318e19f..44851fa3 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -39,7 +40,6 @@ class PlacefileText::Impl const std::string& text, const std::string& hoverText, boost::gil::rgba8_pixel_t color, - std::size_t fontNumber, float x, float y); @@ -157,13 +157,36 @@ void PlacefileText::Impl::RenderTextDrawItem( screenCoordinates.y * mapBearingCos_; } + // Clamp font number to 0-8 + std::size_t fontNumber = std::clamp(di->fontNumber_, 0, 8); + + // Set the font for the drop shadow and text + ImGui::PushFont(fonts_[fontNumber]->font()); + + if (settings::TextSettings::Instance() + .placefile_text_drop_shadow_enabled() + .GetValue()) + { + // Draw a drop shadow 1 pixel to the lower right, in black, with the + // original transparency level + RenderText(params, + di->text_, + {}, + boost::gil::rgba8_pixel_t {0, 0, 0, di->color_[3]}, + rotatedX + di->x_ + halfWidth_ + 1.0f, + rotatedY + di->y_ + halfHeight_ - 1.0f); + } + + // Draw the text RenderText(params, di->text_, di->hoverText_, di->color_, - std::clamp(di->fontNumber_, 1, 8), rotatedX + di->x_ + halfWidth_, rotatedY + di->y_ + halfHeight_); + + // Reset the font + ImGui::PopFont(); } } @@ -172,7 +195,6 @@ void PlacefileText::Impl::RenderText( const std::string& text, const std::string& hoverText, boost::gil::rgba8_pixel_t color, - std::size_t fontNumber, float x, float y) { @@ -192,12 +214,10 @@ void PlacefileText::Impl::RenderText( ImGuiWindowFlags_NoBackground); // Render text - ImGui::PushFont(fonts_[fontNumber - 1]->font()); ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(color[0], color[1], color[2], color[3])); ImGui::TextUnformatted(text.c_str()); ImGui::PopStyleColor(); - ImGui::PopFont(); // Store hover text for mouse picking pass if (!hoverText.empty() && ImGui::IsItemHovered()) @@ -248,10 +268,10 @@ void PlacefileText::SetFonts( auto defaultFont = manager::FontManager::Instance().GetImGuiFont( types::FontCategory::Default); - // Valid font numbers are from 1 to 8, place in 0-based font vector - for (std::size_t i = 1; i <= 8; ++i) + // Valid font numbers are from 1 to 8, use 0 for the default font + for (std::size_t i = 0; i <= 8; ++i) { - auto it = fonts.find(i); + auto it = (i > 0) ? fonts.find(i) : fonts.cend(); if (it != fonts.cend()) { p->newFonts_.push_back(it->second); diff --git a/scwx-qt/source/scwx/qt/settings/text_settings.cpp b/scwx-qt/source/scwx/qt/settings/text_settings.cpp index fdf41acf..c6c221d4 100644 --- a/scwx-qt/source/scwx/qt/settings/text_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/text_settings.cpp @@ -49,6 +49,7 @@ class TextSettings::Impl hoverTextWrap_.SetDefault(80); hoverTextWrap_.SetMinimum(0); hoverTextWrap_.SetMaximum(999); + placefileTextDropShadowEnabled_.SetDefault(true); tooltipMethod_.SetDefault(defaultTooltipMethodValue); tooltipMethod_.SetValidator( @@ -93,12 +94,17 @@ class TextSettings::Impl SettingsVariable hoverTextWrap_ {"hover_text_wrap"}; SettingsVariable tooltipMethod_ {"tooltip_method"}; + + SettingsVariable placefileTextDropShadowEnabled_ { + "placefile_text_drop_shadow_enabled"}; }; TextSettings::TextSettings() : SettingsCategory("text"), p(std::make_unique(this)) { - RegisterVariables({&p->hoverTextWrap_, &p->tooltipMethod_}); + RegisterVariables({&p->hoverTextWrap_, + &p->placefileTextDropShadowEnabled_, + &p->tooltipMethod_}); SetDefaults(); } TextSettings::~TextSettings() = default; @@ -162,6 +168,11 @@ SettingsVariable& TextSettings::hover_text_wrap() const return p->hoverTextWrap_; } +SettingsVariable& TextSettings::placefile_text_drop_shadow_enabled() const +{ + return p->placefileTextDropShadowEnabled_; +} + SettingsVariable& TextSettings::tooltip_method() const { return p->tooltipMethod_; @@ -177,6 +188,8 @@ bool operator==(const TextSettings& lhs, const TextSettings& rhs) { return (lhs.p->fontData_ == rhs.p->fontData_ && lhs.p->hoverTextWrap_ == rhs.p->hoverTextWrap_ && + lhs.p->placefileTextDropShadowEnabled_ == + rhs.p->placefileTextDropShadowEnabled_ && lhs.p->tooltipMethod_ == rhs.p->tooltipMethod_); } diff --git a/scwx-qt/source/scwx/qt/settings/text_settings.hpp b/scwx-qt/source/scwx/qt/settings/text_settings.hpp index a0347b4f..ac300abf 100644 --- a/scwx-qt/source/scwx/qt/settings/text_settings.hpp +++ b/scwx-qt/source/scwx/qt/settings/text_settings.hpp @@ -34,6 +34,7 @@ class TextSettings : public SettingsCategory font_point_size(types::FontCategory fontCategory) const; SettingsVariable& hover_text_wrap() const; + SettingsVariable& placefile_text_drop_shadow_enabled() const; SettingsVariable& tooltip_method() const; static TextSettings& Instance(); diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index 9e7310a2..328f805a 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -102,7 +102,8 @@ class SettingsDialogImpl &updateNotificationsEnabled_, &debugEnabled_, &hoverTextWrap_, - &tooltipMethod_}} + &tooltipMethod_, + &placefileTextDropShadowEnabled_}} { // Configure default alert phenomena colors auto& paletteSettings = settings::PaletteSettings::Instance(); @@ -198,6 +199,7 @@ class SettingsDialogImpl settings::SettingsInterface hoverTextWrap_ {}; settings::SettingsInterface tooltipMethod_ {}; + settings::SettingsInterface placefileTextDropShadowEnabled_ {}; std::vector settings_; }; @@ -808,6 +810,11 @@ void SettingsDialogImpl::SetupTextTab() }); tooltipMethod_.SetEditWidget(self_->ui->tooltipMethodComboBox); tooltipMethod_.SetResetButton(self_->ui->resetTooltipMethodButton); + + placefileTextDropShadowEnabled_.SetSettingsVariable( + textSettings.placefile_text_drop_shadow_enabled()); + placefileTextDropShadowEnabled_.SetEditWidget( + self_->ui->placefileTextDropShadowCheckBox); } QImage SettingsDialogImpl::GenerateColorTableImage( diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui index 787c124e..8b0d2179 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui @@ -626,13 +626,6 @@ 0 - - - - Hover text character wrap (0 to disable) - - - @@ -640,6 +633,9 @@ + + + @@ -658,8 +654,12 @@ - - + + + + Hover text character wrap (0 to disable) + + @@ -672,6 +672,13 @@ + + + + Placefile Text Drop Shadow + + + diff --git a/test/data b/test/data index 1685e404..58d61ba3 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 1685e4048ef4a9f34bc11ecbb8db4905dd0a2e19 +Subproject commit 58d61ba37385c699df1eca547668ec3c2a93871e