diff --git a/src/demo/NodeTest.h b/src/demo/NodeTest.h index eff3ed1..2a51d72 100644 --- a/src/demo/NodeTest.h +++ b/src/demo/NodeTest.h @@ -1,9 +1,11 @@ #ifndef NODE_TEST_H #define NODE_TEST_H -#include +#include #include +DisplayMatrix<32, 8> display; + class NodeTest final : public Node { public: diff --git a/src/patrix/display/DisplayMatrix.h b/src/patrix/display/DisplayMatrix.h new file mode 100644 index 0000000..f6335f5 --- /dev/null +++ b/src/patrix/display/DisplayMatrix.h @@ -0,0 +1,60 @@ +#ifndef DISPLAY_MATRIX_H +#define DISPLAY_MATRIX_H + +#include "DisplayMatrix_FontCommon.h" + +template +class DisplayMatrix { + + Color matrix[H][W] = {}; + +public: + + Color foreground = White; + + Color background = Transparent; + + uint8_t alpha = 255; + + int cursorX = 0; + + int cursorY = 0; + + // draw ----------------------------------------------------------------------------------------- + + void clear(); + + void fillRect(int w = W, int h = H) const; + + // print ---------------------------------------------------------------------------------------- + + void printf(const char *format, ...); + + void print(const char *str); + + void print(const char **cPP); + + void print(Symbol1 s); + + void print(Symbol2 s); + + void print(Symbol3 s); + + void print(Symbol4 s); + + void print(Symbol5 s); + + void print(bool **s, size_t w, size_t h); + + void print(SymbolRGB8x8 s); + + void print(Color **s, size_t w, size_t h); + +}; + +// ReSharper disable CppUnusedIncludeDirective +#include +#include +// ReSharper restore CppUnusedIncludeDirective + +#endif diff --git a/src/patrix/display/DisplayMatrix_FontCommon.h b/src/patrix/display/DisplayMatrix_FontCommon.h new file mode 100644 index 0000000..a081be6 --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontCommon.h @@ -0,0 +1,13 @@ +#ifndef DISPLAY_MATRIX_FONT_COMMON_H +#define DISPLAY_MATRIX_FONT_COMMON_H + +#include "DisplayMatrix_common.h" + +typedef bool Symbol1[5][1]; +typedef bool Symbol2[5][2]; +typedef bool Symbol3[5][3]; +typedef bool Symbol4[5][4]; +typedef bool Symbol5[5][5]; +typedef Color SymbolRGB8x8[8][8]; + +#endif diff --git a/src/patrix/display/DisplayMatrix_FontLower.cpp b/src/patrix/display/DisplayMatrix_FontLower.cpp new file mode 100644 index 0000000..619bfee --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontLower.cpp @@ -0,0 +1,186 @@ +#include "DisplayMatrix_FontLower.h" + +Symbol5 FONT_LOWER[] = { + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {_,X,X,_,_}, + {X,_,X,_,_}, + {_,X,X,_,_}, + }, + { + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,X,_,_,_}, + {X,_,X,_,_}, + {X,X,_,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {_,X,X,_,_}, + {X,_,_,_,_}, + {_,X,X,_,_}, + }, + { + {_,_,X,_,_}, + {_,_,X,_,_}, + {_,X,X,_,_}, + {X,_,X,_,_}, + {_,X,X,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {_,X,_,_,_}, + {X,X,X,_,_}, + {X,_,_,_,_}, + }, + { + {_,_,X,_,_}, + {_,X,_,_,_}, + {X,X,X,_,_}, + {_,X,_,_,_}, + {_,X,_,_,_}, + }, + { + {_,_,_,_,_}, + {_,X,_,_,_}, + {X,_,X,_,_}, + {_,X,X,_,_}, + {X,X,X,_,_}, + }, + { + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,X,_,_,_}, + {X,_,X,_,_}, + {X,_,X,_,_}, + }, + { + {_,_,_,_,_}, + {X,_,_,_,_}, + {_,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + }, + { + {_,_,_,_,_}, + {_,X,_,_,_}, + {_,_,_,_,_}, + {_,X,_,_,_}, + {X,X,_,_,_}, + }, + { + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,X,_,_}, + {X,X,_,_,_}, + {X,_,X,_,_}, + }, + { + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + {_,X,_,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {X,_,X,_,_}, + {X,X,X,X,X}, + {X,_,X,_,X}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {X,_,_,_,_}, + {X,X,X,_,_}, + {X,_,X,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {_,X,_,_,_}, + {X,_,X,_,_}, + {_,X,_,_,_}, + }, + { + {_,_,_,_,_}, + {X,X,_,_,_}, + {X,_,X,_,_}, + {X,X,_,_,_}, + {X,_,_,_,_}, + }, + { + {_,_,_,_,_}, + {_,X,X,_,_}, + {X,_,X,_,_}, + {_,X,X,_,_}, + {_,_,X,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {X,_,X,_,_}, + {X,X,_,_,_}, + {X,_,_,_,_}, + }, + { + {_,_,_,_,_}, + {_,X,_,_,_}, + {X,_,_,_,_}, + {_,X,_,_,_}, + {X,_,_,_,_}, + }, + { + {_,X,_,_,_}, + {X,X,X,_,_}, + {_,X,_,_,_}, + {_,X,_,_,_}, + {_,_,X,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {X,_,X,_,_}, + {X,_,X,_,_}, + {_,X,_,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {_,_,_,_,_}, + {X,_,X,_,_}, + {_,X,_,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {_,_,_,_,_}, + {X,_,X,_,X}, + {_,X,_,X,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {X,_,X,_,_}, + {_,X,_,_,_}, + {X,_,X,_,_}, + }, + { + {_,_,_,_,_}, + {_,_,_,_,_}, + {X,_,X,_,_}, + {_,X,_,_,_}, + {X,_,_,_,_}, + }, + { + {_,_,_,_,_}, + {X,X,X,X,_}, + {_,_,X,_,_}, + {_,X,_,_,_}, + {X,X,X,X,_}, + }, +}; diff --git a/src/patrix/display/DisplayMatrix_FontLower.h b/src/patrix/display/DisplayMatrix_FontLower.h new file mode 100644 index 0000000..da40f9f --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontLower.h @@ -0,0 +1,8 @@ +#ifndef DISPLAY_MATRIX_FONT_LOWER_H +#define DISPLAY_MATRIX_FONT_LOWER_H + +#include "DisplayMatrix_FontCommon.h" + +extern Symbol5 FONT_LOWER[]; + +#endif diff --git a/src/patrix/display/DisplayMatrix_FontNumber.cpp b/src/patrix/display/DisplayMatrix_FontNumber.cpp new file mode 100644 index 0000000..56fa73a --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontNumber.cpp @@ -0,0 +1,74 @@ +#include "DisplayMatrix_FontNumber.h" + +Symbol4 FONT_NUMBER[] = { + { + {_,X,X,_}, + {X,_,_,X}, + {X,_,_,X}, + {X,_,_,X}, + {_,X,X,_}, + }, + { + {_,_,X,_}, + {_,X,X,_}, + {X,_,X,_}, + {_,_,X,_}, + {_,_,X,_}, + }, + { + {_,X,X,_}, + {X,_,_,X}, + {_,_,X,_}, + {_,X,_,_}, + {X,X,X,X}, + }, + { + {_,X,X,_}, + {X,_,_,X}, + {_,_,X,_}, + {X,_,_,X}, + {_,X,X,_}, + }, + { + {X,_,_,X}, + {X,_,_,X}, + {X,X,X,X}, + {_,_,_,X}, + {_,_,_,X}, + }, + { + {X,X,X,X}, + {X,_,_,_}, + {X,X,X,_}, + {_,_,_,X}, + {X,X,X,_}, + }, + { + {_,X,X,_}, + {X,_,_,_}, + {X,X,X,_}, + {X,_,_,X}, + {_,X,X,_}, + }, + { + {X,X,X,X}, + {_,_,_,X}, + {_,_,X,_}, + {_,X,_,_}, + {X,_,_,_}, + }, + { + {_,X,X,_}, + {X,_,_,X}, + {_,X,X,_}, + {X,_,_,X}, + {_,X,X,_}, + }, + { + {_,X,X,_}, + {X,_,_,X}, + {_,X,X,X}, + {_,_,_,X}, + {_,X,X,_}, + }, +}; diff --git a/src/patrix/display/DisplayMatrix_FontNumber.h b/src/patrix/display/DisplayMatrix_FontNumber.h new file mode 100644 index 0000000..d2f160d --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontNumber.h @@ -0,0 +1,8 @@ +#ifndef DISPLAY_MATRIX_FONT_NUMBER_H +#define DISPLAY_MATRIX_FONT_NUMBER_H + +#include "DisplayMatrix_FontCommon.h" + +extern Symbol4 FONT_NUMBER[]; + +#endif diff --git a/src/patrix/display/DisplayMatrix_FontSpecial.cpp b/src/patrix/display/DisplayMatrix_FontSpecial.cpp new file mode 100644 index 0000000..a09f78b --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontSpecial.cpp @@ -0,0 +1,276 @@ +#include "DisplayMatrix_FontSpecial.h" + +Symbol3 FONT_CHAR_SPACE = { + {_,_,_}, + {_,_,_}, + {_,_,_}, + {_,_,_}, + {_,_,_}, +}; + +Symbol3 FONT_CHAR_MINUS = { + {_,_,_}, + {_,_,_}, + {X,X,X}, + {_,_,_}, + {_,_,_}, +}; + +Symbol3 FONT_CHAR_PLUS = { + {_,_,_}, + {_,X,_}, + {X,X,X}, + {_,X,_}, + {_,_,_}, +}; + +Symbol3 FONT_CHAR_UNDERLINE = { + {_,_,_}, + {_,_,_}, + {_,_,_}, + {_,_,_}, + {X,X,X}, +}; + +Symbol3 FONT_CHAR_DEGREE = { + {_,X,_}, + {X,_,X}, + {_,X,_}, + {_,_,_}, + {_,_,_}, +}; +Symbol4 FONT_CHAR_EURO = { + {_,X,X,_}, + {X,_,_,_}, + {X,X,_,_}, + {X,_,_,_}, + {_,X,X,_}, +}; +Symbol4 FONT_CHAR_QUESTION = { + {_,X,X,_}, + {X,_,_,X}, + {_,_,X,X}, + {_,_,_,_}, + {_,_,X,_}, +}; +Symbol1 FONT_CHAR_EXCLAMATION = { + {X}, + {X}, + {X}, + {_}, + {X}, +}; +Symbol1 FONT_CHAR_POINT = { + {_}, + {_}, + {_}, + {_}, + {X}, +}; +Symbol1 FONT_CHAR_COMMA = { + {_}, + {_}, + {_}, + {X}, + {X}, +}; +Symbol1 FONT_CHAR_SEMICOLON = { + {_}, + {X}, + {_}, + {X}, + {X}, +}; +Symbol1 FONT_CHAR_COLON = { + {_}, + {X}, + {_}, + {X}, + {_}, +}; +Symbol5 FONT_CHAR_SHARP = { + {_,X,_,X,_}, + {X,X,X,X,X}, + {_,X,_,X,_}, + {X,X,X,X,X}, + {_,X,_,X,_}, +}; +Symbol4 FONT_CHAR_TILDE = { + {_,_,_,_}, + {_,X,_,X}, + {X,_,X,_}, + {_,_,_,_}, + {_,_,_,_}, +}; +Symbol3 FONT_CHAR_ASTERISK = { + {X,_,X}, + {_,X,_}, + {X,_,X}, + {_,_,_}, + {_,_,_}, +}; +Symbol3 FONT_CHAR_QUOTE_DOUBLE = { + {X,_,X}, + {X,_,X}, + {_,_,_}, + {_,_,_}, + {_,_,_}, +}; +Symbol1 FONT_CHAR_QUOTE_SINGLE = { + {X}, + {X}, + {_}, + {_}, + {_}, +}; +Symbol3 FONT_CHAR_EQUALS = { + {_,_,_}, + {X,X,X}, + {_,_,_}, + {X,X,X}, + {_,_,_}, +}; +Symbol2 FONT_CHAR_PAR_L = { + {_,X}, + {X,_}, + {X,_}, + {X,_}, + {_,X}, +}; +Symbol2 FONT_CHAR_PAR_R = { + {X,_}, + {_,X}, + {_,X}, + {_,X}, + {X,_}, +}; +Symbol2 FONT_CHAR_BRACKET_L = { + {X,X}, + {X,_}, + {X,_}, + {X,_}, + {X,X}, +}; +Symbol2 FONT_CHAR_BRACKET_R = { + {X,X}, + {_,X}, + {_,X}, + {_,X}, + {X,X}, +}; +Symbol3 FONT_CHAR_CURL_L = { + {_,X,X}, + {_,X,_}, + {X,_,_}, + {_,X,_}, + {_,X,X}, +}; +Symbol3 FONT_CHAR_CURL_R = { + {X,X,_}, + {_,X,_}, + {_,X,X}, + {_,X,_}, + {X,_,_}, +}; +Symbol3 FONT_CHAR_SLASH = { + {_,_,X}, + {_,X,_}, + {_,X,_}, + {_,X,_}, + {X,_,_}, +}; +Symbol3 FONT_CHAR_BACKSLASH = { + {X,_,_}, + {_,X,_}, + {_,X,_}, + {_,X,_}, + {_,_,X}, +}; +Symbol4 FONT_CHAR_AND = { + {_,X,_,_}, + {X,_,X,_}, + {_,X,_,X}, + {X,_,X,_}, + {_,X,_,X}, +}; +Symbol1 FONT_CHAR_PIPE = { + {X}, + {X}, + {X}, + {X}, + {X}, +}; +Symbol4 FONT_CHAR_DOLLAR = { + {_,X,X,X}, + {X,_,X,_}, + {_,X,X,_}, + {_,X,_,X}, + {X,X,X,_}, +}; +Symbol5 FONT_CHAR_AT = { + {_,X,X,X,_}, + {X,_,_,_,X}, + {X,_,X,X,_}, + {X,_,_,_,_}, + {_,X,X,X,_}, +}; +Symbol2 FONT_CHAR_LT = { + {_,_}, + {_,X}, + {X,_}, + {_,X}, + {_,_}, +}; +Symbol2 FONT_CHAR_GT = { + {_,_}, + {X,_}, + {_,X}, + {X,_}, + {_,_}, +}; +Symbol4 FONT_ERROR_ = { + {X,X,X,X}, + {X,X,X,X}, + {X,X,X,X}, + {X,X,X,X}, + {X,X,X,X}, +}; + +Symbol5 FONT_CHAR_PERCENT = { + {X,_,_,_,X}, + {_,_,_,X,_}, + {_,_,X,_,_}, + {_,X,_,_,_}, + {X,_,_,_,X}, +}; + +//@formatter:off +const auto B = Black; +Color M{204, 0, 250}; +Color m{224, 121, 250}; +Color g{130, 213, 0}; +Color G{ 48, 89, 55}; +Color F{ 75, 202, 0}; +//@formatter:on + +SymbolRGB8x8 FONT_CREEPER = { + {g, F, F, F, g, g, g, F}, + {F, F, F, F, F, g, F, F}, + {F, G, G, g, g, G, G, F}, + {F, G, B, g, g, B, G, F}, + {g, F, F, G, G, F, F, F}, + {g, F, G, B, B, G, F, g}, + {g, F, B, B, B, B, F, F}, + {F, g, G, g, g, G, F, F}, +}; + +SymbolRGB8x8 FONT_ENDERMAN = { + {B, B, B, B, B, B, B, B}, + {B, B, B, B, B, B, B, B}, + {B, B, B, B, B, B, B, B}, + {B, B, B, B, B, B, B, B}, + {m, M, m, B, B, m, M, m}, + {B, B, B, B, B, B, B, B}, + {B, B, B, B, B, B, B, B}, + {B, B, B, B, B, B, B, B}, +}; diff --git a/src/patrix/display/DisplayMatrix_FontSpecial.h b/src/patrix/display/DisplayMatrix_FontSpecial.h new file mode 100644 index 0000000..e725d40 --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontSpecial.h @@ -0,0 +1,43 @@ +#ifndef DISPLAY_MATRIX_FONT_SPECIAL_H +#define DISPLAY_MATRIX_FONT_SPECIAL_H + +#include "DisplayMatrix_FontCommon.h" + +extern Symbol3 FONT_CHAR_SPACE; +extern Symbol3 FONT_CHAR_MINUS; +extern Symbol3 FONT_CHAR_PLUS; +extern Symbol3 FONT_CHAR_UNDERLINE; +extern Symbol3 FONT_CHAR_DEGREE; +extern Symbol4 FONT_CHAR_EURO; +extern Symbol4 FONT_CHAR_QUESTION; +extern Symbol1 FONT_CHAR_EXCLAMATION; +extern Symbol1 FONT_CHAR_POINT; +extern Symbol1 FONT_CHAR_COMMA; +extern Symbol1 FONT_CHAR_SEMICOLON; +extern Symbol1 FONT_CHAR_COLON; +extern Symbol5 FONT_CHAR_SHARP; +extern Symbol4 FONT_CHAR_TILDE; +extern Symbol3 FONT_CHAR_ASTERISK; +extern Symbol3 FONT_CHAR_QUOTE_DOUBLE; +extern Symbol1 FONT_CHAR_QUOTE_SINGLE; +extern Symbol3 FONT_CHAR_EQUALS; +extern Symbol2 FONT_CHAR_PAR_L; +extern Symbol2 FONT_CHAR_PAR_R; +extern Symbol2 FONT_CHAR_BRACKET_L; +extern Symbol2 FONT_CHAR_BRACKET_R; +extern Symbol3 FONT_CHAR_CURL_L; +extern Symbol3 FONT_CHAR_CURL_R; +extern Symbol3 FONT_CHAR_SLASH; +extern Symbol3 FONT_CHAR_BACKSLASH; +extern Symbol4 FONT_CHAR_AND; +extern Symbol1 FONT_CHAR_PIPE; +extern Symbol4 FONT_CHAR_DOLLAR; +extern Symbol5 FONT_CHAR_AT; +extern Symbol2 FONT_CHAR_LT; +extern Symbol2 FONT_CHAR_GT; +extern Symbol4 FONT_ERROR_; +extern Symbol5 FONT_CHAR_PERCENT; +extern SymbolRGB8x8 FONT_CREEPER; +extern SymbolRGB8x8 FONT_ENDERMAN; + +#endif diff --git a/src/patrix/display/DisplayMatrix_FontUpper.cpp b/src/patrix/display/DisplayMatrix_FontUpper.cpp new file mode 100644 index 0000000..55cc2eb --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontUpper.cpp @@ -0,0 +1,186 @@ +#include "DisplayMatrix_FontUpper.h" + +Symbol5 FONT_UPPER[] = { + { + {_,_,X,_,_}, + {_,X,_,X,_}, + {X,_,_,_,X}, + {X,X,X,X,X}, + {X,_,_,_,X}, + }, + { + {X,X,X,_,_}, + {X,_,_,X,_}, + {X,X,X,_,_}, + {X,_,_,X,_}, + {X,X,X,_,_}, + }, + { + {_,X,X,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + {_,X,X,_,_}, + }, + { + {X,X,X,_,_}, + {X,_,_,X,_}, + {X,_,_,X,_}, + {X,_,_,X,_}, + {X,X,X,_,_}, + }, + { + {X,X,X,X,_}, + {X,_,_,_,_}, + {X,X,X,_,_}, + {X,_,_,_,_}, + {X,X,X,X,_}, + }, + { + {X,X,X,X,_}, + {X,_,_,_,_}, + {X,X,X,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + }, + { + {_,X,X,X,_}, + {X,_,_,_,_}, + {X,_,X,X,X}, + {X,_,_,_,X}, + {_,X,X,X,_}, + }, + { + {X,_,_,X,_}, + {X,_,_,X,_}, + {X,X,X,X,_}, + {X,_,_,X,_}, + {X,_,_,X,_}, + }, + { + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + }, + { + {X,X,X,_,_}, + {_,_,X,_,_}, + {_,_,X,_,_}, + {X,_,X,_,_}, + {_,X,_,_,_}, + }, + { + {X,_,_,X,_}, + {X,_,X,_,_}, + {X,X,_,_,_}, + {X,_,X,_,_}, + {X,_,_,X,_}, + }, + { + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + {X,X,X,_,_}, + }, + { + {X,_,_,_,X}, + {X,X,_,X,X}, + {X,_,X,_,X}, + {X,_,_,_,X}, + {X,_,_,_,X}, + }, + { + {X,_,_,_,X}, + {X,X,_,_,X}, + {X,_,X,_,X}, + {X,_,_,X,X}, + {X,_,_,_,X}, + }, + { + {_,X,X,X,_}, + {X,_,_,_,X}, + {X,_,_,_,X}, + {X,_,_,_,X}, + {_,X,X,X,_}, + }, + { + {X,X,X,_,_}, + {X,_,_,X,_}, + {X,X,X,_,_}, + {X,_,_,_,_}, + {X,_,_,_,_}, + }, + { + {_,X,X,X,_}, + {X,_,_,_,X}, + {X,_,X,_,X}, + {X,_,_,X,_}, + {_,X,X,_,X}, + }, + { + {X,X,X,_,_}, + {X,_,_,X,_}, + {X,X,X,_,_}, + {X,_,X,_,_}, + {X,_,_,X,_}, + }, + { + {_,X,X,X,_}, + {X,_,_,_,_}, + {_,X,X,_,_}, + {_,_,_,X,_}, + {X,X,X,_,_}, + }, + { + {X,X,X,X,X}, + {_,_,X,_,_}, + {_,_,X,_,_}, + {_,_,X,_,_}, + {_,_,X,_,_}, + }, + { + {X,_,_,_,X}, + {X,_,_,_,X}, + {X,_,_,_,X}, + {X,_,_,_,X}, + {_,X,X,X,_}, + }, + { + {X,_,_,_,X}, + {X,_,_,_,X}, + {_,X,_,X,_}, + {_,X,_,X,_}, + {_,_,X,_,_}, + }, + { + {X,_,_,_,X}, + {X,_,_,_,X}, + {X,_,X,_,X}, + {X,X,_,X,X}, + {X,_,_,_,X}, + }, + { + {X,_,_,_,X}, + {_,X,_,X,_}, + {_,_,X,_,_}, + {_,X,_,X,_}, + {X,_,_,_,X}, + }, + { + {X,_,_,_,X}, + {_,X,_,X,_}, + {_,_,X,_,_}, + {_,X,_,_,_}, + {X,_,_,_,_}, + }, + { + {X,X,X,X,X}, + {_,_,_,X,_}, + {_,_,X,_,_}, + {_,X,_,_,_}, + {X,X,X,X,X}, + }, +}; diff --git a/src/patrix/display/DisplayMatrix_FontUpper.h b/src/patrix/display/DisplayMatrix_FontUpper.h new file mode 100644 index 0000000..39d4b93 --- /dev/null +++ b/src/patrix/display/DisplayMatrix_FontUpper.h @@ -0,0 +1,8 @@ +#ifndef DISPLAY_MATRIX_FONT_UPPER_H +#define DISPLAY_MATRIX_FONT_UPPER_H + +#include "DisplayMatrix_FontCommon.h" + +extern Symbol5 FONT_UPPER[]; + +#endif diff --git a/src/patrix/display/DisplayMatrix_common.cpp b/src/patrix/display/DisplayMatrix_common.cpp new file mode 100644 index 0000000..c3f9670 --- /dev/null +++ b/src/patrix/display/DisplayMatrix_common.cpp @@ -0,0 +1,14 @@ +#include "DisplayMatrix_common.h" + +//@formatter:off +const Color Transparent { 0, 0, 0, 0}; +const Color Black { 0, 0, 0, 255}; +const Color Red {255, 0, 0, 255}; +const Color Yellow {255, 255, 0, 255}; +const Color Green { 0, 255, 0, 255}; +const Color Cyan { 0, 255, 255, 255}; +const Color Blue { 0, 0, 255, 255}; +const Color Magenta {255, 0, 255, 255}; +const Color Gray {127, 127, 127, 255}; +const Color White {255, 255, 255, 255}; +//@formatter:on diff --git a/src/patrix/display/DisplayMatrix_common.h b/src/patrix/display/DisplayMatrix_common.h new file mode 100644 index 0000000..ff59700 --- /dev/null +++ b/src/patrix/display/DisplayMatrix_common.h @@ -0,0 +1,42 @@ +#ifndef DISPLAY_MATRIX_COMMON_H +#define DISPLAY_MATRIX_COMMON_H + +#include + +#define _ false +#define X true + +#define countof(a) (sizeof(a)/sizeof(a[0])) + +struct Color { + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; + + void blend(const Color other, const uint8_t alpha) { + const auto thisFactor = other.a * alpha / (255.0 * 255.0); + const auto otherFactor = 1.0 - thisFactor; + blend(&this->r, thisFactor, other.r, otherFactor); + blend(&this->g, thisFactor, other.g, otherFactor); + blend(&this->b, thisFactor, other.b, otherFactor); + } + + static void blend(uint8_t *thisValue, const double thisFactor, const uint8_t otherValue, const double otherFactor) { + *thisValue = static_cast(round(max(0.0, min(255.0, (*thisValue * thisFactor + otherValue * otherFactor) / 2.0)))); + } + +}; + +extern const Color Transparent; +extern const Color Black; +extern const Color Red; +extern const Color Yellow; +extern const Color Green; +extern const Color Cyan; +extern const Color Blue; +extern const Color Magenta; +extern const Color Gray; +extern const Color White; + +#endif diff --git a/src/patrix/display/DisplayMatrix_draw.h b/src/patrix/display/DisplayMatrix_draw.h new file mode 100644 index 0000000..2199b23 --- /dev/null +++ b/src/patrix/display/DisplayMatrix_draw.h @@ -0,0 +1,21 @@ +#ifndef DISPLAY_MATRIX_DRAW_H +#define DISPLAY_MATRIX_DRAW_H + +template +void DisplayMatrix::clear() { + const auto backup = foreground; + foreground = Black; + this->fillRect(); + foreground = backup; +} + +template +void DisplayMatrix::fillRect(const int w, const int h) const { + for (auto y = cursorY; y < cursorY + h; ++y) { + for (auto x = cursorX; x < cursorX + w; ++x) { + matrix[y][x].blend(foreground, alpha); + } + } +} + +#endif diff --git a/src/patrix/display/DisplayMatrix_print.h b/src/patrix/display/DisplayMatrix_print.h new file mode 100644 index 0000000..8843ff5 --- /dev/null +++ b/src/patrix/display/DisplayMatrix_print.h @@ -0,0 +1,154 @@ +#ifndef DISPLAYMATRIX_PRINT_H +#define DISPLAYMATRIX_PRINT_H + +#include "DisplayMatrix_FontLower.h" +#include "DisplayMatrix_FontNumber.h" +#include "DisplayMatrix_FontSpecial.h" +#include "DisplayMatrix_FontUpper.h" + +template +void DisplayMatrix::printf(const char *format, ...) { + char buffer[64]; + va_list args; + va_start(args, format); + vsnprintf(buffer, sizeof buffer, format, args); + va_end(args); + print(buffer); +} + +template +void DisplayMatrix::print(const char *str) { + while (*str != '\0') { + print(&str); + } +} + +template +void DisplayMatrix::print(const char **cPP) { + const auto a = *(*cPP)++; + auto b = '\0'; + auto c = '\0'; + if ('a' <= a && a <= 'z') { + return print(FONT_LOWER[a - 'a']); + } + if ('A' <= a && a <= 'Z') { + return print(FONT_UPPER[a - 'A']); + } + if ('0' <= a && a <= '9') { + return print(FONT_NUMBER[a - '0']); + } + if (a == 0xC2) { + b = *(*cPP)++; + switch (b) { + case 0xB0: return print(FONT_CHAR_DEGREE); + default: return print(FONT_ERROR_); + } + } + if (a == 0xE2) { + b = *(*cPP)++; + switch (b) { + case 0x82: + c = *(*cPP)++; + switch (c) { + case 0xAC: return print(FONT_CHAR_EURO); + default: return print(FONT_ERROR_); + } + default: return print(FONT_ERROR_); + } + } + switch (a) { + case ' ': return print(FONT_CHAR_SPACE); + case '-': return print(FONT_CHAR_MINUS); + case '+': return print(FONT_CHAR_PLUS); + case '_': return print(FONT_CHAR_UNDERLINE); + case '%': return print(FONT_CHAR_PERCENT); + case '?': return print(FONT_CHAR_QUESTION); + case '!': return print(FONT_CHAR_EXCLAMATION); + case '.': return print(FONT_CHAR_POINT); + case ',': return print(FONT_CHAR_COMMA); + case ';': return print(FONT_CHAR_SEMICOLON); + case ':': return print(FONT_CHAR_COLON); + case '#': return print(FONT_CHAR_SHARP); + case '~': return print(FONT_CHAR_TILDE); + case '*': return print(FONT_CHAR_ASTERISK); + case '"': return print(FONT_CHAR_QUOTE_DOUBLE); + case '\'': return print(FONT_CHAR_QUOTE_SINGLE); + case '=': return print(FONT_CHAR_EQUALS); + case '(': return print(FONT_CHAR_PAR_L); + case ')': return print(FONT_CHAR_PAR_R); + case '[': return print(FONT_CHAR_BRACKET_L); + case ']': return print(FONT_CHAR_BRACKET_R); + case '{': return print(FONT_CHAR_CURL_L); + case '}': return print(FONT_CHAR_CURL_R); + case '/': return print(FONT_CHAR_SLASH); + case '\\': return print(FONT_CHAR_BACKSLASH); + case '&': return print(FONT_CHAR_AND); + case '|': return print(FONT_CHAR_PIPE); + case '$': return print(FONT_CHAR_DOLLAR); + case '@': return print(FONT_CHAR_AT); + case '<': return print(FONT_CHAR_LT); + case '>': return print(FONT_CHAR_GT); + default: return print(FONT_ERROR_); + + } +} + +template +void DisplayMatrix::print(Symbol1 s) { + print(reinterpret_cast(s),countof(Symbol1),countof(Symbol1[0])); +} + +template +void DisplayMatrix::print(Symbol2 s) { + print(reinterpret_cast(s),countof(Symbol2),countof(Symbol2[0])); +} + +template +void DisplayMatrix::print(Symbol3 s) { + print(reinterpret_cast(s),countof(Symbol3),countof(Symbol3[0])); +} + +template +void DisplayMatrix::print(Symbol4 s) { + print(reinterpret_cast(s),countof(Symbol4),countof(Symbol4[0])); +} + +template +void DisplayMatrix::print(Symbol5 s) { + print(reinterpret_cast(s),countof(Symbol5),countof(Symbol5[0])); +} + +template +void DisplayMatrix::print(bool **s, const size_t w, const size_t h) { + auto xMax = 0; + for (auto y = 0; y < h; y++) { + for (auto x = 0; x < w; x++) { + const auto c = s[y][x]; + if (c) { + matrix[y][x].blend(foreground, alpha); + xMax = x > xMax ? x : xMax; + } else { + matrix[y][x].blend(background, alpha); + } + } + } + cursorX += xMax; +} + +template +void DisplayMatrix::print(SymbolRGB8x8 s) { + print(reinterpret_cast(s),countof(SymbolRGB8x8),countof(SymbolRGB8x8[0])); +} + +template +void DisplayMatrix::print(Color **s, const size_t w, const size_t h) { + for (auto y = 0; y < h; y++) { + for (auto x = 0; x < w; x++) { + const auto color = s[y][x]; + matrix[y][x].blend(color, alpha); + } + } + cursorX += w; +} + +#endif