diff --git a/ledy.ino b/ledy.ino index 1371bd7..db37e16 100644 --- a/ledy.ino +++ b/ledy.ino @@ -77,15 +77,33 @@ void scrollAllScrollableTexts() { if (!text_nodes[i].is_deleted && text_nodes[i].is_scrolling) { + short x1 = text_nodes[i].pos_x; + short y1 = text_nodes[i].pos_y; + short x2 = text_nodes[i].pos_x + text_nodes[i].characterSize.width * text_nodes[i].character_count + text_nodes[i].character_count - 1; + short y2 = text_nodes[i].pos_y + text_nodes[i].characterSize.height - 1; + // If the text is scrolling on the upper part of the screen, scroll it to the left. if (text_nodes[i].pos_y < 7) { - shiftGivenRectangleLeft(text_nodes[i].pos_x, text_nodes[i].pos_y, text_nodes[i].pos_x + text_nodes[i].characterSize.width * text_nodes[i].character_count + text_nodes[i].character_count - 1, text_nodes[i].pos_y + text_nodes[i].characterSize.height - 1, text_nodes[i].scroll_slowness); + // If the text is completely out of the screen, mark it as deleted. + if (x2 < 0) + { + text_nodes[i].is_deleted = true; + continue; + } + shiftGivenRectangleLeft(x1, y1, x2, y2, text_nodes[i].scroll_slowness); text_nodes[i].pos_x -= text_nodes[i].scroll_slowness; } + // If the text is scrolling on the lower part of the screen, scroll it to the right. else { - shiftGivenRectangleRight(text_nodes[i].pos_x, text_nodes[i].pos_y, text_nodes[i].pos_x + text_nodes[i].characterSize.width * text_nodes[i].character_count + text_nodes[i].character_count - 1, text_nodes[i].pos_y + text_nodes[i].characterSize.height - 1, text_nodes[i].scroll_slowness); - text_nodes[i].pos_x += text_6nodes[i].scroll_slowness; + // If the text is completely out of the screen, mark it as deleted. + if (x1 > PANEL_MAX_X) + { + text_nodes[i].is_deleted = true; + continue; + } + shiftGivenRectangleRight(x1, y1, x2, y2, text_nodes[i].scroll_slowness); + text_nodes[i].pos_x += text_nodes[i].scroll_slowness; } } } diff --git a/structs.h b/structs.h index 4e14bd1..9729bdb 100644 --- a/structs.h +++ b/structs.h @@ -35,7 +35,7 @@ struct TextNode bool is_scrolling; - TextNode() : color(0), pos_x(0), pos_y(0), character_count(0), scroll_slowness(1), characterSize({7,5}), is_deleted(true), is_scrolling(true) {} + TextNode() : color(0), pos_x(0), pos_y(0), character_count(0), scroll_slowness(1), characterSize({7,5}), is_deleted(true), is_scrolling() {} }; #endif // STRUCTS_H