Skip to content

Commit d8f0aa4

Browse files
committed
Bangle.js2: Ensure overlays don't use the current Graphics colors
1 parent e2c67e6 commit d8f0aa4

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
E.defrag now defrags with interrupts enabled (also fix potential crash with 2 flat strings end to end)
1515
Swap to using locks for watch&timer arrays (uses 4b more RAM, but faster and no defrag issues)
1616
Bangle.js2: Remove buzz when going back in a menu using the button (not the widget)
17+
Bangle.js2: Ensure overlays don't use the current Graphics colors
1718

1819
2v28 : Add `E.internal` as a way to access the 'hidden root' containing Espruino internal variables that previously needed `global["\xff"]`
1920
Bangle.js: Fix back handler not removed when using E.setUI with a back button but without widgets (#2636)

libs/graphics/lcd_memlcd.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,18 @@ void lcdMemLCD_flip(JsGraphics *gfx) {
291291

292292
bool hasOverlay = false;
293293
GfxDrawImageInfo overlayImg;
294-
if (lcdOverlayImage)
294+
if (lcdOverlayImage) {
295+
// Set colors to current theme
296+
unsigned int oldFgColor = gfx->data.fgColor;
297+
unsigned int oldBgColor = gfx->data.bgColor;
298+
gfx->data.fgColor = graphicsTheme.fg;
299+
gfx->data.bgColor = graphicsTheme.bg;
300+
// parse image (which will generate palette)
295301
hasOverlay = _jswrap_graphics_parseImage(gfx, lcdOverlayImage, 0, &overlayImg);
302+
// Restore colors to previous state
303+
gfx->data.fgColor = oldFgColor;
304+
gfx->data.bgColor = oldBgColor;
305+
}
296306

297307
jshPinSetValue(LCD_SPI_CS, 1);
298308
if (hasOverlay) {
@@ -311,11 +321,6 @@ void lcdMemLCD_flip(JsGraphics *gfx) {
311321
bool isRotated180 = (graphicsInternal.data.flags & (JSGRAPHICSFLAGS_SWAP_XY | JSGRAPHICSFLAGS_INVERT_X | JSGRAPHICSFLAGS_INVERT_Y)) ==
312322
(JSGRAPHICSFLAGS_INVERT_X | JSGRAPHICSFLAGS_INVERT_Y);
313323
int ovY = isRotated180 ? (LCD_HEIGHT-(lcdOverlayY+overlayImg.height)) : lcdOverlayY;
314-
// Set colors to current theme
315-
unsigned int oldFgColor = gfx->data.fgColor;
316-
unsigned int oldBgColor = gfx->data.bgColor;
317-
gfx->data.fgColor = graphicsTheme.fg;
318-
gfx->data.bgColor = graphicsTheme.bg;
319324
// initialise image layer
320325
GfxDrawImageLayer l;
321326
l.x1 = 0;
@@ -359,9 +364,6 @@ void lcdMemLCD_flip(JsGraphics *gfx) {
359364
jshSPISendMany(LCD_SPI, lcdBuffer, NULL, 2, NULL);
360365
lcdMemLCD_flip_spi_callback();
361366
#endif
362-
// Restore colors to previous state
363-
gfx->data.fgColor = oldFgColor;
364-
gfx->data.bgColor = oldBgColor;
365367
} else { // standard, non-overlay
366368
#ifdef EMULATED
367369
memcpy(fakeLCDBuffer, lcdBuffer, LCD_HEIGHT*LCD_STRIDE);

0 commit comments

Comments
 (0)