Louis Mayencourt
/
NRFBOY
MBED NRF51 Arduboy port
Diff: abstractarduboy.cpp
- Revision:
- 7:fb7e549d1cf6
- Parent:
- 4:63cfe7ff1c02
--- a/abstractarduboy.cpp Sat Jan 07 22:03:21 2017 +0100 +++ b/abstractarduboy.cpp Sat Jan 07 23:35:36 2017 +0100 @@ -429,6 +429,7 @@ if (x + w < 0 || x > WIDTH - 1 || y + h < 0 || y > HEIGHT - 1) return; + int yOffset = abs(y) % 8; int sRow = y / 8; if (y < 0) { @@ -456,6 +457,17 @@ } } } + +/* + for (int16_t j=0; j<h; j++) + { + for (int16_t i=0; i<w; i++ ) + { + if (bitmap[i + (j/8)*w] & _BV(j%8)) + drawPixel(x+i, y+j, color); + } + } + */ } @@ -477,7 +489,7 @@ if (cs.bit == 0x100) { cs.bit = 0x1; - cs.byte = pgm_read_byte(&cs.src[cs.src_pos]); + cs.byte = cs.src[cs.src_pos]; cs.src_pos ++; } if (cs.byte & cs.bit) @@ -619,6 +631,45 @@ // draw a character void AbstractArduboy::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size) { + boolean draw_background = bg != color; + + if ((x >= WIDTH) || // Clip right + (y >= HEIGHT) || // Clip bottom + ((x + 5 * size - 1) < 0) || // Clip left + ((y + 8 * size - 1) < 0) // Clip top + ) + { + return; + } + + for (int8_t i=0; i<6; i++ ) + { + uint8_t line; + if (i == 5) + { + line = 0x0; + } + else + { + line = font[(c*5)+i]; + } + + for (int8_t j = 0; j<8; j++) + { + uint8_t draw_color = (line & 0x1) ? color : bg; + + if (draw_color || draw_background) { + for (uint8_t a = 0; a < size; a++ ) { + for (uint8_t b = 0; b < size; b++ ) { + drawPixel(x + (i * size) + a, y + (j * size) + b, draw_color); + } + } + } + line >>= 1; + } + } + + /* if( (x >= WIDTH) || // Clip right (y >= HEIGHT) || // Clip bottom @@ -663,6 +714,7 @@ line >>= 1; } } + */ } void AbstractArduboy::swap(int16_t &a, int16_t &b)