metaforce/Runtime/GuiSys/CRasterFont.hpp

167 lines
5.2 KiB
C++
Raw Normal View History

2016-03-11 00:23:16 +00:00
#ifndef __URDE_CRASTERFONT_HPP__
#define __URDE_CRASTERFONT_HPP__
2016-03-11 22:52:55 +00:00
#include "IOStreams.hpp"
2016-03-12 05:10:14 +00:00
#include "CToken.hpp"
2016-03-16 19:53:06 +00:00
#include "zeus/CVector2i.hpp"
2016-03-19 00:07:31 +00:00
#include "CGuiTextSupport.hpp"
2017-01-29 03:58:16 +00:00
#include "Graphics/CTexture.hpp"
2016-03-11 22:52:55 +00:00
2016-03-11 00:23:16 +00:00
namespace urde
{
2016-03-11 22:52:55 +00:00
class IObjectStore;
2016-03-19 00:07:31 +00:00
class CDrawStringOptions;
class CTextRenderBuffer;
2016-03-16 19:53:06 +00:00
/* NOTE: Is this a good place for CGlyph and CKernPair? */
2016-03-11 22:52:55 +00:00
class CGlyph
{
private:
s16 x0_leftPadding;
s16 x2_advance;
s16 x4_rightPadding;
2016-03-11 22:52:55 +00:00
float x8_startU;
float xc_startV;
float x10_endU;
float x14_endV;
s16 x18_cellWidth;
s16 x1a_cellHeight;
s16 x1c_baseline;
s16 x1e_kernStart;
2017-01-29 03:58:16 +00:00
s16 m_layer;
public:
CGlyph() = default;
CGlyph(s16 a, s16 b, s32 c, float startU, float startV, float endU, float endV,
2017-01-29 03:58:16 +00:00
s16 cellWidth, s16 cellHeight, s16 baseline, s16 kernStart, s16 layer=0)
: x0_leftPadding(a), x2_advance(b), x4_rightPadding(c),
x8_startU(startU), xc_startV(startV), x10_endU(endU), x14_endV(endV),
x18_cellWidth(cellWidth), x1a_cellHeight(cellHeight),
2017-01-29 03:58:16 +00:00
x1c_baseline(baseline), x1e_kernStart(kernStart), m_layer(layer)
{}
2016-03-11 22:52:55 +00:00
2017-01-29 03:58:16 +00:00
s16 GetLeftPadding() const { return x0_leftPadding; }
s16 GetAdvance() const { return x2_advance; }
s16 GetRightPadding() const { return x4_rightPadding; }
float GetStartU() const { return x8_startU; }
float GetStartV() const { return xc_startV; }
float GetEndU() const { return x10_endU; }
float GetEndV() const { return x14_endV; }
s16 GetCellWidth() const { return x18_cellWidth; }
s16 GetCellHeight() const { return x1a_cellHeight; }
s16 GetBaseline() const { return x1c_baseline; }
s16 GetKernStart() const { return x1e_kernStart; }
s16 GetLayer() const { return m_layer; }
2016-03-11 22:52:55 +00:00
};
class CKernPair
2016-03-11 22:52:55 +00:00
{
private:
2017-01-24 07:41:33 +00:00
char16_t x0_first;
char16_t x2_second;
2016-03-11 22:52:55 +00:00
s32 x4_howMuch;
public:
CKernPair() = default;
2017-01-24 07:41:33 +00:00
CKernPair(char16_t first, char16_t second, s32 howMuch)
2017-02-01 07:20:18 +00:00
: x0_first(first), x2_second(second), x4_howMuch(howMuch)
{}
2017-01-24 07:41:33 +00:00
char16_t GetFirst() const { return x0_first; }
char16_t GetSecond() const { return x2_second; }
2017-02-01 07:20:18 +00:00
s32 GetHowMuch() const { return x4_howMuch; }
2016-03-11 22:52:55 +00:00
};
class CFontInfo
2016-03-11 00:23:16 +00:00
{
2016-03-11 22:52:55 +00:00
bool x0_ = false;
bool x1_ = false;
s32 x4_ = 0;
s32 x8_fontSize = 0;
2016-03-18 02:22:19 +00:00
char xc_name[40];
public:
CFontInfo() = default;
CFontInfo(bool a, bool b, s32 c, s32 fontSize, const char* name)
: x0_(a), x1_(b), x4_(c), x8_fontSize(fontSize)
{
strcpy(xc_name, name);
(void)x0_;
(void)x1_;
(void)x4_;
(void)x8_fontSize;
}
};
class CRasterFont
{
2016-03-23 20:38:01 +00:00
bool x0_initialized = false;
2016-03-12 05:10:14 +00:00
s32 x4_monoWidth = 16;
s32 x8_monoHeight = 16;
2017-01-24 07:41:33 +00:00
std::vector<std::pair<char16_t, CGlyph>> xc_glyphs;
2016-03-11 22:52:55 +00:00
std::vector<CKernPair> x1c_kerning;
2016-03-21 00:25:53 +00:00
EColorType x2c_mode = EColorType::Main;
CFontInfo x30_fontInfo;
2016-03-18 02:22:19 +00:00
TLockedToken<CTexture> x80_texture;
2016-03-12 05:10:14 +00:00
s32 x8c_baseline;
2016-03-17 20:21:08 +00:00
s32 x90_lineMargin = 0;
2016-03-12 05:10:14 +00:00
2017-01-24 07:41:33 +00:00
const CGlyph* InternalGetGlyph(char16_t chr) const
2016-03-12 05:10:14 +00:00
{
u32 i = 0;
for (; i < xc_glyphs.size(); ++i)
if (chr == xc_glyphs[i].first)
break;
2016-03-12 05:10:14 +00:00
2018-05-08 05:10:24 +00:00
if (i == xc_glyphs.size())
return nullptr;
return &xc_glyphs[i].second;
2016-03-12 05:10:14 +00:00
}
2016-03-11 22:52:55 +00:00
public:
CRasterFont(CInputStream& in, IObjectStore& store);
2016-03-17 20:21:08 +00:00
s32 GetMonoWidth() const { return x4_monoWidth; }
s32 GetMonoHeight() const { return x8_monoHeight; }
2016-03-19 00:07:31 +00:00
EColorType GetMode() const { return x2c_mode; }
2016-03-17 20:21:08 +00:00
s32 GetLineMargin() const { return x90_lineMargin; }
s32 GetCarriageAdvance() const { return GetLineMargin() + GetMonoHeight(); }
s32 GetBaseline() const { return x8c_baseline; }
2017-02-01 07:20:18 +00:00
static s32 KernLookup(const std::vector<CKernPair>& kernTable, s32 kernStart, char16_t chr)
2016-03-11 22:52:55 +00:00
{
2016-03-11 22:59:54 +00:00
auto iter = kernTable.cbegin() + kernStart;
2016-03-11 23:19:02 +00:00
for (; iter != kernTable.cend() && iter->GetFirst() == kernTable[kernStart].GetFirst() ; ++iter)
2016-03-11 22:52:55 +00:00
{
2016-03-11 23:19:02 +00:00
if (iter->GetSecond() == chr)
return iter->GetHowMuch();
2016-03-11 22:52:55 +00:00
}
return 0;
}
2016-03-16 19:53:06 +00:00
void SinglePassDrawString(const CDrawStringOptions&, int x, int y, int& xout, int& yout,
2017-02-01 07:20:18 +00:00
CTextRenderBuffer* renderBuf, const char16_t* str, s32 len) const;
2016-03-16 19:53:06 +00:00
void DrawSpace(const CDrawStringOptions& opts, int x, int y, int& xout, int& yout, int len) const;
2016-03-16 19:56:57 +00:00
void DrawString(const CDrawStringOptions& opts, int x, int y, int& xout, int& yout,
2016-03-16 19:53:06 +00:00
CTextRenderBuffer* renderBuf,
2017-01-24 07:41:33 +00:00
const char16_t* str, int len) const;
const CGlyph* GetGlyph(char16_t chr) const
2016-03-16 19:53:06 +00:00
{
return InternalGetGlyph(chr);
}
void GetSize(const CDrawStringOptions& opts, int& width, int& height,
2017-01-24 07:41:33 +00:00
const char16_t* str, int len) const;
const boo::ObjToken<boo::ITexture>& GetTexture()
{ return x80_texture->GetFontTexture(CTexture::EFontType(x2c_mode)); }
2017-01-30 04:16:20 +00:00
bool IsFinishedLoading() const;
2016-03-11 00:23:16 +00:00
};
std::unique_ptr<IObj> FRasterFontFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
CObjectReference* selfRef);
2016-03-11 00:23:16 +00:00
}
#endif // __URDE_CRASTERFONT_HPP__