Skip to content

Commit

Permalink
Added character bounds clipping to drawChar()
Browse files Browse the repository at this point in the history
  • Loading branch information
PaintYourDragon committed Jan 5, 2012
1 parent 0c792aa commit 9dd9cd8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions RGBmatrixPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ size_t RGBmatrixPanel::write(uint8_t c) {
void RGBmatrixPanel::write(uint8_t c) {
#endif
if (c == '\n') {
cursor_y += textsize*8;
cursor_x = 0;
cursor_y += textsize * 8;
cursor_x = 0;
} else if (c == '\r') {
// skip em
} else {
Expand All @@ -474,9 +474,16 @@ void RGBmatrixPanel::write(uint8_t c) {
// draw a character
void RGBmatrixPanel::drawChar(
int x, int y, char c, uint16_t color, uint8_t size) {
for (uint8_t i =0; i<5; i++ ) {

if((x >= WIDTH) || // Clip right
(y >= (nRows * 2)) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;

for (uint8_t i=0; i<5; i++ ) {
uint8_t line = pgm_read_byte(font+(c*5)+i);
for (uint8_t j = 0; j<8; j++) {
for (uint8_t j=0; j<8; j++) {
if (line & 0x1) {
if (size == 1) // default size
drawPixel(x+i, y+j, color);
Expand Down

0 comments on commit 9dd9cd8

Please sign in to comment.