Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
DisplayElement.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
12class DisplayElement : public DoublyLinkable<DisplayElement> {
13 protected:
19 // The elements are sorted by the address of their displays.
20 // This way, all display elements that draw to the same display are next
21 // to each other. This means that the display buffer can be reused, and
22 // makes it easier to iterate over the displays and draw to them.
23 elements.insertSorted(
24 this, [](const DisplayElement &lhs, const DisplayElement &rhs) {
25 return reinterpret_cast<uintptr_t>(&lhs.getDisplay()) <
26 reinterpret_cast<uintptr_t>(&rhs.getDisplay());
27 });
28 }
29
32
35 void enable() {
36 if (isEnabled()) {
37 ERROR(F("Error: This element is already enabled."), 0x9212);
38 return;
39 }
40 elements.append(this);
41 }
42
45 void disable() {
46 if (!isEnabled()) {
47 ERROR(F("Error: This element is already disabled."), 0x9213);
48 return;
49 }
50 elements.remove(this);
51 }
52
59 bool isEnabled() const { return elements.couldContain(this); }
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:19
#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.
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32