Skip to content

Commit

Permalink
remove Snooty "font tweaks" by making client code use at least 12-pix…
Browse files Browse the repository at this point in the history
…el widget regions with it (11 seems to be the minimum to avoid descenders being truncated)
  • Loading branch information
sophiapoirier committed Jul 24, 2021
1 parent 4b99360 commit 3fda8d8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 104 deletions.
105 changes: 33 additions & 72 deletions dfxgui/dfxguitextdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ To contact the author, use the contact form at http://destroyfx.org/
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string_view>

#include "dfxguieditor.h"
#include "dfxguimisc.h"
#include "dfxmath.h"

using DGFontTweaks = internal::DGFontTweaks;

//-----------------------------------------------------------------------------
static constexpr VSTGUI::CHoriTxtAlign DFXGUI_TextAlignmentToVSTGUI(dfx::TextAlignment inTextAlignment) noexcept
Expand All @@ -53,25 +53,30 @@ static constexpr VSTGUI::CHoriTxtAlign DFXGUI_TextAlignmentToVSTGUI(dfx::TextAli
}

//-----------------------------------------------------------------------------
static constexpr bool DFXGUI_IsBitmapFont(DGFontTweaks inFontTweaks) noexcept
static bool DFXGUI_IsBitmapFont(char const* inFontName) noexcept
{
switch (inFontTweaks)
if (inFontName)
{
case DGFontTweaks::SNOOTY10PX:
case DGFontTweaks::PASEMENT9PX:
std::string_view const fontNameView(inFontName);
if (fontNameView.compare(dfx::kFontName_Snooty10px) == 0)
{
return true;
}
if (fontNameView.compare(dfx::kFontName_Pasement9px) == 0)
{
return true;
default:
return false;
}
}
return false;
}

//-----------------------------------------------------------------------------
// Constructor-time setup. Returns computed font tweaks enum to be saved for draw-time tweaking.
[[nodiscard]] static DGFontTweaks DFXGUI_ConfigureTextDisplay(DfxGuiEditor* inOwnerEditor,
VSTGUI::CTextLabel* inTextDisplay,
dfx::TextAlignment inTextAlignment,
float inFontSize, DGColor inFontColor,
char const* inFontName)
// common constructor-time setup
static void DFXGUI_ConfigureTextDisplay(DfxGuiEditor* inOwnerEditor,
VSTGUI::CTextLabel* inTextDisplay,
dfx::TextAlignment inTextAlignment,
float inFontSize, DGColor inFontColor,
char const* inFontName)
{
inTextDisplay->setTransparency(true);

Expand All @@ -83,45 +88,17 @@ static constexpr bool DFXGUI_IsBitmapFont(DGFontTweaks inFontTweaks) noexcept
inTextDisplay->setFont(fontDesc);
}

DGFontTweaks const fontTweaks = [inFontName]
{
if (inFontName)
{
if (strcmp(inFontName, dfx::kFontName_Snooty10px) == 0)
{
return DGFontTweaks::SNOOTY10PX;
}
if (strcmp(inFontName, dfx::kFontName_Pasement9px) == 0)
{
return DGFontTweaks::PASEMENT9PX;
}
}
return DGFontTweaks::NONE;
}();
inTextDisplay->setAntialias(!DFXGUI_IsBitmapFont(fontTweaks));

return fontTweaks;
inTextDisplay->setAntialias(!DFXGUI_IsBitmapFont(inFontName));
}

//-----------------------------------------------------------------------------
static DGRect DFXGUI_GetTextDrawRegion(DGFontTweaks inFontTweaks, DGRect const& inRegion)
static DGRect DFXGUI_GetTextDrawRegion(DGRect const& inRegion, bool inIsBitmapFont)
{
auto textArea = inRegion;
if (DFXGUI_IsBitmapFont(inFontTweaks))
if (inIsBitmapFont)
{
textArea.makeIntegral();
}
if (inFontTweaks == DGFontTweaks::SNOOTY10PX)
{
// TODO tom: It looks like we want this offset on windows too,
// to match Sophia's screenshots, but doing so clips the top
// of the text. Don't know why. Maybe we should just be adjusting
// the coordinates in the client GUI code?
#if TARGET_OS_MAC
textArea.offset(0, -2);
#endif
textArea.setHeight(textArea.getHeight() + 2);
}
return textArea;
}

Expand All @@ -144,9 +121,10 @@ DGTextDisplay::DGTextDisplay(DfxGuiEditor* inOwnerEditor,
char const* inFontName)
: DGControl<VSTGUI::CTextEdit>(inRegion, inOwnerEditor, inParamID, nullptr, inBackgroundImage),
mValueToTextProc(inTextProc ? inTextProc : valueToTextProc_Generic),
mValueToTextUserData(inUserData)
mValueToTextUserData(inUserData),
mIsBitmapFont(DFXGUI_IsBitmapFont(inFontName))
{
mFontTweaks = DFXGUI_ConfigureTextDisplay(inOwnerEditor, this, inTextAlignment, inFontSize, inFontColor, inFontName);
DFXGUI_ConfigureTextDisplay(inOwnerEditor, this, inTextAlignment, inFontSize, inFontColor, inFontName);

setValueToStringFunction(std::bind(&DGTextDisplay::valueToTextProcBridge, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
Expand Down Expand Up @@ -320,7 +298,7 @@ void DGTextDisplay::takeFocus()
//-----------------------------------------------------------------------------
void DGTextDisplay::drawPlatformText(VSTGUI::CDrawContext* inContext, VSTGUI::IPlatformString* inString, VSTGUI::CRect const& inRegion)
{
auto const textArea = DFXGUI_GetTextDrawRegion(mFontTweaks, inRegion);
auto const textArea = DFXGUI_GetTextDrawRegion(inRegion, mIsBitmapFont);
VSTGUI::CTextEdit::drawPlatformText(inContext, inString, textArea);
}

Expand Down Expand Up @@ -360,24 +338,6 @@ bool DGTextDisplay::textToValueProcBridge(VSTGUI::UTF8StringPtr inText, float& o
return valueFromText.has_value();
}

//-----------------------------------------------------------------------------
// This is called by VSTGUI when the text display transitions to the platform's text
// editor. We move the text editor up so that it lands where the text label was.
// (XXX presumably there is a less hacky way to do this??)
VSTGUI::CRect DGTextDisplay::platformGetSize() const
{
VSTGUI::CRect rect = DGControl<VSTGUI::CTextEdit>::platformGetSize();
if (mFontTweaks == DGFontTweaks::SNOOTY10PX)
{
#if TARGET_OS_MAC
rect.top -= 2;
#else
rect.top ++;
#endif
}
return rect;
}




Expand All @@ -388,9 +348,10 @@ VSTGUI::CRect DGTextDisplay::platformGetSize() const
DGStaticTextDisplay::DGStaticTextDisplay(DfxGuiEditor* inOwnerEditor, DGRect const& inRegion, DGImage* inBackgroundImage,
dfx::TextAlignment inTextAlignment, float inFontSize,
DGColor inFontColor, char const* inFontName)
: DGControl<VSTGUI::CTextLabel>(inRegion, nullptr, inBackgroundImage)
: DGControl<VSTGUI::CTextLabel>(inRegion, nullptr, inBackgroundImage),
mIsBitmapFont(DFXGUI_IsBitmapFont(inFontName))
{
mFontTweaks = DFXGUI_ConfigureTextDisplay(inOwnerEditor, this, inTextAlignment, inFontSize, inFontColor, inFontName);
DFXGUI_ConfigureTextDisplay(inOwnerEditor, this, inTextAlignment, inFontSize, inFontColor, inFontName);

setMouseEnabled(false);
}
Expand All @@ -416,7 +377,7 @@ void DGStaticTextDisplay::setCFText(CFStringRef inText)
//-----------------------------------------------------------------------------
void DGStaticTextDisplay::drawPlatformText(VSTGUI::CDrawContext* inContext, VSTGUI::IPlatformString* inString, VSTGUI::CRect const& inRegion)
{
auto const textArea = DFXGUI_GetTextDrawRegion(mFontTweaks, inRegion);
auto const textArea = DFXGUI_GetTextDrawRegion(inRegion, mIsBitmapFont);
VSTGUI::CTextLabel::drawPlatformText(inContext, inString, textArea);
}

Expand Down Expand Up @@ -522,9 +483,9 @@ void DGHelpBox::draw(VSTGUI::CDrawContext* inContext)
image->draw(inContext, getViewSize());
}

constexpr VSTGUI::CCoord textHeight = 10;
auto const fontHeight = getFont()->getSize();
DGRect textArea(getViewSize());
textArea.setSize(textArea.getWidth() - mTextMargin.x, textHeight);
textArea.setSize(textArea.getWidth() - mTextMargin.x, fontHeight + 2);
textArea.offset(mTextMargin);

std::istringstream stream(text);
Expand All @@ -539,13 +500,13 @@ void DGHelpBox::draw(VSTGUI::CDrawContext* inContext)
drawPlatformText(inContext, VSTGUI::UTF8String(line).getPlatformString(), textArea);
textArea.offset(1, 0);
drawPlatformText(inContext, VSTGUI::UTF8String(line).getPlatformString(), textArea);
textArea.offset(-1, textHeight + mLineSpacing + 2);
textArea.offset(-1, fontHeight + mLineSpacing + 2);
setFontColor(entryFontColor);
}
else
{
drawPlatformText(inContext, VSTGUI::UTF8String(line).getPlatformString(), textArea);
textArea.offset(0, textHeight + mLineSpacing);
textArea.offset(0, fontHeight + mLineSpacing);
}
}

Expand Down
16 changes: 2 additions & 14 deletions dfxgui/dfxguitextdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ To contact the author, use the contact form at http://destroyfx.org/

#include "dfxguicontrol.h"

namespace internal
{
// Some fonts have tweaks that we apply on a platform-by-platform basis
// to get pixel-perfect alignment.
enum class DGFontTweaks
{
NONE,
SNOOTY10PX,
PASEMENT9PX,
};
} // namespace internal

//-----------------------------------------------------------------------------
class DGTextDisplay : public DGControl<VSTGUI::CTextEdit>
Expand Down Expand Up @@ -88,7 +77,6 @@ class DGTextDisplay : public DGControl<VSTGUI::CTextEdit>
protected:
void takeFocus() override;
void drawPlatformText(VSTGUI::CDrawContext* inContext, VSTGUI::IPlatformString* inString, VSTGUI::CRect const& inRegion) override;
VSTGUI::CRect platformGetSize() const override;

bool valueToTextProcBridge(float inValue, char outTextUTF8[kTextMaxLength], CParamDisplay* inUserData);
bool textToValueProcBridge(VSTGUI::UTF8StringPtr inText, float& outValue, VSTGUI::CTextEdit* textEdit);
Expand All @@ -101,7 +89,7 @@ class DGTextDisplay : public DGControl<VSTGUI::CTextEdit>
private:
static bool valueToTextProc_Generic(float inValue, char outTextUTF8[], void* inUserData);

internal::DGFontTweaks mFontTweaks = internal::DGFontTweaks::NONE;
bool const mIsBitmapFont;
};


Expand All @@ -126,7 +114,7 @@ class DGStaticTextDisplay : public DGControl<VSTGUI::CTextLabel>
void drawPlatformText(VSTGUI::CDrawContext* inContext, VSTGUI::IPlatformString* inString, VSTGUI::CRect const& inRegion) override;

private:
internal::DGFontTweaks mFontTweaks = internal::DGFontTweaks::NONE;
bool const mIsBitmapFont;
};


Expand Down
10 changes: 5 additions & 5 deletions geometer/gui/geometereditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ enum {
pos_sliderincY = 35,

pos_sliderlabelX = 19,
pos_sliderlabelY = pos_sliderY - 1,
pos_sliderlabelY = pos_sliderY - 3,
pos_sliderlabelwidth = 32,
pos_sliderlabelheight = 10,
pos_sliderlabelheight = 12,

pos_finedownX = 27,
pos_finedownY = 263,
Expand All @@ -77,7 +77,7 @@ enum {
pos_finebuttonincX = 240,
pos_finebuttonincY = pos_sliderincY,

pos_displayheight = 10,
pos_displayheight = 12,
pos_displayX = 180,
pos_displayY = pos_sliderY - pos_displayheight,
pos_displaywidth = pos_sliderX + pos_sliderwidth - pos_displayX,
Expand Down Expand Up @@ -138,8 +138,8 @@ void GeometerHelpBox::draw(VSTGUI::CDrawContext * inContext) {
image->draw(inContext, getViewSize());

DGRect textpos(getViewSize());
textpos.setSize(textpos.getWidth() - 5, 10);
textpos.offset(4, 3);
textpos.setSize(textpos.getWidth() - 5, getFont()->getSize() + 2);
textpos.offset(4, 1);

auto const helpstrings = [this]() -> char const * {
switch (helpCategory) {
Expand Down
6 changes: 3 additions & 3 deletions rezsynth/gui/rezsyntheditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum
kHorizontalSliderHeight = 23,

kHorizontalDisplayWidth = kHorizontalSliderWidth / 2,
kHorizontalDisplayHeight = 10,
kHorizontalDisplayHeight = 12,
kHorizontalDisplayX = kHorizontalSliderX + kHorizontalSliderWidth - kHorizontalDisplayWidth - 3,
kHorizontalDisplayY = kHorizontalSliderY - kHorizontalDisplayHeight,

Expand All @@ -53,7 +53,7 @@ enum
kVerticalSliderNameWidth = 13,

kVerticalDisplayX = kVerticalSliderX - 21,
kVerticalDisplayY = kVerticalSliderY + kVerticalSliderHeight + 11,
kVerticalDisplayY = kVerticalSliderY + kVerticalSliderHeight + 9,
kVerticalDisplayWidth = 48,
kVerticalDisplayHeight = kHorizontalDisplayHeight,

Expand Down Expand Up @@ -378,7 +378,7 @@ long RezSynthEditor::OpenEditor()
// help display
pos.set(kHelpX, kHelpY, kHelpWidth, kHelpHeight);
mHelpBox = emplaceControl<DGHelpBox>(this, pos, std::bind(&RezSynthEditor::GetHelpForControl, this, std::placeholders::_1), nullptr, DGColor::kWhite);
mHelpBox->setTextMargin({11, 8});
mHelpBox->setTextMargin({11, 6});



Expand Down
4 changes: 2 additions & 2 deletions scrubby/gui/scrubbyeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ enum

kDisplayWidth = 90,
kDisplayWidth_big = 117, // for seek rate
kDisplayHeight = 10,
kDisplayHeight = 12,
kDisplayInsetX = 0,
kDisplayInsetX_leftAlign = 2,
kDisplayInsetY = 0,
Expand Down Expand Up @@ -522,7 +522,7 @@ long ScrubbyEditor::OpenEditor()
pos.set(kHelpX, kHelpY, helpBackgroundImage->getWidth(), helpBackgroundImage->getHeight());
mHelpBox = emplaceControl<DGHelpBox>(this, pos, std::bind(&ScrubbyEditor::GetHelpForControl, this, _1), helpBackgroundImage, DGColor::kWhite);
mHelpBox->setHeaderFontColor(DGColor::kBlack);
mHelpBox->setTextMargin({12, 4});
mHelpBox->setTextMargin({12, 2});



Expand Down
4 changes: 2 additions & 2 deletions skidder/gui/skiddereditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum
kSliderInc = 64,

kDisplayX = 334,
kDisplayY = kSliderY + 11,
kDisplayY = kSliderY + 10,
kDisplayWidth = 70,
kDisplayHeight = 12,

Expand Down Expand Up @@ -297,7 +297,7 @@ long SkidderEditor::OpenEditor()
// help display
pos.set(kHelpX, kHelpY, kHelpWidth, kHelpHeight);
mHelpBox = emplaceControl<DGHelpBox>(this, pos, std::bind(&SkidderEditor::GetHelpForControl, this, std::placeholders::_1), nullptr, DGColor::kWhite);
mHelpBox->setTextMargin({8, 12});
mHelpBox->setTextMargin({8, 10});
mHelpBox->setLineSpacing(3);


Expand Down
12 changes: 6 additions & 6 deletions transverb/gui/transverbeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ enum
kTallFaderY = 265,
kTallFaderInc = 28,

kDisplayX = 318 + 1,
kDisplayWidth = 180,
kDisplayHeight = 12,
kDisplayY = kWideFaderY - kDisplayHeight - 1,

kQualityButtonX = 425,
kTomsoundButtonX = kQualityButtonX,
kFreezeButtonX = kWideFaderX,
Expand All @@ -68,12 +73,7 @@ enum
kDFXLinkX = 107,
kDFXLinkY = 281,
kDestroyFXLinkX = 351,
kDestroyFXLinkY = 339,

kDisplayX = 318 + 1,
kDisplayY = 24,
kDisplayWidth = 180,
kDisplayHeight = 10
kDestroyFXLinkY = 339
};


Expand Down

0 comments on commit 3fda8d8

Please sign in to comment.