colors
This commit is contained in:
@@ -16,8 +16,10 @@
|
||||
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
TextNode text_nodes[MAX_TEXT_NODES_COUNT];
|
||||
MultiColorTextNode multi_color_text_node[MAX_TEXT_NODES_COUNT];
|
||||
Cursor cursor;
|
||||
short ever_created_text_nodes = 0;
|
||||
unsigned char ever_created_text_nodes = 0;
|
||||
unsigned char ever_created_multi_color_text_nodes = 0;
|
||||
|
||||
Image saved_images[MAX_IMAGES_SAVED] = {
|
||||
{},{}
|
||||
@@ -133,6 +135,121 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
|
||||
}
|
||||
}
|
||||
|
||||
void addNewMultiColor
|
||||
(
|
||||
char text[TEXT_MAX_LENGTH + 1], RGBWithIndex colors[4], unsigned char color_count, bool handle_pos_via_cursor = true, short pos_x = 0, short pos_y = 0,
|
||||
unsigned char scroll_slowness = 1, bool is_scrolling = true, bool is_small = true
|
||||
)
|
||||
{
|
||||
unsigned char text_length = strlen(text);
|
||||
if (text_length == 0){return;}
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (multi_color_text_node[i].is_deleted)
|
||||
{
|
||||
strncpy(multi_color_text_node[i].content, text, TEXT_MAX_LENGTH);
|
||||
multi_color_text_node[i].color_count = color_count;
|
||||
for(int j = 0; j < color_count; j++)
|
||||
{
|
||||
multi_color_text_node[i].colors[j] = colors[j];
|
||||
}
|
||||
|
||||
if (handle_pos_via_cursor)
|
||||
{
|
||||
multi_color_text_node[i].pos_x = cursor.x;
|
||||
multi_color_text_node[i].pos_y = cursor.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
multi_color_text_node[i].pos_x = pos_x;
|
||||
multi_color_text_node[i].pos_y = pos_y;
|
||||
}
|
||||
|
||||
multi_color_text_node[i].characterSize.height = is_small ? SMALL_TEXT_HEIGHT : MEDIUM_TEXT_HEIGHT;
|
||||
multi_color_text_node[i].characterSize.width = is_small ? SMALL_TEXT_WIDTH : MEDIUM_TEXT_WIDTH;
|
||||
multi_color_text_node[i].character_count = text_length;
|
||||
multi_color_text_node[i].scroll_slowness = scroll_slowness;
|
||||
multi_color_text_node[i].is_scrolling = is_scrolling;
|
||||
multi_color_text_node[i].is_deleted = false;
|
||||
ever_created_multi_color_text_nodes++;
|
||||
|
||||
if (handle_pos_via_cursor)
|
||||
{
|
||||
cursor.x += (multi_color_text_node[i].characterSize.width + 1) * text_length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
short getMultiColorTextNodeX2(MultiColorTextNode *node)
|
||||
{
|
||||
if (node->character_count == 0) return node->pos_x;
|
||||
return node->pos_x + (node->characterSize.width * node->character_count) + (node->character_count - 1) - 1;
|
||||
}
|
||||
|
||||
void scrollAllMultiColorTexts(bool split_scroll_mode = false)
|
||||
{
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (multi_color_text_node[i].is_deleted) {continue;}
|
||||
|
||||
if (multi_color_text_node[i].is_scrolling)
|
||||
{
|
||||
if (multi_color_text_node[i].scroll_slowness > multi_color_text_node[i].scroll_progress)
|
||||
{
|
||||
multi_color_text_node[i].scroll_progress++;
|
||||
}
|
||||
else
|
||||
{
|
||||
multi_color_text_node[i].scroll_progress = 0;
|
||||
|
||||
short x1 = multi_color_text_node[i].pos_x;
|
||||
short x2 = getMultiColorTextNodeX2(&multi_color_text_node[i]);
|
||||
if (split_scroll_mode || multi_color_text_node[i].pos_y < 7)
|
||||
{
|
||||
if (x2 < 0)
|
||||
{
|
||||
multi_color_text_node[i].is_deleted = true;
|
||||
continue;
|
||||
}
|
||||
multi_color_text_node[i].pos_x--;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x1 > DISPLAY_MAX_X)
|
||||
{
|
||||
multi_color_text_node[i].is_deleted = true;
|
||||
continue;
|
||||
}
|
||||
multi_color_text_node[i].pos_x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cursor.x = multi_color_text_node[i].pos_x;
|
||||
cursor.y = multi_color_text_node[i].pos_y;
|
||||
|
||||
uint32_t current_color = pixels.Color(multi_color_text_node[i].colors[0].r, multi_color_text_node[i].colors[0].g, multi_color_text_node[i].colors[0].b);
|
||||
unsigned char color_index = 0;
|
||||
|
||||
for (unsigned char j = 0; j < multi_color_text_node[i].character_count; j++)
|
||||
{
|
||||
if (color_index < multi_color_text_node[i].color_count - 1 && multi_color_text_node[i].colors[color_index+1].start_index == j)
|
||||
{
|
||||
color_index++;
|
||||
current_color = pixels.Color(multi_color_text_node[i].colors[color_index].r, multi_color_text_node[i].colors[color_index].g, multi_color_text_node[i].colors[color_index].b);
|
||||
}
|
||||
char ch = multi_color_text_node[i].content[j];
|
||||
if (ch < '!' || ch > '~')
|
||||
{
|
||||
ch = ' ';
|
||||
}
|
||||
drawCharacter(font7x5[ch - ' '], multi_color_text_node[i].characterSize.height, multi_color_text_node[i].characterSize.width, current_color, &cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawImageFromMemoryByIndex(unsigned char image_index, short pos_x, short pos_y, unsigned char brightness)
|
||||
{
|
||||
Image* img = &saved_images[image_index];
|
||||
@@ -143,12 +260,12 @@ void drawImageFromMemoryByIndex(unsigned char image_index, short pos_x, short po
|
||||
};
|
||||
|
||||
for (unsigned char y = 0; y < img->height; y++)
|
||||
{
|
||||
for (unsigned char x = 0; x < img->width; x++)
|
||||
{
|
||||
for (unsigned char x = 0; x < img->width; x++)
|
||||
{
|
||||
setPixel(x + pos_x, y + pos_y, pixels.Color(dimBy(img->pixels[y][x].r), dimBy(img->pixels[y][x].g), dimBy(img->pixels[y][x].b)));
|
||||
}
|
||||
setPixel(x + pos_x, y + pos_y, pixels.Color(dimBy(img->pixels[y][x].r), dimBy(img->pixels[y][x].g), dimBy(img->pixels[y][x].b)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
@@ -162,6 +279,9 @@ void setup()
|
||||
addNewTextNode("NET", 0xFF050505, false, 0, 0);
|
||||
addNewTextNode("AWAIT", 0xFF050505, false, 0, 9);
|
||||
|
||||
RGBWithIndex colors[2] = {RGBWithIndex(255, 0, 0, 0), RGBWithIndex(0, 0, 255, 6)};
|
||||
addNewMultiColor("HELLO WORLD", colors, 2, false, 0, 0, 1, true, true);
|
||||
|
||||
pixels.show();
|
||||
start_server();
|
||||
}
|
||||
@@ -170,19 +290,8 @@ void loop()
|
||||
{
|
||||
pixels.clear();
|
||||
handle_server();
|
||||
|
||||
if (saved_images[0].width > 0)
|
||||
{
|
||||
drawImageFromMemoryByIndex(0, 0, 0, brightness);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (text_nodes[0].is_deleted && text_nodes[2].is_deleted)
|
||||
{
|
||||
|
||||
}
|
||||
scrollAllScrollableTexts();
|
||||
}
|
||||
scrollAllScrollableTexts();
|
||||
scrollAllMultiColorTexts();
|
||||
|
||||
pixels.show();
|
||||
}
|
||||
Reference in New Issue
Block a user