Skip to content

Commit b3d0ade

Browse files
committed
Prepare for release.
1 parent f2d5f10 commit b3d0ade

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+400
-227
lines changed

examples/arduino32/dynamicMenuItems/dynamicMenuItems.emf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@
607607
"menuDefinitions": []
608608
},
609609
"packageNamespace": "",
610-
"appIsModular": false
610+
"appIsModular": false,
611+
"listOfEmbeddedForms": []
611612
},
612613
"stringLists": []
613614
}

examples/arduino32/dynamicMenuItems/generated/dynamicMenuItems_menu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ BooleanMenuItem menuMainPower(&minfoMainPower, false, &menuOven, INFO_LOCATION_P
7979
void setupMenu() {
8080
// First we set up eeprom and authentication (if needed).
8181
setSizeBasedEEPROMStorageEnabled(false);
82-
// Code generated by plugins.
82+
// Code generated by plugins and new operators.
8383
gfx.initR(INITR_BLACKTAB);
8484
gfx.setRotation(1);
8585
renderer.setUpdatesPerSecond(5);

examples/arduino32/dynamicMenuItems/generated/tcMenuAdaFruitGfx.cpp

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ using namespace tcgfx;
3434
#endif // AVR reduced size buffer
3535
#endif // COOKIE_CUT_MEMBUFFER_SIZE
3636

37+
uint16_t memBuffer[COOKIE_CUT_MEMBUFFER_SIZE];
38+
3739
void AdafruitDrawable::transaction(bool isStarting, bool redrawNeeded) {
3840
if(!isStarting) refreshDisplayIfNeeded(graphics, redrawNeeded);
3941
}
@@ -52,15 +54,58 @@ void AdafruitDrawable::drawBitmap(const Coord &where, const DrawableIcon *icon,
5254
if(icon->getIconType() == DrawableIcon::ICON_XBITMAP) {
5355
graphics->fillRect(where.x, where.y, icon->getDimensions().x, icon->getDimensions().y, backgroundColor);
5456
graphics->drawXBitmap(where.x, where.y, icon->getIcon(selected), icon->getDimensions().x, icon->getDimensions().y, drawColor);
55-
}
56-
else if(icon->getIconType() == DrawableIcon::ICON_NATIVE) {
57+
} else if(icon->getIconType() == DrawableIcon::ICON_NATIVE) {
5758
graphics->drawRGBBitmap(where.x, where.y, (const uint16_t*)icon->getIcon(selected), icon->getDimensions().x, icon->getDimensions().y);
58-
}
59-
else if(icon->getIconType() == DrawableIcon::ICON_MONO) {
59+
} else if(icon->getIconType() == DrawableIcon::ICON_MONO) {
6060
graphics->drawBitmap(where.x, where.y, icon->getIcon(selected), icon->getDimensions().x, icon->getDimensions().y, drawColor, backgroundColor);
61+
} else if(icon->getPalette() != nullptr){
62+
auto bpp = icon->getIconType() == tcgfx::DrawableIcon::ICON_PALLETE_2BPP ? 2 : 4;
63+
drawBitmapNbpp(where, icon->getIcon(selected), icon->getDimensions(), bpp, icon->getPalette());
6164
}
6265
}
6366

67+
void AdafruitDrawable::drawBitmapNbpp(const Coord& where, const uint8_t* data, const Coord& size, int bpp, const color_t* palette) {
68+
auto* asTft = reinterpret_cast<Adafruit_SPITFT *>(graphics);
69+
auto yTot = int16_t(where.y + size.y);
70+
auto xTot = int16_t(where.x + size.x);
71+
int bitsInByte = bpp == 2 ? 4 : 2;
72+
uint8_t downShift = bpp == 2 ? 6 : 4;
73+
74+
uint16_t next = 0;
75+
uint8_t byteIteration = bitsInByte;
76+
uint8_t current;
77+
78+
asTft->startWrite();
79+
80+
for(int16_t y = where.y; y<yTot; y++) {
81+
asTft->setAddrWindow(where.x, y, size.x, 1);
82+
for(int16_t x = where.x; x<xTot; x++) {
83+
if(byteIteration == bitsInByte) {
84+
current = pgm_read_byte(data);
85+
data += 1;
86+
byteIteration = 0;
87+
}
88+
uint8_t idx = current >> downShift;
89+
current = current << bpp;
90+
byteIteration++;
91+
92+
memBuffer[next] = palette[idx];
93+
next = next + 1;
94+
if(next == COOKIE_CUT_MEMBUFFER_SIZE) {
95+
asTft->writePixels(memBuffer, next);
96+
next = 0;
97+
}
98+
}
99+
if(next != 0) {
100+
asTft->writePixels(memBuffer, next);
101+
next = 0;
102+
}
103+
byteIteration = bitsInByte; // always need a new byte in this case
104+
}
105+
106+
asTft->endWrite();
107+
}
108+
64109
void AdafruitDrawable::drawXBitmap(const Coord &where, const Coord &size, const uint8_t *data) {
65110
graphics->fillRect(where.x, where.y, size.x, size.y, backgroundColor);
66111
graphics->drawXBitmap(where.x, where.y, data, size.x, size.y, drawColor);
@@ -69,8 +114,7 @@ void AdafruitDrawable::drawXBitmap(const Coord &where, const Coord &size, const
69114
void AdafruitDrawable::drawBox(const Coord &where, const Coord &size, bool filled) {
70115
if(filled) {
71116
graphics->fillRect(where.x, where.y, size.x, size.y, drawColor);
72-
}
73-
else {
117+
} else {
74118
graphics->drawRect(where.x, where.y, size.x, size.y, drawColor);
75119
}
76120
}
@@ -157,8 +201,6 @@ UnicodeFontHandler *AdafruitDrawable::createFontHandler() {
157201
// helper functions
158202
//
159203

160-
uint16_t memBuffer[COOKIE_CUT_MEMBUFFER_SIZE];
161-
162204
void drawCookieCutBitmap(Adafruit_SPITFT* gfx, int16_t x, int16_t y, const uint8_t *bitmap, int16_t w,
163205
int16_t h, int16_t totalWidth, int16_t xStart, int16_t yStart,
164206
uint16_t fgColor, uint16_t bgColor) {
@@ -519,7 +561,7 @@ DeviceDrawable *AdafruitDrawable::getSubDeviceFor(const Coord &where, const Coor
519561
}
520562

521563
AdafruitCanvasDrawable2bpp::AdafruitCanvasDrawable2bpp(AdafruitDrawable *root, int width, int height) : root(root),
522-
sizeMax({width, height}), sizeCurrent(), palette{} {
564+
sizeMax({width, height}), sizeCurrent(), palette{} {
523565
canvas = new TcGFXcanvas2(width, height);
524566
setGraphics(canvas);
525567
}
@@ -561,3 +603,26 @@ DeviceDrawable *AdafruitCanvasDrawable2bpp::getSubDeviceFor(const Coord&, const
561603
return nullptr; // don't allow further nesting.
562604
}
563605

606+
void AdafruitCanvasDrawable2bpp::drawBitmapNbpp(const Coord& where, const uint8_t* data, const Coord& size, int bpp, const uint16_t* palette) {
607+
auto yTot = int16_t(where.y + size.y);
608+
auto xTot = int16_t(where.x + size.x);
609+
int bitsInByte = bpp == 2 ? 4 : 2;
610+
uint8_t downShift = bpp == 2 ? 6 : 4;
611+
612+
uint8_t byteIteration = bitsInByte;
613+
uint8_t current;
614+
for(int16_t y = where.y; y<yTot; y++) {
615+
for(int16_t x = where.x; x<xTot; x++) {
616+
if(byteIteration == bitsInByte) {
617+
current = pgm_read_byte(data);
618+
data += 1;
619+
byteIteration = 0;
620+
}
621+
uint8_t idx = current >> downShift;
622+
current = current << bitsInByte;
623+
byteIteration++;
624+
canvas->drawPixel(x, y, idx);
625+
}
626+
byteIteration = bitsInByte; // always need a new byte in this case
627+
}
628+
}

examples/arduino32/dynamicMenuItems/generated/tcMenuAdaFruitGfx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class AdafruitDrawable : public DeviceDrawable {
176176
void internalDrawText(const Coord &where, const void *font, int mag, const char *text) override;
177177
void drawBitmap(const Coord &where, const DrawableIcon *icon, bool selected) override;
178178
void drawXBitmap(const Coord &where, const Coord &size, const uint8_t *data) override;
179+
virtual void drawBitmapNbpp(const Coord& where, const uint8_t* data, const Coord& size, int bpp, const color_t* palette);
179180
void drawBox(const Coord &where, const Coord &size, bool filled) override;
180181
void drawCircle(const Coord& where, int radius, bool filled) override;
181182
void drawPolygon(const Coord points[], int numPoints, bool filled) override;
@@ -212,6 +213,7 @@ class AdafruitCanvasDrawable2bpp : public AdafruitDrawable {
212213
void transaction(bool isStarting, bool redrawNeeded) override;
213214
color_t getUnderlyingColor(color_t col) override;
214215
DeviceDrawable *getSubDeviceFor(const Coord &where, const Coord &size, const color_t *palette, int paletteSize) override;
216+
void drawBitmapNbpp(const Coord& where, const uint8_t* data, const Coord& size, int bpp, const color_t* palette) override;
215217
};
216218

217219
#endif /* _TCMENU_TCMENUADAFRUITGFX_H_ */

examples/arduino32/stm32DuinoDemo/generated/stm32DuinoDemo_menu.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,41 +136,43 @@ void setupMenu() {
136136

137137
const uint8_t formData_MobileFriendly_d8[] {
138138
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xd5,0x96,0x5d,0x6f,0x9b,0x30,
139-
0x18,0x85,0xef,0x27,0xed,0x3f,0x58,0x96,0x7a,0x97,0x2c,0x40,0x80,0xa4,0x12,0xb4,
140-
0xca,0x12,0xb2,0x46,0x22,0x30,0x25,0xb0,0x4a,0xbb,0x41,0x26,0x76,0x2a,0x24,0x63,
141-
0x57,0x7c,0xb4,0xcd,0xbf,0xef,0x0b,0x8d,0x56,0xac,0x69,0x6d,0x2e,0x22,0x91,0xdd,
142-
0x20,0x73,0xb0,0x8e,0x1f,0x1f,0xfc,0xf1,0x3a,0xb7,0x2f,0x39,0x47,0x4f,0xac,0x28,
143-
0x33,0x29,0x5c,0xac,0x7f,0xd3,0x30,0x62,0x62,0x27,0x69,0x26,0x1e,0x5c,0x1c,0x47,
144-
0xcb,0xe1,0x14,0xa3,0xb2,0x22,0x82,0x12,0x2e,0x05,0x73,0xb1,0x90,0xf8,0xf6,0xe6,
145-
0xeb,0x17,0xc7,0xcb,0x53,0x46,0xe7,0x52,0x54,0x85,0xe4,0x28,0x95,0xa4,0xa0,0x71,
146-
0x9d,0x51,0x17,0xb3,0x1d,0xb5,0x6c,0x6d,0xb2,0x1f,0x5a,0x16,0x4b,0x87,0xa6,0x61,
147-
0x19,0x43,0x62,0xe9,0xf0,0x20,0xe9,0xc4,0xbe,0x36,0x2d,0x83,0xd2,0x31,0x46,0x9c,
148-
0x1c,0x64,0x5d,0x05,0x24,0x07,0xc7,0xb5,0x4c,0x33,0xce,0xd0,0xb2,0xc8,0x98,0xa0,
149-
0xfc,0x80,0xc1,0x1d,0x21,0x67,0xcd,0x44,0xed,0xb7,0xbd,0xca,0x56,0x50,0x24,0xb4,
150-
0x93,0xbc,0x74,0xb1,0x81,0xd1,0x1e,0x08,0x56,0x62,0x2f,0x01,0x5d,0xd3,0xae,0x30,
151-
0x2a,0xd8,0xae,0x86,0xb9,0x3c,0x81,0x6f,0x55,0xd4,0x0c,0x04,0x29,0xab,0x15,0x70,
152-
0x69,0xf8,0x68,0x73,0x34,0xf2,0x38,0xcb,0x99,0xa8,0x10,0xe1,0xd9,0x83,0x68,0x5a,
153-
0x2e,0x9e,0x7b,0x41,0xe4,0x6d,0x70,0x63,0x2e,0x8b,0x2d,0x03,0xe5,0x07,0x97,0x29,
154-
0xe1,0x8d,0xd2,0xce,0x33,0x3a,0x3c,0x82,0xef,0xf7,0x38,0x8a,0xc2,0x20,0x99,0x87,
155-
0x41,0xb4,0x09,0x7d,0xf8,0x58,0x97,0x95,0xcc,0x17,0x05,0x79,0x6e,0xd2,0x11,0x30,
156-
0x26,0x85,0xf6,0x5a,0x52,0xe8,0xbb,0xbd,0x0b,0xef,0x93,0x60,0xb6,0xf6,0xfe,0x26,
157-
0x85,0x31,0xeb,0x06,0x4c,0xbf,0xc6,0xe8,0x51,0x96,0x59,0xd5,0xfe,0x00,0x6d,0xa0,
158-
0xe1,0xd1,0x85,0x92,0x1a,0x9a,0x4a,0xaa,0x5f,0x2e,0xa9,0xde,0x25,0xd5,0x7b,0xcf,
159-
0x34,0xf9,0x35,0xf3,0xe3,0x0f,0x78,0x6d,0x15,0xb7,0xef,0x60,0x3f,0xc3,0x9d,0x74,
160-
0x71,0x8d,0xde,0xd3,0xfd,0x37,0xe8,0x54,0x05,0x3d,0x25,0x57,0xdf,0x5b,0x46,0x9f,
161-
0x62,0xde,0x85,0x9b,0xd5,0x6f,0x60,0x9c,0xf9,0xc9,0xd6,0x5f,0x2d,0xda,0x89,0x9d,
162-
0x23,0x58,0x63,0xdc,0x05,0x1e,0x0f,0x60,0x8f,0x0d,0x8c,0x8b,0x87,0x36,0xbb,0xd0,
163-
0xe6,0x7f,0x02,0x6d,0x75,0xa1,0xad,0x93,0xa1,0x7b,0x3a,0xcf,0x94,0x03,0xc2,0xbe,
164-
0xe0,0x1d,0x67,0xaa,0xa0,0x7d,0x9f,0x64,0x1f,0x5c,0xbb,0xca,0x15,0x31,0x39,0x29,
165-
0xd2,0x5e,0x57,0xac,0xc2,0x3b,0x3d,0x1f,0x6f,0xfc,0x33,0x59,0x84,0xf7,0xe7,0xbe,
166-
0x22,0x74,0x5b,0xc5,0x7d,0x5f,0x08,0xce,0xe8,0xbd,0x8e,0x7b,0x2b,0xf5,0x3a,0xc2,
167-
0x5b,0xad,0xe7,0xcc,0x8f,0xc8,0xe5,0xe8,0xf8,0xfe,0x07,0x09,0xca,0xd2,0x56,0x74,
168-
0x46,0xdd,0x02,0x14,0x84,0x57,0xce,0xa7,0x82,0x91,0xc9,0x0a,0x00,0x00
139+
0x18,0x85,0xef,0x27,0xed,0x3f,0x58,0x96,0x76,0x97,0x2c,0x40,0x80,0xa4,0x12,0xb4,
140+
0xca,0x12,0xb2,0x46,0x22,0x50,0x05,0x58,0xa5,0xdd,0x20,0x83,0x9d,0x0a,0xc9,0xd8,
141+
0x15,0x98,0xae,0xf9,0xf7,0x33,0x34,0x5a,0xa0,0xd3,0x5a,0x2e,0x2a,0xc1,0x6e,0x90,
142+
0x39,0x58,0xc7,0x8f,0x0f,0xfe,0x78,0xad,0x9b,0xe7,0x9c,0x82,0x27,0x52,0x94,0x19,
143+
0x67,0x36,0x54,0xbf,0x2a,0x10,0x10,0x96,0x72,0x9c,0xb1,0x07,0x1b,0x46,0xe1,0x76,
144+
0xba,0x84,0xa0,0x14,0x88,0x61,0x44,0x39,0x23,0x36,0x64,0x1c,0xde,0x5c,0x7f,0xfe,
145+
0x64,0x39,0x79,0x42,0xf0,0x9a,0x33,0x51,0x70,0x0a,0x12,0x8e,0x0a,0x1c,0x55,0x19,
146+
0xb6,0x21,0x49,0xb1,0x61,0x2a,0x8b,0xe3,0xd4,0x30,0x48,0x32,0xd5,0x35,0x43,0x9b,
147+
0x22,0x43,0x95,0x0f,0x94,0x2c,0xcc,0x2b,0xdd,0xd0,0x30,0x9e,0x43,0x40,0xd1,0x89,
148+
0x57,0xc2,0x43,0xb9,0x74,0xdc,0xf3,0x24,0xa3,0x04,0x6c,0x8b,0x8c,0x30,0x4c,0x4f,
149+
0x50,0xba,0x03,0x60,0xed,0x09,0xab,0xdc,0xa6,0x57,0xd9,0x08,0x1d,0x09,0xa4,0x9c,
150+
0x96,0x36,0xd4,0x20,0x38,0x4a,0x82,0x1d,0x3b,0x72,0x89,0xae,0x28,0x5f,0x20,0x28,
151+
0x48,0x5a,0xc9,0xb9,0x3c,0x49,0x5f,0x51,0x54,0x44,0x0a,0x9c,0x8b,0x9d,0xe4,0x52,
152+
0xe0,0xd9,0xe6,0x6c,0xe4,0x50,0x92,0x13,0x26,0x00,0xa2,0xd9,0x03,0xab,0x5b,0x36,
153+
0x5c,0x3b,0x5e,0xe8,0x1c,0x60,0x6d,0xce,0x8b,0x80,0x48,0xe5,0x3b,0xe5,0x09,0xa2,
154+
0xb5,0xd2,0xcc,0x33,0x3c,0x3d,0x4a,0xdf,0x6f,0x51,0x18,0xfa,0x5e,0xbc,0xf6,0xbd,
155+
0xf0,0xe0,0xbb,0xf2,0x63,0x55,0x0a,0x9e,0x6f,0x0a,0xf4,0xab,0x4e,0x87,0xc9,0x31,
156+
0xb1,0x6c,0xef,0x39,0x96,0x7d,0x83,0x5b,0xff,0x3e,0xf6,0x56,0x7b,0xe7,0x6f,0x52,
157+
0x39,0x66,0x55,0x83,0xa9,0x57,0x10,0x3c,0xf2,0x32,0x13,0xcd,0x0f,0x50,0x26,0x0a,
158+
0x9c,0x8d,0x94,0x54,0x53,0xba,0xa4,0xea,0x78,0x49,0xd5,0x36,0xa9,0x3a,0x78,0xa6,
159+
0xf1,0x8f,0x95,0x1b,0xbd,0xc1,0x6b,0x76,0x71,0x87,0x0e,0xf6,0x3d,0xdc,0x45,0x1b,
160+
0x57,0x1b,0x3c,0xdd,0x7f,0x83,0x2e,0xbb,0xa0,0x7d,0x72,0x75,0x9d,0x6d,0xf8,0x2e,
161+
0xe6,0xad,0x7f,0xd8,0xfd,0x94,0x8c,0x2b,0x37,0x0e,0xdc,0xdd,0xa6,0x99,0xd8,0x47,
162+
0x04,0xab,0xcd,0xdb,0xc0,0xf3,0x89,0xdc,0x63,0x13,0x6d,0xf4,0xd0,0x7a,0x1b,0x5a,
163+
0xff,0x4f,0xa0,0x8d,0x36,0xb4,0xd1,0x1b,0x7a,0xa0,0xf3,0xac,0x73,0x40,0x98,0x23,
164+
0xde,0x71,0x7a,0x17,0x74,0xe8,0x93,0xec,0x8d,0x6b,0xb7,0x73,0x45,0x2c,0xba,0x91,
165+
0x06,0x02,0x89,0x2c,0x0d,0xc9,0x73,0xaf,0x05,0xfb,0x7a,0x88,0xb6,0xad,0x0a,0xaf,
166+
0x03,0x9e,0x13,0x50,0x7b,0x59,0xb3,0x8b,0xef,0xb8,0x77,0x47,0x27,0x9b,0x65,0xaf,
167+
0xe5,0xd6,0x8b,0x37,0xba,0x8b,0x37,0xfe,0xfd,0x47,0x5f,0x47,0xaa,0xd9,0xc5,0xbd,
168+
0x2c,0x3a,0x6b,0x76,0xa9,0x19,0x5f,0xca,0xca,0x96,0xf0,0x52,0x57,0x5a,0xeb,0x33,
169+
0x72,0x39,0x3b,0xbf,0xff,0x41,0x92,0x25,0x70,0x23,0x5a,0xb3,0x76,0xb1,0x2b,0x85,
170+
0xdf,0x3b,0xb6,0x57,0x86,0x35,0x0b,0x00,0x00
169171
};
170172
const EmbedControlFlashedForm formData_MobileFriendly {
171173
"Mobile Friendly",
172174
formData_MobileFriendly_d8,
173-
494
175+
521
174176
};
175177

176178
const EmbedControlFlashedForm* tcMenuAllEmbeddedForms[] { &formData_MobileFriendly, nullptr };

examples/avr/adafruitST7735Mega/adafruitST7735Mega.emf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@
274274
"menuDefinitions": []
275275
},
276276
"packageNamespace": "",
277-
"appIsModular": false
277+
"appIsModular": false,
278+
"listOfEmbeddedForms": []
278279
},
279280
"stringLists": []
280281
}

examples/avr/adafruitST7735Mega/adafruitST7735Mega_menu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ AnalogMenuItem menuAnalog(&minfoAnalog, 0, &menuBool, INFO_LOCATION_PGM);
3838
void setupMenu() {
3939
// First we set up eeprom and authentication (if needed).
4040
setSizeBasedEEPROMStorageEnabled(false);
41-
// Code generated by plugins.
41+
// Code generated by plugins and new operators.
4242
gfx.initR(INITR_BLACKTAB);
4343
gfx.setRotation(3);
4444
renderer.setUpdatesPerSecond(4);

examples/avr/adafruitST7735Mega/tcMenuAdaFruitGfx.cpp

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ using namespace tcgfx;
3434
#endif // AVR reduced size buffer
3535
#endif // COOKIE_CUT_MEMBUFFER_SIZE
3636

37+
uint16_t memBuffer[COOKIE_CUT_MEMBUFFER_SIZE];
38+
3739
void AdafruitDrawable::transaction(bool isStarting, bool redrawNeeded) {
3840
if(!isStarting) refreshDisplayIfNeeded(graphics, redrawNeeded);
3941
}
@@ -52,15 +54,58 @@ void AdafruitDrawable::drawBitmap(const Coord &where, const DrawableIcon *icon,
5254
if(icon->getIconType() == DrawableIcon::ICON_XBITMAP) {
5355
graphics->fillRect(where.x, where.y, icon->getDimensions().x, icon->getDimensions().y, backgroundColor);
5456
graphics->drawXBitmap(where.x, where.y, icon->getIcon(selected), icon->getDimensions().x, icon->getDimensions().y, drawColor);
55-
}
56-
else if(icon->getIconType() == DrawableIcon::ICON_NATIVE) {
57+
} else if(icon->getIconType() == DrawableIcon::ICON_NATIVE) {
5758
graphics->drawRGBBitmap(where.x, where.y, (const uint16_t*)icon->getIcon(selected), icon->getDimensions().x, icon->getDimensions().y);
58-
}
59-
else if(icon->getIconType() == DrawableIcon::ICON_MONO) {
59+
} else if(icon->getIconType() == DrawableIcon::ICON_MONO) {
6060
graphics->drawBitmap(where.x, where.y, icon->getIcon(selected), icon->getDimensions().x, icon->getDimensions().y, drawColor, backgroundColor);
61+
} else if(icon->getPalette() != nullptr){
62+
auto bpp = icon->getIconType() == tcgfx::DrawableIcon::ICON_PALLETE_2BPP ? 2 : 4;
63+
drawBitmapNbpp(where, icon->getIcon(selected), icon->getDimensions(), bpp, icon->getPalette());
6164
}
6265
}
6366

67+
void AdafruitDrawable::drawBitmapNbpp(const Coord& where, const uint8_t* data, const Coord& size, int bpp, const color_t* palette) {
68+
auto* asTft = reinterpret_cast<Adafruit_SPITFT *>(graphics);
69+
auto yTot = int16_t(where.y + size.y);
70+
auto xTot = int16_t(where.x + size.x);
71+
int bitsInByte = bpp == 2 ? 4 : 2;
72+
uint8_t downShift = bpp == 2 ? 6 : 4;
73+
74+
uint16_t next = 0;
75+
uint8_t byteIteration = bitsInByte;
76+
uint8_t current;
77+
78+
asTft->startWrite();
79+
80+
for(int16_t y = where.y; y<yTot; y++) {
81+
asTft->setAddrWindow(where.x, y, size.x, 1);
82+
for(int16_t x = where.x; x<xTot; x++) {
83+
if(byteIteration == bitsInByte) {
84+
current = pgm_read_byte(data);
85+
data += 1;
86+
byteIteration = 0;
87+
}
88+
uint8_t idx = current >> downShift;
89+
current = current << bpp;
90+
byteIteration++;
91+
92+
memBuffer[next] = palette[idx];
93+
next = next + 1;
94+
if(next == COOKIE_CUT_MEMBUFFER_SIZE) {
95+
asTft->writePixels(memBuffer, next);
96+
next = 0;
97+
}
98+
}
99+
if(next != 0) {
100+
asTft->writePixels(memBuffer, next);
101+
next = 0;
102+
}
103+
byteIteration = bitsInByte; // always need a new byte in this case
104+
}
105+
106+
asTft->endWrite();
107+
}
108+
64109
void AdafruitDrawable::drawXBitmap(const Coord &where, const Coord &size, const uint8_t *data) {
65110
graphics->fillRect(where.x, where.y, size.x, size.y, backgroundColor);
66111
graphics->drawXBitmap(where.x, where.y, data, size.x, size.y, drawColor);
@@ -69,8 +114,7 @@ void AdafruitDrawable::drawXBitmap(const Coord &where, const Coord &size, const
69114
void AdafruitDrawable::drawBox(const Coord &where, const Coord &size, bool filled) {
70115
if(filled) {
71116
graphics->fillRect(where.x, where.y, size.x, size.y, drawColor);
72-
}
73-
else {
117+
} else {
74118
graphics->drawRect(where.x, where.y, size.x, size.y, drawColor);
75119
}
76120
}
@@ -157,8 +201,6 @@ UnicodeFontHandler *AdafruitDrawable::createFontHandler() {
157201
// helper functions
158202
//
159203

160-
uint16_t memBuffer[COOKIE_CUT_MEMBUFFER_SIZE];
161-
162204
void drawCookieCutBitmap(Adafruit_SPITFT* gfx, int16_t x, int16_t y, const uint8_t *bitmap, int16_t w,
163205
int16_t h, int16_t totalWidth, int16_t xStart, int16_t yStart,
164206
uint16_t fgColor, uint16_t bgColor) {
@@ -519,7 +561,7 @@ DeviceDrawable *AdafruitDrawable::getSubDeviceFor(const Coord &where, const Coor
519561
}
520562

521563
AdafruitCanvasDrawable2bpp::AdafruitCanvasDrawable2bpp(AdafruitDrawable *root, int width, int height) : root(root),
522-
sizeMax({width, height}), sizeCurrent(), palette{} {
564+
sizeMax({width, height}), sizeCurrent(), palette{} {
523565
canvas = new TcGFXcanvas2(width, height);
524566
setGraphics(canvas);
525567
}
@@ -561,3 +603,26 @@ DeviceDrawable *AdafruitCanvasDrawable2bpp::getSubDeviceFor(const Coord&, const
561603
return nullptr; // don't allow further nesting.
562604
}
563605

606+
void AdafruitCanvasDrawable2bpp::drawBitmapNbpp(const Coord& where, const uint8_t* data, const Coord& size, int bpp, const uint16_t* palette) {
607+
auto yTot = int16_t(where.y + size.y);
608+
auto xTot = int16_t(where.x + size.x);
609+
int bitsInByte = bpp == 2 ? 4 : 2;
610+
uint8_t downShift = bpp == 2 ? 6 : 4;
611+
612+
uint8_t byteIteration = bitsInByte;
613+
uint8_t current;
614+
for(int16_t y = where.y; y<yTot; y++) {
615+
for(int16_t x = where.x; x<xTot; x++) {
616+
if(byteIteration == bitsInByte) {
617+
current = pgm_read_byte(data);
618+
data += 1;
619+
byteIteration = 0;
620+
}
621+
uint8_t idx = current >> downShift;
622+
current = current << bitsInByte;
623+
byteIteration++;
624+
canvas->drawPixel(x, y, idx);
625+
}
626+
byteIteration = bitsInByte; // always need a new byte in this case
627+
}
628+
}

0 commit comments

Comments
 (0)