Added TextDrawer classes
Former-commit-id: 4c5ace385f1a9b9ceebb774022bbc001b69a3bb4
This commit is contained in:
42
include/Nazara/Utility/AbstractTextDrawer.hpp
Normal file
42
include/Nazara/Utility/AbstractTextDrawer.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ABSTRACTTEXTDRAWER_HPP
|
||||
#define NAZARA_ABSTRACTTEXTDRAWER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
class NzAbstractImage;
|
||||
class NzFont;
|
||||
|
||||
class NAZARA_API NzAbstractTextDrawer
|
||||
{
|
||||
public:
|
||||
struct Glyph;
|
||||
|
||||
NzAbstractTextDrawer() = default;
|
||||
virtual ~NzAbstractTextDrawer();
|
||||
|
||||
virtual const NzRectui& GetBounds() const = 0;
|
||||
virtual NzFont* GetFont(unsigned int index) const = 0;
|
||||
virtual unsigned int GetFontCount() const = 0;
|
||||
virtual const Glyph& GetGlyph(unsigned int index) const = 0;
|
||||
virtual unsigned int GetGlyphCount() const = 0;
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
NzColor color;
|
||||
NzRectui atlasRect;
|
||||
NzVector2f corners[4];
|
||||
NzAbstractImage* atlas;
|
||||
bool flipped;
|
||||
};
|
||||
};
|
||||
|
||||
#endif // NAZARA_ABSTRACTTEXTDRAWER_HPP
|
||||
59
include/Nazara/Utility/SimpleTextDrawer.hpp
Normal file
59
include/Nazara/Utility/SimpleTextDrawer.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SIMPLETEXTDRAWER_HPP
|
||||
#define NAZARA_SIMPLETEXTDRAWER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ResourceListener.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/Font.hpp>
|
||||
#include <vector>
|
||||
|
||||
class NAZARA_API NzSimpleTextDrawer : public NzAbstractTextDrawer, NzResourceListener
|
||||
{
|
||||
public:
|
||||
NzSimpleTextDrawer();
|
||||
virtual ~NzSimpleTextDrawer();
|
||||
|
||||
const NzRectui& GetBounds() const;
|
||||
unsigned int GetCharacterSize() const;
|
||||
const NzColor& GetColor() const;
|
||||
NzFont* GetFont() const;
|
||||
nzUInt32 GetStyle() const;
|
||||
|
||||
void SetCharacterSize(unsigned int characterSize);
|
||||
void SetColor(const NzColor& color);
|
||||
void SetFont(NzFont* font);
|
||||
void SetStyle(nzUInt32 style);
|
||||
void SetText(const NzString& str);
|
||||
|
||||
static NzSimpleTextDrawer Draw(unsigned int characterSize, const NzString& str, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
|
||||
static NzSimpleTextDrawer Draw(NzFont* font, unsigned int characterSize, const NzString& str, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
|
||||
|
||||
private:
|
||||
NzFont* GetFont(unsigned int index) const override;
|
||||
unsigned int GetFontCount() const override;
|
||||
const Glyph& GetGlyph(unsigned int index) const override;
|
||||
unsigned int GetGlyphCount() const override;
|
||||
|
||||
bool OnResourceModified(const NzResource* resource, int index, unsigned int code) override;
|
||||
void OnResourceReleased(const NzResource* resource, int index) override;
|
||||
void UpdateGlyphs() const;
|
||||
|
||||
mutable std::vector<Glyph> m_glyphs;
|
||||
NzColor m_color;
|
||||
NzFontRef m_font;
|
||||
mutable NzRectui m_bounds;
|
||||
NzString m_text;
|
||||
nzUInt32 m_style;
|
||||
mutable bool m_glyphUpdated;
|
||||
unsigned int m_characterSize;
|
||||
};
|
||||
|
||||
#endif // NAZARA_SIMPLETEXTDRAWER_HPP
|
||||
Reference in New Issue
Block a user