MCPcopy Create free account
hub / github.com/OpenEPaperLink/OpenEPaperLink / drawElement

Function drawElement

ESP32_AP-Flasher/src/contentmanager.cpp:2886–2971  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2884 return 1;
2885}
2886void drawElement(const JsonObject &element, TFT_eSprite &spr, imgParam &imageParams, uint8_t &currentOrientation) {
2887 if (element["text"].is<JsonArray>()) {
2888 const JsonArray &textArray = element["text"];
2889 const uint16_t align = textArray[5] | 0;
2890 const uint16_t size = textArray[6] | 0;
2891 const String bgcolorstr = textArray[7].as<String>();
2892 const uint16_t bgcolor = (bgcolorstr.length() > 0) ? getColor(bgcolorstr) : TFT_WHITE;
2893 drawString(spr, textArray[2], textArray[0].as<int>(), textArray[1].as<int>(), textArray[3], align, getColor(textArray[4]), size, bgcolor);
2894 } else if (element["textbox"].is<JsonArray>()) {
2895 // posx, posy, width, height, text, font, color, lineheight, align
2896 const JsonArray &textArray = element["textbox"];
2897 float lineheight = textArray[7].as<float>();
2898 if (lineheight == 0) lineheight = 1;
2899 int16_t posx = textArray[0] | 0;
2900 int16_t posy = textArray[1] | 0;
2901 String text = textArray[4];
2902 const uint16_t align = textArray[8] | 0;
2903 drawTextBox(spr, text, posx, posy, textArray[2], textArray[3], textArray[5], getColor(textArray[6]), TFT_WHITE, lineheight, align);
2904 } else if (element["box"].is<JsonArray>()) {
2905 const JsonArray &boxArray = element["box"];
2906 spr.fillRect(boxArray[0].as<int>(), boxArray[1].as<int>(), boxArray[2].as<int>(), boxArray[3].as<int>(), getColor(boxArray[4]));
2907 if (boxArray.size()>=7) {
2908 for (int i=0; i < boxArray[6].as<int>(); i++) {
2909 spr.drawRect(boxArray[0].as<int>() + i, boxArray[1].as<int>() + i, boxArray[2].as<int>() - 2 * i, boxArray[3].as<int>() - 2 * i, getColor(boxArray[5]));
2910 }
2911 }
2912 } else if (element["rbox"].is<JsonArray>()) {
2913 const JsonArray &rboxArray = element["rbox"];
2914 spr.fillRoundRect(rboxArray[0].as<int>(), rboxArray[1].as<int>(), rboxArray[2].as<int>(), rboxArray[3].as<int>(), rboxArray[4].as<int>(), getColor(rboxArray[5]));
2915 if (rboxArray.size() >= 8) {
2916 for (int i = 0; i < rboxArray[7].as<int>(); i++) {
2917 spr.drawRoundRect(rboxArray[0].as<int>() + i, rboxArray[1].as<int>() + i, rboxArray[2].as<int>() - 2 * i, rboxArray[3].as<int>() - 2 * i, rboxArray[4].as<int>() - i / 1.41, getColor(rboxArray[6]));
2918 if (i > 0) {
2919 spr.drawRoundRect(rboxArray[0].as<int>() + i - 1, rboxArray[1].as<int>() + i, rboxArray[2].as<int>() - 2 * i + 2, rboxArray[3].as<int>() - 2 * i, rboxArray[4].as<int>() - i / 1.41, getColor(rboxArray[6]));
2920 }
2921 }
2922 }
2923 } else if (element["line"].is<JsonArray>()) {
2924 const JsonArray &lineArray = element["line"];
2925 spr.drawLine(lineArray[0].as<int>(), lineArray[1].as<int>(), lineArray[2].as<int>(), lineArray[3].as<int>(), getColor(lineArray[4]));
2926 } else if (element["triangle"].is<JsonArray>()) {
2927 const JsonArray &lineArray = element["triangle"];
2928 spr.fillTriangle(lineArray[0].as<int>(), lineArray[1].as<int>(), lineArray[2].as<int>(), lineArray[3].as<int>(), lineArray[4].as<int>(), lineArray[5].as<int>(), getColor(lineArray[6]));
2929 } else if (element["circle"].is<JsonArray>()) {
2930 const JsonArray &circleArray = element["circle"];
2931 spr.fillCircle(circleArray[0].as<int>(), circleArray[1].as<int>(), circleArray[2].as<int>(), getColor(circleArray[3]));
2932 if (circleArray.size() >= 6) {
2933 for (int i = 0; i < circleArray[5].as<int>(); i++) {
2934 spr.drawCircle(circleArray[0].as<int>(), circleArray[1].as<int>(), circleArray[2].as<int>() - i, getColor(circleArray[4]));
2935 if (i > 0) {
2936 spr.drawCircle(circleArray[0].as<int>(), circleArray[1].as<int>(), circleArray[2].as<int>() - i - 0.5, getColor(circleArray[4]));
2937 }
2938 }
2939 }
2940 } else if (element["image"].is<JsonArray>()) {
2941 const JsonArray &imgArray = element["image"];
2942
2943 TJpgDec.setSwapBytes(true);

Callers 2

drawAPinfoFunction · 0.85
drawJsonStreamFunction · 0.85

Calls 15

getColorFunction · 0.85
drawStringFunction · 0.85
drawTextBoxFunction · 0.85
wsErrFunction · 0.85
rotateBufferFunction · 0.85
fillRectMethod · 0.80
drawRectMethod · 0.80
fillRoundRectMethod · 0.80
drawRoundRectMethod · 0.80
drawLineMethod · 0.80
fillTriangleMethod · 0.80
fillCircleMethod · 0.80

Tested by

no test coverage detected