// The '(x != 0 && y != 0)' test in the last line of this function // may be omitted for a performance benefit if the radius of the // circle is known to be non-zero. static void plot4points(uint16_t cx, uint16_t cy, uint16_t x, uint16_t y, uint32_t color) { fgui_set_pixel(cx + x, cy + y, color); if (x != 0) fgui_set_pixel(cx - x, cy + y, color); if (y != 0) fgui_set_pixel(cx + x, cy - y, color); if (x != 0 && y != 0) fgui_set_pixel(cx - x, cy - y, color); }
/** * Bresenham's line algorithm: * http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm */ void fgui_draw_line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t color) { int16_t dx, dy, sx, sy, err, e2; dx = abs(x1 - x0); dy = abs(y1 - y0); sx = x0 < x1 ? 1 : -1; sy = y0 < y1 ? 1 : -1; err = dx - dy; while (1) { fgui_set_pixel(x0, y0, color); if (x0 == x1 && y0 == y1) { break; } e2 = 2 * err; if (e2 > -dy) { err = err - dy; x0 = x0 + sx; } if (e2 < dx) { err = err + dx; y0 = y0 + sy; } } }
void fgui_fill_rectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color) { uint16_t xpos, ypos; for (ypos = y; ypos < y + h; ypos++) { for (xpos = x; xpos < x + w; xpos++) { fgui_set_pixel(xpos, ypos, color); } } }
void fgui_combobox_draw(struct fgui_widget *widget) { size_t i; struct fgui_combobox *combobox = (struct fgui_combobox *)widget; int n = 1; int h = combobox->base.area.h*n; int x1 = combobox->base.area.x+2; int y1 = combobox->base.area.y; int x2 = x1+combobox->base.area.w-5; int y2 = y1+h-1; if (!combobox->base.has_focus && !fgui_combobox_type) { // Cheap hack combobox->is_expanded = false; } else if (combobox->is_expanded) { n = combobox->num_items; h = combobox->base.area.h*n; y2 = y1+h-1; } /* combobox background */ fgui_fill_rectangle(combobox->base.area.x, combobox->base.area.y, combobox->base.area.w, h, FGUI_COMBOBOX_BG_COLOR); if (fgui_combobox_type == 0){ // Cheap hack to multipurpose combobox /* border */ fgui_draw_line(x1, y1, x2, y1, FGUI_COMBOBOX_BORDER_COLOR); fgui_draw_line(x1, y2, x2, y2, FGUI_COMBOBOX_BORDER_COLOR); fgui_draw_line(x1-2, y1+2, x1-2, y2-2, FGUI_COMBOBOX_BORDER_COLOR); fgui_draw_line(x2+2, y1+2, x2+2, y2-2, FGUI_COMBOBOX_BORDER_COLOR); /* border shading */ fgui_draw_line(x1, 1+y1, x2, 1+y1, FGUI_COMBOBOX_TOP_COLOR); fgui_draw_line(x1, 2+y1, x2, 2+y1, FGUI_COMBOBOX_TOQ_COLOR); fgui_draw_line(x1, 3+y1, x2, 3+y1, FGUI_COMBOBOX_TOR_COLOR); fgui_draw_line(x1, y2-1, x2, y2-1, FGUI_COMBOBOX_BOT_COLOR); fgui_draw_line(x1, y2-2, x2, y2-2, FGUI_COMBOBOX_BOQ_COLOR); fgui_draw_line(x1, y2-3, x2, y2-3, FGUI_COMBOBOX_BOR_COLOR); fgui_draw_line(x1-1, y1+2, x1-1, y2-2, FGUI_COMBOBOX_TOP_COLOR); fgui_draw_line(x2+1, y1+2, x2+1, y2-2, FGUI_COMBOBOX_BOT_COLOR); } if (combobox->is_expanded) { /* highlight current item */ fgui_fill_rectangle(x1-1, y1+1 + combobox->base.area.h * combobox->current_item, combobox->base.area.w-2, combobox->base.area.h-2, FGUI_COMBOBOX_HIGHLIGHT_COLOR); for (i = 0; i < combobox->num_items; i++) { /* current item text */ fgui_draw_string(combobox->items[i].text, x1, combobox->base.area.y+2 + combobox->base.area.h * i, FGUI_COMBOBOX_TEXT_COLOR, NULL); } } else { /* if focus, draw red border */ if (combobox->base.has_focus) { fgui_draw_rectangle(combobox->base.area.x, combobox->base.area.y, combobox->base.area.w, combobox->base.area.h, FGUI_COMBOBOX_FOCUS_COLOR); } /* current item text */ fgui_draw_string(combobox->items[combobox->current_item].text, x1, combobox->base.area.y+2, FGUI_COMBOBOX_TEXT_COLOR, NULL); /* draw arrow to indicate that this is a combobox */ fgui_draw_triangle(combobox->base.area.x + combobox->base.area.w - 15, combobox->base.area.y + combobox->base.area.h / 2 - 2, combobox->base.area.x + combobox->base.area.w - 5, combobox->base.area.y + combobox->base.area.h / 2 - 2, combobox->base.area.x + combobox->base.area.w - 10, combobox->base.area.y + combobox->base.area.h / 2 + 3, FGUI_COMBOBOX_BORDER_COLOR); } if (fgui_combobox_type == 0){ // Cheap hack to multipurpose combobox /* draw rounded border corners */ fgui_set_pixel(x1-1,y1+1, FGUI_COMBOBOX_BORDER_COLOR); fgui_set_pixel(x2+1,y1+1, FGUI_COMBOBOX_BORDER_COLOR); fgui_set_pixel(x1-1,y2-1, FGUI_COMBOBOX_BORDER_COLOR); fgui_set_pixel(x2+1,y2-1, FGUI_COMBOBOX_BORDER_COLOR); } }
void fgui_draw_point(uint16_t x, uint16_t y, uint32_t color, struct fgui_rect *clip) { if (clip == NULL || is_in_rect(x, y, clip)) { fgui_set_pixel(x, y, color); } }