From 6b53558f65faeb6f580e86fbe5aa9f6c673935c1 Mon Sep 17 00:00:00 2001 From: Sophia Poirier <2997196+sophiapoirier@users.noreply.github.com> Date: Sat, 24 Jul 2021 10:11:02 -0700 Subject: [PATCH] a little bit of font tweakz for Snooty placement on Windows --- dfxgui/dfxguitextdisplay.cpp | 25 +++++++++++++++++++++++++ dfxgui/dfxguitextdisplay.h | 7 +++++++ geometer/gui/geometereditor.cpp | 6 ++++++ 3 files changed, 38 insertions(+) diff --git a/dfxgui/dfxguitextdisplay.cpp b/dfxgui/dfxguitextdisplay.cpp index fd0fea79..5a47efc8 100644 --- a/dfxgui/dfxguitextdisplay.cpp +++ b/dfxgui/dfxguitextdisplay.cpp @@ -70,6 +70,19 @@ static bool DFXGUI_IsBitmapFont(char const* inFontName) noexcept return false; } +//----------------------------------------------------------------------------- +VSTGUI::CPoint detail::GetTextViewPlatformOffset(char const* inFontName) noexcept +{ +#if TARGET_OS_WIN32 + // HACK: on Windows, Snooty renders 1 pixel lower vertically + if (inFontName && (std::string(inFontName) == dfx::kFontName_Snooty10px)) + { + return VSTGUI::CPoint(0, -1); + } +#endif + return {}; +} + //----------------------------------------------------------------------------- // common constructor-time setup static void DFXGUI_ConfigureTextDisplay(DfxGuiEditor* inOwnerEditor, @@ -89,6 +102,10 @@ static void DFXGUI_ConfigureTextDisplay(DfxGuiEditor* inOwnerEditor, } inTextDisplay->setAntialias(!DFXGUI_IsBitmapFont(inFontName)); + + auto adjustedRegion = inTextDisplay->getViewSize(); + adjustedRegion.offset(detail::GetTextViewPlatformOffset(inFontName)); + inTextDisplay->setViewSize(adjustedRegion, false); } //----------------------------------------------------------------------------- @@ -465,6 +482,12 @@ DGHelpBox::DGHelpBox(DfxGuiEditor* inOwnerEditor, DGRect const& inRegion, { assert(inOwnerEditor); assert(inTextForControlProc); + + // HACK part 1: undo "view platform offset", because at the control level, that includes the background, + // but what we more narrowly want is to offset the individual regions of each line of text + auto adjustedRegion = getViewSize(); + adjustedRegion.offset(-detail::GetTextViewPlatformOffset(getFont()->getName())); + setViewSize(adjustedRegion, false); } //----------------------------------------------------------------------------- @@ -487,6 +510,8 @@ void DGHelpBox::draw(VSTGUI::CDrawContext* inContext) DGRect textArea(getViewSize()); textArea.setSize(textArea.getWidth() - mTextMargin.x, fontHeight + 2); textArea.offset(mTextMargin); + // HACK part 2: apply "view platform offset" to the text draw region itself + textArea.offset(detail::GetTextViewPlatformOffset(getFont()->getName())); std::istringstream stream(text); std::string line; diff --git a/dfxgui/dfxguitextdisplay.h b/dfxgui/dfxguitextdisplay.h index 79e24847..77f1815a 100644 --- a/dfxgui/dfxguitextdisplay.h +++ b/dfxgui/dfxguitextdisplay.h @@ -32,6 +32,13 @@ To contact the author, use the contact form at http://destroyfx.org/ #include "dfxguicontrol.h" +//----------------------------------------------------------------------------- +namespace detail +{ +VSTGUI::CPoint GetTextViewPlatformOffset(char const* inFontName) noexcept; +} + + //----------------------------------------------------------------------------- class DGTextDisplay : public DGControl { diff --git a/geometer/gui/geometereditor.cpp b/geometer/gui/geometereditor.cpp index 9e67365e..c3b1dd1f 100644 --- a/geometer/gui/geometereditor.cpp +++ b/geometer/gui/geometereditor.cpp @@ -124,6 +124,10 @@ GeometerHelpBox::GeometerHelpBox(DfxGuiEditor * inOwnerEditor, DGRect const & in dfx::kFontSize_Snooty10px, DGColor::kBlack, dfx::kFontName_Snooty10px), helpCategory(HELP_CATEGORY_GENERAL), itemNum(HELP_EMPTY) { + // HACK: duplicated from DGHelpBox (TODO: unify this code with DGHelpBox) + auto adjustedRegion = getViewSize(); + adjustedRegion.offset(-detail::GetTextViewPlatformOffset(getFont()->getName())); + setViewSize(adjustedRegion, false); } //-------------------------------------------------------------------------- @@ -140,6 +144,8 @@ void GeometerHelpBox::draw(VSTGUI::CDrawContext * inContext) { DGRect textpos(getViewSize()); textpos.setSize(textpos.getWidth() - 5, getFont()->getSize() + 2); textpos.offset(4, 1); + // HACK: duplicated from DGHelpBox (TODO: unify this code with DGHelpBox) + textpos.offset(detail::GetTextViewPlatformOffset(getFont()->getName())); auto const helpstrings = [this]() -> char const * { switch (helpCategory) {