void glcd_draw_rect_thick(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tx, uint8_t ty, uint8_t color) { int16_t i, t; if (tx == 0) { tx = 1; } if (ty == 0) { ty = 1; } for (i=x; i<x+w; i++) { /* Top and bottom sides */ for (t=0; t<(ty); t++) { glcd_set_pixel(i, y+t, color); glcd_set_pixel(i, y+h-1-t, color); } } for (i=y; i<y+h; i++) { /* Left and right sides */ for (t=0; t<(tx); t++) { glcd_set_pixel(x+t, i, color); glcd_set_pixel(x+w-1-t, i, color); } } glcd_update_bbox(x, y, x+w-1, y+h-1); }
void glcd_draw_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) { int16_t i; for (i=x; i<x+w; i++) { glcd_set_pixel(i, y, color); glcd_set_pixel(i, y+h-1, color); } for (i=y; i<y+h; i++) { glcd_set_pixel(x, i, color); glcd_set_pixel(x+w-1, i, color); } glcd_update_bbox(x, y, x+w-1, y+h-1); }
void glcd_tiny_draw_char_xy(uint8_t x, uint8_t y, char c) { uint8_t i; uint8_t xvar, yvar; uint8_t dat; /* Only works for fonts < 8 bits in height */ /* Check all important bounds requirements are okay */ if ( (y >= GLCD_LCD_HEIGHT) || ((x+font_current.width) >= GLCD_LCD_WIDTH) || (font_current.height >= 8) || font_current.table_type != STANG) { return; } if (c < font_current.start_char || c > font_current.end_char) { c = '.'; } xvar = x; for ( i = 0; i < font_current.width; i++ ) { dat = *( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); for (yvar = 0; yvar < font_current.height; yvar++) { glcd_set_pixel(xvar,y+yvar, (dat & (1<<yvar) ? 1 : 0) ); } xvar++; } glcd_update_bbox(x, y, x+font_current.width,y+font_current.height); }
/* Bresenham's algorithm - based on PCD8544 library Limor Fried */ void glcd_draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color) { uint8_t steep = abs(y1 - y0) > abs(x1 - x0); uint8_t dx, dy; int8_t err; int8_t ystep; if (steep) { swap(x0, y0); swap(x1, y1); } if (x0 > x1) { swap(x0, x1); swap(y0, y1); } glcd_update_bbox( x0, y0, x1, y1 ); dx = x1 - x0; dy = abs(y1 - y0); err = dx / 2; if (y0 < y1) { ystep = 1; } else { ystep = -1; } for (; x0<=x1; x0++) { if (steep) { glcd_set_pixel(y0, x0, color); } else { glcd_set_pixel(x0, y0, color); } err -= dy; if (err < 0) { y0 += ystep; err += dx; } } }
void glcd_fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color) { int16_t i; for (i=x; i<x+w; i++) { int16_t j; for (j=y; j<y+h; j++) { glcd_set_pixel(i, j, color); } } glcd_update_bbox(x, y, x+w-1, y+h-1); }
void glcd_fill_circle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color) { int8_t f = 1 - r; int8_t ddF_x = 1; int8_t ddF_y = -2 * r; int8_t x = 0; int8_t y = r; int16_t i; glcd_update_bbox(x0-r, y0-r, x0+r, y0+r); for (i=y0-r; i<=y0+r; i++) { glcd_set_pixel(x0, i, color); } while (x < y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; for (i=y0-y; i<=y0+y; i++) { glcd_set_pixel(x0+x, i, color); glcd_set_pixel(x0-x, i, color); } for (i=y0-x; i<=y0+x; i++) { glcd_set_pixel(x0+y, i, color); glcd_set_pixel(x0-y, i, color); } } }
uint8_t glcd_draw_char_xy(uint8_t x, uint8_t y, char c) { if (c < font_current.start_char || c > font_current.end_char) { c = '.'; } if (font_current.table_type == STANG) { // font table in Pascal Stang format (single byte height with with no width specifier uint8_t i; for ( i = 0; i < font_current.width; i++ ) { #if defined(GLCD_DEVICE_AVR8) uint8_t dat = pgm_read_byte( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); #else uint8_t dat = *( font_current.font_table + ((c - font_current.start_char) * (font_current.width)) + i ); #endif uint8_t j; for (j = 0; j < 8; j++) { if (x+i >= GLCD_LCD_WIDTH || y+j >= GLCD_LCD_HEIGHT) { return 0; } if (dat & (1<<j)) { glcd_set_pixel(x+i,y+j,BLACK); } else { glcd_set_pixel(x+i,y+j,WHITE); } } } return font_current.width; } else if (font_current.table_type == MIKRO) { // font table in MikroElecktronica format uint8_t i; uint8_t var_width; uint8_t bytes_high = font_current.height / 8 + 1; uint8_t bytes_per_char = font_current.width * bytes_high + 1; const char *p; p = font_current.font_table + (c - font_current.start_char) * bytes_per_char; #if defined(GLCD_DEVICE_AVR8) var_width = pgm_read_byte(p); #else var_width = *p; #endif p++; // step over the variable width field /* if (x+var_width >= GLCD_LCD_WIDTH || y+font_current.height >= GLCD_LCD_HEIGHT) { return; } */ for ( i = 0; i < var_width; i++ ) { uint8_t j; for ( j = 0; j < bytes_high; j++ ) { #if defined(GLCD_DEVICE_AVR8) uint8_t dat = pgm_read_byte( p + i*bytes_high + j ); #else uint8_t dat = *( p + i*bytes_high + j ); #endif uint8_t bit; for (bit = 0; bit < 8; bit++) { if (x+i >= GLCD_LCD_WIDTH || y+j*8+bit >= GLCD_LCD_HEIGHT) { return 0; } if (dat & (1<<bit)) { glcd_set_pixel(x+i,y+j*8+bit,BLACK); } else { glcd_set_pixel(x+i,y+j*8+bit,WHITE); } } } } return var_width; } else { // don't recognise the font table return 0; } }
void glcd_draw_circle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color) { int8_t f = 1 - r; int8_t ddF_x = 1; int8_t ddF_y = -2 * r; int8_t x = 0; int8_t y = r; glcd_update_bbox(x0-r, y0-r, x0+r, y0+r); glcd_set_pixel(x0, y0+r, color); glcd_set_pixel(x0, y0-r, color); glcd_set_pixel(x0+r, y0, color); glcd_set_pixel(x0-r, y0, color); while (x<y) { if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; glcd_set_pixel(x0 + x, y0 + y, color); glcd_set_pixel(x0 - x, y0 + y, color); glcd_set_pixel(x0 + x, y0 - y, color); glcd_set_pixel(x0 - x, y0 - y, color); glcd_set_pixel(x0 + y, y0 + x, color); glcd_set_pixel(x0 - y, y0 + x, color); glcd_set_pixel(x0 + y, y0 - x, color); glcd_set_pixel(x0 - y, y0 - x, color); } }