Line data Source code
1 : #pragma once 2 : 3 : #include <AH/Containers/LinkedList.hpp> 4 : #include <Def/Def.hpp> 5 : #include <Print.h> 6 : 7 : BEGIN_CS_NAMESPACE 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 { 15 : protected: 16 : DisplayInterface() = default; 17 : 18 : public: 19 : virtual ~DisplayInterface() = default; 20 : 21 : /// Initialize the display. 22 : virtual void begin(); 23 : 24 : /// Clear the frame buffer or clear the display. 25 : virtual void clear() = 0; 26 : /// Draw a custom background. 27 0 : virtual void drawBackground(){}; 28 : /// Write the frame buffer to the display. If your display library writes to 29 : /// the display directly, without a display buffer in RAM, you can leave 30 : /// this function empty. 31 : virtual void display() = 0; 32 : 33 : /// Paint a single pixel with the given color. 34 : virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; 35 : 36 : /// Set the text color. 37 : virtual void setTextColor(uint16_t color) = 0; 38 : /// Set the text size. 39 : virtual void setTextSize(uint8_t size) = 0; 40 : /// Set the cursor position. 41 : virtual void setCursor(int16_t x, int16_t y) = 0; 42 : 43 : /** 44 : * @brief Write a character to the display. 45 : * 46 : * @see setCursor 47 : * @see setTextSize 48 : * @see setTextColor 49 : */ 50 : size_t write(uint8_t c) override = 0; 51 : 52 : /// Draw a line between two points. 53 : virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 54 : uint16_t color) = 0; 55 : /// Draw a vertical line. 56 : virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, 57 : uint16_t color) = 0; 58 : /// Draw a horizontal line. 59 : virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, 60 : uint16_t color) = 0; 61 : 62 : /// Draw a bitmap to the display. 63 : virtual void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], 64 : int16_t w, int16_t h, uint16_t color) = 0; 65 : 66 : /// Draw a filled rectangle. 67 : virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 68 : uint16_t color); 69 : 70 : /// Draw a circle. 71 : virtual void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 72 : 73 : /// Draw a disk (filled circle). 74 : virtual void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 75 : 76 : /** 77 : * @brief Clear the frame buffer, and draw the custom background. 78 : * @see clear 79 : * @see drawBackground 80 : */ 81 0 : void clearAndDrawBackground() { 82 0 : clear(); 83 0 : drawBackground(); 84 0 : } 85 : }; 86 : 87 : END_CS_NAMESPACE