ai added lifespans
This commit is contained in:
@@ -41,14 +41,14 @@ short getTextNodeX2(TextNode *node)
|
||||
void addNewTextNode
|
||||
(
|
||||
char text[TEXT_MAX_LENGTH + 1], uint32_t color, 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 scroll_slowness = 1, bool is_scrolling = true, bool is_small = true, short disappear_time = -1
|
||||
)
|
||||
{
|
||||
unsigned char text_length = strlen(text);
|
||||
if (text_length == 0){return;}
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (text_nodes[i].is_deleted)
|
||||
if (text_nodes[i].disappear_time == 0)
|
||||
{
|
||||
strncpy(text_nodes[i].content, text, TEXT_MAX_LENGTH);
|
||||
text_nodes[i].color = color;
|
||||
@@ -69,7 +69,7 @@ void addNewTextNode
|
||||
text_nodes[i].character_count = text_length;
|
||||
text_nodes[i].scroll_slowness = scroll_slowness;
|
||||
text_nodes[i].is_scrolling = is_scrolling;
|
||||
text_nodes[i].is_deleted = false;
|
||||
text_nodes[i].disappear_time = disappear_time;
|
||||
ever_created_text_nodes++;
|
||||
|
||||
if (handle_pos_via_cursor)
|
||||
@@ -85,7 +85,7 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
|
||||
{
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (text_nodes[i].is_deleted) {continue;}
|
||||
if (text_nodes[i].disappear_time == 0) {continue;}
|
||||
|
||||
if (text_nodes[i].is_scrolling)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
|
||||
{
|
||||
if (x2 < 0)
|
||||
{
|
||||
text_nodes[i].is_deleted = true;
|
||||
text_nodes[i].disappear_time = 1;
|
||||
continue;
|
||||
}
|
||||
text_nodes[i].pos_x--;
|
||||
@@ -112,7 +112,7 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
|
||||
{
|
||||
if (x1 > DISPLAY_MAX_X)
|
||||
{
|
||||
text_nodes[i].is_deleted = true;
|
||||
text_nodes[i].disappear_time = 1;
|
||||
continue;
|
||||
}
|
||||
text_nodes[i].pos_x++;
|
||||
@@ -138,14 +138,14 @@ 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 scroll_slowness = 1, bool is_scrolling = true, bool is_small = true, short disappear_time = -1
|
||||
)
|
||||
{
|
||||
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)
|
||||
if (multi_color_text_node[i].disappear_time == 0)
|
||||
{
|
||||
strncpy(multi_color_text_node[i].content, text, TEXT_MAX_LENGTH);
|
||||
multi_color_text_node[i].color_count = color_count;
|
||||
@@ -170,7 +170,7 @@ void addNewMultiColor
|
||||
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;
|
||||
multi_color_text_node[i].disappear_time = disappear_time;
|
||||
ever_created_multi_color_text_nodes++;
|
||||
|
||||
if (handle_pos_via_cursor)
|
||||
@@ -192,7 +192,7 @@ 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].disappear_time == 0) {continue;}
|
||||
|
||||
if (multi_color_text_node[i].is_scrolling)
|
||||
{
|
||||
@@ -210,7 +210,7 @@ void scrollAllMultiColorTexts(bool split_scroll_mode = false)
|
||||
{
|
||||
if (x2 < 0)
|
||||
{
|
||||
multi_color_text_node[i].is_deleted = true;
|
||||
multi_color_text_node[i].disappear_time = 1;
|
||||
continue;
|
||||
}
|
||||
multi_color_text_node[i].pos_x--;
|
||||
@@ -219,7 +219,7 @@ void scrollAllMultiColorTexts(bool split_scroll_mode = false)
|
||||
{
|
||||
if (x1 > DISPLAY_MAX_X)
|
||||
{
|
||||
multi_color_text_node[i].is_deleted = true;
|
||||
multi_color_text_node[i].disappear_time = 1;
|
||||
continue;
|
||||
}
|
||||
multi_color_text_node[i].pos_x++;
|
||||
@@ -268,6 +268,36 @@ void drawImageFromMemoryByIndex(unsigned char image_index, short pos_x, short po
|
||||
}
|
||||
}
|
||||
|
||||
void handleDisappearTimers()
|
||||
{
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (text_nodes[i].disappear_time > 0)
|
||||
{
|
||||
text_nodes[i].disappear_time--;
|
||||
if (text_nodes[i].disappear_time == 0)
|
||||
{
|
||||
fillPixels(text_nodes[i].pos_x, text_nodes[i].pos_y, getTextNodeX2(&text_nodes[i]), getTextNodeY2(&text_nodes[i]), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handleMultiColorDisappearTimers()
|
||||
{
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (multi_color_text_node[i].disappear_time > 0)
|
||||
{
|
||||
multi_color_text_node[i].disappear_time--;
|
||||
if (multi_color_text_node[i].disappear_time == 0)
|
||||
{
|
||||
fillPixels(multi_color_text_node[i].pos_x, multi_color_text_node[i].pos_y, getMultiColorTextNodeX2(&multi_color_text_node[i]), multi_color_text_node[i].pos_y + multi_color_text_node[i].characterSize.height - 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@@ -276,11 +306,11 @@ void setup()
|
||||
pixels.begin();
|
||||
pixels.clear();
|
||||
|
||||
addNewTextNode("NET", 0xFF050505, false, 0, 0);
|
||||
addNewTextNode("AWAIT", 0xFF050505, false, 0, 9);
|
||||
addNewTextNode("NET", 0xFF050505, false, 0, 0, 1, true, true, -1);
|
||||
addNewTextNode("AWAIT", 0xFF050505, false, 0, 9, 1, true, true, -1);
|
||||
|
||||
RGBWithIndex colors[2] = {RGBWithIndex(255, 0, 0, 0), RGBWithIndex(0, 0, 255, 6)};
|
||||
addNewMultiColor("HELLO WORLD", colors, 2, false, 0, 0, 1, true, true);
|
||||
addNewMultiColor("HELLO WORLD", colors, 2, false, 0, 0, 1, true, true, -1);
|
||||
|
||||
pixels.show();
|
||||
start_server();
|
||||
@@ -290,6 +320,8 @@ void loop()
|
||||
{
|
||||
pixels.clear();
|
||||
handle_server();
|
||||
handleDisappearTimers();
|
||||
handleMultiColorDisappearTimers();
|
||||
scrollAllScrollableTexts();
|
||||
scrollAllMultiColorTexts();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user