Control Surface  1.1.0
MIDI Control Surface library for Arduino
DisplayInterface.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Def/Def.hpp>
5 #include <Print.h>
6 
8 
9 /**
10  * @brief An interface for displays.
11  *
12  * Inspired by the Adafruit GFX library for easy compatibility.
13  */
14 class DisplayInterface : public Print, public DoublyLinkable<DisplayInterface> {
15  protected:
16  /// @todo Do I need to keep a list now that I have sorted all
17  /// DisplayElement%s?
19 
20  public:
21  /// @todo Do I need to keep a list now that I have sorted all
22  /// DisplayElement%s?
23  // Note to self: don't forget to make destructor = default
24  // instead of deleting it altogether
25  virtual ~DisplayInterface() { elements.remove(this); }
26 
27  /// Initialize the display.
28  virtual void begin();
29 
30  /// Clear the frame buffer or display.
31  virtual void clear() = 0;
32  /// Draw a custom background.
33  virtual void drawBackground(){};
34  /// Write the frame buffer to the display.
35  virtual void display() = 0;
36 
37  /// Paint a single pixel with the given color.
38  virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
39 
40  /// Set the text color.
41  virtual void setTextColor(uint16_t color) = 0;
42  /// Set the text size.
43  virtual void setTextSize(uint8_t size) = 0;
44  /// Set the cursor position.
45  virtual void setCursor(int16_t x, int16_t y) = 0;
46 
47  /**
48  * @brief Write a character to the display.
49  *
50  * @see setCursor
51  * @see setTextSize
52  * @see setTextColor
53  */
54  size_t write(uint8_t c) override = 0;
55 
56  /// Draw a line between two points.
57  virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
58  uint16_t color) = 0;
59  /// Draw a vertical line.
60  virtual void drawFastVLine(int16_t x, int16_t y, int16_t h,
61  uint16_t color) = 0;
62  /// Draw a horizontal line.
63  virtual void drawFastHLine(int16_t x, int16_t y, int16_t w,
64  uint16_t color) = 0;
65 
66  /// Draw a bitmap to the display.
67  virtual void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
68  int16_t w, int16_t h, uint16_t color) = 0;
69 
70  /// Draw a filled rectangle.
71  virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
72  uint16_t color);
73 
74  /// Draw a circle.
75  virtual void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
76 
77  /// Draw a disk (filled circle).
78  virtual void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
79 
80  /// Initialize all displays.
81  /// @see begin
82  static void beginAll();
83 
84  /**
85  * @brief Clear the frame buffer, and draw the custom background.
86  * @see clear
87  * @see drawBackground
88  */
90  clear();
92  }
93 
94  private:
96 };
97 
DisplayInterface::drawFastVLine
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)=0
Draw a vertical line.
DisplayInterface::elements
static DoublyLinkedList< DisplayInterface > elements
Definition: DisplayInterface.hpp:95
DisplayInterface::beginAll
static void beginAll()
Initialize all displays.
Definition: DisplayInterface.cpp:61
DisplayInterface::fillCircle
virtual void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a disk (filled circle).
Definition: DisplayInterface.cpp:42
DisplayInterface::~DisplayInterface
virtual ~DisplayInterface()
Definition: DisplayInterface.hpp:25
DisplayInterface::drawBackground
virtual void drawBackground()
Draw a custom background.
Definition: DisplayInterface.hpp:33
DisplayInterface
An interface for displays.
Definition: DisplayInterface.hpp:14
DoublyLinkedList::append
void append(Node *node)
Append a node to a linked list.
Definition: LinkedList.hpp:117
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
DisplayInterface::clearAndDrawBackground
void clearAndDrawBackground()
Clear the frame buffer, and draw the custom background.
Definition: DisplayInterface.hpp:89
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
LinkedList.hpp
DoublyLinkedList::remove
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:200
DisplayInterface::drawLine
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)=0
Draw a line between two points.
DisplayInterface::clear
virtual void clear()=0
Clear the frame buffer or display.
DisplayInterface::setCursor
virtual void setCursor(int16_t x, int16_t y)=0
Set the cursor position.
DisplayInterface::setTextSize
virtual void setTextSize(uint8_t size)=0
Set the text size.
DisplayInterface::drawFastHLine
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)=0
Draw a horizontal line.
DisplayInterface::write
size_t write(uint8_t c) override=0
Write a character to the display.
DisplayInterface::drawCircle
virtual void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a circle.
Definition: DisplayInterface.cpp:19
DisplayInterface::drawPixel
virtual void drawPixel(int16_t x, int16_t y, uint16_t color)=0
Paint a single pixel with the given color.
DoublyLinkedList< DisplayInterface >
DoublyLinkable
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:302
DisplayInterface::display
virtual void display()=0
Write the frame buffer to the display.
DisplayInterface::DisplayInterface
DisplayInterface()
Definition: DisplayInterface.hpp:18
DisplayInterface::fillRect
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a filled rectangle.
Definition: DisplayInterface.cpp:13
DisplayInterface::drawXBitmap
virtual void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)=0
Draw a bitmap to the display.
DisplayInterface::begin
virtual void begin()
Initialize the display.
Definition: DisplayInterface.cpp:7
DisplayInterface::setTextColor
virtual void setTextColor(uint16_t color)=0
Set the text color.