displaylib_1bit_PICO 2.2.0
1-bit colour graphic display library, Rpi PICO RP2040 library
Loading...
Searching...
No Matches
display_graphics.hpp
Go to the documentation of this file.
1
7#pragma once
8
9
10#include <cmath> // for "abs"
11#include "display_fonts.hpp"
12#include "display_print.hpp"
13
14// Define to enable advanced graphics functions such as drawArc, drawPolygon, drawEllipse etc.
15// Default is ON. Can be turned off to save flash space if not needed.
16#define _ADVANCED_GRAPHICS_ENABLE
17
18#ifdef _ADVANCED_GRAPHICS_ENABLE
19#include <vector>
20#endif
21
24{
25
26 public:
27
28 displaylib_graphics(int16_t w, int16_t h); // Constructor
29
31 enum PixelColor : uint8_t {
34 INVERSE = 2
35 };
36
38 enum display_rotate_e : uint8_t
39 {
43 rDegrees_270 = 3
44 };
45
46 virtual void drawPixel(int16_t x, int16_t y, uint8_t color) = 0;
47 // Graphics functions
48 void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color);
49 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint8_t color);
50 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint8_t color);
51 void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
52 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
53 void fillScreen(uint8_t color);
54
55 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color);
56 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color);
57 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
58 int16_t x2, int16_t y2, uint8_t color);
59 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
60 int16_t x2, int16_t y2, uint8_t color);
61 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
62 int16_t radius, uint8_t color);
63 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
64 int16_t radius, uint8_t color);
65 void setCursor(int16_t x, int16_t y);
66
67 // Text related functions
68 virtual size_t write(uint8_t);
69 DisplayRet::Ret_Codes_e writeChar( int16_t x, int16_t y, char value );
70 DisplayRet::Ret_Codes_e writeCharString( int16_t x, int16_t y, char *text);
71 void setTextWrap(bool w);
72
73 void setDrawBitmapAddr(bool mode);
74 DisplayRet::Ret_Codes_e drawBitmap(int16_t x, int16_t y, std::span<const uint8_t> bitmap,
75 int16_t w, int16_t h, uint8_t color, uint8_t bg);
76
77 int16_t height(void) const;
78 int16_t width(void) const;
81
82
83#ifdef _ADVANCED_GRAPHICS_ENABLE
84 void drawLineAngle(int16_t x, int16_t y, int angle, uint8_t start,
85 uint8_t length, int offset, uint8_t color);
86 void drawQuadrilateral(int16_t x0, int16_t y0,int16_t x1, int16_t y1,
87 int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint8_t color);
88 void fillQuadrilateral(int16_t x0, int16_t y0,int16_t x1, int16_t y1,
89 int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint8_t color);
90 DisplayRet::Ret_Codes_e drawPolygon(int16_t x, int16_t y, uint8_t sides,
91 int16_t diameter, float rotation, bool fill , uint8_t color);
92 void drawArc(uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness,
93 float startAngle, float endAngle, uint8_t color);
94 void drawSimpleArc(int16_t cx, int16_t cy, int16_t radius, float startAngle,
95 float endAngle, uint8_t color);
96 void drawEllipse(int16_t cx, int16_t cy, int16_t semiMajorAxis,
97 int16_t semiMinorAxis, bool fill, uint8_t color);
98 DisplayRet::Ret_Codes_e drawDotGrid(int16_t x, int16_t y, int16_t w,
99 int16_t h, uint8_t DotGridGap, uint8_t color);
100 float getArcAngleMax() const;
101 void setArcAngleMax(float arcAngleMax);
102 int getArcAngleOffset() const;
103 void setArcAngleOffset(int arcAngleOffset);
104
105#endif
106
107 protected:
108
109 const int16_t WIDTH;
110 const int16_t HEIGHT;
112 int16_t _width;
113 int16_t _height;
114 int16_t _cursor_x = 0;
115 int16_t _cursor_y = 0;
117 bool _textwrap = true;
118#ifdef _ADVANCED_GRAPHICS_ENABLE
119 float _arcAngleMax = 360.0f;
121 float sineFromDegrees(float angle);
122 float cosineFromDegrees(float angle);
123 void ellipseHelper(uint16_t cx, uint16_t cy, uint16_t x, uint16_t y, uint8_t color);
124 void drawArcHelper(uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness, float start, float end, uint8_t color);
125#endif
126
127 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
128 uint8_t color);
129 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
130 int16_t delta, uint8_t color);
131 private:
139 inline void swapInt16display(int16_t& a, int16_t& b) {
140 int16_t t = a;
141 a = b;
142 b = t;
143 }
144};
145
class that provides polymorphic print methods for printing data
Definition display_print.hpp:24
Font class to hold font data object
Definition display_fonts.hpp:39
Graphics class to hold graphic related functions.
Definition display_graphics.hpp:24
DisplayRet::Ret_Codes_e writeChar(int16_t x, int16_t y, char value)
Write 1 character on OLED.
Definition display_graphics.cpp:37
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint8_t color)
Draws a vertical line starting at (x,y) with height h.
Definition display_graphics.cpp:447
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color)
draws a line from (x0,y0) to (x1,y1).
Definition display_graphics.cpp:377
void fillQuadrilateral(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint8_t color)
Fills a quadrilateral with the specified color using triangles. This function fills a quadrilateral b...
Definition display_graphics.cpp:1076
int getArcAngleOffset() const
Get the current angle offset.
Definition display_graphics.cpp:866
float _arcAngleMax
Definition display_graphics.hpp:119
void swapInt16display(int16_t &a, int16_t &b)
Swaps the values of two int16_t variables.
Definition display_graphics.hpp:139
int16_t height(void) const
Gets the height of the display (per current _rotation)
Definition display_graphics.cpp:677
display_rotate_e getRotation(void)
Gets the _rotation of the display.
Definition display_graphics.cpp:686
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)
draws a triangle of coordinates (x0,y0), (x1,y1) and (x2,y2).
Definition display_graphics.cpp:542
void setCursor(int16_t x, int16_t y)
set the cursor position
Definition display_graphics.cpp:649
bool _drawBitmapAddr
Definition display_graphics.hpp:116
const int16_t WIDTH
Definition display_graphics.hpp:109
DisplayRet::Ret_Codes_e drawPolygon(int16_t x, int16_t y, uint8_t sides, int16_t diameter, float rotation, bool fill, uint8_t color)
Draws a polygon with a specified number of sides, diameter, rotation, and color. This function draws ...
Definition display_graphics.cpp:891
int16_t width(void) const
Gets the width of the display (per current _rotation)
Definition display_graphics.cpp:668
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color)
draws rectangle at (x,y) where h is height and w is width of the rectangle.
Definition display_graphics.cpp:430
void setDrawBitmapAddr(bool mode)
sets the data addressing mode in drawBitmap function.
Definition display_graphics.cpp:839
void drawEllipse(int16_t cx, int16_t cy, int16_t semiMajorAxis, int16_t semiMinorAxis, bool fill, uint8_t color)
Draw an ellipse on the display. This function uses the midpoint ellipse algorithm to efficiently draw...
Definition display_graphics.cpp:1105
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint8_t color)
draws a rectangle with rounded edges
Definition display_graphics.cpp:501
void setTextWrap(bool w)
turn on or off screen _textwrap of the text (fonts 1-6)
Definition display_graphics.cpp:659
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color)
fills a circle where (x0,y0) are center coordinates an r is circle radius.
Definition display_graphics.cpp:311
int16_t _cursor_x
Definition display_graphics.hpp:114
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)
Fills a triangle defined by the coordinates (x0, y0), (x1, y1), and (x2, y2).
Definition display_graphics.cpp:561
void setRotation(display_rotate_e r)
Sets the _rotation of the display.
Definition display_graphics.cpp:695
float cosineFromDegrees(float angle)
Computes the cosine of an angle given in degrees. This function converts the input angle from degrees...
Definition display_graphics.cpp:1426
PixelColor
Display Pixel colours definition.
Definition display_graphics.hpp:31
@ INVERSE
Definition display_graphics.hpp:34
@ FG_COLOR
Definition display_graphics.hpp:33
@ BG_COLOR
Definition display_graphics.hpp:32
DisplayRet::Ret_Codes_e writeCharString(int16_t x, int16_t y, char *text)
Write Text character array on OLED.
Definition display_graphics.cpp:125
DisplayRet::Ret_Codes_e drawBitmap(int16_t x, int16_t y, std::span< const uint8_t > bitmap, int16_t w, int16_t h, uint8_t color, uint8_t bg)
Draw a 1-bit color bitmap.
Definition display_graphics.cpp:732
int16_t _height
Definition display_graphics.hpp:113
display_rotate_e
Definition display_graphics.hpp:39
@ rDegrees_270
Definition display_graphics.hpp:43
@ rDegrees_180
Definition display_graphics.hpp:42
@ rDegrees_90
Definition display_graphics.hpp:41
@ rDegrees_0
Definition display_graphics.hpp:40
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color)
fills a rectangle starting from coordinates (x,y) with width of w and height of h.
Definition display_graphics.cpp:474
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color)
Draws a circle with center coordinates (centerX, centerY) and a given radius.
Definition display_graphics.cpp:202
display_rotate_e _display_rotate
Definition display_graphics.hpp:111
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint8_t color)
Fills a rectangle with rounded edges.
Definition display_graphics.cpp:524
void drawSimpleArc(int16_t cx, int16_t cy, int16_t radius, float startAngle, float endAngle, uint8_t color)
Draw a simple arc of one pixel on the display( no offsets , thickness or maximum arc calculations) Th...
Definition display_graphics.cpp:1402
void drawArc(uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness, float startAngle, float endAngle, uint8_t color)
Draw an arc on the TFT display. This function draws an arc between two angles (start and end) on a ci...
Definition display_graphics.cpp:1376
bool _textwrap
Definition display_graphics.hpp:117
const int16_t HEIGHT
Definition display_graphics.hpp:110
void setArcAngleOffset(int arcAngleOffset)
Set a new angle offset.
Definition display_graphics.cpp:873
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint8_t color)
Draws a horizontal line starting at (x,y) with width w.
Definition display_graphics.cpp:460
float getArcAngleMax() const
Get the current maximum angle of the arc.
Definition display_graphics.cpp:850
int16_t _width
Definition display_graphics.hpp:112
int16_t _cursor_y
Definition display_graphics.hpp:115
void drawLineAngle(int16_t x, int16_t y, int angle, uint8_t start, uint8_t length, int offset, uint8_t color)
Draws a line using an angle and length as parameters. This function draws a line starting from (x,...
Definition display_graphics.cpp:1016
DisplayRet::Ret_Codes_e drawDotGrid(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t DotGridGap, uint8_t color)
Draws a grid of dots on the screen starting from the given coordinates. This function draws a grid of...
Definition display_graphics.cpp:971
virtual size_t write(uint8_t)
write method used in the print class when user calls print
Definition display_graphics.cpp:164
int _arcAngleOffset
Definition display_graphics.hpp:120
void drawQuadrilateral(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint8_t color)
Draws a quadrilateral (four-sided polygon) by connecting four points with lines. This function draws ...
Definition display_graphics.cpp:1055
void setArcAngleMax(float arcAngleMax)
Set a new maximum angle for the arc.
Definition display_graphics.cpp:857
float sineFromDegrees(float angle)
Computes the sine of an angle given in degrees. This function converts the input angle from degrees t...
Definition display_graphics.cpp:1439
void fillScreen(uint8_t color)
Fills the whole screen with a given color.
Definition display_graphics.cpp:487
font data file 10 fonts. Data Vertical addressed 1-bit color displays.
Base class that provides print() and println() for 1-bit color displays. library.
Ret_Codes_e
Definition display_data.hpp:32