From: svenhoefer Date: Tue, 3 May 2016 10:09:29 +0000 (+0200) Subject: - add center function for images/ttf X-Git-Url: https://git.webhop.me/?a=commitdiff_plain;h=ff527da9085906ce2af9e64e4741ef949361c6ff;p=lcd4linux.git - add center function for images/ttf --- diff --git a/drv_generic_graphic.c b/drv_generic_graphic.c index ccf1dee..847bbf4 100644 --- a/drv_generic_graphic.c +++ b/drv_generic_graphic.c @@ -571,8 +571,31 @@ int drv_generic_graphic_image_draw(WIDGET * W) return 0; } - /* maybe grow layout framebuffer */ - drv_generic_graphic_resizeFB(row + height, col + width); + int center = P2N(&Image->center); + if (center) { + int aHight = Image->height; + if (Image->oldheight > Image->height) aHight = Image->oldheight; + // set layout framebuffer to a fixed size + drv_generic_graphic_resizeFB(row + aHight, LCOLS); + // flush area + drv_generic_graphic_blit(row, 0, aHight, LCOLS); + // fill it black or transparent + for (y = 0; y < aHight; y++) { + for (x = 0; x < LCOLS; x++) { + int i = (row + y ) * LCOLS + LCOLS + x; + drv_generic_graphic_FB[layer][i] = (Driver == "SamsungSPF") ? BG_COL : NO_COL; + } + } + // align logo in the area + if (width < LCOLS) + col = (LCOLS / 2) - (width / 2); + else + col = 1; + row += (aHight - height) / 2; + } else { + /* maybe grow layout framebuffer */ + drv_generic_graphic_resizeFB(row + height, col + width); + } /* render image */ visible = P2N(&Image->visible); diff --git a/widget_image.c b/widget_image.c index 19f472c..a0bd3eb 100644 --- a/widget_image.c +++ b/widget_image.c @@ -78,6 +78,7 @@ static void widget_image_render(const char *Name, WIDGET_IMAGE * Image) /* clear bitmap */ if (Image->bitmap) { + Image->oldheight = Image->height; int i; for (i = 0; i < Image->height * Image->width; i++) { RGBA empty = {.R = 0x00,.G = 0x00,.B = 0x00,.A = 0x00 }; @@ -138,12 +139,12 @@ static void widget_image_render(const char *Name, WIDGET_IMAGE * Image) /* maybe resize bitmap */ gdImage = Image->gdImage; - if (gdImage->sx > Image->width) { + if (gdImage->sx > Image->width || P2N(&Image->center)) { Image->width = gdImage->sx; free(Image->bitmap); Image->bitmap = NULL; } - if (gdImage->sy > Image->height) { + if (gdImage->sy > Image->height || P2N(&Image->center)) { Image->height = gdImage->sy; free(Image->bitmap); Image->bitmap = NULL; @@ -202,6 +203,7 @@ static void widget_image_update(void *Self) property_eval(&Image->reload); property_eval(&Image->visible); property_eval(&Image->inverted); + property_eval(&Image->center); /* render image into bitmap */ widget_image_render(W->name, Image); @@ -249,6 +251,7 @@ int widget_image_init(WIDGET * Self) property_load(section, "reload", "0", &Image->reload); property_load(section, "visible", "1", &Image->visible); property_load(section, "inverted", "0", &Image->inverted); + property_load(section, "center", "0", &Image->center); /* sanity checks */ if (!property_valid(&Image->file)) { @@ -292,6 +295,7 @@ int widget_image_quit(WIDGET * Self) property_free(&Image->reload); property_free(&Image->visible); property_free(&Image->inverted); + property_free(&Image->center); free(Self->data); Self->data = NULL; } diff --git a/widget_image.h b/widget_image.h index 3480504..6a4edc1 100644 --- a/widget_image.h +++ b/widget_image.h @@ -36,12 +36,14 @@ typedef struct WIDGET_IMAGE { void *gdImage; /* raw gd image */ RGBA *bitmap; /* image bitmap */ int width, height; /* size of the image */ + int oldheight; /* height of the image before */ PROPERTY file; /* image filename */ PROPERTY scale; /* scale image in percent */ PROPERTY update; /* update interval */ PROPERTY reload; /* reload image on update? */ PROPERTY visible; /* image visible? */ PROPERTY inverted; /* image inverted? */ + PROPERTY center; /* image centered? */ } WIDGET_IMAGE; extern WIDGET_CLASS Widget_Image; diff --git a/widget_ttf.c b/widget_ttf.c index df08126..b103c96 100644 --- a/widget_ttf.c +++ b/widget_ttf.c @@ -87,6 +87,7 @@ static void widget_ttf_render(const char *Name, WIDGET_TTF * Image) /* clear bitmap */ if (Image->bitmap) { + Image->oldheight = Image->height; int i; for (i = 0; i < Image->height * Image->width; i++) { @@ -143,13 +144,13 @@ static void widget_ttf_render(const char *Name, WIDGET_TTF * Image) /* maybe resize bitmap */ gdImage = Image->gdImage; - if (gdImage->sx > Image->width) + if (gdImage->sx > Image->width || P2N(&Image->center)) { { Image->width = gdImage->sx; free(Image->bitmap); Image->bitmap = NULL; } - if (gdImage->sy > Image->height) + if (gdImage->sy > Image->height || P2N(&Image->center)) { { Image->height = gdImage->sy; free(Image->bitmap); @@ -219,6 +220,7 @@ static void widget_ttf_update(void *Self) property_eval(&Image->reload); property_eval(&Image->visible); property_eval(&Image->inverted); + property_eval(&Image->center); /* render image into bitmap */ widget_ttf_render(W->name, Image); @@ -270,6 +272,7 @@ int widget_ttf_init(WIDGET * Self) property_load(section, "reload", "0", &Image->reload); property_load(section, "visible", "1", &Image->visible); property_load(section, "inverted", "0", &Image->inverted); + property_load(section, "center", "0", &Image->center); /* sanity checks */ if (!property_valid(&Image->font)) @@ -322,6 +325,7 @@ int widget_ttf_quit(WIDGET * Self) property_free(&Image->reload); property_free(&Image->visible); property_free(&Image->inverted); + property_free(&Image->center); free(Self->data); Self->data = NULL; } diff --git a/widget_ttf.h b/widget_ttf.h index f53dfe9..b56ba12 100644 --- a/widget_ttf.h +++ b/widget_ttf.h @@ -33,6 +33,7 @@ typedef struct WIDGET_TTF void *gdImage; /* raw gd image */ RGBA *bitmap; /* image bitmap */ int width, height; /* size of the image */ + int oldheight; /* height of the image before */ PROPERTY value; /* text to render */ PROPERTY size; /* fontsize */ PROPERTY font; /* path to font */ @@ -41,6 +42,7 @@ typedef struct WIDGET_TTF PROPERTY reload; /* reload image on update? */ PROPERTY visible; /* image visible? */ PROPERTY inverted; /* image inverted? */ + PROPERTY center; /* image centered? */ } WIDGET_TTF; extern WIDGET_CLASS Widget_Truetype;