Skip to content

Commit

Permalink
a little bit of font tweakz for Snooty placement on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiapoirier committed Jul 24, 2021
1 parent 3fda8d8 commit 6b53558
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
25 changes: 25 additions & 0 deletions dfxgui/dfxguitextdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
}

//-----------------------------------------------------------------------------
Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions dfxgui/dfxguitextdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VSTGUI::CTextEdit>
{
Expand Down
6 changes: 6 additions & 0 deletions geometer/gui/geometereditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//--------------------------------------------------------------------------
Expand All @@ -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) {
Expand Down

0 comments on commit 6b53558

Please sign in to comment.