diff --git a/ledy.ino b/ledy.ino index f0ad1d3..63551dd 100644 --- a/ledy.ino +++ b/ledy.ino @@ -24,7 +24,8 @@ unsigned short getTextNodeY2(TextNode *node) unsigned short getTextNodeX2(TextNode *node) { - return node->pos_x + node->characterSize.width * node->character_count + node->character_count - 1; + 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 addNewTextNode diff --git a/lowLevel.h b/lowLevel.h index 6ec5f90..da7ada8 100644 --- a/lowLevel.h +++ b/lowLevel.h @@ -16,7 +16,8 @@ uint32_t getPixelColor(unsigned short x, unsigned short y); void drawImageFromSaved(unsigned short offset_x, unsigned short offset_y, unsigned char i); void drawCharacter(const bool (*character)[5], unsigned char height, unsigned char width, uint32_t color, Cursor (*used_cursor)); void fillPixels(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, uint32_t color); -void shiftGivenRectangle(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); +void shiftGivenRectangleRight(short x1, short y1, short x2, short y2, unsigned char shift_by); #endif // LOWLEVEL_H diff --git a/lowLevel.ino b/lowLevel.ino index 26aa212..74c0c6b 100644 --- a/lowLevel.ino +++ b/lowLevel.ino @@ -109,8 +109,8 @@ void drawCharacter(const bool (*character)[5], unsigned char height, unsigned ch unsigned short pixel_x = col + used_cursor->x; unsigned short pixel_y = row + used_cursor->y; - if (pixel_x >= 0 && pixel_x < NUMPIXELS && - pixel_y >= 0 && pixel_y < NUMPIXELS) + if (pixel_x <= PANEL_MAX_X && + pixel_y <= PANEL_MAX_Y) { setPixel(pixel_x, pixel_y, color); } @@ -151,27 +151,48 @@ void shiftGivenRectangleLeft(short x1, short y1, short x2, short y2, unsigned ch } if (x1 > x2) { - unsigned short tmp = x1; x1 = x2; x2 = tmp; + short tmp = x1; x1 = x2; x2 = tmp; } if (y1 > y2) { - unsigned short tmp = y1; y1 = y2; y2 = tmp; + 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 (short i = 0; i < height; i++) { - for (unsigned short j = 0; j < width + shift_by; j++) + short y = y1 + i; + if (y < 0 || y > PANEL_MAX_Y) continue; + + for (short j = 0; j < width; j++) { - setPixel(x1 + j - shift_by, y1 + i, getPixelColor(x1 + j, y1 + i)); - setPixel(x1 + j, y1 + i, 0x00000000); + short src_x = x1 + j; + short dest_x = src_x - shift_by; + + uint32_t color = 0; + if (src_x >= 0 && src_x <= PANEL_MAX_X) { + color = getPixelColor(src_x, y); + } + + if (dest_x >= 0 && dest_x <= PANEL_MAX_X) { + setPixel(dest_x, y, color); + } } } + // Clear the trailing edge that was shifted from + for (short y = y1; y <= y2; y++) { + if (y < 0 || y > PANEL_MAX_Y) continue; + for (short x = x2 - shift_by + 1; x <= x2; x++) { + if (x >= 0 && x <= PANEL_MAX_X) { + setPixel(x, y, 0); + } + } + } } -void shiftGivenRectangleRight(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned char shift_by) +void shiftGivenRectangleRight(short x1, short y1, short x2, short y2, unsigned char shift_by) { if (!shift_by) { @@ -179,22 +200,43 @@ void shiftGivenRectangleRight(unsigned short x1, unsigned short y1, unsigned sh } if (x1 > x2) { - unsigned short tmp = x1; x1 = x2; x2 = tmp; + short tmp = x1; x1 = x2; x2 = tmp; } if (y1 > y2) { - unsigned short tmp = y1; y1 = y2; y2 = tmp; + 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 (short i = 0; i < height; i++) { - for (short j = width + shift_by - 1; j >= 0; j--) + short y = y1 + i; + if (y < 0 || y > PANEL_MAX_Y) continue; + + for (short j = width - 1; j >= 0; j--) { - setPixel(x1 + j, y1 + i, getPixelColor(x1 + j - shift_by, y1 + i)); - setPixel(x1 + j - shift_by, y1 + i, 0x00000000); + short src_x = x1 + j; + short dest_x = src_x + shift_by; + + uint32_t color = 0; + if (src_x >= 0 && src_x <= PANEL_MAX_X) { + color = getPixelColor(src_x, y); + } + + if (dest_x >= 0 && dest_x <= PANEL_MAX_X) { + setPixel(dest_x, y, color); + } + } + } + // Clear the trailing edge that was shifted from + for (short y = y1; y <= y2; y++) { + if (y < 0 || y > PANEL_MAX_Y) continue; + for (short x = x1; x < x1 + shift_by; x++) { + if (x >= 0 && x <= PANEL_MAX_X) { + setPixel(x, y, 0); + } } } }