picture buttons part 1

This commit is contained in:
gemu2015 2021-01-04 16:29:34 +01:00
parent aa943fc696
commit 448daed0d1
7 changed files with 77 additions and 51 deletions

View File

@ -1579,6 +1579,8 @@ void Adafruit_GFX_Button::initButtonUL(
strncpy(_label, label, 9);
}
void draw_picture(char *path, uint32_t xp, uint32_t yp, uint32_t xs, uint32_t ys, bool inverted);
/**************************************************************************/
/*!
@brief Draw the button on the screen
@ -1598,16 +1600,20 @@ void Adafruit_GFX_Button::drawButton(boolean inverted) {
text = _fillcolor;
}
if (_label[0]=='/') {
// picture path
draw_picture(_label, _x1, _y1, _w, _h, inverted);
_gfx->drawRect(_x1, _y1, _w, _h, text);
} else {
uint8_t r = min(_w, _h) / 4; // Corner radius
_gfx->fillRoundRect(_x1, _y1, _w, _h, r, fill);
_gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline);
_gfx->setCursor(_x1 + (_w/2) - (strlen(_label) * 3 * _textsize_x),
_y1 + (_h/2) - (4 * _textsize_y));
_gfx->setCursor(_x1 + (_w/2) - (strlen(_label) * 3 * _textsize_x), _y1 + (_h/2) - (4 * _textsize_y));
_gfx->setTextColor(text);
_gfx->setTextSize(_textsize_x, _textsize_y);
_gfx->print(_label);
}
}
/**************************************************************************/

View File

@ -545,6 +545,12 @@ void ILI9341_2::DisplayOnff(int8_t on) {
}
}
void ILI9341_2::invertDisplay(boolean i) {
ILI9341_2_CS_LOW
writecmd(i ? ILI9341_2_INVOFF : ILI9341_2_INVON);
ILI9341_2_CS_HIGH
}
void ili9342_dimm(uint8_t dim);
// dimmer 0-100

View File

@ -119,30 +119,6 @@ class ILI9341_2 : public Renderer {
ILI9341_2(int8_t cs, int8_t res, int8_t dc, int8_t bp);
void init(uint16_t width, uint16_t height);
/*
void begin(void);
void DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font);
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void setScrollArea(uint16_t topFixedArea, uint16_t bottomFixedArea);
void scroll(uint16_t pixels);
void pushColor(uint16_t color);
void pushColors(uint16_t *data, uint8_t len, boolean first);
//void drawImage(const uint8_t* img, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
void fillScreen(uint16_t color);
void drawPixel(int16_t x, int16_t y, uint16_t color);
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,uint16_t color);
void setRotation(uint8_t r);
void invertDisplay(boolean i);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
void DisplayOnff(int8_t on);
void writecommand(uint8_t c);
void writedata(uint8_t d);
void write16BitColor(uint16_t color);
void commandList(uint8_t *addr);
void hw_spi_init();
void dim(uint8_t contrast);*/
uint16_t GetColorFromIndex(uint8_t index);
private:
@ -161,7 +137,7 @@ class ILI9341_2 : public Renderer {
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void dim(uint8_t dim);
void pushColors(uint16_t *data, uint8_t len, boolean first);
void invertDisplay(boolean i);
void spiwrite(uint8_t c);
void spiwrite16(uint16_t c);
void spiwrite32(uint32_t c);

View File

@ -503,6 +503,16 @@ void ILI9488::scroll(uint16_t pixels){
}*/
void ILI9488::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
if (!x0 && !y0 && !x1 && !y1) {
x0=0;
y0=0;
x1=_width;
y1=_height;
}
setAddrWindow_int(x0, y0, x1-1, y1-1);
}
void ILI9488::setAddrWindow_int(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
uint8_t flag=0;
if (!x0 && !y0 && !x1 && !y1) {
@ -594,6 +604,7 @@ void ILI9488::pushColor(uint16_t color) {
ILI9488_STOP
}
#if 1
void ILI9488::pushColors(uint16_t *data, uint8_t len, boolean first) {
uint16_t color;
uint8_t buff[len*3+1];
@ -616,6 +627,17 @@ void ILI9488::pushColors(uint16_t *data, uint8_t len, boolean first) {
ILI9488_STOP
}
#else
void ILI9488::pushColors(uint16_t *data, uint8_t len, boolean first) {
uint16_t color;
while (len--) {
write16BitColor(*data++);
}
ILI9488_STOP
}
#endif
void ILI9488::write16BitColor(uint16_t color){
// #if (__STM32F1__)
@ -688,7 +710,7 @@ void ILI9488::drawPixel(int16_t x, int16_t y, uint16_t color) {
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
setAddrWindow(x,y,x+1,y+1);
setAddrWindow_int(x,y,x+1,y+1);
write16BitColor(color);
ILI9488_STOP
}
@ -702,7 +724,7 @@ void ILI9488::drawFastVLine(int16_t x, int16_t y, int16_t h,
if((y+h-1) >= _height)
h = _height-y;
setAddrWindow(x, y, x, y+h-1);
setAddrWindow_int(x, y, x, y+h-1);
uint8_t r = (color & 0xF800) >> 11;
uint8_t g = (color & 0x07E0) >> 5;
@ -770,7 +792,7 @@ void ILI9488::drawFastHLine(int16_t x, int16_t y, int16_t w,
if((x >= _width) || (y >= _height)) return;
if((x+w-1) >= _width) w = _width-x;
setAddrWindow(x, y, x+w-1, y);
setAddrWindow_int(x, y, x+w-1, y);
uint8_t r = (color & 0xF800) >> 11;
uint8_t g = (color & 0x07E0) >> 5;
@ -905,7 +927,7 @@ void ILI9488::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t colo
if((x + w - 1) >= _width) w = _width - x;
if((y + h - 1) >= _height) h = _height - y;
setAddrWindow(x, y, x+w-1, y+h-1);
setAddrWindow_int(x, y, x+w-1, y+h-1);
//ILI9488_START
uint8_t r = (color & 0xF800) >> 11;
@ -1050,7 +1072,7 @@ void ILI9488::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t colo
if((x + w - 1) >= _width) w = _width - x;
if((y + h - 1) >= _height) h = _height - y;
setAddrWindow(x, y, x+w-1, y+h-1);
setAddrWindow_int(x, y, x+w-1, y+h-1);
uint8_t r = (color & 0xF800) >> 11;
uint8_t g = (color & 0x07E0) >> 5;

View File

@ -136,6 +136,7 @@ class ILI9488 : public Renderer {
void begin(void);
void DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font);
void setAddrWindow_int(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void setScrollArea(uint16_t topFixedArea, uint16_t bottomFixedArea);
void scroll(uint16_t pixels);

View File

@ -32,6 +32,10 @@
//#define USE_GFX_FONTS
#define USE_TINY_FONT
#ifdef ESP32
#define USE_ICON_FONT
#endif
uint8_t wr_redir=0;
uint8_t *buffer;
@ -223,27 +227,32 @@ void Renderer::setTextFont(uint8_t f) {
break;
case 7:
selected_font = &RAFont;
break;
default:
font=0;
selected_font = &Font12;
break;
}
#else
#ifdef USE_EPD_FONTS
if (1 == font) {
switch (font) {
selected_font = &Font12;
} else {
#ifdef USE_TINY_FONT
if (2 == font) {
break;
case 2:
selected_font = &Font24;
} else {
break;
case 3:
#ifdef USE_TINY_FONT
selected_font = &Font8;
}
#else
selected_font = &Font24;
#endif
break;
default:
selected_font = &Font12;
break;
}
#endif
#endif
}
@ -513,6 +522,9 @@ void Renderer::setDrawMode(uint8_t mode) {
drawmode=mode;
}
void Renderer::invertDisplay(boolean i) {
}
void VButton::xdrawButton(bool inverted) {
wr_redir=1;
drawButton(inverted);
@ -520,4 +532,6 @@ void VButton::xdrawButton(bool inverted) {
}
/* END OF FILE */

View File

@ -35,6 +35,7 @@ public:
virtual void dim(uint8_t contrast);
virtual void pushColors(uint16_t *data, uint8_t len, boolean first);
virtual void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
virtual void invertDisplay(boolean i);
void setDrawMode(uint8_t mode);
uint8_t drawmode;
virtual void FastString(uint16_t x,uint16_t y,uint16_t tcolor, const char* str);