Add custom background
This commit is contained in:
@ -8,8 +8,8 @@
|
||||
#include "tftcolors.h"
|
||||
|
||||
namespace espgui {
|
||||
ProgressBar::ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color) :
|
||||
m_x{x}, m_y{y}, m_width{width}, m_height{height}, m_min{min}, m_max{max}, m_color{color}
|
||||
ProgressBar::ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color, uint32_t backgroundColor) :
|
||||
m_x{x}, m_y{y}, m_width{width}, m_height{height}, m_min{min}, m_max{max}, m_color{color}, m_backgroundColor{backgroundColor}
|
||||
{
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ void ProgressBar::start(TftInterface &tft)
|
||||
{
|
||||
m_lastValue = m_x+1;
|
||||
tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE);
|
||||
tft.fillRect(m_x+1, m_y+1, m_width-2, m_height-2, m_backgroundColor);
|
||||
}
|
||||
|
||||
void ProgressBar::redraw(TftInterface &tft, int value)
|
||||
@ -24,7 +25,7 @@ void ProgressBar::redraw(TftInterface &tft, int value)
|
||||
value = cpputils::mapValueClamped(value, m_min, m_max, m_x+1, m_x+m_width-1);
|
||||
|
||||
if (value < m_lastValue)
|
||||
tft.fillRect(value, m_y+1, m_lastValue-value, m_height-2, TFT_BLACK);
|
||||
tft.fillRect(value, m_y+1, m_lastValue-value, m_height-2, m_backgroundColor);
|
||||
else if (value > m_lastValue)
|
||||
tft.fillRect(m_lastValue, m_y+1, value-m_lastValue, m_height-2, m_color);
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace espgui {
|
||||
class ProgressBar
|
||||
{
|
||||
public:
|
||||
ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color = TFT_YELLOW);
|
||||
ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color = TFT_YELLOW, uint32_t backgroundColor = TFT_BLACK);
|
||||
|
||||
void start(TftInterface &tft);
|
||||
void redraw(TftInterface &tft, int value);
|
||||
@ -29,6 +29,7 @@ private:
|
||||
const int m_min;
|
||||
const int m_max;
|
||||
const uint32_t m_color;
|
||||
const uint32_t m_backgroundColor;
|
||||
|
||||
int m_lastValue{};
|
||||
};
|
||||
|
Reference in New Issue
Block a user