Utility: Replace UInt32 by TextStyleFlags
This commit is contained in:
parent
e665ea5373
commit
0582cbfc26
|
|
@ -180,6 +180,8 @@ Nazara Engine:
|
|||
- ⚠ Default TextureSampler WrapMode is now Clamp (instead of Repeat)
|
||||
- Fixed StateMachine ignoring transitions made in Enter/Leave events of states
|
||||
- Fixed Material::Configure resetting textures
|
||||
- ⚠ Renamed TextStyleFlags enum to TextStyle, introduced Flags specialization of TextStyle as TextStyleFlags
|
||||
- ⚠ Font, FontData and SimpleTextDrawer now use a proper TextStyleFlags instead of a UInt32
|
||||
|
||||
Nazara Development Kit:
|
||||
- Added ImageWidget (#139)
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ namespace Ndk
|
|||
case 2:
|
||||
{
|
||||
unsigned int characterSize = lua.Check<unsigned int>(&argIndex);
|
||||
Nz::UInt32 style = lua.Check<Nz::UInt32>(&argIndex);
|
||||
Nz::TextStyleFlags style = lua.Check<Nz::TextStyleFlags>(&argIndex);
|
||||
|
||||
lua.Push(instance->GetCachedGlyphCount(characterSize, style));
|
||||
return 1;
|
||||
|
|
@ -146,7 +146,7 @@ namespace Ndk
|
|||
|
||||
font.BindMethod("IsValid", &Nz::Font::IsValid);
|
||||
|
||||
font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache);
|
||||
font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::TextStyleFlags, const Nz::String&) const) &Nz::Font::Precache);
|
||||
|
||||
font.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder);
|
||||
font.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize);
|
||||
|
|
|
|||
|
|
@ -329,18 +329,26 @@ namespace Nz
|
|||
TextAlign_Max = TextAlign_Right
|
||||
};
|
||||
|
||||
enum TextStyleFlags
|
||||
enum TextStyle
|
||||
{
|
||||
TextStyle_Regular = 0x0,
|
||||
TextStyle_Bold,
|
||||
TextStyle_Italic,
|
||||
TextStyle_StrikeThrough,
|
||||
TextStyle_Underlined,
|
||||
|
||||
TextStyle_Bold = 0x1,
|
||||
TextStyle_Italic = 0x2,
|
||||
TextStyle_StrikeThrough = 0x4,
|
||||
TextStyle_Underlined = 0x8,
|
||||
|
||||
TextStyle_Max = TextStyle_Underlined*2-1
|
||||
TextStyle_Max = TextStyle_Underlined
|
||||
};
|
||||
|
||||
template<>
|
||||
struct EnumAsFlags<TextStyle>
|
||||
{
|
||||
static constexpr TextStyle max = TextStyle_Max;
|
||||
};
|
||||
|
||||
using TextStyleFlags = Flags<TextStyle>;
|
||||
|
||||
constexpr TextStyleFlags TextStyle_Regular = 0;
|
||||
|
||||
enum VertexComponent
|
||||
{
|
||||
VertexComponent_Unused = -1,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Utility/AbstractAtlas.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
@ -58,14 +59,14 @@ namespace Nz
|
|||
bool Create(FontData* data);
|
||||
void Destroy();
|
||||
|
||||
bool ExtractGlyph(unsigned int characterSize, char32_t character, UInt32 style, FontGlyph* glyph) const;
|
||||
bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, FontGlyph* glyph) const;
|
||||
|
||||
const std::shared_ptr<AbstractAtlas>& GetAtlas() const;
|
||||
std::size_t GetCachedGlyphCount(unsigned int characterSize, UInt32 style) const;
|
||||
std::size_t GetCachedGlyphCount(unsigned int characterSize, TextStyleFlags style) const;
|
||||
std::size_t GetCachedGlyphCount() const;
|
||||
String GetFamilyName() const;
|
||||
int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const;
|
||||
const Glyph& GetGlyph(unsigned int characterSize, UInt32 style, char32_t character) const;
|
||||
const Glyph& GetGlyph(unsigned int characterSize, TextStyleFlags style, char32_t character) const;
|
||||
unsigned int GetGlyphBorder() const;
|
||||
unsigned int GetMinimumStepSize() const;
|
||||
const SizeInfo& GetSizeInfo(unsigned int characterSize) const;
|
||||
|
|
@ -73,8 +74,8 @@ namespace Nz
|
|||
|
||||
bool IsValid() const;
|
||||
|
||||
bool Precache(unsigned int characterSize, UInt32 style, char32_t character) const;
|
||||
bool Precache(unsigned int characterSize, UInt32 style, const String& characterSet) const;
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, char32_t character) const;
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, const String& characterSet) const;
|
||||
|
||||
void SetAtlas(const std::shared_ptr<AbstractAtlas>& atlas);
|
||||
void SetGlyphBorder(unsigned int borderSize);
|
||||
|
|
@ -130,11 +131,11 @@ namespace Nz
|
|||
private:
|
||||
using GlyphMap = std::unordered_map<char32_t, Glyph>;
|
||||
|
||||
UInt64 ComputeKey(unsigned int characterSize, UInt32 style) const;
|
||||
UInt64 ComputeKey(unsigned int characterSize, TextStyleFlags style) const;
|
||||
void OnAtlasCleared(const AbstractAtlas* atlas);
|
||||
void OnAtlasLayerChange(const AbstractAtlas* atlas, AbstractImage* oldLayer, AbstractImage* newLayer);
|
||||
void OnAtlasRelease(const AbstractAtlas* atlas);
|
||||
const Glyph& PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, UInt32 style, char32_t character) const;
|
||||
const Glyph& PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, TextStyleFlags style, char32_t character) const;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -21,7 +22,7 @@ namespace Nz
|
|||
FontData() = default;
|
||||
virtual ~FontData();
|
||||
|
||||
virtual bool ExtractGlyph(unsigned int characterSize, char32_t character, UInt32 style, FontGlyph* dst) = 0;
|
||||
virtual bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, FontGlyph* dst) = 0;
|
||||
|
||||
virtual String GetFamilyName() const = 0;
|
||||
virtual String GetStyleName() const = 0;
|
||||
|
|
@ -35,7 +36,7 @@ namespace Nz
|
|||
virtual float QueryUnderlinePosition(unsigned int characterSize) const = 0;
|
||||
virtual float QueryUnderlineThickness(unsigned int characterSize) const = 0;
|
||||
|
||||
virtual bool SupportsStyle(UInt32 style) const = 0;
|
||||
virtual bool SupportsStyle(TextStyleFlags style) const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,20 +38,20 @@ namespace Nz
|
|||
std::size_t GetGlyphCount() const override;
|
||||
const Line& GetLine(std::size_t index) const override;
|
||||
std::size_t GetLineCount() const override;
|
||||
UInt32 GetStyle() const;
|
||||
TextStyleFlags GetStyle() const;
|
||||
const String& GetText() const;
|
||||
|
||||
void SetCharacterSize(unsigned int characterSize);
|
||||
void SetColor(const Color& color);
|
||||
void SetFont(Font* font);
|
||||
void SetStyle(UInt32 style);
|
||||
void SetStyle(TextStyleFlags style);
|
||||
void SetText(const String& str);
|
||||
|
||||
SimpleTextDrawer& operator=(const SimpleTextDrawer& drawer);
|
||||
SimpleTextDrawer& operator=(SimpleTextDrawer&& drawer);
|
||||
|
||||
static SimpleTextDrawer Draw(const String& str, unsigned int characterSize, UInt32 style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, UInt32 style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static SimpleTextDrawer Draw(const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
|
||||
private:
|
||||
void ClearGlyphs() const;
|
||||
|
|
@ -76,8 +76,8 @@ namespace Nz
|
|||
mutable Rectf m_workingBounds;
|
||||
mutable Recti m_bounds;
|
||||
String m_text;
|
||||
TextStyleFlags m_style;
|
||||
mutable UInt32 m_previousCharacter;
|
||||
UInt32 m_style;
|
||||
mutable Vector2ui m_drawPos;
|
||||
mutable bool m_colorUpdated;
|
||||
mutable bool m_glyphUpdated;
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
bool Font::ExtractGlyph(unsigned int characterSize, char32_t character, UInt32 style, FontGlyph* glyph) const
|
||||
bool Font::ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, FontGlyph* glyph) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!IsValid())
|
||||
|
|
@ -127,7 +127,7 @@ namespace Nz
|
|||
return m_atlas;
|
||||
}
|
||||
|
||||
std::size_t Font::GetCachedGlyphCount(unsigned int characterSize, UInt32 style) const
|
||||
std::size_t Font::GetCachedGlyphCount(unsigned int characterSize, TextStyleFlags style) const
|
||||
{
|
||||
UInt64 key = ComputeKey(characterSize, style);
|
||||
auto it = m_glyphes.find(key);
|
||||
|
|
@ -187,7 +187,7 @@ namespace Nz
|
|||
return it->second; // Présent dans le cache, tout va bien
|
||||
}
|
||||
|
||||
const Font::Glyph& Font::GetGlyph(unsigned int characterSize, UInt32 style, char32_t character) const
|
||||
const Font::Glyph& Font::GetGlyph(unsigned int characterSize, TextStyleFlags style, char32_t character) const
|
||||
{
|
||||
UInt64 key = ComputeKey(characterSize, style);
|
||||
return PrecacheGlyph(m_glyphes[key], characterSize, style, character);
|
||||
|
|
@ -256,13 +256,13 @@ namespace Nz
|
|||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
bool Font::Precache(unsigned int characterSize, UInt32 style, char32_t character) const
|
||||
bool Font::Precache(unsigned int characterSize, TextStyleFlags style, char32_t character) const
|
||||
{
|
||||
UInt64 key = ComputeKey(characterSize, style);
|
||||
return PrecacheGlyph(m_glyphes[key], characterSize, style, character).valid;
|
||||
}
|
||||
|
||||
bool Font::Precache(unsigned int characterSize, UInt32 style, const String& characterSet) const
|
||||
bool Font::Precache(unsigned int characterSize, TextStyleFlags style, const String& characterSet) const
|
||||
{
|
||||
///TODO: Itération UTF-8 => UTF-32 sans allocation de buffer (Exposer utf8cpp ?)
|
||||
std::u32string set = characterSet.GetUtf32String();
|
||||
|
|
@ -399,7 +399,7 @@ namespace Nz
|
|||
s_defaultMinimumStepSize = minimumStepSize;
|
||||
}
|
||||
|
||||
UInt64 Font::ComputeKey(unsigned int characterSize, UInt32 style) const
|
||||
UInt64 Font::ComputeKey(unsigned int characterSize, TextStyleFlags style) const
|
||||
{
|
||||
// On prend le pas en compte
|
||||
UInt64 sizePart = static_cast<UInt32>((characterSize/m_minimumStepSize)*m_minimumStepSize);
|
||||
|
|
@ -471,7 +471,7 @@ namespace Nz
|
|||
NazaraError("Atlas has been released while in use");
|
||||
}
|
||||
|
||||
const Font::Glyph& Font::PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, UInt32 style, char32_t character) const
|
||||
const Font::Glyph& Font::PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, TextStyleFlags style, char32_t character) const
|
||||
{
|
||||
auto it = glyphMap.find(character);
|
||||
if (it != glyphMap.end()) // Si le glyphe n'est pas déjà chargé
|
||||
|
|
@ -492,7 +492,7 @@ namespace Nz
|
|||
glyph.requireFauxBold = false;
|
||||
glyph.requireFauxItalic = false;
|
||||
|
||||
UInt32 supportedStyle = style;
|
||||
TextStyleFlags supportedStyle = style;
|
||||
if (style & TextStyle_Bold && !m_data->SupportsStyle(TextStyle_Bold))
|
||||
{
|
||||
glyph.requireFauxBold = true;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
|||
|
||||
FT_Library s_library;
|
||||
std::shared_ptr<FreeTypeLibrary> s_libraryOwner;
|
||||
float s_invScaleFactor = 1.f / (1 << 6); // 1/64
|
||||
constexpr float s_invScaleFactor = 1.f / (1 << 6); // 1/64
|
||||
|
||||
extern "C"
|
||||
unsigned long FT_StreamRead(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count)
|
||||
|
|
@ -96,7 +96,7 @@ namespace Nz
|
|||
return FT_Open_Face(s_library, &m_args, -1, nullptr) == 0;
|
||||
}
|
||||
|
||||
bool ExtractGlyph(unsigned int characterSize, char32_t character, UInt32 style, FontGlyph* dst) override
|
||||
bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, FontGlyph* dst) override
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (!dst)
|
||||
|
|
@ -118,7 +118,7 @@ namespace Nz
|
|||
|
||||
const FT_Pos boldStrength = 2 << 6;
|
||||
|
||||
bool embolden = (style & TextStyle_Bold);
|
||||
bool embolden = (style & TextStyle_Bold) != 0;
|
||||
|
||||
dst->advance = (embolden) ? boldStrength >> 6 : 0;
|
||||
|
||||
|
|
@ -312,7 +312,7 @@ namespace Nz
|
|||
m_args.stream = &m_stream;
|
||||
}
|
||||
|
||||
bool SupportsStyle(UInt32 style) const override
|
||||
bool SupportsStyle(TextStyleFlags style) const override
|
||||
{
|
||||
///TODO
|
||||
return style == TextStyle_Regular || style == TextStyle_Bold;
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ namespace Nz
|
|||
return m_lines.size();
|
||||
}
|
||||
|
||||
UInt32 SimpleTextDrawer::GetStyle() const
|
||||
TextStyleFlags SimpleTextDrawer::GetStyle() const
|
||||
{
|
||||
return m_style;
|
||||
}
|
||||
|
|
@ -159,7 +159,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
void SimpleTextDrawer::SetStyle(UInt32 style)
|
||||
void SimpleTextDrawer::SetStyle(TextStyleFlags style)
|
||||
{
|
||||
m_style = style;
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ namespace Nz
|
|||
return *this;
|
||||
}
|
||||
|
||||
SimpleTextDrawer SimpleTextDrawer::Draw(const String& str, unsigned int characterSize, UInt32 style, const Color& color)
|
||||
SimpleTextDrawer SimpleTextDrawer::Draw(const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color)
|
||||
{
|
||||
SimpleTextDrawer drawer;
|
||||
drawer.SetCharacterSize(characterSize);
|
||||
|
|
@ -218,7 +218,7 @@ namespace Nz
|
|||
return drawer;
|
||||
}
|
||||
|
||||
SimpleTextDrawer SimpleTextDrawer::Draw(Font* font, const String& str, unsigned int characterSize, UInt32 style, const Color& color)
|
||||
SimpleTextDrawer SimpleTextDrawer::Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color)
|
||||
{
|
||||
SimpleTextDrawer drawer;
|
||||
drawer.SetCharacterSize(characterSize);
|
||||
|
|
|
|||
Loading…
Reference in New Issue