support for centered pictures (#21140)

This commit is contained in:
gemu 2024-04-11 15:36:37 +02:00 committed by GitHub
parent d5ee89677b
commit 7984b7513c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -593,11 +593,22 @@ void DisplayText(void)
*ep = 0; *ep = 0;
ep++; ep++;
int16_t scale = 0; int16_t scale = 0;
int16_t xs = 0;
int16_t ys = 0;
if (isdigit(*ep)) { if (isdigit(*ep)) {
var = atoiv(ep, &scale); var = atoiv(ep, &scale);
ep += var; ep += var;
if (*ep == ':') {
ep++;
var = atoiv(ep, &xs);
ep += var;
ep++;
var = atoiv(ep, &ys);
ep += var;
} }
Draw_RGB_Bitmap(cp,disp_xpos,disp_ypos, scale, false); }
Draw_RGB_Bitmap(cp, disp_xpos, disp_ypos, scale, false, xs, ys);
cp = ep; cp = ep;
} }
} }
@ -1066,19 +1077,29 @@ extern FS *ffsp;
#ifdef USE_TOUCH_BUTTONS #ifdef USE_TOUCH_BUTTONS
case 'b': case 'b':
{ int16_t num, gxp, gyp, gxs, gys, outline, fill, textcolor, textsize; uint8_t dflg = 1, sbt = 0; { int16_t num, gxp, gyp, gxs, gys, outline, fill, textcolor, textsize; uint8_t dflg = 1, sbt = 0;
if (*cp == 'e' || *cp == 'd') { if (*cp == 'e' || *cp == 'd' || *cp == 'D') {
// enable disable // enable disable delete
uint8_t dis = 0; uint8_t dis = 0;
if (*cp == 'd') dis = 1; if (*cp == 'd') dis = 1;
uint8_t del = 0;
if (*cp == 'D') {
del = 1;
}
cp++; cp++;
var = atoiv(cp, &num); var = atoiv(cp, &num);
num = num % MAX_TOUCH_BUTTONS; num = num % MAX_TOUCH_BUTTONS;
cp += var; cp += var;
if (buttons[num]) { if (buttons[num]) {
if (del) {
if (renderer) renderer->fillRect(buttons[num]->spars.xp, buttons[num]->spars.yp, buttons[num]->spars.xs, buttons[num]->spars.ys, bg_color);
delete buttons[num];
buttons[num] = 0;
} else {
buttons[num]->vpower.disable = dis; buttons[num]->vpower.disable = dis;
if (!dis) { if (!dis) {
if (buttons[num]->vpower.is_virtual) buttons[num]->xdrawButton(buttons[num]->vpower.on_off); if (buttons[num]->vpower.is_virtual) buttons[num]->xdrawButton(buttons[num]->vpower.on_off);
else buttons[num]->xdrawButton(bitRead(TasmotaGlobal.power,num)); else buttons[num]->xdrawButton(bitRead(TasmotaGlobal.power, num));
}
} }
} }
break; break;
@ -1091,10 +1112,10 @@ extern FS *ffsp;
cp++; cp++;
sbt = 1; sbt = 1;
} }
var=atoiv(cp,&num); var = atoiv(cp,&num);
cp+=var; cp += var;
uint8_t bflags=num>>8; uint8_t bflags = num >> 8;
num=num%MAX_TOUCH_BUTTONS; num = num % MAX_TOUCH_BUTTONS;
if (*cp == 's') { if (*cp == 's') {
cp++; cp++;
var=atoiv(cp,&gxp); var=atoiv(cp,&gxp);
@ -1144,7 +1165,7 @@ extern FS *ffsp;
delete buttons[num]; delete buttons[num];
} }
if (renderer) { if (renderer) {
buttons[num]= new VButton(); buttons[num] = new VButton();
if (buttons[num]) { if (buttons[num]) {
if (!sbt) { if (!sbt) {
buttons[num]->vpower.slider = 0; buttons[num]->vpower.slider = 0;
@ -2291,7 +2312,7 @@ char ppath[16];
} else { } else {
strcat(ppath, ".jpg"); strcat(ppath, ".jpg");
} }
Draw_RGB_Bitmap(ppath, xp, yp, 0, inverted); Draw_RGB_Bitmap(ppath, xp, yp, 0, inverted, 0, 0);
} }
#endif // USE_TOUCH_BUTTONS #endif // USE_TOUCH_BUTTONS
@ -2311,7 +2332,7 @@ char get_jpeg_size(unsigned char* data, unsigned int data_size, unsigned short *
#ifdef USE_UFILESYS #ifdef USE_UFILESYS
extern FS *ufsp; extern FS *ufsp;
#define XBUFF_LEN 128 #define XBUFF_LEN 128
void Draw_RGB_Bitmap(char *file, uint16_t xp, uint16_t yp, uint8_t scale, bool inverted ) { void Draw_RGB_Bitmap(char *file, uint16_t xp, uint16_t yp, uint8_t scale, bool inverted, uint16_t xs, uint16_t ys ) {
if (!renderer) return; if (!renderer) return;
File fp; File fp;
char *ending = 0; char *ending = 0;
@ -2327,7 +2348,6 @@ void Draw_RGB_Bitmap(char *file, uint16_t xp, uint16_t yp, uint8_t scale, bool i
for (uint32_t cnt = 0; cnt < strlen(ending); cnt++) { for (uint32_t cnt = 0; cnt < strlen(ending); cnt++) {
estr[cnt] = tolower(ending[cnt]); estr[cnt] = tolower(ending[cnt]);
} }
estr[3] = 0;
if (!strcmp(estr,"rgb")) { if (!strcmp(estr,"rgb")) {
// special rgb format // special rgb format
@ -2337,6 +2357,16 @@ void Draw_RGB_Bitmap(char *file, uint16_t xp, uint16_t yp, uint8_t scale, bool i
fp.read((uint8_t*)&xsize, 2); fp.read((uint8_t*)&xsize, 2);
uint16_t ysize; uint16_t ysize;
fp.read((uint8_t*)&ysize, 2); fp.read((uint8_t*)&ysize, 2);
uint16_t xoffs;
uint16_t yoffs;
if (xs > 0) {
// center in area
xoffs = (xs - xsize) / 2;
yoffs = (ys - ysize) / 2;
xp += xoffs;
yp += yoffs;
}
#ifndef SLOW_RGB16 #ifndef SLOW_RGB16
renderer->setAddrWindow(xp, yp, xp + xsize, yp + ysize); renderer->setAddrWindow(xp, yp, xp + xsize, yp + ysize);
uint16_t *rgb = (uint16_t *)special_malloc(xsize * 2); uint16_t *rgb = (uint16_t *)special_malloc(xsize * 2);
@ -2364,7 +2394,7 @@ void Draw_RGB_Bitmap(char *file, uint16_t xp, uint16_t yp, uint8_t scale, bool i
} }
#endif #endif
fp.close(); fp.close();
} else if (!strcmp(estr,"jpg")) { } else if (!strcmp(estr,"jpg") || !strcmp(estr,"jpeg")) {
// jpeg files on ESP32 with more memory // jpeg files on ESP32 with more memory
#ifdef ESP32 #ifdef ESP32
#ifdef JPEG_PICTS #ifdef JPEG_PICTS
@ -2381,8 +2411,17 @@ void Draw_RGB_Bitmap(char *file, uint16_t xp, uint16_t yp, uint8_t scale, bool i
if (res) { if (res) {
uint16_t xsize; uint16_t xsize;
uint16_t ysize; uint16_t ysize;
uint16_t xoffs;
uint16_t yoffs;
if (mem[0] == 0xff && mem[1] == 0xd8) { if (mem[0] == 0xff && mem[1] == 0xd8) {
get_jpeg_size(mem, size, &xsize, &ysize); get_jpeg_size(mem, size, &xsize, &ysize);
if (xs > 0) {
// center in area
xoffs = (xs - xsize) / 2;
yoffs = (ys - ysize) / 2;
xp += xoffs;
yp += yoffs;
}
//Serial.printf(" x,y,fs %d - %d - %d\n",xsize, ysize, size ); //Serial.printf(" x,y,fs %d - %d - %d\n",xsize, ysize, size );
if (xsize && ysize) { if (xsize && ysize) {
uint8_t *out_buf = (uint8_t *)special_malloc((xsize * ysize * 3) + 4); uint8_t *out_buf = (uint8_t *)special_malloc((xsize * ysize * 3) + 4);
@ -2411,6 +2450,9 @@ void Draw_RGB_Bitmap(char *file, uint16_t xp, uint16_t yp, uint8_t scale, bool i
} }
} }
} }
if (scale) {
if (renderer) renderer->drawRect(xp, yp, xsize, ysize, GetColorFromIndex(scale));
}
} }
free(mem); free(mem);
} }