COSA
An Object-Oriented Platform for Arduino Programming
|
#include <Canvas.hh>
Classes | |
struct | circle16_t |
union | color16_t |
class | Context |
class | Element |
class | Image |
struct | pos16_t |
struct | rect16_t |
Public Types | |
enum | { BLACK = 0x0000U, WHITE = 0xFFFFU, RED = 0xF800U, GREEN = 0x07E0U, BLUE = 0x001FU, YELLOW = RED + GREEN, CYAN = GREEN + BLUE, MAGENTA = RED + BLUE } |
enum | { PORTRAIT = 0, LANDSCAPE = 1 } |
enum | { END_SCRIPT = 0, CALL_SCRIPT, SET_CANVAS_COLOR, SET_PEN_COLOR, SET_TEXT_COLOR, SET_TEXT_SCALE, SET_TEXT_FONT, SET_CURSOR, MOVE_CURSOR, DRAW_BITMAP, DRAW_ICON, DRAW_PIXEL, DRAW_LINE, DRAW_POLY, DRAW_STROKE, DRAW_RECT, FILL_RECT, DRAW_ROUNDRECT, FILL_ROUNDRECT, DRAW_CIRCLE, FILL_CIRCLE, DRAW_CHAR, DRAW_STRING, FILL_SCREEN } |
Public Member Functions | |
Canvas (uint16_t width, uint16_t height, Context *context=&Canvas::context) | |
virtual bool | begin ()=0 |
Context * | get_context () const |
Context * | set_context (Context *context) |
color16_t | get_canvas_color () const |
color16_t | set_canvas_color (color16_t color) |
color16_t | get_pen_color () const |
color16_t | set_pen_color (color16_t color) |
color16_t | get_text_color () const |
color16_t | set_text_color (color16_t color) |
Font * | get_text_font () const |
Font * | set_text_font (Font *font) |
uint8_t | get_text_scale () const |
uint8_t | set_text_scale (uint8_t scale) |
void | get_cursor (uint16_t &x, uint16_t &y) const |
void | set_cursor (uint16_t x, uint16_t y) |
void | move_cursor (int16_t dx, int16_t dy) |
color16_t | color (uint8_t red, uint8_t green, uint8_t blue) |
virtual uint8_t | get_orientation () |
virtual uint8_t | set_orientation (uint8_t direction) |
virtual void | draw_pixel (uint16_t x, uint16_t y) |
void | draw_pixel () |
virtual void | draw_bitmap (uint16_t x, uint16_t y, const uint8_t *bp, uint16_t width, uint16_t height, uint8_t scale=1) |
void | draw_bitmap (const uint8_t *bp, uint16_t width, uint16_t height, uint8_t scale=1) |
virtual void | draw_icon (uint16_t x, uint16_t y, const uint8_t *bp, uint16_t width, uint16_t height, uint8_t scale=1) |
virtual void | draw_icon (uint16_t x, uint16_t y, const uint8_t *bp, uint8_t scale=1) |
void | draw_icon (const uint8_t *bp, uint8_t scale=1) |
virtual void | draw_image (uint16_t x, uint16_t y, Image *image) |
void | draw_image (Image *image) |
virtual void | draw_line (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) |
void | draw_line (uint16_t x1, uint16_t y1) |
virtual void | draw_vertical_line (uint16_t x, uint16_t y, uint16_t length) |
void | draw_vertical_line (uint16_t length) |
virtual void | draw_horizontal_line (uint16_t x, uint16_t y, uint16_t length) |
void | draw_horizontal_line (uint16_t length) |
virtual void | draw_poly_P (const int8_t *poly, uint8_t scale=1) |
virtual void | draw_stroke_P (const int8_t *stroke, uint8_t scale=1) |
virtual void | draw_rect (uint16_t x, uint16_t y, uint16_t width, uint16_t height) |
void | draw_rect (uint16_t width, uint16_t height) |
virtual void | fill_rect (uint16_t x, uint16_t y, uint16_t width, uint16_t height) |
void | fill_rect (uint16_t width, uint16_t height) |
virtual void | draw_roundrect (uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t radius) |
void | draw_roundrect (uint16_t width, uint16_t height, uint16_t radius) |
virtual void | fill_roundrect (uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t radius) |
void | fill_roundrect (uint16_t width, uint16_t height, uint16_t radius) |
virtual void | draw_circle (uint16_t x, uint16_t y, uint16_t radius) |
void | draw_circle (uint16_t radius) |
virtual void | fill_circle (uint16_t x, uint16_t y, uint16_t radius) |
void | fill_circle (uint16_t radius) |
virtual void | draw_char (uint16_t x, uint16_t y, char c) |
void | draw_char (char c) |
virtual void | draw_string (char *s) |
virtual void | draw_string (str_P s) |
virtual void | fill_screen () |
virtual bool | end ()=0 |
void | run (uint8_t ix, const void_P *tab, uint8_t max) |
Static Public Member Functions | |
static color16_t | shade (color16_t color, uint8_t scale) |
static color16_t | blend (color16_t c1, color16_t c2) |
Public Attributes | |
uint16_t | WIDTH |
uint16_t | HEIGHT |
Protected Attributes | |
Context * | m_context |
uint8_t | m_direction |
Static Protected Attributes | |
static Context | context |
Virtual Canvas device; abstraction of small screens, LCD/TFT. Device drivers need to override at least begin(), fill_rect() and end(). See ST7735R and ILI9341 for examples of usage.
Color model is 16-bit RGB<5,6,5>. Canvas size is max 64K square.
Inspired by GFX graphics library by ladyada/adafruit, the glcd library by Michael Margolis and Bill Perry, and scd library by Sungjune Lee.
anonymous enum |
anonymous enum |
Canvas script instructions. See macro set below for arguments.
|
inline |
|
pure virtual |
Start interaction with device. Must override.
Implemented in OffScreen< width, height >, and GDDRAM.
|
static |
Blend the two colors.
[in] | c1. | |
[in] | c2. |
Definition at line 39 of file Canvas.cpp.
|
inline |
|
virtual |
Draw bitmap with current pen color. The bitmap must be stored in program memory.
[in] | x. | |
[in] | y. | |
[in] | bp. | |
[in] | width. | |
[in] | height. | |
[in] | scale. |
Definition at line 69 of file Canvas.cpp.
|
inline |
|
virtual |
Draw character with current text color, font and scale.
[in] | x | position. |
[in] | y | position. |
[in] | c | character. |
Definition at line 378 of file Canvas.cpp.
|
inline |
|
virtual |
Draw circle with current pen color.
[in] | x. | |
[in] | y. | |
[in] | radius. |
Definition at line 247 of file Canvas.cpp.
|
inline |
|
virtual |
Draw horizontal line with current pen color.
[in] | x. | |
[in] | y. | |
[in] | length. |
Reimplemented in GDDRAM.
Definition at line 204 of file Canvas.cpp.
|
inline |
|
virtual |
Draw icon at given position with current pen color. The icon must be stored in program memory.
[in] | x. | |
[in] | y. | |
[in] | bp. | |
[in] | width. | |
[in] | height. | |
[in] | scale. |
Definition at line 105 of file Canvas.cpp.
|
virtual |
Draw icon at given position with current pen color. The icon must be stored in program memory.
[in] | x. | |
[in] | y. | |
[in] | bp. | |
[in] | scale. |
Definition at line 113 of file Canvas.cpp.
|
inline |
|
virtual |
Draw image on canvas at given position.
[in] | x. | |
[in] | y. | |
[in] | image. |
Reimplemented in GDDRAM.
Definition at line 121 of file Canvas.cpp.
|
inline |
|
virtual |
Draw line with current pen color.
[in] | x0. | |
[in] | y0. | |
[in] | x1. | |
[in] | y1. |
Definition at line 167 of file Canvas.cpp.
|
inline |
|
virtual |
Set pixel with current pen color.
[in] | x. | |
[in] | y. |
Reimplemented in OffScreen< width, height >, and GDDRAM.
Definition at line 63 of file Canvas.cpp.
|
inline |
|
virtual |
Draw polygon from program memory with current pen color. Vector of delta positions, terminate with 0, 0. Update cursor to end position.
[in] | poly. | |
[in] | scale. |
Definition at line 210 of file Canvas.cpp.
|
virtual |
Draw rectangle with current pen color.
[in] | x. | |
[in] | y. | |
[in] | width. | |
[in] | height. |
Definition at line 142 of file Canvas.cpp.
|
inline |
|
virtual |
Draw round corner rectangle with current pen color.
[in] | x. | |
[in] | y. | |
[in] | width. | |
[in] | height. | |
[in] | radius. |
Definition at line 301 of file Canvas.cpp.
|
inline |
|
virtual |
Draw string in current text color, font and scale.
[in] | s | string. |
Definition at line 389 of file Canvas.cpp.
|
virtual |
Draw string from program memory with current text color and font.
[in] | s | string in program memory (PSTR). |
Definition at line 397 of file Canvas.cpp.
|
virtual |
Draw stroke from program memory with current pen color. Vector of delta positions, terminated with 0, 0. The cursor is moved for when both dx and dy are zero or negative. Update cursor to new position.
[in] | stroke. | |
[in] | scale. |
Definition at line 226 of file Canvas.cpp.
|
virtual |
Draw vertical line with current pen color.
[in] | x. | |
[in] | y. | |
[in] | length. |
Reimplemented in GDDRAM.
Definition at line 198 of file Canvas.cpp.
|
inline |
|
pure virtual |
Stop sequence of interaction with device. Must override.
Implemented in GDDRAM, and OffScreen< width, height >.
|
virtual |
Fill circle with current pen color.
[in] | x. | |
[in] | y. | |
[in] | radius. |
Definition at line 280 of file Canvas.cpp.
|
inline |
|
virtual |
Fill rectangle with current pen color. Must override.
[in] | x. | |
[in] | y. | |
[in] | width. | |
[in] | height. |
Reimplemented in GDDRAM.
Definition at line 151 of file Canvas.cpp.
|
inline |
|
virtual |
Fill round corner rectangle with current pen color.
[in] | x. | |
[in] | y. | |
[in] | width. | |
[in] | height. | |
[in] | radius. |
Definition at line 346 of file Canvas.cpp.
|
inline |
|
virtual |
Fill screen with canvas color.
Reimplemented in OffScreen< width, height >.
Definition at line 406 of file Canvas.cpp.
|
inline |
|
inline |
|
inline |
|
virtual |
Get screen orientation.
Definition at line 49 of file Canvas.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void Canvas::run | ( | uint8_t | ix, |
const void_P * | tab, | ||
uint8_t | max | ||
) |
Run canvas drawing script. Table may contain sub-scripts, strings and icons. All should be in program memory. Use the support macro set to write scripts.
[in] | ix | script to run. |
[in] | tab | script table in program memory. |
[in] | max | size of script table. |
Definition at line 414 of file Canvas.cpp.
|
inline |
|
virtual |
Set screen orientation. Return previous orientation.
[in] | direction | (Canvas::LANDSCAPE/PORTRAIT). |
Reimplemented in ILI9163, ST7735, and GDDRAM.
Definition at line 55 of file Canvas.cpp.
|
inline |
|
static |
Create color shade (0..100%).
[in] | color. | |
[in] | scale. |
Definition at line 28 of file Canvas.cpp.
|
staticprotected |
|
protected |
|
protected |
uint16_t Canvas::WIDTH |