| 761 | } |
| 762 | |
| 763 | void drawTextBox(TFT_eSprite &spr, String &content, int16_t &posx, int16_t &posy, int16_t boxwidth, int16_t boxheight, String font, uint16_t color, uint16_t bgcolor, float lineheight, byte align) { |
| 764 | replaceVariables(content); |
| 765 | switch (processFontPath(font)) { |
| 766 | case 2: { |
| 767 | // truetype |
| 768 | Serial.println("truetype font not implemented for drawTextBox"); |
| 769 | } break; |
| 770 | case 3: { |
| 771 | // vlw bitmap font |
| 772 | // spr.drawRect(posx, posy, boxwidth, boxheight, TFT_BLACK); |
| 773 | spr.setTextDatum(align); |
| 774 | if (font != "") spr.loadFont(font.substring(1), *contentFS); |
| 775 | spr.setTextWrap(false, false); |
| 776 | spr.setTextColor(color, bgcolor); |
| 777 | |
| 778 | int length = content.length(); |
| 779 | int startPos = 0; |
| 780 | int startPosY = posy; |
| 781 | |
| 782 | while (startPos < length && posy + spr.gFont.yAdvance <= startPosY + boxheight) { |
| 783 | int endPos = startPos; |
| 784 | bool hasspace = false; |
| 785 | |
| 786 | while (endPos < length && spr.textWidth(content.substring(startPos, endPos + 1).c_str()) <= boxwidth && content.charAt(endPos) != '\n') { |
| 787 | if (content.charAt(endPos) == ' ' || content.charAt(endPos) == '-') hasspace = true; |
| 788 | endPos++; |
| 789 | } |
| 790 | while (endPos < length && endPos > startPos && hasspace == true && content.charAt(endPos - 1) != ' ' && content.charAt(endPos - 1) != '-' && content.charAt(endPos) != '\n') { |
| 791 | endPos--; |
| 792 | } |
| 793 | spr.drawString(content.substring(startPos, endPos), posx, posy); |
| 794 | posy += spr.gFont.yAdvance * lineheight; |
| 795 | |
| 796 | if (content.charAt(endPos) == '\n') endPos++; |
| 797 | startPos = endPos; |
| 798 | while (startPos < length && content.charAt(startPos) == ' ') { |
| 799 | startPos++; |
| 800 | } |
| 801 | } |
| 802 | if (font != "") spr.unloadFont(); |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | void initSprite(TFT_eSprite &spr, int w, int h, imgParam &imageParams) { |
| 808 | spr.setColorDepth(16); |
no test coverage detected