Skip to content

Commit

Permalink
Graphics: Ensure a scroll inside a cliprect can't go out of bounds (p…
Browse files Browse the repository at this point in the history
…reviously it was bounded to screen)
  • Loading branch information
gfwilliams committed Dec 12, 2022
1 parent 51b22bb commit f612b25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -9,6 +9,7 @@
Bangle.js1/2: Fix showMenu/showScroller spacing with back if no widgets loaded (ref #2286)
Bangle.js1: Bangle.setUI({back}) now responds to BTN3 if there were no other watches on buttons
ESP32: Allow up to 16k vars (if enough memory), allow non-active scan, and remove 30s BLE scan limit
Graphics: Ensure a scroll inside a cliprect can't go out of bounds (previously it was bounded to screen)

2v16 : JIT functions now execute in their own function scope (allows arguments)
Move older 'HY' boards to use `g` for the built-in graphics, not `LCD` (and change docs)
Expand Down
17 changes: 10 additions & 7 deletions libs/graphics/graphics.c
Expand Up @@ -873,13 +873,7 @@ void graphicsScroll(JsGraphics *gfx, int xdir, int ydir) {
graphicsToDeviceCoordinates(gfx, &x2, &y2);
xdir = x2-x1;
ydir = y2-y1;
// range check - if too big no point scrolling
bool scroll = true;
if (xdir>gfx->data.width) { xdir=gfx->data.width; scroll=false; }
if (xdir<-gfx->data.width) { xdir=-gfx->data.width; scroll=false; }
if (ydir>gfx->data.height) { ydir=gfx->data.height; scroll=false; }
if (ydir<-gfx->data.height) { ydir=-gfx->data.height; scroll=false; }
// do the scrolling
// work out cliprect
#ifdef NO_MODIFIED_AREA
x1=0;
y1=0;
Expand All @@ -891,6 +885,15 @@ void graphicsScroll(JsGraphics *gfx, int xdir, int ydir) {
x2=gfx->data.clipRect.x2;
y2=gfx->data.clipRect.y2;
#endif
// range check - if too big no point scrolling
bool scroll = true;
int w = 1+x2-x1;
int h = 1+y2-y1;
if (xdir>=w) { xdir=w; scroll=false; }
if (xdir<=-w) { xdir=-w; scroll=false; }
if (ydir>=h) { ydir=h; scroll=false; }
if (ydir<=-h) { ydir=-h; scroll=false; }
// do the scrolling
if (scroll) gfx->scroll(gfx, xdir, ydir, x1,y1,x2,y2);
graphicsSetModified(gfx, x1,y1,x2,y2);
// fill the new area
Expand Down

0 comments on commit f612b25

Please sign in to comment.