diff --git a/src/gui/components/cc_item_picture.cpp b/src/gui/components/cc_item_picture.cpp index 43ecb2e64..893301c43 100644 --- a/src/gui/components/cc_item_picture.cpp +++ b/src/gui/components/cc_item_picture.cpp @@ -72,10 +72,10 @@ void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w, cc_item_type = CC_ITEMTYPE_PICTURE; //CComponents - x = x_pos; - y = y_pos; - width = dx = w; - height = dy = h; + x = x_old = x_pos; + y = y_old = y_pos; + width = dx = dxc = w; + height = dy = dyc = h; pic_name = pic_name_old = image_name; shadow = shadow_mode; shadow_w = SHADOW_OFFSET; @@ -91,7 +91,7 @@ void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w, cc_paint_cache = false; //bg keep_dx_aspect = false; keep_dy_aspect = false; - + need_init = true; initCCItem(); initParent(parent); } @@ -109,6 +109,7 @@ void CComponentsPicture::setPicture(const std::string& picture_name) { if (pic_name == picture_name) return; + need_init = true; clearCache(); pic_name = picture_name; initCCItem(); @@ -124,7 +125,10 @@ void CComponentsPicture::setPicture(const char* picture_name) void CComponentsPicture::setWidth(const int& w, bool keep_aspect) { - CComponentsItem::setWidth(w), + CComponentsItem::setWidth(w); + if (w == width && keep_aspect == keep_dy_aspect) + return; + need_init = true; do_scale = true; keep_dy_aspect = keep_aspect; initCCItem(); @@ -132,7 +136,10 @@ void CComponentsPicture::setWidth(const int& w, bool keep_aspect) void CComponentsPicture::setHeight(const int& h, bool keep_aspect) { - CComponentsItem::setHeight(h), + CComponentsItem::setHeight(h); + if (h == height && keep_aspect == keep_dx_aspect) + return; + need_init = true; do_scale = true; keep_dx_aspect = keep_aspect; initCCItem(); @@ -140,10 +147,11 @@ void CComponentsPicture::setHeight(const int& h, bool keep_aspect) void CComponentsPicture::initCCItem() { - if (pic_name.empty()){ + if (pic_name.empty() || !need_init){ dprintf(DEBUG_DEBUG, "[CComponentsPicture] %s - %d : no image file assigned...\n", __func__, __LINE__); return; } + need_init = false; //avoid new init if not required //check for path or name, set icon or image with full path, has no path, then use as icon and disble scale mode string::size_type pos = pic_name.find("/", 0); @@ -255,6 +263,7 @@ void CComponentsPicture::paintPicture() initPosition(&x_pic, &y_pic); x_pic += fr_thickness; y_pic += fr_thickness; + initCCItem(); if (pic_name.empty()){ @@ -272,11 +281,13 @@ void CComponentsPicture::paintPicture() frameBuffer->SetTransparentDefault(); if (enable_cache){ dprintf(DEBUG_DEBUG, "\033[31m[CComponentsPicture] %s - %d: create cached image from pic_name=%s\033[0m\n", __func__, __LINE__, pic_name.c_str()); - image_cache = getScreen(x_pic, y_pic, width, height); + dxc = width; + dyc = height; + image_cache = getScreen(x_pic, y_pic, dxc, dyc); } }else{ dprintf(DEBUG_DEBUG, "\033[36m[CComponentsPicture] %s - %d: paint cached image from pic_name=%s\033[0m\n", __func__, __LINE__, pic_name.c_str()); - frameBuffer->RestoreScreen(x_pic, y_pic, width, height, image_cache); + frameBuffer->RestoreScreen(x_pic, y_pic, dxc, dyc, image_cache); } } @@ -350,6 +361,9 @@ void CComponentsChannelLogo::init(const uint64_t& channelId, const std::string& } void CComponentsChannelLogo::setAltLogo(const std::string& picture_name) { + if (alt_pic_name == picture_name) + return; + need_init = true; alt_pic_name = picture_name; channel_id = 0; channel_name = ""; @@ -368,7 +382,16 @@ void CComponentsChannelLogo::setAltLogo(const char* picture_name) void CComponentsChannelLogo::setChannel(const uint64_t& channelId, const std::string& channelName) { - channel_id = channelId; + if (channel_id) + if (channel_id == channelId) + return; + channel_id = channelId; + + if (!channel_name.empty()) + if (channel_name == channelName) + return; + + need_init = true; channel_name = channelName; int dummy; diff --git a/src/gui/components/cc_item_picture.h b/src/gui/components/cc_item_picture.h index 5a790d056..4708d1742 100644 --- a/src/gui/components/cc_item_picture.h +++ b/src/gui/components/cc_item_picture.h @@ -58,6 +58,9 @@ class CComponentsPicture : public CComponentsItem ///current original image dimensions int dx, dy; + ///cached image dimensions + int dxc, dyc; + ///property: name of image (without extensionn) full path to image (with extension), icon names to find in /widget/icons.h, icons will paint never scaled std::string pic_name, pic_name_old; @@ -75,6 +78,8 @@ class CComponentsPicture : public CComponentsItem ///sets internal option for keeping aspect, see also setHeight(), setWidth(), default value = false bool keep_dx_aspect; bool keep_dy_aspect; + ///helper: indicate for reinit + bool need_init; void init( const int &x_pos, const int &y_pos, const int &w, const int &h, const std::string& image_name, @@ -151,9 +156,9 @@ class CComponentsPicture : public CComponentsItem ///set height of object and image, value >0 causes scale of image, parameter keep_aspect = true causes scaling of width with same aspect, , default = false virtual void setHeight(const int& h, bool keep_aspect = false); ///set width of object and image related to current screen size, see also CComponentsItem::setWidthP(), parameter as uint8_t - virtual void setWidthP(const uint8_t& w_percent){CComponentsItem::setWidthP(w_percent), do_scale = true; initCCItem();} + virtual void setWidthP(const uint8_t& w_percent){CComponentsItem::setWidthP(w_percent), do_scale = true; need_init = hasChanges(); initCCItem();} ///set height of object and image related to current screen size, see also CComponentsItem::setHeightP(), parameter as uint8_t - virtual void setHeightP(const uint8_t& h_percent){CComponentsItem::setHeightP(h_percent), do_scale = true; initCCItem();} + virtual void setHeightP(const uint8_t& h_percent){CComponentsItem::setHeightP(h_percent), do_scale = true; need_init = hasChanges(); initCCItem();} ///return paint mode of internal image, true=image was painted, please do not to confuse with isPainted()! isPainted() is related to item itself. virtual inline bool isPicPainted(){return is_image_painted;}; @@ -249,6 +254,7 @@ class CComponentsChannelLogo : public CComponentsPicture ///set channel id and/or channel name, NOTE: channel name is prefered void setChannel(const uint64_t& channelId, const std::string& channelName); + uint64_t getChannelID(){return channel_id;} ///set an alternate logo if no logo is available NOTE: value of has_logo will set to true void setAltLogo(const std::string& picture_name);