COSA
An Object-Oriented Platform for Arduino Programming
OffScreen.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_CANVAS_OFFSCREEN_HH
22 #define COSA_CANVAS_OFFSCREEN_HH
23 
24 #include "Cosa/Types.h"
25 
33 template<uint16_t width, uint16_t height>
34 class OffScreen : public Canvas {
35 public:
39  OffScreen() : Canvas(width, height) {}
40 
45  uint8_t* bitmap()
46  {
47  return (m_bitmap);
48  }
49 
55  virtual bool begin()
56  {
57  fill_screen();
58  return (true);
59  }
60 
67  virtual void draw_pixel(uint16_t x, uint16_t y)
68  {
69  if (UNLIKELY((x > WIDTH) || (y > HEIGHT))) return;
70  uint8_t* bp = &m_bitmap[((y >> 3) * WIDTH) + x];
71  uint8_t pos = (y & 0x07);
73  *bp |= (1 << pos);
74  else
75  *bp &= ~(1 << pos);
76  }
77 
82  virtual void fill_screen()
83  {
84  memset(m_bitmap, (get_canvas_color().rgb == Canvas::BLACK), COUNT);
85  }
86 
92  virtual bool end()
93  {
94  return (true);
95  }
96 
97 private:
98  static const uint16_t COUNT = (width * height) / CHARBITS;
99  uint8_t m_bitmap[COUNT];
100 };
101 
102 #endif
virtual bool end()
Definition: OffScreen.hh:92
virtual void fill_screen()
Definition: OffScreen.hh:82
virtual bool begin()
Definition: OffScreen.hh:55
uint8_t * bitmap()
Definition: OffScreen.hh:45
color16_t get_canvas_color() const
Definition: Canvas.hh:422
color16_t get_pen_color() const
Definition: Canvas.hh:441
virtual void draw_pixel(uint16_t x, uint16_t y)
Definition: OffScreen.hh:67
uint16_t rgb
Definition: Canvas.hh:50
#define CHARBITS
Definition: Types.h:57
uint16_t HEIGHT
Definition: Canvas.hh:370
#define UNLIKELY(x)
Definition: Types.h:153
Definition: Canvas.hh:44
uint16_t WIDTH
Definition: Canvas.hh:369