CCDraw: add possibility to use background images as item background

Provides functionality to use a backround image instead to render
usual box. If an image is defined, box render is disabled, but behavior
for hide, kill, cache... is not changed.

TODO:
- maybe needs global caching because images are not yet managed like icons in framebuffer class
This commit is contained in:
2017-03-11 00:45:25 +01:00
parent c857fc49be
commit ccb82083e2
2 changed files with 152 additions and 60 deletions

View File

@@ -3,7 +3,7 @@
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components. Classes for generic GUI-related components.
Copyright (C) 2015, Thilo Graf 'dbt' Copyright (C) 2012-2017, Thilo Graf 'dbt'
Copyright (C) 2012, Michael Liebmann 'micha-bbg' Copyright (C) 2012, Michael Liebmann 'micha-bbg'
License: GPL License: GPL
@@ -27,8 +27,9 @@
#include "cc_draw.h" #include "cc_draw.h"
#include "cc_timer.h" #include "cc_timer.h"
#include <cs_api.h> #include <cs_api.h>
#include <driver/pictureviewer/pictureviewer.h>
#include <system/debug.h> #include <system/debug.h>
extern CPictureViewer * g_PicViewer;
CCDraw::CCDraw() : COSDFader(g_settings.theme.menu_Content_alpha) CCDraw::CCDraw() : COSDFader(g_settings.theme.menu_Content_alpha)
{ {
@@ -44,6 +45,8 @@ CCDraw::CCDraw() : COSDFader(g_settings.theme.menu_Content_alpha)
col_frame = col_frame_old = COL_FRAME_PLUS_0; col_frame = col_frame_old = COL_FRAME_PLUS_0;
col_shadow_clean = 0; col_shadow_clean = 0;
cc_body_image = cc_body_image_old = string();
fr_thickness = fr_thickness_old = 0; fr_thickness = fr_thickness_old = 0;
corner_type = corner_type_old = CORNER_ALL; corner_type = corner_type_old = CORNER_ALL;
@@ -176,6 +179,11 @@ inline bool CCDraw::applyColChanges()
cc_body_gradient_direction_old = cc_body_gradient_direction; cc_body_gradient_direction_old = cc_body_gradient_direction;
ret = true; ret = true;
} }
if (cc_body_image != cc_body_image_old){
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], col changes cc_body_image %s != cc_body_image_old %s...\033[0m\n", __func__, __LINE__, cc_body_image.c_str(), cc_body_image_old.c_str());
cc_body_image_old = cc_body_image;
ret = true;
}
return ret; return ret;
} }
@@ -467,13 +475,13 @@ void CCDraw::enablePaintCache(bool enable)
//paint framebuffer layers //paint framebuffer layers
void CCDraw::paintFbItems(bool do_save_bg) void CCDraw::paintFbItems(bool do_save_bg)
{ {
//pick up signal if filled //Pick up signal if filled and execute slots.
OnBeforePaintLayers(); OnBeforePaintLayers();
//first modify background handling //First we modify background handling.
enableSaveBg(do_save_bg); enableSaveBg(do_save_bg);
//save background before first paint, cc_save_bg must be true //Save background before first paint, cc_save_bg must be true.
if (firstPaint && cc_save_bg){ if (firstPaint && cc_save_bg){
/* On first we must ensure that screen buffer is empty. /* On first we must ensure that screen buffer is empty.
* Here we clean possible screen buffers in bg layers, * Here we clean possible screen buffers in bg layers,
@@ -482,7 +490,7 @@ void CCDraw::paintFbItems(bool do_save_bg)
clearSavedScreen(); clearSavedScreen();
/* On second step we check for /* On second step we check for
* usable item dimensions and exit here if found any problem * usable item dimensions and exit here if found any problem.
*/ */
for(size_t i=0; i<v_fbdata.size(); i++){ for(size_t i=0; i<v_fbdata.size(); i++){
if (!CheckFbData(v_fbdata[i], __func__, __LINE__)){ if (!CheckFbData(v_fbdata[i], __func__, __LINE__)){
@@ -499,7 +507,7 @@ void CCDraw::paintFbItems(bool do_save_bg)
v_fbdata[i].dx, v_fbdata[i].dx,
v_fbdata[i].dy); v_fbdata[i].dy);
/* here we save the background of current box before paint. /* Here we save the background of current box before paint.
* Only the reserved fbdata type CC_FBDATA_TYPE_BGSCREEN is here required and is used for this. * Only the reserved fbdata type CC_FBDATA_TYPE_BGSCREEN is here required and is used for this.
* This pixel buffer is required for the hide() method that will * This pixel buffer is required for the hide() method that will
* call the restore method from framebuffer class to restore * call the restore method from framebuffer class to restore
@@ -516,7 +524,7 @@ void CCDraw::paintFbItems(bool do_save_bg)
for(size_t i=0; i< v_fbdata.size(); i++){ for(size_t i=0; i< v_fbdata.size(); i++){
cc_fbdata_t& fbdata = v_fbdata[i]; cc_fbdata_t& fbdata = v_fbdata[i];
// Don't paint on dimension or position error dx or dy are 0 // Don't paint on dimension or position error dx or dy are 0.
if (!CheckFbData(fbdata, __func__, __LINE__)){ if (!CheckFbData(fbdata, __func__, __LINE__)){
continue; continue;
} }
@@ -531,10 +539,10 @@ void CCDraw::paintFbItems(bool do_save_bg)
fbdata.dx, fbdata.dx,
fbdata.dy); fbdata.dy);
/*paint all fb relevant basic parts (shadow, frame and body) /* Paint all fb relevant basic parts (shadow, frame and body)
* with all specified properties, paint_bg must be enabled * with all specified properties, paint_bg must be enabled.
*/ */
if (cc_enable_frame){ if (cc_enable_frame && cc_body_image.empty()){
if (fbtype == CC_FBDATA_TYPE_FRAME) { if (fbtype == CC_FBDATA_TYPE_FRAME) {
if (fbdata.frame_thickness > 0 && cc_allow_paint){ if (fbdata.frame_thickness > 0 && cc_allow_paint){
frameBuffer->paintBoxFrame(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.frame_thickness, fbdata.color, fbdata.r, fbdata.rtype); frameBuffer->paintBoxFrame(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.frame_thickness, fbdata.color, fbdata.r, fbdata.rtype);
@@ -550,10 +558,10 @@ void CCDraw::paintFbItems(bool do_save_bg)
} }
if (fbtype == CC_FBDATA_TYPE_SHADOW_BOX && ((!is_painted || !fbdata.is_painted)|| shadow_force || force_paint_bg)) { if (fbtype == CC_FBDATA_TYPE_SHADOW_BOX && ((!is_painted || !fbdata.is_painted)|| shadow_force || force_paint_bg)) {
if (fbdata.enabled) { if (fbdata.enabled) {
/* here we paint the shadow around the body /* Here we paint the shadow around the body.
* on 1st step we check for already cached screen buffer, if true * On 1st step we check for already cached screen buffer, if true
* then restore this instead to call the paint methode. * then restore this instead to call the paint methode.
* This could be usally, if we use existant instances of "this" object * This could be usally, if we use an existant instances of "this" object
*/ */
if (cc_allow_paint){ if (cc_allow_paint){
if (fbdata.pixbuf){ if (fbdata.pixbuf){
@@ -562,7 +570,7 @@ void CCDraw::paintFbItems(bool do_save_bg)
}else{ }else{
frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.color, fbdata.r, fbdata.rtype); frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.color, fbdata.r, fbdata.rtype);
} }
//if is paint cache enabled //If is paint cache enabled, catch screen into cache
if (cc_paint_cache && fbdata.pixbuf == NULL) if (cc_paint_cache && fbdata.pixbuf == NULL)
fbdata.pixbuf = getScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy); fbdata.pixbuf = getScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy);
fbdata.is_painted = true; fbdata.is_painted = true;
@@ -572,63 +580,104 @@ void CCDraw::paintFbItems(bool do_save_bg)
if (paint_bg){ if (paint_bg){
if (fbtype == CC_FBDATA_TYPE_BOX){ if (fbtype == CC_FBDATA_TYPE_BOX){
if(cc_allow_paint) { if(cc_allow_paint) {
/* here we paint the main body of box /* Here we paint the main body of box.
* on 1st step we check for already cached background buffer, if true * On 1st step we check for already cached background buffer, if true
* then restore this instead to call the paint methodes and gradient creation * then restore this instead to call the paint methodes and gradient creation.
* paint cache can be enable/disable with enablePaintCache() * Paint cache can be enable/disable with enablePaintCache()
*/ */
if (fbdata.pixbuf){ if (fbdata.pixbuf){
/* If is paint cache enabled and cache is filled, it's prefered to paint
* from cache. Cache is also filled if body background images are used
*/
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], paint body from cache...\033[0m\n", __func__, __LINE__); dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], paint body from cache...\033[0m\n", __func__, __LINE__);
frameBuffer->RestoreScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.pixbuf); frameBuffer->RestoreScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.pixbuf);
}else{ }else{
//ensure clean gradient data on disabled gradient //Ensure clean gradient data on disabled gradient.
if(cc_body_gradient_enable == CC_COLGRAD_OFF && fbdata.gradient_data){ if(cc_body_gradient_enable == CC_COLGRAD_OFF && fbdata.gradient_data){
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], gradient mode is disabled but filled\033[0m\n", __func__, __LINE__); dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], gradient mode is disabled but filled\033[0m\n", __func__, __LINE__);
clearFbGradientData(); clearFbGradientData();
} }
if (cc_body_gradient_enable != CC_COLGRAD_OFF){
/* if color gradient enabled we create a gradient_data /* If background image is defined,
* instance and add it to the fbdata object * we try to render an image instead to render default box.
* On disabled coloor gradient we do paint only a default box * Paint of background image is prefered, next steps will be ignored!
*/ */
if (fbdata.gradient_data == NULL){ if (!cc_body_image.empty()){
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], crate new gradient data)...\033[0m\n", __func__, __LINE__); if (g_PicViewer->DisplayImage(cc_body_image, fbdata.x, fbdata.y, fbdata.dx, fbdata.dy)){
fbdata.gradient_data = getGradientData(); // catch screen and store into paint cache
fbdata.pixbuf = getScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy);
fbdata.is_painted = true;
}else{
if (fbdata.pixbuf){
delete[] fbdata.pixbuf;
fbdata.pixbuf = NULL;
}
fbdata.is_painted = false;
} }
// if found empty gradient buffer, create it, otherwise paint from gradient cache // On failed image paint, write this into log and reset image name.
if (fbdata.gradient_data->boxBuf == NULL){ if (!fbdata.is_painted){
if (!fbdata.pixbuf){ dprintf(DEBUG_NORMAL, "\033[33m\[CCDraw]\t[%s - %d], WARNING: bg image %s defined, but paint failed,\nfallback to default rendering...\033[0m\n", __func__, __LINE__, cc_body_image.c_str());
// on enabled clean up, paint blank screen before create gradient box, this prevents possible ghost text with hw acceleration cc_body_image = "";
if (cc_gradient_bg_cleanup) }
frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, 0, fbdata.r, fbdata.rtype); }
// create gradient buffer and paint gradient box /* If no background image is defined, we paint default box or box with gradient
fbdata.gradient_data->boxBuf = frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, 0, fbdata.gradient_data, fbdata.r, fbdata.rtype); * This is also possible if any background image is defined but image paint ist failed
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], paint and cache new gradient into gradient cache...\033[0m\n", __func__, __LINE__); */
if (cc_body_image.empty()){
if (cc_body_gradient_enable != CC_COLGRAD_OFF ){
/* If color gradient enabled we create a gradient_data
* instance and add it to the fbdata object
* On disabled color gradient or image paint was failed, we do paint only a default box
*/
if (fbdata.gradient_data == NULL){
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], create new gradient data)...\033[0m\n", __func__, __LINE__);
fbdata.gradient_data = getGradientData();
} }
/* On enabled paint cache or clean up, catch the screen into paint cache and clean up unused gradient buffer. if (fbdata.gradient_data->boxBuf == NULL){
* If we don't do this, gradient cache is used. if (fbdata.pixbuf == NULL){
*/ /* Before we paint any gradient box with hw acceleration, we must cleanup first.
if (cc_paint_cache || cc_gradient_bg_cleanup){ * FIXME: This is only a workaround for this framebuffer behavior on enabled hw acceleration.
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], cache new created gradient into external cache...\033[0m\n", __func__, __LINE__); * Without this, ugly ghost letters or ghost images inside gradient boxes are possible.
fbdata.pixbuf = getScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy); */
if (clearFbGradientData()) if (cc_gradient_bg_cleanup)
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], remove unused gradient data...\033[0m\n", __func__, __LINE__); frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, 0, fbdata.r, fbdata.rtype);
// create gradient buffer and paint gradient box
fbdata.gradient_data->boxBuf = frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, 0, fbdata.gradient_data, fbdata.r, fbdata.rtype);
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], paint and cache new gradient into gradient cache...\033[0m\n", __func__, __LINE__);
}
/* On enabled paint cache or clean up, catch the screen into paint cache and clean up unused gradient buffer.
* If we don't do this explicit, gradient cache is used.
*/
if (cc_paint_cache || cc_gradient_bg_cleanup){
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], cache new created gradient into external cache...\033[0m\n", __func__, __LINE__);
fbdata.pixbuf = getScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy);
if (clearFbGradientData())
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], remove unused gradient data...\033[0m\n", __func__, __LINE__);
}
}else{
// If found gradient buffer, paint box from gradient cache.
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], paint cached gradient)...\033[0m\n", __func__, __LINE__);
frameBuffer->checkFbArea(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, true);
frameBuffer->blitBox2FB(fbdata.gradient_data->boxBuf, fbdata.gradient_data->dx, fbdata.dy, fbdata.gradient_data->x, fbdata.y);
frameBuffer->checkFbArea(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, false);
} }
}else{ }else{
//use gradient cache to repaint gradient box /* If is nothihng cached or no background image was defined or image paint was failed,
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], paint cached gradient)...\033[0m\n", __func__, __LINE__); * render a default box.
frameBuffer->checkFbArea(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, true); */
frameBuffer->blitBox2FB(fbdata.gradient_data->boxBuf, fbdata.gradient_data->dx, fbdata.dy, fbdata.gradient_data->x, fbdata.y); dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], paint default box)...\033[0m\n", __func__, __LINE__);
frameBuffer->checkFbArea(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, false); frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.color, fbdata.r, fbdata.rtype);
//If is paint cache enabled, catch screen into cache.
if (cc_paint_cache)
fbdata.pixbuf = getScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy);
} }
}else{
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], paint default box)...\033[0m\n", __func__, __LINE__);
frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.color, fbdata.r, fbdata.rtype);
if (cc_paint_cache)
fbdata.pixbuf = getScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy);
} }
} }
v_fbdata[i].is_painted = true; v_fbdata[i].is_painted = true;
@@ -653,7 +702,6 @@ void CCDraw::paintFbItems(bool do_save_bg)
//reset is painted ignore flag to default value //reset is painted ignore flag to default value
force_paint_bg = false; force_paint_bg = false;
//pick up signal if filled
OnAfterPaintLayers(); OnAfterPaintLayers();
} }
@@ -797,3 +845,21 @@ bool CCDraw::cancelBlink(bool keep_on_screen)
return res; return res;
} }
bool CCDraw::setBodyBGImage(const std::string& image_path)
{
if (cc_body_image == image_path)
return false;
cc_body_image = image_path;
if (clearPaintCache())
dprintf(DEBUG_NORMAL, "\033[33m\[CCDraw]\t[%s - %d], new body background image defined: %s , \033[0m\n", __func__, __LINE__, cc_body_image.c_str());
return true;
}
bool CCDraw::setBodyBGImageName(const std::string& image_name)
{
return setBodyBGImage(frameBuffer->getIconPath(image_name));
}

View File

@@ -3,7 +3,7 @@
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components. Classes for generic GUI-related components.
Copyright (C) 2015, Thilo Graf 'dbt' Copyright (C) 2012-2017, Thilo Graf 'dbt'
Copyright (C) 2012, Michael Liebmann 'micha-bbg' Copyright (C) 2012, Michael Liebmann 'micha-bbg'
License: GPL License: GPL
@@ -78,6 +78,8 @@ class CCDraw : public COSDFader, public CComponentsSignals
fb_pixel_t col_frame, col_frame_old; fb_pixel_t col_frame, col_frame_old;
///internal property: color for shadow clean up ///internal property: color for shadow clean up
fb_pixel_t col_shadow_clean; fb_pixel_t col_shadow_clean;
///property: background image, see also setBodyBGImage()
std::string cc_body_image, cc_body_image_old;
///property: frame thickness, see also setFrameThickness() ///property: frame thickness, see also setFrameThickness()
int fr_thickness, fr_thickness_old; int fr_thickness, fr_thickness_old;
@@ -407,8 +409,32 @@ class CCDraw : public COSDFader, public CComponentsSignals
*/ */
virtual void killShadow(const fb_pixel_t& bg_color = COL_BACKGROUND_PLUS_0, const int& corner_radius = -1); virtual void killShadow(const fb_pixel_t& bg_color = COL_BACKGROUND_PLUS_0, const int& corner_radius = -1);
virtual void enableGradientBgCleanUp(bool enable = true) { cc_gradient_bg_cleanup = enable; }; virtual void enableGradientBgCleanUp(bool enable = true) { cc_gradient_bg_cleanup = enable; }
virtual void disableGradientBgCleanUp(){ enableGradientBgCleanUp(false); }; virtual void disableGradientBgCleanUp(){ enableGradientBgCleanUp(false); }
/**Sets an image path for body background, returns true if new image was applied.
*
* @return bool
*
* @param[in] image_path Path to image.
*
* @see
* cc_body_image
* setBodyBGImageName()
*/
virtual bool setBodyBGImage(const std::string& image_path);
/**Sets an image name for body background, returns true if new image was applied.
*
* @return bool
*
* @param[in] image_name Basename of image.
*
* @see
* cc_body_image
* setBodyBGImage()
*/
virtual bool setBodyBGImageName(const std::string& image_name);
}; };
#endif #endif