displaylib_1bit_PICO 2.0.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 _ADVANCED_GRAPHICS_ENABLE
15
16#ifdef _ADVANCED_GRAPHICS_ENABLE
17#include <vector>
18#endif
19
22{
23
24 public:
25
26 displaylib_graphics(int16_t w, int16_t h); // Constructor
27
29 enum PixelColor : uint8_t {
32 INVERSE = 2
33 };
34
36 enum display_rotate_e : uint8_t
37 {
41 rDegrees_270 = 3
42 };
43
44 virtual void drawPixel(int16_t x, int16_t y, uint8_t color) = 0;
45 // Graphics functions
46 void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color);
47 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint8_t color);
48 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint8_t color);
49 void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
50 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color);
51 void fillScreen(uint8_t color);
52
53 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color);
54 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color);
55 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
56 int16_t x2, int16_t y2, uint8_t color);
57 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
58 int16_t x2, int16_t y2, uint8_t color);
59 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
60 int16_t radius, uint8_t color);
61 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
62 int16_t radius, uint8_t color);
63 void setCursor(int16_t x, int16_t y);
64
65 // Text related functions
66 virtual size_t write(uint8_t);
67 DisplayRet::Ret_Codes_e writeChar( int16_t x, int16_t y, char value );
68 DisplayRet::Ret_Codes_e writeCharString( int16_t x, int16_t y, char *text);
69 void setTextWrap(bool w);
70
71 void setDrawBitmapAddr(bool mode);
72 DisplayRet::Ret_Codes_e drawBitmap(int16_t x, int16_t y, std::span<const uint8_t> bitmap,
73 int16_t w, int16_t h, uint8_t color, uint8_t bg);
74
75 int16_t height(void) const;
76 int16_t width(void) const;
79
80
81#ifdef _ADVANCED_GRAPHICS_ENABLE
82 void drawLineAngle(int16_t x, int16_t y, int angle, uint8_t start,
83 uint8_t length, int offset, uint8_t color);
84 void drawQuadrilateral(int16_t x0, int16_t y0,int16_t x1, int16_t y1,
85 int16_t x2, int16_t y2, int16_t x3, int16_t y3, uint8_t color);
86 void fillQuadrilateral(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 DisplayRet::Ret_Codes_e drawPolygon(int16_t x, int16_t y, uint8_t sides,
89 int16_t diameter, float rotation, bool fill , uint8_t color);
90 void drawArc(uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness,
91 float startAngle, float endAngle, uint8_t color);
92 void drawSimpleArc(int16_t cx, int16_t cy, int16_t radius, float startAngle,
93 float endAngle, uint8_t color);
94 void drawEllipse(int16_t cx, int16_t cy, int16_t semiMajorAxis,
95 int16_t semiMinorAxis, bool fill, uint8_t color);
96 DisplayRet::Ret_Codes_e drawDotGrid(int16_t x, int16_t y, int16_t w,
97 int16_t h, uint8_t DotGridGap, uint8_t color);
98 float getArcAngleMax() const;
99 void setArcAngleMax(float arcAngleMax);
100 int getArcAngleOffset() const;
101 void setArcAngleOffset(int arcAngleOffset);
102
103#endif
104
105 protected:
106
107 const int16_t WIDTH;
108 const int16_t HEIGHT;
110 int16_t _width;
111 int16_t _height;
112 int16_t _cursor_x = 0;
113 int16_t _cursor_y = 0;
115 bool _textwrap = true;
116#ifdef _ADVANCED_GRAPHICS_ENABLE
117 float _arcAngleMax = 360.0f;
119 float sineFromDegrees(float angle);
120 float cosineFromDegrees(float angle);
121 void ellipseHelper(uint16_t cx, uint16_t cy, uint16_t x, uint16_t y, uint8_t color);
122 void drawArcHelper(uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness, float start, float end, uint8_t color);
123#endif
124
125 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
126 uint8_t color);
127 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
128 int16_t delta, uint8_t color);
129 private:
136 inline void swapInt16display(int16_t& a, int16_t& b) {
137 int16_t t = a;
138 a = b;
139 b = t;
140 }
141};
142
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:22
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:1079
int getArcAngleOffset() const
Get the current angle offset.
Definition display_graphics.cpp:866
float _arcAngleMax
Definition display_graphics.hpp:117
void swapInt16display(int16_t &a, int16_t &b)
Swaps the values of two int16_t variables.
Definition display_graphics.hpp:136
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:114
const int16_t WIDTH
Definition display_graphics.hpp:107
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:1108
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:112
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:1429
PixelColor
Display Pixel colours definition.
Definition display_graphics.hpp:29
@ INVERSE
Definition display_graphics.hpp:32
@ FG_COLOR
Definition display_graphics.hpp:31
@ BG_COLOR
Definition display_graphics.hpp:30
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:111
display_rotate_e
Definition display_graphics.hpp:37
@ rDegrees_270
Definition display_graphics.hpp:41
@ rDegrees_180
Definition display_graphics.hpp:40
@ rDegrees_90
Definition display_graphics.hpp:39
@ rDegrees_0
Definition display_graphics.hpp:38
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:109
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:1405
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:1379
bool _textwrap
Definition display_graphics.hpp:115
const int16_t HEIGHT
Definition display_graphics.hpp:108
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:110
int16_t _cursor_y
Definition display_graphics.hpp:113
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:118
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:1442
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