scolled text scrolled to left worksd
This commit is contained in:
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AgentMigrationStateService">
|
||||||
|
<option name="migrationStatus" value="COMPLETED" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AskMigrationStateService">
|
||||||
|
<option name="migrationStatus" value="COMPLETED" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
constexpr bool font7x5[95][7][5] =
|
constexpr bool font7x5[96][7][5] =
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
{false, false, false, false, false},
|
||||||
|
{false, false, false, false, false},
|
||||||
|
{false, false, false, false, false},
|
||||||
|
{false, false, false, false, false},
|
||||||
|
{false, false, false, false, false},
|
||||||
|
{false, false, false, false, false},
|
||||||
|
{false, false, false, false, false},
|
||||||
|
},
|
||||||
// ! (ASCII 33)
|
// ! (ASCII 33)
|
||||||
{
|
{
|
||||||
{false, false, true, false, false},
|
{false, false, true, false, false},
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
|||||||
|
|
||||||
TextNode text_nodes[MAX_TEXT_NODES_COUNT];
|
TextNode text_nodes[MAX_TEXT_NODES_COUNT];
|
||||||
|
|
||||||
|
Cursor cursor;
|
||||||
|
|
||||||
void addNewTextNode
|
void addNewTextNode
|
||||||
(
|
(
|
||||||
char text[TEXT_MAX_LENGTH + 1], uint32_t color = 0x00010101, unsigned short pos_x = 65535, unsigned short pos_y = 0,
|
char text[TEXT_MAX_LENGTH + 1], uint32_t color = 0x00010101, unsigned short pos_x = 0, unsigned short pos_y = 0,
|
||||||
bool is_small = true
|
unsigned char scroll_slowness = 1, bool is_scrolling = true, bool is_small = true
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
unsigned char text_length = strlen(text);
|
unsigned char text_length = strlen(text);
|
||||||
@@ -34,21 +36,26 @@ void addNewTextNode
|
|||||||
text_nodes[i].characterSize.height = is_small ? SMALL_TEXT_HEIGHT : MEDIUM_TEXT_HEIGHT;
|
text_nodes[i].characterSize.height = is_small ? SMALL_TEXT_HEIGHT : MEDIUM_TEXT_HEIGHT;
|
||||||
text_nodes[i].characterSize.width = is_small ? SMALL_TEXT_WIDTH : MEDIUM_TEXT_WIDTH;
|
text_nodes[i].characterSize.width = is_small ? SMALL_TEXT_WIDTH : MEDIUM_TEXT_WIDTH;
|
||||||
text_nodes[i].character_count = text_length;
|
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].is_deleted = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawTextNodes()
|
void drawTextNodes(bool reset_cursor = true)
|
||||||
{
|
{
|
||||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||||
{
|
{
|
||||||
if (!text_nodes[i].is_deleted)
|
if (!text_nodes[i].is_deleted)
|
||||||
{
|
{
|
||||||
Cursor cursor;
|
if (reset_cursor)
|
||||||
cursor.x = text_nodes[i].pos_x;
|
{
|
||||||
cursor.y = text_nodes[i].pos_y;
|
cursor.x = text_nodes[i].pos_x;
|
||||||
|
cursor.y = text_nodes[i].pos_y;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned char j = 0; j < text_nodes[i].character_count; j++)
|
for (unsigned char j = 0; j < text_nodes[i].character_count; j++)
|
||||||
{
|
{
|
||||||
@@ -57,13 +64,32 @@ void drawTextNodes()
|
|||||||
{
|
{
|
||||||
ch = ' ';
|
ch = ' ';
|
||||||
}
|
}
|
||||||
drawCharacter(font7x5[ch - '!'], text_nodes[i].characterSize.height, text_nodes[i].characterSize.width, text_nodes[i].color, &cursor);
|
|
||||||
|
drawCharacter(font7x5[ch - ' '], text_nodes[i].characterSize.height, text_nodes[i].characterSize.width, text_nodes[i].color, &cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void scrollTextNodeByAmount(unsigned )
|
void scrollAllScrollableTexts()
|
||||||
|
{
|
||||||
|
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||||
|
{
|
||||||
|
if (!text_nodes[i].is_deleted && text_nodes[i].is_scrolling)
|
||||||
|
{
|
||||||
|
if (text_nodes[i].pos_y < 7)
|
||||||
|
{
|
||||||
|
shiftGivenRectangleLeft(text_nodes[i].pos_x, text_nodes[i].pos_y, text_nodes[i].characterSize.width * text_nodes[i].character_count, text_nodes[i].characterSize.height, text_nodes[i].scroll_slowness);
|
||||||
|
text_nodes[i].pos_x -= text_nodes[i].scroll_slowness;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shiftGivenRectangleRight(text_nodes[i].pos_x, text_nodes[i].pos_y, text_nodes[i].characterSize.width * text_nodes[i].character_count, text_nodes[i].characterSize.height, text_nodes[i].scroll_slowness);
|
||||||
|
text_nodes[i].pos_x += text_nodes[i].scroll_slowness;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@@ -72,7 +98,8 @@ void setup()
|
|||||||
pixels.begin();
|
pixels.begin();
|
||||||
pixels.clear();
|
pixels.clear();
|
||||||
|
|
||||||
addNewTextNode("TEst", 0x0001700, 0, 0, true);
|
addNewTextNode("NET", 0xFF150000);
|
||||||
|
addNewTextNode("FAILED", 0xFF150000, 0, 9);
|
||||||
drawTextNodes();
|
drawTextNodes();
|
||||||
|
|
||||||
pixels.show();
|
pixels.show();
|
||||||
@@ -81,7 +108,7 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
shiftGivenRectangleLefr(0, 0, 23, 7, 1);
|
scrollAllScrollableTexts();
|
||||||
pixels.show();
|
pixels.show();
|
||||||
handle_server();
|
handle_server();
|
||||||
}
|
}
|
||||||
+27
-1
@@ -143,7 +143,7 @@ void fillPixels(unsigned short x1, unsigned short y1, unsigned short x2, unsigne
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void shiftGivenRectangleLefr(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned char shift_by)
|
void shiftGivenRectangleLeft(short x1, short y1, short x2, short y2, unsigned char shift_by)
|
||||||
{
|
{
|
||||||
if (!shift_by)
|
if (!shift_by)
|
||||||
{
|
{
|
||||||
@@ -171,4 +171,30 @@ void shiftGivenRectangleLefr(unsigned short x1, unsigned short y1, unsigned shor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void shiftGivenRectangleRight(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned char shift_by)
|
||||||
|
{
|
||||||
|
if (!shift_by)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (x1 > x2)
|
||||||
|
{
|
||||||
|
unsigned short tmp = x1; x1 = x2; x2 = tmp;
|
||||||
|
}
|
||||||
|
if (y1 > y2)
|
||||||
|
{
|
||||||
|
unsigned short tmp = y1; y1 = y2; y2 = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short width = (unsigned short)(x2 - x1 + 1);
|
||||||
|
unsigned short height = (unsigned short)(y2 - y1 + 1);
|
||||||
|
|
||||||
|
for (unsigned short i = 0; i < height; i++)
|
||||||
|
{
|
||||||
|
for (unsigned short j = 0; j < width + shift_by; j++)
|
||||||
|
{
|
||||||
|
setPixel(x1 + j - shift_by, y1 - 1 , getPixelColor(x1 + j, y1 + i));
|
||||||
|
setPixel(x1 + j, y1 + i, 0x00000000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,11 +30,12 @@ struct TextNode
|
|||||||
unsigned short width;
|
unsigned short width;
|
||||||
} characterSize;
|
} characterSize;
|
||||||
unsigned char character_count;
|
unsigned char character_count;
|
||||||
|
unsigned char scroll_slowness;
|
||||||
bool is_deleted;
|
bool is_deleted;
|
||||||
bool is_scrolled;
|
bool is_scrolling;
|
||||||
|
|
||||||
|
|
||||||
TextNode() : color(0), pos_x(0), pos_y(0), character_count(0), characterSize({7,5}), is_deleted(true) {}
|
TextNode() : color(0), pos_x(0), pos_y(0), character_count(0), scroll_slowness(1), characterSize({7,5}), is_deleted(true), is_scrolling(true) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STRUCTS_H
|
#endif // STRUCTS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user