Stuff from text.h is now const.
This commit is contained in:
parent
540b188058
commit
26761226d0
@ -13,9 +13,9 @@ class BigClockEffect : public Effect {
|
|||||||
|
|
||||||
void drawText(char *text, int x, int y, CRGB color);
|
void drawText(char *text, int x, int y, CRGB color);
|
||||||
|
|
||||||
unsigned char* font_char(unsigned char* font, char c);
|
const unsigned char* font_char(const unsigned char* font, char c);
|
||||||
|
|
||||||
void drawSprite(unsigned char* sprite, int xOffset, int yOffset, CRGB color);
|
void drawSprite(const unsigned char* sprite, int xOffset, int yOffset, CRGB color);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void loop();
|
void loop();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
|
|
||||||
static unsigned char font5x7[] = {
|
const unsigned char font5x7[] = {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00,// (space)
|
0x00, 0x00, 0x00, 0x00, 0x00,// (space)
|
||||||
0x00, 0x00, 0x5F, 0x00, 0x00,// !
|
0x00, 0x00, 0x5F, 0x00, 0x00,// !
|
||||||
0x00, 0x07, 0x00, 0x07, 0x00,// "
|
0x00, 0x07, 0x00, 0x07, 0x00,// "
|
||||||
@ -102,7 +102,7 @@ static unsigned char font5x7[] = {
|
|||||||
0x08, 0x1C, 0x2A, 0x08, 0x08 // <-
|
0x08, 0x1C, 0x2A, 0x08, 0x08 // <-
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned char numbers4x7[] = {
|
const unsigned char numbers4x7[] = {
|
||||||
0x3E, 0x51, 0x45, 0x3E,// 0
|
0x3E, 0x51, 0x45, 0x3E,// 0
|
||||||
0x00, 0x42, 0x7F, 0x40,// 1
|
0x00, 0x42, 0x7F, 0x40,// 1
|
||||||
0x42, 0x61, 0x49, 0x46,// 2
|
0x42, 0x61, 0x49, 0x46,// 2
|
||||||
@ -115,7 +115,7 @@ static unsigned char numbers4x7[] = {
|
|||||||
0x06, 0x49, 0x29, 0x1E // 9
|
0x06, 0x49, 0x29, 0x1E // 9
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned char numbers3x5[] = {
|
const unsigned char numbers3x5[] = {
|
||||||
B01110, B10001, B01110, // 0
|
B01110, B10001, B01110, // 0
|
||||||
B01000, B11111, B00000, // 1
|
B01000, B11111, B00000, // 1
|
||||||
B01001, B10011, B01101, // 2
|
B01001, B10011, B01101, // 2
|
||||||
@ -128,12 +128,12 @@ static unsigned char numbers3x5[] = {
|
|||||||
B11101, B10101, B11111, // 9
|
B11101, B10101, B11111, // 9
|
||||||
};
|
};
|
||||||
|
|
||||||
void drawTextSprite(Window window, unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color, boolean invert);
|
void drawTextSprite(Window window, const unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color, boolean invert);
|
||||||
|
|
||||||
void drawChar(Window window, unsigned char* font, int w, int h, int x, int y, char c, CRGB color);
|
void drawChar(Window window, const unsigned char* font, int w, int h, int x, int y, char c, CRGB color);
|
||||||
|
|
||||||
void drawDigit(Window window, unsigned char* font, int w, int h, int x, int y, int digit, CRGB color, boolean invert);
|
void drawDigit(Window window, const unsigned char* font, int w, int h, int x, int y, int digit, CRGB color, boolean invert);
|
||||||
|
|
||||||
void drawText(Window window, char *font, int w, int h, char *text, int x, int y, CRGB color);
|
void drawText(Window window, const char *font, int w, int h, char *text, int x, int y, CRGB color);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,11 +16,11 @@ void BigClockEffect::drawText(char *text, int x, int y, CRGB color) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* BigClockEffect::font_char(unsigned char* font, char c) {
|
const unsigned char* BigClockEffect::font_char(const unsigned char* font, char c) {
|
||||||
return &font[(c - 48) * 4];
|
return font + (c - 48) * 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BigClockEffect::drawSprite(unsigned char* sprite, int xOffset, int yOffset, CRGB color) {
|
void BigClockEffect::drawSprite(const unsigned char* sprite, int xOffset, int yOffset, CRGB color) {
|
||||||
for ( byte y = 0; y < 7; y++) {
|
for ( byte y = 0; y < 7; y++) {
|
||||||
for ( byte x = 0; x < 4; x++) {
|
for ( byte x = 0; x < 4; x++) {
|
||||||
bool on = (sprite[x] >> y & 1) * 255;
|
bool on = (sprite[x] >> y & 1) * 255;
|
||||||
|
12
src/text.cpp
12
src/text.cpp
@ -1,7 +1,7 @@
|
|||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|
||||||
void drawTextSprite(Window window, unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color, boolean invert) {
|
void drawTextSprite(Window window, const unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color, boolean invert) {
|
||||||
for (byte y=0; y<h; y++) for (byte x=0; x<w; x++) {
|
for (byte y=0; y<h; y++) for (byte x=0; x<w; x++) {
|
||||||
bool on = (sprite[x]>>(h-1-y)&1)*255;
|
bool on = (sprite[x]>>(h-1-y)&1)*255;
|
||||||
if (invert) on = !on;
|
if (invert) on = !on;
|
||||||
@ -9,17 +9,17 @@ void drawTextSprite(Window window, unsigned char* sprite, int w, int h, int xPos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawChar(Window window, unsigned char* font, int w, int h, int x, int y, char c, CRGB color) {
|
void drawChar(Window window, const unsigned char* font, int w, int h, int x, int y, char c, CRGB color) {
|
||||||
unsigned char* sprite = &font[(c-32)*w];
|
const unsigned char* sprite = &font[(c-32)*w];
|
||||||
drawTextSprite(window, sprite, w, h, x, y, color, false);
|
drawTextSprite(window, sprite, w, h, x, y, color, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawDigit(Window window, unsigned char* font, int w, int h, int x, int y, int digit, CRGB color, boolean invert) {
|
void drawDigit(Window window, const unsigned char* font, int w, int h, int x, int y, int digit, CRGB color, boolean invert) {
|
||||||
unsigned char* sprite = &font[digit*w];
|
const unsigned char* sprite = &font[digit*w];
|
||||||
drawTextSprite(window, sprite, w, h, x, y, color, invert);
|
drawTextSprite(window, sprite, w, h, x, y, color, invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawText(Window window, char *font, int w, int h, char *text, int x, int y, CRGB color) {
|
void drawText(Window window, const char *font, int w, int h, char *text, int x, int y, CRGB color) {
|
||||||
for (uint16_t i = 0; i < strlen(text); i++) {
|
for (uint16_t i = 0; i < strlen(text); i++) {
|
||||||
drawChar(window, font5x7, 5, 7, x+i*(w+1), y, text[i], color);
|
drawChar(window, font5x7, 5, 7, x+i*(w+1), y, text[i], color);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user