Skip to content

Commit 390d5a2

Browse files
add shade function
1 parent 674ecce commit 390d5a2

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/canvas/Arduino_Canvas.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,46 @@ void Arduino_Canvas::flushQuad(bool force_flush)
613613
}
614614
}
615615

616+
void Arduino_Canvas::shade(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t shade_mask)
617+
{
618+
if (_rotation > 0)
619+
{
620+
int16_t t = x;
621+
switch (_rotation)
622+
{
623+
case 1:
624+
x = WIDTH - y - h;
625+
y = t;
626+
t = w;
627+
w = h;
628+
h = t;
629+
break;
630+
case 2:
631+
x = WIDTH - x - w;
632+
y = HEIGHT - y - h;
633+
break;
634+
case 3:
635+
x = y;
636+
y = HEIGHT - t - w;
637+
t = w;
638+
w = h;
639+
h = t;
640+
break;
641+
}
642+
}
643+
uint16_t *row = _framebuffer;
644+
row += y * WIDTH;
645+
row += x;
646+
for (int j = 0; j < h; j++)
647+
{
648+
for (int i = 0; i < w; i++)
649+
{
650+
row[i] &= shade_mask;
651+
}
652+
row += WIDTH;
653+
}
654+
}
655+
616656
uint16_t *Arduino_Canvas::getFramebuffer()
617657
{
618658
return _framebuffer;

src/canvas/Arduino_Canvas.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ class Arduino_Canvas : public Arduino_GFX
2525
void draw16bitRGBBitmapWithTranColor(int16_t x, int16_t y, uint16_t *bitmap, uint16_t transparent_color, int16_t w, int16_t h) override;
2626
void draw16bitBeRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) override;
2727
void flush(bool force_flush = false) override;
28-
void flushQuad(bool force_flush = false);
2928

29+
void flushQuad(bool force_flush = false);
30+
void shade(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t shade_mask);
3031
uint16_t *getFramebuffer();
3132

3233
protected:

0 commit comments

Comments
 (0)