void LCDdrawchar(uint8_t x, uint8_t y, char c) { if (y >= LCDHEIGHT) return; if ((x+5) >= LCDWIDTH) return; uint8_t i,j; for ( i =0; i<5; i++ ) { uint8_t d = *(font+(c*5)+i); uint8_t j; for (j = 0; j<8; j++) { if (d & _BV(j)) { my_setpixel(x+i, y+j, textcolor); } else { my_setpixel(x+i, y+j, !textcolor); } } } for ( j = 0; j<8; j++) { my_setpixel(x+5, y+j, !textcolor); } updateBoundingBox(x, y, x+5, y + 8); }
void ST7565::fillcircle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color) { updateBoundingBox(x0-r, y0-r, x0+r, y0+r); int8_t f = 1 - r; int8_t ddF_x = 1; int8_t ddF_y = -2 * r; int8_t x = 0; int8_t y = r; for (uint8_t i=y0-r; i<=y0+r; i++) { my_setpixel(x0, i, color); } while (x<y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; for (uint8_t i=y0-y; i<=y0+y; i++) { my_setpixel(x0+x, i, color); my_setpixel(x0-x, i, color); } for (uint8_t i=y0-x; i<=y0+x; i++) { my_setpixel(x0+y, i, color); my_setpixel(x0-y, i, color); } } }
/* bresenham's algorithm - thx wikpedia */ void LCDdrawline(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color) { uint8_t steep = abs(y1 - y0) > abs(x1 - x0); if (steep) { swap(x0, y0); swap(x1, y1); } if (x0 > x1) { swap(x0, x1); swap(y0, y1); } /* much faster to put the test here, since we've already sorted the points */ updateBoundingBox(x0, y0, x1, y1); uint8_t dx, dy; dx = x1 - x0; dy = abs(y1 - y0); int8_t err = dx / 2; int8_t ystep; if (y0 < y1) { ystep = 1; } else { ystep = -1; } for (; x0<=x1; x0++) { if (steep) { my_setpixel(y0, x0, color); } else { my_setpixel(x0, y0, color); } err -= dy; if (err < 0) { y0 += ystep; err += dx; } } }
void ST7565::invertRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h) { // stupidest version - just pixels - but fast with internal buffer! for (uint8_t i=x; i<x+w; i++) { for (uint8_t j=y; j<y+h; j++) { if(getpixel(i,j)) my_setpixel(i, j, WHITE); else my_setpixel(i, j, BLACK); } } updateBoundingBox(x, y, x+w, y+h); }
// draw a rectangle void ST7565::drawrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) { // stupidest version - just pixels - but fast with internal buffer! for (uint8_t i=x; i<x+w; i++) { my_setpixel(i, y, color); my_setpixel(i, y+h-1, color); } for (uint8_t i=y; i<y+h; i++) { my_setpixel(x, i, color); my_setpixel(x+w-1, i, color); } updateBoundingBox(x, y, x+w, y+h); }
void PCD8544::drawchar(uint8_t x, uint8_t y, char c) { if (y >= LCDHEIGHT) return; if ((x+5) >= LCDWIDTH) return; for (uint8_t i =0; i<5; i++ ) { uint8_t d = pgm_read_byte(font+(c*5)+i); for (uint8_t j = 0; j<8; j++) { if (d & _BV(j)) { my_setpixel(x+i, y+j, textcolor); } else { my_setpixel(x+i, y+j, !textcolor); } } } for (uint8_t j = 0; j<8; j++) { my_setpixel(x+5, y+j, !textcolor); } updateBoundingBox(x, y, x+5, y + 8); }
// filled rectangle void ST7565::fillrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) { // stupidest version - just pixels - but fast with internal buffer! for (uint8_t i=x; i<x+w; i++) { for (uint8_t j=y; j<y+h; j++) { my_setpixel(i, j, color); } } updateBoundingBox(x, y, x+w, y+h); }
void ST7565::drawbitmap(uint8_t x, uint8_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color) { for (uint8_t j=0; j<h; j++) { for (uint8_t i=0; i<w; i++ ) { if (pgm_read_byte(bitmap + i + (j/8)*w) & _BV(j%8)) { my_setpixel(x+i, y+j, color); } } } updateBoundingBox(x, y, x+w, y+h); }
void LCDdrawbitmap(uint8_t x, uint8_t y,const uint8_t *bitmap, uint8_t w, uint8_t h,uint8_t color) { uint8_t j,i; for ( j=0; j<h; j++) { for ( i=0; i<w; i++ ) { if (*(bitmap + i + (j/8)*w) & _BV(j%8)) { my_setpixel(x+i, y+j, color); } } } updateBoundingBox(x, y, x+w, y+h); }
// draw a circle outline void ST7565::drawcircle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color) { updateBoundingBox(x0-r, y0-r, x0+r, y0+r); int8_t f = 1 - r; int8_t ddF_x = 1; int8_t ddF_y = -2 * r; int8_t x = 0; int8_t y = r; my_setpixel(x0, y0+r, color); my_setpixel(x0, y0-r, color); my_setpixel(x0+r, y0, color); my_setpixel(x0-r, y0, color); while (x<y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; my_setpixel(x0 + x, y0 + y, color); my_setpixel(x0 - x, y0 + y, color); my_setpixel(x0 + x, y0 - y, color); my_setpixel(x0 - x, y0 - y, color); my_setpixel(x0 + y, y0 + x, color); my_setpixel(x0 - y, y0 + x, color); my_setpixel(x0 + y, y0 - x, color); my_setpixel(x0 - y, y0 - x, color); } }