forked from Bodmer/TFT_eSPI
Added drawSunkenRect() and made color565() constexpr
This commit is contained in:
29
TFT_eSPI.cpp
29
TFT_eSPI.cpp
@@ -2489,6 +2489,25 @@ void TFT_eSPI::fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t
|
||||
end_tft_write(); // Does nothing if Sprite class uses this function
|
||||
}
|
||||
|
||||
void TFT_eSPI::drawSunkenRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color0, uint32_t color1, uint32_t color2)
|
||||
{
|
||||
//begin_tft_write(); // Sprite class can use this function, avoiding begin_tft_write()
|
||||
inTransaction = true;
|
||||
|
||||
drawFastHLine(x, y, w, color0);
|
||||
drawFastHLine(x, y + h - 1, w, color1);
|
||||
// Avoid drawing corner pixels twice
|
||||
drawFastVLine(x, y+1, h-2, color0);
|
||||
drawFastVLine(x + w - 1, y+1, h-2, color1);
|
||||
|
||||
setWindow(x + 1, y + 1, x + w - 2, y + h - 2);
|
||||
|
||||
pushBlock(color2, (w - 2) * (h - 2));
|
||||
|
||||
inTransaction = false;
|
||||
end_tft_write(); // Does nothing if Sprite class uses this function
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
** Function name: drawTriangle
|
||||
@@ -4173,16 +4192,6 @@ uint16_t TFT_eSPI::color565(uint8_t r, uint8_t g, uint8_t b)
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
** Function name: color16to8
|
||||
** Description: convert 16 bit colour to an 8 bit 332 RGB colour value
|
||||
***************************************************************************************/
|
||||
uint8_t TFT_eSPI::color16to8(uint16_t c)
|
||||
{
|
||||
return ((c & 0xE000)>>8) | ((c & 0x0700)>>6) | ((c & 0x0018)>>3);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************
|
||||
** Function name: color8to16
|
||||
** Description: convert 8 bit colour to a 16 bit 565 colour value
|
||||
|
10
TFT_eSPI.h
10
TFT_eSPI.h
@@ -498,6 +498,9 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect
|
||||
// If bg_color is not included the background pixel colour will be read from TFT or sprite
|
||||
void drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
|
||||
|
||||
void drawSunkenRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color0, uint32_t color1, uint32_t color2);
|
||||
|
||||
|
||||
void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color),
|
||||
drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color),
|
||||
fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color),
|
||||
@@ -624,8 +627,11 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect
|
||||
|
||||
|
||||
// Colour conversion
|
||||
// Convert 8 bit red, green and blue to 16 bits
|
||||
uint16_t color565(uint8_t red, uint8_t green, uint8_t blue);
|
||||
// Convert 8 bit red, green and blue to 16 bits
|
||||
static constexpr uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) noexcept
|
||||
{
|
||||
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
|
||||
}
|
||||
|
||||
// Convert 8 bit colour to 16 bits
|
||||
uint16_t color8to16(uint8_t color332);
|
||||
|
Reference in New Issue
Block a user