chardacters render
This commit is contained in:
@@ -1375,7 +1375,7 @@ const uint8_t Font12_Table[] =
|
||||
0x00, //
|
||||
};
|
||||
|
||||
sFONT Font12 = {
|
||||
sFONT Font12_t = {
|
||||
Font12_Table,
|
||||
7, /* Width */
|
||||
12, /* Height */
|
||||
|
||||
@@ -1755,7 +1755,7 @@ const uint8_t Font16_Table[] =
|
||||
0x00, 0x00, //
|
||||
};
|
||||
|
||||
sFONT Font16 = {
|
||||
sFONT Font16_t = {
|
||||
Font16_Table,
|
||||
11, /* Width */
|
||||
16, /* Height */
|
||||
|
||||
@@ -2133,7 +2133,7 @@ const uint8_t Font20_Table[] =
|
||||
};
|
||||
|
||||
|
||||
sFONT Font20 = {
|
||||
sFONT Font20_t = {
|
||||
Font20_Table,
|
||||
14, /* Width */
|
||||
20, /* Height */
|
||||
|
||||
@@ -2511,7 +2511,7 @@ const uint8_t Font24_Table [] =
|
||||
0x00, 0x00, 0x00, //
|
||||
};
|
||||
|
||||
sFONT Font24 = {
|
||||
sFONT Font24_t = {
|
||||
Font24_Table,
|
||||
17, /* Width */
|
||||
24, /* Height */
|
||||
|
||||
@@ -995,7 +995,7 @@ const uint8_t Font8_Table[] =
|
||||
0x00, //
|
||||
};
|
||||
|
||||
sFONT Font8 = {
|
||||
const sFONT Font8_t = {
|
||||
Font8_Table,
|
||||
5, /* Width */
|
||||
8, /* Height */
|
||||
|
||||
@@ -55,38 +55,11 @@
|
||||
typedef struct _tFont
|
||||
{
|
||||
const uint8_t *table;
|
||||
uint16_t Width;
|
||||
uint16_t Height;
|
||||
const uint16_t Width;
|
||||
const uint16_t Height;
|
||||
|
||||
} sFONT;
|
||||
|
||||
|
||||
//GB2312
|
||||
// typedef struct // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>ݽṹ
|
||||
// {
|
||||
// const char index[2]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// const char matrix[MAX_HEIGHT_FONT*MAX_WIDTH_FONT/8+2]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// }CH_CN;
|
||||
|
||||
|
||||
// typedef struct
|
||||
// {
|
||||
// const CH_CN *table;
|
||||
// uint16_t size;
|
||||
// uint16_t ASCII_Width;
|
||||
// uint16_t Width;
|
||||
// uint16_t Height;
|
||||
|
||||
// }cFONT;
|
||||
|
||||
// extern sFONT Font24;
|
||||
// extern sFONT Font20;
|
||||
// extern sFONT Font16;
|
||||
// extern sFONT Font12;
|
||||
// extern sFONT Font8;
|
||||
|
||||
// extern cFONT Font12CN;
|
||||
// extern cFONT Font24CN;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -270,7 +270,7 @@ namespace Render{
|
||||
void setRadius(uint16_t radius) { _radius = radius; };
|
||||
const uint16_t getRadius() { return _radius; };
|
||||
void setOutline(bool outline) { _outline = outline; };
|
||||
const getOutline() { return _outline; };
|
||||
const bool getOutline() { return _outline; };
|
||||
|
||||
private:
|
||||
void render();
|
||||
@@ -296,7 +296,7 @@ namespace Render{
|
||||
// members
|
||||
private:
|
||||
Font _fontEnum;
|
||||
_tFont _font;
|
||||
const _tFont* _font;
|
||||
char _char;
|
||||
};
|
||||
|
||||
@@ -307,12 +307,13 @@ namespace Render{
|
||||
|
||||
public:
|
||||
void setString(std::string& s) { _s = s; };
|
||||
const std::string& getString() { return &s; };
|
||||
const std::string& getString() { return _s; };
|
||||
void setFont(Font f) { _fontEnum = f; };
|
||||
const Font getFont() { return _fontEnum; };
|
||||
void setRotation(TextRotation rotation) { _rotation = rotation; };
|
||||
const TextRotation getRotation() { return _rotation; };
|
||||
|
||||
void setSpacing(uint8_t hSpace, uint8_t vSpace) {_vSpace= vSpace; _hSpace=hSpace;}
|
||||
const pos_t getSpacing() { return {_hSpace,_vSpace}; };
|
||||
private:
|
||||
void render();
|
||||
|
||||
@@ -322,6 +323,7 @@ namespace Render{
|
||||
TextRotation _rotation;
|
||||
std::string _s;
|
||||
std::vector<DrawableChar*> _chars;
|
||||
uint8_t _hSpace=2, _vSpace=2;
|
||||
};
|
||||
|
||||
class DrawableCustom: public Drawable {
|
||||
|
||||
@@ -231,11 +231,11 @@ namespace Render {
|
||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||
//Character
|
||||
|
||||
extern const _tFont* Font8;
|
||||
extern const _tFont* Font12;
|
||||
extern const _tFont* Font16;
|
||||
extern const _tFont* Font20;
|
||||
extern const _tFont* Font24;
|
||||
extern const _tFont* Font8_t;
|
||||
extern const _tFont* Font12_t;
|
||||
extern const _tFont* Font16_t;
|
||||
extern const _tFont* Font20_t;
|
||||
extern const _tFont* Font24_t;
|
||||
|
||||
|
||||
DrawableChar::DrawableChar(const size_t id, Drawable* parent, Mare* engine, char c, Font f) :
|
||||
@@ -246,23 +246,23 @@ namespace Render {
|
||||
switch (_fontEnum)
|
||||
{
|
||||
case Font::Font8:
|
||||
_font = *Font8;
|
||||
_font = Font8_t;
|
||||
break;
|
||||
|
||||
case Font::Font12:
|
||||
_font = *Font12;
|
||||
_font = Font12_t;
|
||||
break;
|
||||
|
||||
case Font::Font16:
|
||||
_font = *Font16;
|
||||
_font = Font16_t;
|
||||
break;
|
||||
|
||||
case Font::Font20:
|
||||
_font = *Font20;
|
||||
_font = Font20_t;
|
||||
break;
|
||||
|
||||
case Font::Font24:
|
||||
_font = *Font24;
|
||||
_font = Font24_t;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -275,7 +275,22 @@ namespace Render {
|
||||
}
|
||||
|
||||
void DrawableChar::render() {
|
||||
|
||||
uint8_t* buf = getBuffer();
|
||||
const pos_t o = getOrigin();
|
||||
const BlendMode bm = getBlendMode();
|
||||
const uint8_t w = _font->Width;
|
||||
const uint8_t h = _font->Height;
|
||||
const uint16_t w_ch = w%7 ? (w/7)+1 : w/7;
|
||||
const uint8_t* ch = _font->table + (_char - ' ') * w_ch * h;
|
||||
for(uint8_t y(0); y < h; y++) {
|
||||
for(uint8_t x(0); x < w; x++) {
|
||||
const uint8_t* ch_v = ch + x / 7 + y * w_ch;
|
||||
if (ch_v == 0) continue;
|
||||
if ((*ch_v >> x) & 0x01){
|
||||
engine()->setPixel(buf,o.x+x, o.y+y, bm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------+--------+--------+--------+--------+--------+--------+--------+--------+--------//
|
||||
@@ -289,7 +304,7 @@ namespace Render {
|
||||
_chars.reserve(s.size());
|
||||
uint16_t idx(0);
|
||||
for(auto c : _s){
|
||||
_chars.push_back(engine->addDrawable<DrawableChar>(c.c_str(),_fontEnum));
|
||||
_chars.push_back(engine->addDrawable<DrawableChar>(reinterpret_cast<char>(c),_fontEnum));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -304,9 +319,32 @@ namespace Render {
|
||||
}
|
||||
|
||||
void DrawableString::render() {
|
||||
pos_t ofs;
|
||||
int32_t ofsX=0, ofsY=0;
|
||||
switch(_rotation) {
|
||||
case TextRotation::Rot0: {
|
||||
ofsX = _chars.front()->_font->Width + _hSpace;
|
||||
break;
|
||||
}
|
||||
case TextRotation::Rot180:{
|
||||
ofsY = -_chars.front()->_font->Width - _hSpace;
|
||||
break;
|
||||
}
|
||||
case TextRotation::Rot90: {
|
||||
ofsY = _chars.front()->_font->Height + _vSpace;
|
||||
break;
|
||||
}
|
||||
case TextRotation::Rot270: {
|
||||
ofsY = _chars.front()->_font->Height + _vSpace;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (auto c : _chars){
|
||||
if (c != nullptr){
|
||||
c->setOrigin(ofs);
|
||||
c->render();
|
||||
ofs.x += ofsX;
|
||||
ofs.y += ofsY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user