chardacters render

This commit is contained in:
Emanuele Trabattoni
2021-08-15 18:54:16 +02:00
parent 487054ff76
commit c34e6931eb
8 changed files with 63 additions and 50 deletions

View File

@@ -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;
}
}
}