2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
#ifndef __TEXT_HPP
|
|
|
|
#define __TEXT_HPP
|
|
|
|
|
2012-05-06 14:03:43 +02:00
|
|
|
#include <vector>
|
2012-01-21 21:57:41 +01:00
|
|
|
#include <string>
|
|
|
|
|
2013-02-07 13:25:39 +01:00
|
|
|
#include "fmt.h"
|
2012-01-21 21:57:41 +01:00
|
|
|
#include "FreeTypeGX.h"
|
|
|
|
#include "video.hpp"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "wstringEx/wstringEx.hpp"
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2021-09-06 21:16:45 +02:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
2012-05-06 14:03:43 +02:00
|
|
|
|
2016-07-22 01:40:12 +02:00
|
|
|
class SFont// should be either struct SFont or class CFont
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-11-03 20:16:03 +01:00
|
|
|
public:
|
2013-09-02 00:31:46 +02:00
|
|
|
SFont(void) : font(NULL), fSize(0), lineSpacing(0), weight(0), index(0), data(NULL), dataSize(0) { memset(name, 0, 128); };
|
2012-11-03 20:16:03 +01:00
|
|
|
~SFont(void) { };
|
|
|
|
void ClearData(void);
|
2013-09-02 00:31:46 +02:00
|
|
|
bool fromBuffer(const u8 *buffer, const u32 bufferSize, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0, const char *fontname = "");
|
|
|
|
bool fromFile(const char *path, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0, const char *fontname = "");
|
2012-11-03 20:16:03 +01:00
|
|
|
FreeTypeGX *font;
|
2013-09-02 00:31:46 +02:00
|
|
|
u32 fSize;
|
2012-01-21 21:57:41 +01:00
|
|
|
u32 lineSpacing;
|
|
|
|
u32 weight;
|
|
|
|
u32 index;
|
2013-09-02 00:31:46 +02:00
|
|
|
char name[128];
|
2012-11-03 20:16:03 +01:00
|
|
|
private:
|
|
|
|
u8 *data;
|
2018-05-08 15:49:43 +02:00
|
|
|
u32 dataSize;
|
2012-01-21 21:57:41 +01:00
|
|
|
};
|
|
|
|
|
2013-01-21 00:30:28 +01:00
|
|
|
struct SWord
|
|
|
|
{
|
|
|
|
wstringEx text;
|
|
|
|
Vector3D pos;
|
|
|
|
Vector3D targetPos;
|
|
|
|
};
|
|
|
|
typedef vector<SWord> CLine;
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
class CText
|
|
|
|
{
|
|
|
|
public:
|
2012-11-03 20:16:03 +01:00
|
|
|
void setText(const SFont &font, const wstringEx &t);
|
|
|
|
void setText(const SFont &font, const wstringEx &t, u32 startline);
|
2012-01-21 21:57:41 +01:00
|
|
|
void setColor(const CColor &c);
|
|
|
|
void setFrame(float width, u16 style, bool ignoreNewlines = false, bool instant = false);
|
|
|
|
void tick(void);
|
|
|
|
void draw(void);
|
|
|
|
int getTotalHeight();
|
|
|
|
private:
|
2012-05-06 14:03:43 +02:00
|
|
|
vector<CLine> m_lines;
|
2012-01-21 21:57:41 +01:00
|
|
|
SFont m_font;
|
|
|
|
CColor m_color;
|
|
|
|
u32 firstLine;
|
|
|
|
u32 totalHeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Nothing to do with CText. Q&D helpers for string formating.
|
2012-05-04 14:30:43 +02:00
|
|
|
|
2021-09-06 21:16:45 +02:00
|
|
|
string sfmt(const char *format, ...);
|
2012-01-21 21:57:41 +01:00
|
|
|
wstringEx wfmt(const wstringEx &format, ...);
|
|
|
|
bool checkFmt(const wstringEx &ref, const wstringEx &format);
|
2021-09-06 21:16:45 +02:00
|
|
|
string vectorToString(const vector<string> &vect, string sep);
|
2012-05-06 14:03:43 +02:00
|
|
|
wstringEx vectorToString(const vector<wstringEx> &vect, char sep);
|
|
|
|
vector<wstringEx> stringToVector(const wstringEx &text, char sep);
|
2021-09-06 21:16:45 +02:00
|
|
|
vector<std::string> stringToVector(const string &text, char sep);
|
|
|
|
string upperCase(string text);
|
|
|
|
string lowerCase(string text);
|
2022-09-07 16:33:31 +02:00
|
|
|
//string ltrim(string s);
|
|
|
|
//string rtrim(string s);
|
2013-04-10 01:24:42 +02:00
|
|
|
bool wchar_cmp(const wchar_t *first, const wchar_t *second, u32 first_len, u32 second_len);
|
2013-08-03 08:21:54 +02:00
|
|
|
bool char_cmp(const char *first, const char *second, u32 first_len, u32 second_len);
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
#endif // !defined(__TEXT_HPP)
|