mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-28 16:01:20 +02:00
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:
@@ -3,7 +3,7 @@
|
||||
Copyright (C) 2001 by Steffen Hehn 'McClean'
|
||||
|
||||
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'
|
||||
|
||||
License: GPL
|
||||
@@ -27,8 +27,9 @@
|
||||
#include "cc_draw.h"
|
||||
#include "cc_timer.h"
|
||||
#include <cs_api.h>
|
||||
|
||||
#include <driver/pictureviewer/pictureviewer.h>
|
||||
#include <system/debug.h>
|
||||
extern CPictureViewer * g_PicViewer;
|
||||
|
||||
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_shadow_clean = 0;
|
||||
|
||||
cc_body_image = cc_body_image_old = string();
|
||||
|
||||
fr_thickness = fr_thickness_old = 0;
|
||||
|
||||
corner_type = corner_type_old = CORNER_ALL;
|
||||
@@ -176,6 +179,11 @@ inline bool CCDraw::applyColChanges()
|
||||
cc_body_gradient_direction_old = cc_body_gradient_direction;
|
||||
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;
|
||||
}
|
||||
@@ -467,13 +475,13 @@ void CCDraw::enablePaintCache(bool enable)
|
||||
//paint framebuffer layers
|
||||
void CCDraw::paintFbItems(bool do_save_bg)
|
||||
{
|
||||
//pick up signal if filled
|
||||
//Pick up signal if filled and execute slots.
|
||||
OnBeforePaintLayers();
|
||||
|
||||
//first modify background handling
|
||||
//First we modify background handling.
|
||||
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){
|
||||
/* On first we must ensure that screen buffer is empty.
|
||||
* Here we clean possible screen buffers in bg layers,
|
||||
@@ -482,7 +490,7 @@ void CCDraw::paintFbItems(bool do_save_bg)
|
||||
clearSavedScreen();
|
||||
|
||||
/* 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++){
|
||||
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].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.
|
||||
* This pixel buffer is required for the hide() method that will
|
||||
* 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++){
|
||||
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__)){
|
||||
continue;
|
||||
}
|
||||
@@ -531,10 +539,10 @@ void CCDraw::paintFbItems(bool do_save_bg)
|
||||
fbdata.dx,
|
||||
fbdata.dy);
|
||||
|
||||
/*paint all fb relevant basic parts (shadow, frame and body)
|
||||
* with all specified properties, paint_bg must be enabled
|
||||
/* Paint all fb relevant basic parts (shadow, frame and body)
|
||||
* 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 (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);
|
||||
@@ -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 (fbdata.enabled) {
|
||||
/* here we paint the shadow around the body
|
||||
* on 1st step we check for already cached screen buffer, if true
|
||||
* then restore this instead to call the paint methode.
|
||||
* This could be usally, if we use existant instances of "this" object
|
||||
/* Here we paint the shadow around the body.
|
||||
* On 1st step we check for already cached screen buffer, if true
|
||||
* then restore this instead to call the paint methode.
|
||||
* This could be usally, if we use an existant instances of "this" object
|
||||
*/
|
||||
if (cc_allow_paint){
|
||||
if (fbdata.pixbuf){
|
||||
@@ -562,7 +570,7 @@ void CCDraw::paintFbItems(bool do_save_bg)
|
||||
}else{
|
||||
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)
|
||||
fbdata.pixbuf = getScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy);
|
||||
fbdata.is_painted = true;
|
||||
@@ -572,63 +580,104 @@ void CCDraw::paintFbItems(bool do_save_bg)
|
||||
if (paint_bg){
|
||||
if (fbtype == CC_FBDATA_TYPE_BOX){
|
||||
if(cc_allow_paint) {
|
||||
/* here we paint the main body of box
|
||||
* on 1st step we check for already cached background buffer, if true
|
||||
* then restore this instead to call the paint methodes and gradient creation
|
||||
* paint cache can be enable/disable with enablePaintCache()
|
||||
/* Here we paint the main body of box.
|
||||
* On 1st step we check for already cached background buffer, if true
|
||||
* then restore this instead to call the paint methodes and gradient creation.
|
||||
* Paint cache can be enable/disable with enablePaintCache()
|
||||
*/
|
||||
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__);
|
||||
frameBuffer->RestoreScreen(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, fbdata.pixbuf);
|
||||
}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){
|
||||
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], gradient mode is disabled but filled\033[0m\n", __func__, __LINE__);
|
||||
clearFbGradientData();
|
||||
}
|
||||
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 coloor gradient we do paint only a default box
|
||||
*/
|
||||
if (fbdata.gradient_data == NULL){
|
||||
dprintf(DEBUG_INFO, "\033[33m[CCDraw]\t[%s - %d], crate new gradient data)...\033[0m\n", __func__, __LINE__);
|
||||
fbdata.gradient_data = getGradientData();
|
||||
|
||||
/* If background image is defined,
|
||||
* we try to render an image instead to render default box.
|
||||
* Paint of background image is prefered, next steps will be ignored!
|
||||
*/
|
||||
if (!cc_body_image.empty()){
|
||||
if (g_PicViewer->DisplayImage(cc_body_image, fbdata.x, fbdata.y, fbdata.dx, fbdata.dy)){
|
||||
// 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
|
||||
if (fbdata.gradient_data->boxBuf == NULL){
|
||||
if (!fbdata.pixbuf){
|
||||
// on enabled clean up, paint blank screen before create gradient box, this prevents possible ghost text with hw acceleration
|
||||
if (cc_gradient_bg_cleanup)
|
||||
frameBuffer->paintBoxRel(fbdata.x, fbdata.y, fbdata.dx, fbdata.dy, 0, fbdata.r, fbdata.rtype);
|
||||
// On failed image paint, write this into log and reset image name.
|
||||
if (!fbdata.is_painted){
|
||||
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());
|
||||
cc_body_image = "";
|
||||
}
|
||||
}
|
||||
|
||||
// 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__);
|
||||
/* If no background image is defined, we paint default box or box with gradient
|
||||
* This is also possible if any background image is defined but image paint ist failed
|
||||
*/
|
||||
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 we don't do this, 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__);
|
||||
if (fbdata.gradient_data->boxBuf == NULL){
|
||||
if (fbdata.pixbuf == NULL){
|
||||
/* Before we paint any gradient box with hw acceleration, we must cleanup first.
|
||||
* FIXME: This is only a workaround for this framebuffer behavior on enabled hw acceleration.
|
||||
* Without this, ugly ghost letters or ghost images inside gradient boxes are possible.
|
||||
*/
|
||||
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
|
||||
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{
|
||||
//use gradient cache to repaint gradient box
|
||||
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);
|
||||
/* If is nothihng cached or no background image was defined or image paint was failed,
|
||||
* render a default box.
|
||||
*/
|
||||
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 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;
|
||||
@@ -653,7 +702,6 @@ void CCDraw::paintFbItems(bool do_save_bg)
|
||||
//reset is painted ignore flag to default value
|
||||
force_paint_bg = false;
|
||||
|
||||
//pick up signal if filled
|
||||
OnAfterPaintLayers();
|
||||
}
|
||||
|
||||
@@ -797,3 +845,21 @@ bool CCDraw::cancelBlink(bool keep_on_screen)
|
||||
|
||||
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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user