Control Surface pin-t-adl
MIDI Control Surface library for Arduino
DisplayElement.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
11class DisplayElement : public DoublyLinkable<DisplayElement> {
12 protected:
18 // The elements are sorted by the address of their displays.
19 // This way, all display elements that draw to the same display are next
20 // to each other. This means that the display buffer can be reused, and
21 // makes it easier to iterate over the displays and draw to them.
23 this, [](const DisplayElement &lhs, const DisplayElement &rhs) {
24 return &lhs.getDisplay() < &rhs.getDisplay();
25 });
26 }
27
30
33 void enable() {
34 if (isEnabled()) {
35 ERROR(F("Error: This element is already enabled."), 0x9212);
36 return;
37 }
38 elements.append(this);
39 }
40
43 void disable() {
44 if (!isEnabled()) {
45 ERROR(F("Error: This element is already disabled."), 0x9213);
46 return;
47 }
48 elements.remove(this);
49 }
50
57 bool isEnabled() const {
58 return elements.couldContain(this);
59 }
60
62 static void enable(DisplayElement *element) { element->enable(); }
64 static void enable(DisplayElement &element) { element.enable(); }
66 template <class U, size_t N>
67 static void enable(U (&array)[N]) {
68 for (U &el : array)
69 enable(el);
70 }
71
73 static void disable(DisplayElement *element) { element->disable(); }
75 static void disable(DisplayElement &element) { element.disable(); }
77 template <class U, size_t N>
78 static void disable(U (&array)[N]) {
79 for (U &el : array)
80 disable(el);
81 }
82
84
85 public:
86 virtual ~DisplayElement() { elements.remove(this); }
87
89 virtual void draw() = 0;
90
92 virtual bool getDirty() const = 0;
93
97 const DisplayInterface &getDisplay() const { return display; }
98
101
102 protected:
104
106};
107
#define ERROR(msg, errc)
Definition: Error.hpp:22
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
An interface for elements that draw to a display.
static void enable(DisplayElement &element)
Enable this display element: insert it into the linked list of instances, so it gets drawn to the dis...
static DoublyLinkedList< DisplayElement > elements
static DoublyLinkedList< DisplayElement > & getAll()
Get the list of all DisplayElement instances.
virtual void draw()=0
Draw this DisplayElement to the display buffer.
static void enable(U(&array)[N])
Enable this display element: insert it into the linked list of instances, so it gets drawn to the dis...
virtual bool getDirty() const =0
Check if this DisplayElement has to be re-drawn.
void enable()
Enable this display element: insert it into the linked list of instances, so it gets drawn to the dis...
static void enable(DisplayElement *element)
Enable this display element: insert it into the linked list of instances, so it gets drawn to the dis...
const DisplayInterface & getDisplay() const
Get a const reference to the display that this element draws to.
DisplayElement(DisplayInterface &display)
Create a new DisplayElement.
DisplayInterface & getDisplay()
Get a reference to the display that this element draws to.
virtual ~DisplayElement()
void disable()
Disable this display element: remove it from the linked list of instances, so it no longer gets drawn...
bool isEnabled() const
Check if this display element is enabled.
static void disable(DisplayElement &element)
Disable this display element: remove it from the linked list of instances, so it no longer gets drawn...
static void disable(U(&array)[N])
Disable this display element: remove it from the linked list of instances, so it no longer gets drawn...
static void disable(DisplayElement *element)
Disable this display element: remove it from the linked list of instances, so it no longer gets drawn...
DisplayInterface & display
An interface for displays.
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:321
void append(Node *node)
Append a node to a linked list.
Definition: LinkedList.hpp:120
bool couldContain(const Node *node) const
Check if the linked list could contain the given node.
Definition: LinkedList.hpp:284
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:203
void insertSorted(Node *node, Compare cmp)
Insert a new node at the correct location into a sorted list.
Definition: LinkedList.hpp:173