(Font) Added mutable default values for glyph border and minimum step size

Former-commit-id: 9b69b591afb95fdea9d686ef9b775f965de40d9f
This commit is contained in:
Lynix 2015-01-17 22:03:04 +01:00
parent b787ce94cf
commit f1694fd6e9
2 changed files with 45 additions and 8 deletions

View File

@ -74,6 +74,11 @@ class NAZARA_API NzFont : public NzResource, NzAbstractAtlas::Listener, NzNonCop
void SetGlyphBorder(unsigned int borderSize); void SetGlyphBorder(unsigned int borderSize);
void SetMinimumStepSize(unsigned int minimumSizeStep); void SetMinimumStepSize(unsigned int minimumSizeStep);
static unsigned int GetDefaultGlyphBorder();
static unsigned int GetDefaultMinimumStepSize();
static void SetDefaultGlyphBorder(unsigned int borderSize);
static void SetDefaultMinimumStepSize(unsigned int minimumSizeStep);
enum ModicationCode enum ModicationCode
{ {
ModificationCode_AtlasChanged, ModificationCode_AtlasChanged,
@ -121,6 +126,8 @@ class NAZARA_API NzFont : public NzResource, NzAbstractAtlas::Listener, NzNonCop
unsigned int m_minimumSizeStep; unsigned int m_minimumSizeStep;
static NzFontLoader::LoaderList s_loaders; static NzFontLoader::LoaderList s_loaders;
static unsigned int s_defaultGlyphBorder;
static unsigned int s_defaultMinimumSizeStep;
}; };
#endif // NAZARA_FONT_HPP #endif // NAZARA_FONT_HPP

View File

@ -14,15 +14,15 @@ bool NzFontParams::IsValid() const
} }
NzFont::NzFont() : NzFont::NzFont() :
m_glyphBorder(1), m_glyphBorder(s_defaultGlyphBorder),
m_minimumSizeStep(1) m_minimumSizeStep(s_defaultMinimumSizeStep)
{ {
} }
NzFont::~NzFont() NzFont::~NzFont()
{ {
Destroy(); Destroy();
SetAtlas(nullptr); // On libère l'atlas par la même occasion SetAtlas(nullptr); // On libère l'atlas proprement
} }
void NzFont::ClearGlyphCache() void NzFont::ClearGlyphCache()
@ -302,6 +302,8 @@ void NzFont::SetGlyphBorder(unsigned int borderSize)
} }
void NzFont::SetMinimumStepSize(unsigned int minimumStepSize) void NzFont::SetMinimumStepSize(unsigned int minimumStepSize)
{
if (m_minimumSizeStep != minimumStepSize)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (minimumStepSize == 0) if (minimumStepSize == 0)
@ -311,13 +313,39 @@ void NzFont::SetMinimumStepSize(unsigned int minimumStepSize)
} }
#endif #endif
if (m_minimumSizeStep != minimumStepSize)
{
m_minimumSizeStep = minimumStepSize; m_minimumSizeStep = minimumStepSize;
ClearGlyphCache(); ClearGlyphCache();
} }
} }
unsigned int NzFont::GetDefaultGlyphBorder()
{
return s_defaultGlyphBorder;
}
unsigned int NzFont::GetDefaultMinimumStepSize()
{
return s_defaultMinimumSizeStep;
}
void NzFont::SetDefaultGlyphBorder(unsigned int borderSize)
{
s_defaultGlyphBorder = borderSize;
}
void NzFont::SetDefaultMinimumStepSize(unsigned int minimumSizeStep)
{
#if NAZARA_UTILITY_SAFE
if (minimumStepSize == 0)
{
NazaraError("Minimum step size cannot be zero as it implies division by zero");
return;
}
#endif
s_defaultMinimumSizeStep = minimumSizeStep;
}
nzUInt64 NzFont::ComputeKey(unsigned int characterSize, nzUInt32 style) const nzUInt64 NzFont::ComputeKey(unsigned int characterSize, nzUInt32 style) const
{ {
// On prend le pas en compte // On prend le pas en compte
@ -482,3 +510,5 @@ const NzFont::Glyph& NzFont::PrecacheGlyph(GlyphMap& glyphMap, unsigned int char
} }
NzFontLoader::LoaderList NzFont::s_loaders; NzFontLoader::LoaderList NzFont::s_loaders;
unsigned int NzFont::s_defaultGlyphBorder = 1;
unsigned int NzFont::s_defaultMinimumSizeStep = 1;