Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed an infinite loop when text off screen and fixed word wrap bug #65

Merged
merged 2 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libraries/picosystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ namespace picosystem {
uint32_t i,
int32_t x, int32_t y, int32_t cx, int32_t cy,
int32_t dw, int32_t dh, uint32_t flags);
void text(const char &c, int32_t x, int32_t y);
void text(const char &c);
void text(
const std::string &t,
Expand Down
20 changes: 8 additions & 12 deletions libraries/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace picosystem {
void text(const char &c) {
const uint8_t *p = &_font[(c - 32) * 9];

// get character width
uint8_t w = *p++;

// centre glyph if in fixed with mode
Expand All @@ -19,18 +20,13 @@ namespace picosystem {
xo = (_tlw - w) >> 1;
}

// draw character
for(int32_t y = _ty; y < _ty + 8; y++) {
color_t *dest = _dt->p(_tx + xo, y);
uint8_t pr = *p;
if(pr && y >= _cy && y < _cy + _ch) {
for(uint8_t x = _tx + xo; x < _tx + xo + w; x++) {
if(x >= _cx && x < _cx + _cw && pr & 0x80) {
_bf(&_pen, 0, 0, dest, 1);
}
pr <<= 1; dest++;
}
uint8_t pr = *p++;
for(int32_t x = _tx + xo; x < _tx + xo + w; x++) {
if(pr & 0x80) pixel(x, y);
pr <<= 1;
}
p++;
}

_tx += _char_width(c) + _tls;
Expand Down Expand Up @@ -179,7 +175,7 @@ namespace picosystem {
}break;

case '\t': {
_tx += _font[0] * 10; // four spaces
_tx += _font[0] * 10;
}break;

case '\\': {
Expand All @@ -191,7 +187,7 @@ namespace picosystem {
if(c > 32 && c != '\\') {
// check length to end of word
if(!in_word) {
uint32_t nwl = _next_word_length(t, i);
int32_t nwl = _next_word_length(t, i);
if(wrap != -1 && _tx + nwl > _wtx) {
_tx = _stx;
_ty += _tlh;
Expand Down