@@ -1529,7 +1529,7 @@ void Adafruit_GFX::getTextBounds(const __FlashStringHelper *str, int16_t x,
1529
1529
@param i True if you want to invert, false to make 'normal'
1530
1530
*/
1531
1531
/* *************************************************************************/
1532
- void Adafruit_GFX::invertDisplay (boolean i) {
1532
+ void Adafruit_GFX::invertDisplay (bool i) {
1533
1533
// Do nothing, must be subclassed if supported by hardware
1534
1534
}
1535
1535
@@ -1661,7 +1661,7 @@ void Adafruit_GFX_Button::initButtonUL(Adafruit_GFX *gfx, int16_t x1,
1661
1661
'pressed'
1662
1662
*/
1663
1663
/* *************************************************************************/
1664
- void Adafruit_GFX_Button::drawButton (boolean inverted) {
1664
+ void Adafruit_GFX_Button::drawButton (bool inverted) {
1665
1665
uint16_t fill, outline, text;
1666
1666
1667
1667
if (!inverted) {
@@ -1694,7 +1694,7 @@ void Adafruit_GFX_Button::drawButton(boolean inverted) {
1694
1694
@returns True if within button graphics outline
1695
1695
*/
1696
1696
/* *************************************************************************/
1697
- boolean Adafruit_GFX_Button::contains (int16_t x, int16_t y) {
1697
+ bool Adafruit_GFX_Button::contains (int16_t x, int16_t y) {
1698
1698
return ((x >= _x1) && (x < (int16_t )(_x1 + _w)) && (y >= _y1) &&
1699
1699
(y < (int16_t )(_y1 + _h)));
1700
1700
}
@@ -1705,17 +1705,15 @@ boolean Adafruit_GFX_Button::contains(int16_t x, int16_t y) {
1705
1705
@returns True if was not-pressed before, now is.
1706
1706
*/
1707
1707
/* *************************************************************************/
1708
- boolean Adafruit_GFX_Button::justPressed () { return (currstate && !laststate); }
1708
+ bool Adafruit_GFX_Button::justPressed () { return (currstate && !laststate); }
1709
1709
1710
1710
/* *************************************************************************/
1711
1711
/* !
1712
1712
@brief Query whether the button was released since we last checked state
1713
1713
@returns True if was pressed before, now is not.
1714
1714
*/
1715
1715
/* *************************************************************************/
1716
- boolean Adafruit_GFX_Button::justReleased () {
1717
- return (!currstate && laststate);
1718
- }
1716
+ bool Adafruit_GFX_Button::justReleased () { return (!currstate && laststate); }
1719
1717
1720
1718
// -------------------------------------------------------------------------
1721
1719
@@ -1736,6 +1734,14 @@ boolean Adafruit_GFX_Button::justReleased() {
1736
1734
// scanline pad).
1737
1735
// NOT EXTENSIVELY TESTED YET. MAY CONTAIN WORST BUGS KNOWN TO HUMANKIND.
1738
1736
1737
+ #ifdef __AVR__
1738
+ // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
1739
+ const uint8_t PROGMEM GFXcanvas1::GFXsetBit[] = {0x80 , 0x40 , 0x20 , 0x10 ,
1740
+ 0x08 , 0x04 , 0x02 , 0x01 };
1741
+ const uint8_t PROGMEM GFXcanvas1::GFXclrBit[] = {0x7F , 0xBF , 0xDF , 0xEF ,
1742
+ 0xF7 , 0xFB , 0xFD , 0xFE };
1743
+ #endif
1744
+
1739
1745
/* *************************************************************************/
1740
1746
/* !
1741
1747
@brief Instatiate a GFX 1-bit canvas context for graphics
@@ -1765,18 +1771,10 @@ GFXcanvas1::~GFXcanvas1(void) {
1765
1771
@brief Draw a pixel to the canvas framebuffer
1766
1772
@param x x coordinate
1767
1773
@param y y coordinate
1768
- @param color 16-bit 5-6-5 Color to fill with
1774
+ @param color Binary (on or off) color to fill with
1769
1775
*/
1770
1776
/* *************************************************************************/
1771
1777
void GFXcanvas1::drawPixel (int16_t x, int16_t y, uint16_t color) {
1772
- #ifdef __AVR__
1773
- // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
1774
- static const uint8_t PROGMEM GFXsetBit[] = {0x80 , 0x40 , 0x20 , 0x10 ,
1775
- 0x08 , 0x04 , 0x02 , 0x01 },
1776
- GFXclrBit[] = {0x7F , 0xBF , 0xDF , 0xEF ,
1777
- 0xF7 , 0xFB , 0xFD , 0xFE };
1778
- #endif
1779
-
1780
1778
if (buffer) {
1781
1779
if ((x < 0 ) || (y < 0 ) || (x >= _width) || (y >= _height))
1782
1780
return ;
@@ -1814,10 +1812,67 @@ void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
1814
1812
}
1815
1813
}
1816
1814
1815
+ /* *********************************************************************/
1816
+ /* !
1817
+ @brief Get the pixel color value at a given coordinate
1818
+ @param x x coordinate
1819
+ @param y y coordinate
1820
+ @returns The desired pixel's binary color value, either 0x1 (on) or 0x0
1821
+ (off)
1822
+ */
1823
+ /* *********************************************************************/
1824
+ bool GFXcanvas1::getPixel (int16_t x, int16_t y) const {
1825
+ int16_t t;
1826
+ switch (rotation) {
1827
+ case 1 :
1828
+ t = x;
1829
+ x = WIDTH - 1 - y;
1830
+ y = t;
1831
+ break ;
1832
+ case 2 :
1833
+ x = WIDTH - 1 - x;
1834
+ y = HEIGHT - 1 - y;
1835
+ break ;
1836
+ case 3 :
1837
+ t = x;
1838
+ x = y;
1839
+ y = HEIGHT - 1 - t;
1840
+ break ;
1841
+ }
1842
+ return getRawPixel (x, y);
1843
+ }
1844
+
1845
+ /* *********************************************************************/
1846
+ /* !
1847
+ @brief Get the pixel color value at a given, unrotated coordinate.
1848
+ This method is intended for hardware drivers to get pixel value
1849
+ in physical coordinates.
1850
+ @param x x coordinate
1851
+ @param y y coordinate
1852
+ @returns The desired pixel's binary color value, either 0x1 (on) or 0x0
1853
+ (off)
1854
+ */
1855
+ /* *********************************************************************/
1856
+ bool GFXcanvas1::getRawPixel (int16_t x, int16_t y) const {
1857
+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT))
1858
+ return 0 ;
1859
+ if (this ->getBuffer ()) {
1860
+ uint8_t *buffer = this ->getBuffer ();
1861
+ uint8_t *ptr = &buffer[(x / 8 ) + y * ((WIDTH + 7 ) / 8 )];
1862
+
1863
+ #ifdef __AVR__
1864
+ return ((*ptr) & pgm_read_byte (&GFXsetBit[x & 7 ])) != 0 ;
1865
+ #else
1866
+ return ((*ptr) & (0x80 >> (x & 7 ))) != 0 ;
1867
+ #endif
1868
+ }
1869
+ return 0 ;
1870
+ }
1871
+
1817
1872
/* *************************************************************************/
1818
1873
/* !
1819
1874
@brief Fill the framebuffer completely with one color
1820
- @param color 16-bit 5-6-5 Color to fill with
1875
+ @param color Binary (on or off) color to fill with
1821
1876
*/
1822
1877
/* *************************************************************************/
1823
1878
void GFXcanvas1::fillScreen (uint16_t color) {
@@ -1856,7 +1911,7 @@ GFXcanvas8::~GFXcanvas8(void) {
1856
1911
@brief Draw a pixel to the canvas framebuffer
1857
1912
@param x x coordinate
1858
1913
@param y y coordinate
1859
- @param color 16 -bit 5-6-5 Color to fill with
1914
+ @param color 8 -bit Color to fill with. Only lower byte of uint16_t is used.
1860
1915
*/
1861
1916
/* *************************************************************************/
1862
1917
void GFXcanvas8::drawPixel (int16_t x, int16_t y, uint16_t color) {
@@ -1886,10 +1941,58 @@ void GFXcanvas8::drawPixel(int16_t x, int16_t y, uint16_t color) {
1886
1941
}
1887
1942
}
1888
1943
1944
+ /* *********************************************************************/
1945
+ /* !
1946
+ @brief Get the pixel color value at a given coordinate
1947
+ @param x x coordinate
1948
+ @param y y coordinate
1949
+ @returns The desired pixel's 8-bit color value
1950
+ */
1951
+ /* *********************************************************************/
1952
+ uint8_t GFXcanvas8::getPixel (int16_t x, int16_t y) const {
1953
+ int16_t t;
1954
+ switch (rotation) {
1955
+ case 1 :
1956
+ t = x;
1957
+ x = WIDTH - 1 - y;
1958
+ y = t;
1959
+ break ;
1960
+ case 2 :
1961
+ x = WIDTH - 1 - x;
1962
+ y = HEIGHT - 1 - y;
1963
+ break ;
1964
+ case 3 :
1965
+ t = x;
1966
+ x = y;
1967
+ y = HEIGHT - 1 - t;
1968
+ break ;
1969
+ }
1970
+ return getRawPixel (x, y);
1971
+ }
1972
+
1973
+ /* *********************************************************************/
1974
+ /* !
1975
+ @brief Get the pixel color value at a given, unrotated coordinate.
1976
+ This method is intended for hardware drivers to get pixel value
1977
+ in physical coordinates.
1978
+ @param x x coordinate
1979
+ @param y y coordinate
1980
+ @returns The desired pixel's 8-bit color value
1981
+ */
1982
+ /* *********************************************************************/
1983
+ uint8_t GFXcanvas8::getRawPixel (int16_t x, int16_t y) const {
1984
+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT))
1985
+ return 0 ;
1986
+ if (buffer) {
1987
+ return buffer[x + y * WIDTH];
1988
+ }
1989
+ return 0 ;
1990
+ }
1991
+
1889
1992
/* *************************************************************************/
1890
1993
/* !
1891
1994
@brief Fill the framebuffer completely with one color
1892
- @param color 16 -bit 5-6-5 Color to fill with
1995
+ @param color 8 -bit Color to fill with. Only lower byte of uint16_t is used.
1893
1996
*/
1894
1997
/* *************************************************************************/
1895
1998
void GFXcanvas8::fillScreen (uint16_t color) {
@@ -1995,6 +2098,54 @@ void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) {
1995
2098
}
1996
2099
}
1997
2100
2101
+ /* *********************************************************************/
2102
+ /* !
2103
+ @brief Get the pixel color value at a given coordinate
2104
+ @param x x coordinate
2105
+ @param y y coordinate
2106
+ @returns The desired pixel's 16-bit 5-6-5 color value
2107
+ */
2108
+ /* *********************************************************************/
2109
+ uint16_t GFXcanvas16::getPixel (int16_t x, int16_t y) const {
2110
+ int16_t t;
2111
+ switch (rotation) {
2112
+ case 1 :
2113
+ t = x;
2114
+ x = WIDTH - 1 - y;
2115
+ y = t;
2116
+ break ;
2117
+ case 2 :
2118
+ x = WIDTH - 1 - x;
2119
+ y = HEIGHT - 1 - y;
2120
+ break ;
2121
+ case 3 :
2122
+ t = x;
2123
+ x = y;
2124
+ y = HEIGHT - 1 - t;
2125
+ break ;
2126
+ }
2127
+ return getRawPixel (x, y);
2128
+ }
2129
+
2130
+ /* *********************************************************************/
2131
+ /* !
2132
+ @brief Get the pixel color value at a given, unrotated coordinate.
2133
+ This method is intended for hardware drivers to get pixel value
2134
+ in physical coordinates.
2135
+ @param x x coordinate
2136
+ @param y y coordinate
2137
+ @returns The desired pixel's 16-bit 5-6-5 color value
2138
+ */
2139
+ /* *********************************************************************/
2140
+ uint16_t GFXcanvas16::getRawPixel (int16_t x, int16_t y) const {
2141
+ if ((x < 0 ) || (y < 0 ) || (x >= WIDTH) || (y >= HEIGHT))
2142
+ return 0 ;
2143
+ if (buffer) {
2144
+ return buffer[x + y * WIDTH];
2145
+ }
2146
+ return 0 ;
2147
+ }
2148
+
1998
2149
/* *************************************************************************/
1999
2150
/* !
2000
2151
@brief Fill the framebuffer completely with one color
0 commit comments