Logic_library
Library for Logic board by RoboticsBrno.
Loading...
Searching...
No Matches
Display.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Platform.hpp"
4#include <SmartLeds.h>
5#include <mutex>
6
11struct Rectangle {
12 Rectangle(int x, int y, int w, int h)
13 : x(x)
14 , y(y)
15 , w(w)
16 , h(h) {
17 }
18
19 int x, y;
20 int w, h;
21};
22
27
28class Display {
29 friend class Logic;
30
31private:
32 SmartLed m_displayLeds;
33
34 std::mutex m_mutex;
35
36 const char* m_tag = "Display";
37
38 static constexpr int m_width = 10;
39 static constexpr int m_height = 10;
40 std::array<Rgb, m_width * m_height> m_frame;
41
42 void displayBresenhmCircle(int xCenter, int yCenter, int x, int y, Rgb color);
43
44 Display();
45
46public:
47 Display(Display&) = delete;
48 Display(Display&&) = delete;
51
52 ~Display() = default;
53
58 int width() const { return m_width; }
63 int height() const { return m_height; }
64
69 int sirka() const { return m_width; }
74 int vyska() const { return m_height; }
75
80 int fontWidth() const;
85 int fontHeight() const;
86
91 int sirkaPisma() const { return fontWidth(); }
96 int vyskaPisma() const { return fontHeight(); }
97
105 Rgb& at(int x, int y);
106
114 Rgb& pozice(int x, int y) { return at(x, y); }
115
123 inline void setColor(int x, int y, Rgb color) {
124 if ((x > (m_width - 1)) || (y > (m_width - 1)) || (x < 0) || (y < 0))
125 return;
126 m_frame[(y * m_width) + x] = color;
127 }
128
136 inline void nastavBarvu(int x, int y, Rgb color) { setColor(x, y, color); }
137
141 void clear() {
142 fill(Rgb(0, 0, 0));
143 }
144
148 void vycisti() { clear(); }
149
155 void fill(Rgb color);
156
162 void vypln(Rgb barva) {
163 fill(barva);
164 }
165
176 void
177 drawRectangle(int x, int y, int width, int height, Rgb color, int strokeWidth = 1);
178
186 void drawRectangle(const Rectangle& rect, Rgb color, int strokeWidth = 1) { drawRectangle(rect.x, rect.y, rect.w, rect.h, color, strokeWidth); }
187
197 void drawRectangleFilled(int x, int y, int width, int height, Rgb color) {
198 drawRectangle(x, y, width, height, color, INT_MAX);
199 }
200
207 void drawRectangleFilled(const Rectangle& rect, Rgb color) {
208 drawRectangle(rect.x, rect.y, rect.w, rect.h, color, INT_MAX);
209 }
210
221 void nakresliObdelnik(int x, int y, int sirka, int vyska, Rgb barva, int tloustkaCary = 1) { drawRectangle(x, y, sirka, vyska, barva, tloustkaCary); }
222
230 void nakresliObdelnik(const Obdelnik& obdelnik, Rgb barva, int tloustkaCary = 1) { drawRectangle(obdelnik, barva, tloustkaCary); }
231
241 void nakresliObdelnikVyplneny(int x, int y, int sirka, int vyska, Rgb barva) { drawRectangleFilled(x, y, sirka, vyska, barva); }
242
249 void nakresliObdelnikVyplneny(const Obdelnik& obdelnik, Rgb barva) { drawRectangleFilled(obdelnik, barva); }
250
260 void drawSquare(int x, int y, int size, Rgb color, int strokeWidth = 1) {
261 drawRectangle(x, y, size, size, color, strokeWidth);
262 }
263
272 void drawSquareFilled(int x, int y, int size, Rgb color) { drawSquare(x, y, size, color, INT_MAX); }
273
283 void nakresliCtverec(int x, int y, int strana, Rgb barva, int tlouskaCary = 1) { drawSquare(x, y, strana, barva, tlouskaCary); }
284
293 void nakresliCtverecVyplneny(int x, int y, int strana, Rgb barva) {
294 drawSquareFilled(x, y, strana, barva);
295 }
296
305 void drawCircle(int centerX, int centerY, int radius, Rgb color);
306
315 void drawCircleFilled(int centerX, int centerY, int radius, Rgb color);
316
325 void nakresliKruznici(int stredX, int stredY, int polomer, Rgb barva) { drawCircle(stredX, stredY, polomer, barva); }
326
335 void nakresliKruzniciVyplnenou(int stredX, int stredY, int polomer, Rgb barva) { drawCircleFilled(stredX, stredY, polomer, barva); }
336
347 void drawLine(int x1, int y1, int x2, int y2, Rgb color, int strokeWidth = 1);
348
359 void nakresliCaru(int x1, int y1, int x2, int y2, Rgb barva, int tloustkaCary = 1) {
360 drawLine(x1, y1, x2, y2, barva);
361 }
362
372 void drawCharacter(char c, Rgb color, int offsetX = 2, int offsetY = 0);
373
382 void nakresliZnak(char znak, Rgb barva, int posunX = 2, int posunY = 0) {
383 drawCharacter(znak, barva, posunX, posunY);
384 }
385
396 int drawString(const char* utf8Czech, Rgb color, int offsetX = 2, int offsetY = 0);
397
401 int drawString(const std::string& utf8Czech, Rgb color, int offsetX = 2, int offsetY = 0) {
402 return drawString(utf8Czech.c_str(), color, offsetX, offsetY);
403 }
404
415 int nakresliText(const char* utf8CeskyText, Rgb barva, int posunX = 2, int posunY = 0) {
416 return drawString(utf8CeskyText, barva, posunX, posunY);
417 }
418
422 int nakresliText(const std::string& utf8CeskyText, Rgb barva, int posunX = 2, int posunY = 0) {
423 return drawString(utf8CeskyText, barva, posunX, posunY);
424 }
425
431 void show(int intensity = 255);
432
438 void ukaz(int intenzita = 255) { show(intenzita); }
439
440 Rgb& operator()(int x, int y);
441 Rgb& operator[](int index);
442};
443
445
446static const Rgb Black(0, 0, 0);
447static const Rgb White(255, 255, 255);
448static const Rgb Red(255, 0, 0);
449static const Rgb Green(0, 255, 0);
450static const Rgb Blue(0, 0, 255);
451static const Rgb Yellow(255, 255, 0);
452static const Rgb Cyan(0, 255, 255);
453static const Rgb Magenta(255, 0, 255);
454static const Rgb Purple(128, 0, 128);
455static const Rgb Pink(255, 30, 150);
456
457static const Rgb Cerna(0, 0, 0);
458static const Rgb Bila(255, 255, 255);
459static const Rgb Cervena(255, 0, 0);
460static const Rgb Zelena(0, 255, 0);
461static const Rgb Modra(0, 0, 255);
462static const Rgb Zluta(255, 255, 0);
463static const Rgb Azurova(0, 255, 255);
464static const Rgb Fialova(255, 0, 255);
465static const Rgb Ruzova(255, 30, 150);
static const Rgb Black(0, 0, 0)
static const Rgb Ruzova(255, 30, 150)
static const Rgb Modra(0, 0, 255)
static const Rgb Cervena(255, 0, 0)
Rectangle Obdelnik
Struktura pro kreslení obdélníků
Definition: Display.hpp:26
static const Rgb Zelena(0, 255, 0)
static const Rgb Cerna(0, 0, 0)
static const Rgb Azurova(0, 255, 255)
static const Rgb Blue(0, 0, 255)
static const Rgb Zluta(255, 255, 0)
static const Rgb Pink(255, 30, 150)
static const Rgb Bila(255, 255, 255)
static const Rgb Magenta(255, 0, 255)
static const Rgb White(255, 255, 255)
static const Rgb Yellow(255, 255, 0)
static const Rgb Cyan(0, 255, 255)
static const Rgb Red(255, 0, 0)
static const Rgb Fialova(255, 0, 255)
static const Rgb Green(0, 255, 0)
static const Rgb Purple(128, 0, 128)
Definition: Display.hpp:28
void nakresliKruzniciVyplnenou(int stredX, int stredY, int polomer, Rgb barva)
Nakreslí vyplněnou kružnici (kruh) s danými parametry.
Definition: Display.hpp:335
int vyska() const
Vrací výšku displeje v pixelech.
Definition: Display.hpp:74
void nakresliCaru(int x1, int y1, int x2, int y2, Rgb barva, int tloustkaCary=1)
Nakreslí čáru.
Definition: Display.hpp:359
int fontWidth() const
Returns width of each character in the font used by drawCharacter and drawString.
Definition: Display.cpp:24
int drawString(const char *utf8Czech, Rgb color, int offsetX=2, int offsetY=0)
Draws whole string to the display, handling Czech UTF-8 sequences correctly.
Definition: Display.cpp:148
void clear()
Clear the display.
Definition: Display.hpp:141
void nakresliObdelnikVyplneny(const Obdelnik &obdelnik, Rgb barva)
Nakreslí vyplněný obdélník se zadanými parametry.
Definition: Display.hpp:249
void drawRectangleFilled(const Rectangle &rect, Rgb color)
Draw filled rectangle with specified parameters.
Definition: Display.hpp:207
Display & operator=(Display &)=delete
int fontHeight() const
Returns height of each character in the font used by drawCharacter and drawString.
Definition: Display.cpp:28
int nakresliText(const std::string &utf8CeskyText, Rgb barva, int posunX=2, int posunY=0)
Definition: Display.hpp:422
void nakresliKruznici(int stredX, int stredY, int polomer, Rgb barva)
Nakreslí kružnici s danými parametry.
Definition: Display.hpp:325
void fill(Rgb color)
Fill the display with color.
Definition: Display.cpp:38
void vycisti()
Vyčistí celý displej.
Definition: Display.hpp:148
void show(int intensity=255)
Show prepared frame on display.
Definition: Display.cpp:176
void nakresliCtverecVyplneny(int x, int y, int strana, Rgb barva)
Nakreslí čtverec se zadanými parametry.
Definition: Display.hpp:293
void setColor(int x, int y, Rgb color)
Set the color of pixel at specified position.
Definition: Display.hpp:123
void drawRectangleFilled(int x, int y, int width, int height, Rgb color)
Draw filled rectangle with specified parameters.
Definition: Display.hpp:197
int sirkaPisma() const
Vrátí šířku jednoho znaku z písma použitého v metodách nakresliZnak a nakresliText.
Definition: Display.hpp:91
Display(Display &&)=delete
void drawSquareFilled(int x, int y, int size, Rgb color)
Draw filled square with specified parameters.
Definition: Display.hpp:272
Display(Display &)=delete
void drawSquare(int x, int y, int size, Rgb color, int strokeWidth=1)
Draw square with specified parameters.
Definition: Display.hpp:260
int width() const
Returns width of the display in pixels.
Definition: Display.hpp:58
int drawString(const std::string &utf8Czech, Rgb color, int offsetX=2, int offsetY=0)
Definition: Display.hpp:401
void nastavBarvu(int x, int y, Rgb color)
Nastaví barvu pixelu na dané pozici.
Definition: Display.hpp:136
int sirka() const
Vrací šířku displeje v pixelech.
Definition: Display.hpp:69
void nakresliCtverec(int x, int y, int strana, Rgb barva, int tlouskaCary=1)
Nakreslí čtverec se zadanými parametry.
Definition: Display.hpp:283
void nakresliObdelnik(const Obdelnik &obdelnik, Rgb barva, int tloustkaCary=1)
Nakreslí obdélník se zadanými parametry.
Definition: Display.hpp:230
int vyskaPisma() const
Vrátí výšku jednoho znaku z písma použitého v metodách nakresliZnak a nakresliText.
Definition: Display.hpp:96
void nakresliObdelnikVyplneny(int x, int y, int sirka, int vyska, Rgb barva)
Nakreslí vyplněný obdélník se zadanými parametry.
Definition: Display.hpp:241
Rgb & at(int x, int y)
Returns reference to pixel on that position.
Definition: Display.cpp:32
~Display()=default
Rgb & operator[](int index)
Definition: Display.cpp:193
void drawCircle(int centerX, int centerY, int radius, Rgb color)
Draw circle with specified parameters.
Definition: Display.cpp:55
Rgb & operator()(int x, int y)
Definition: Display.cpp:189
void vypln(Rgb barva)
Vyplň celý displej barvou.
Definition: Display.hpp:162
void nakresliObdelnik(int x, int y, int sirka, int vyska, Rgb barva, int tloustkaCary=1)
Nakreslí obdélník se zadanými parametry.
Definition: Display.hpp:221
void drawCircleFilled(int centerX, int centerY, int radius, Rgb color)
Draw filled circle with specified parameters.
Definition: Display.cpp:74
void ukaz(int intenzita=255)
Vykresli připravený snímek na displeji.
Definition: Display.hpp:438
void drawRectangle(int x, int y, int width, int height, Rgb color, int strokeWidth=1)
Draw rectangle with specified parameters.
Definition: Display.cpp:43
void drawCharacter(char c, Rgb color, int offsetX=2, int offsetY=0)
Draw a single character to the display. The dimensions of the characters can be obtained by calling f...
Definition: Display.cpp:137
void nakresliZnak(char znak, Rgb barva, int posunX=2, int posunY=0)
Nakreslí jeden znak na displej. Velikost znaků dostanete z metod sirkaPisma() a vyskaPisma().
Definition: Display.hpp:382
int height() const
Returns height of the display in pixels.
Definition: Display.hpp:63
int nakresliText(const char *utf8CeskyText, Rgb barva, int posunX=2, int posunY=0)
Nakreslí na displej textový řetězec, včetně český znaků v UTF-8.
Definition: Display.hpp:415
void drawRectangle(const Rectangle &rect, Rgb color, int strokeWidth=1)
Draw rectangle with specified parameters.
Definition: Display.hpp:186
void drawLine(int x1, int y1, int x2, int y2, Rgb color, int strokeWidth=1)
Draw line.
Definition: Display.cpp:83
Display & operator=(Display &&)=delete
Rgb & pozice(int x, int y)
Vrátí pixel na dané pozici.
Definition: Display.hpp:114
Definition: Logic.hpp:14
Structure for describing rectangles on display.
Definition: Display.hpp:11
Rectangle(int x, int y, int w, int h)
Definition: Display.hpp:12
int x
Definition: Display.hpp:19
int w
Definition: Display.hpp:20
int y
Definition: Display.hpp:19
int h
Definition: Display.hpp:20