//-----------------------------------------------------------------// void monograph::draw_string_center_P(const char* text) { int16_t xx = 0; int16_t yy = font_height_; char ch; int16_t l = 0; const char* p = text; while((ch = pgm_read_byte_near(p)) != 0) { p++; if(ch == '\n') { if(xx < l) xx = l; l = 0; yy += font_height_; } else { l += font_width_; } } if(xx < l) xx = l; --p; ch = pgm_read_byte_near(p); if(ch == '\n') yy -= font_height_; draw_string_P(64 - xx / 2, 32 - yy / 2, text); }
void Canvas::run(uint8_t ix, const void_P* tab, uint8_t max) { if (ix >= max) return; const uint8_t* ip = (const uint8_t*) pgm_read_word(tab + ix); uint8_t x, y, r, g, b, w, h, s; int8_t dx, dy; char c; while (1) { switch (pgm_read_byte(ip++)) { case END_SCRIPT: return; case CALL_SCRIPT: ix = pgm_read_byte(ip++); if (ix >= max) return; run(ix, tab, max); break; case SET_CANVAS_COLOR: r = pgm_read_byte(ip++); g = pgm_read_byte(ip++); b = pgm_read_byte(ip++); set_canvas_color(color(r, b, g)); break; case SET_PEN_COLOR: r = pgm_read_byte(ip++); g = pgm_read_byte(ip++); b = pgm_read_byte(ip++); set_pen_color(color(r, g, b)); break; case SET_TEXT_COLOR: r = pgm_read_byte(ip++); g = pgm_read_byte(ip++); b = pgm_read_byte(ip++); set_text_color(color(r, g, b)); break; case SET_TEXT_SCALE: set_text_scale(pgm_read_byte(ip++)); break; case SET_TEXT_FONT: ix = pgm_read_byte(ip++); if (ix >= max) return; set_text_font((Font*) pgm_read_word(tab + ix)); break; case SET_CURSOR: x = pgm_read_byte(ip++); y = pgm_read_byte(ip++); set_cursor(x, y); break; case MOVE_CURSOR: dx = pgm_read_byte(ip++); dy = pgm_read_byte(ip++); move_cursor(dx, dy); break; case DRAW_BITMAP: ix = pgm_read_byte(ip++); if (ix >= max) return; w = pgm_read_byte(ip++); h = pgm_read_byte(ip++); s = pgm_read_byte(ip++); draw_bitmap((const uint8_t*) pgm_read_word(tab + ix), w, h, s); break; case DRAW_ICON: ix = pgm_read_byte(ip++); if (ix >= max) return; s = pgm_read_byte(ip++); draw_icon((const uint8_t*) pgm_read_word(tab + ix), s); break; case DRAW_PIXEL: draw_pixel(); break; case DRAW_LINE: x = pgm_read_byte(ip++); y = pgm_read_byte(ip++); draw_line(x, y); break; case DRAW_POLY: ix = pgm_read_byte(ip++); if (ix >= max) return; s = pgm_read_byte(ip++); draw_poly_P((const int8_t*) pgm_read_word(tab + ix), s); break; case DRAW_STROKE: ix = pgm_read_byte(ip++); if (ix >= max) return; s = pgm_read_byte(ip++); draw_stroke_P((const int8_t*) pgm_read_word(tab + ix), s); break; case DRAW_RECT: w = pgm_read_byte(ip++); h = pgm_read_byte(ip++); draw_rect(w, h); break; case FILL_RECT: w = pgm_read_byte(ip++); h = pgm_read_byte(ip++); fill_rect(w, h); break; case DRAW_ROUNDRECT: w = pgm_read_byte(ip++); h = pgm_read_byte(ip++); r = pgm_read_byte(ip++); draw_roundrect(w, h, r); break; case FILL_ROUNDRECT: w = pgm_read_byte(ip++); h = pgm_read_byte(ip++); r = pgm_read_byte(ip++); fill_roundrect(w, h, r); break; case DRAW_CIRCLE: r = pgm_read_byte(ip++); draw_circle(r); break; case FILL_CIRCLE: r = pgm_read_byte(ip++); fill_circle(r); break; case DRAW_CHAR: c = pgm_read_byte(ip++); draw_char(c); break; case DRAW_STRING: ix = pgm_read_byte(ip++); if (ix >= max) return; draw_string_P((const char*) pgm_read_word(tab + ix)); break; case FILL_SCREEN: fill_screen(); break; default: return; } } }