Skip to content

Commit 372fa78

Browse files
committed
Bangle.js2: g.flip(2) will now flip the screen *and* the entire area of the overlay
1 parent cd6e018 commit 372fa78

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Bangle.js2: Remove buzz when going back in a menu using the button (not the widget)
1717
Bangle.js2: Ensure overlays don't use the current Graphics colors
1818
Bangle.js2: Much faster rendering of overlays
19+
Bangle.js2: g.flip(2) will now flip the screen *and* the entire area of the overlay
1920

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

libs/banglejs/jswrap_bangle.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,13 @@ void graphicsInternalFlip() {
11181118
}
11191119

11201120
/// Flip buffer contents with the screen.
1121-
void lcd_flip(JsVar *parent, bool all) {
1121+
void lcd_flip(JsVar *parent, int all) {
11221122
#ifdef LCD_WIDTH
1123+
#ifdef LCD_CONTROLLER_LPM013M126
1124+
if (all==2) {
1125+
lcdMemLCD_setOverlayModified(&graphicsInternal);
1126+
} else
1127+
#endif
11231128
if (all) {
11241129
graphicsInternal.data.modMinX = 0;
11251130
graphicsInternal.data.modMinY = 0;
@@ -3991,7 +3996,7 @@ NO_INLINE void jswrap_banglejs_init() {
39913996
graphicsInternal.graphicsVar = graphics;
39923997

39933998
// Create 'flip' fn
3994-
JsVar *fn = jsvNewNativeFunction((void (*)(void))lcd_flip, JSWAT_VOID|JSWAT_THIS_ARG|(JSWAT_BOOL << (JSWAT_BITS*1)));
3999+
JsVar *fn = jsvNewNativeFunction((void (*)(void))lcd_flip, JSWAT_VOID|JSWAT_THIS_ARG|(JSWAT_INT32 << (JSWAT_BITS*1)));
39954000
jsvObjectSetChildAndUnLock(graphics,"flip",fn);
39964001

39974002
if (!firstRun) {

libs/graphics/lcd_memlcd.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void lcdMemLCD_flip(JsGraphics *gfx) {
346346
memcpy(buf, &lcdBuffer[LCD_STRIDE*y], LCD_STRIDE);
347347
// overwrite areas with overlay image
348348
if (y>=ovY && y<ovY+overlayImg.height) {
349-
_jswrap_drawImageSimpleRow(gfx, lcdOverlayX, bufferLine, &overlayImg, &it, lcdMemLCD_setPixel, &bits, &colData);
349+
_jswrap_drawImageSimpleRow(gfx, lcdOverlayX, bufferLine, &overlayImg, &it, setPixel, &bits, &colData);
350350
}
351351
// send the line
352352
#ifdef EMULATED
@@ -442,6 +442,24 @@ void lcdMemLCD_setOverlay(JsVar *imgVar, int x, int y) {
442442
}
443443
}
444444

445+
// Sets the modified x/y to the overlay dimensions
446+
void lcdMemLCD_setOverlayModified(JsGraphics *gfx) {
447+
if (lcdOverlayImage) {
448+
GfxDrawImageInfo overlayImg;
449+
if (_jswrap_graphics_parseImage(gfx, lcdOverlayImage, 0, &overlayImg)) {
450+
int x = lcdOverlayX<0?0:lcdOverlayX;
451+
int y = lcdOverlayY<0?0:lcdOverlayY;
452+
int x2 = lcdOverlayX + overlayImg.width-1;
453+
if (x2>LCD_WIDTH-1) x2=LCD_WIDTH-1;
454+
int y2 = lcdOverlayY + overlayImg.height-1;
455+
if (y2>LCD_HEIGHT-1) y2=LCD_HEIGHT-1;
456+
graphicsSetModified(gfx, x,y,x2,y2);
457+
_jswrap_graphics_freeImageInfo(&overlayImg);
458+
}
459+
}
460+
}
461+
462+
445463
void lcdMemLCD_setCallbacks(JsGraphics *gfx) {
446464
gfx->setPixel = lcdMemLCD_setPixel;
447465
gfx->fillRect = lcdMemLCD_fillRect;

libs/graphics/lcd_memlcd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ void lcdMemLCD_extcominToggle();
2525
void lcdMemLCD_extcominBacklight(bool isOn);
2626
// Enable overlay mode (to overlay an image on top of the LCD contents)
2727
void lcdMemLCD_setOverlay(JsVar *imgVar, int x, int y);
28+
// Sets the modified x/y to the overlay dimensions
29+
void lcdMemLCD_setOverlayModified(JsGraphics *gfx);
2830
// return a pointer to the LCD's memory buffer
2931
unsigned char *lcdMemLCD_getRowPtr(int row);

0 commit comments

Comments
 (0)