mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 08:21:12 +02:00
CComponentsPicture: try to rework init behavior inside object
need_init var shoul help to avoid not required inits. Size of cached image are packed into own vars, should avoid possible overwriting with current dimensions.
This commit is contained in:
@@ -72,10 +72,10 @@ void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w,
|
|||||||
cc_item_type = CC_ITEMTYPE_PICTURE;
|
cc_item_type = CC_ITEMTYPE_PICTURE;
|
||||||
|
|
||||||
//CComponents
|
//CComponents
|
||||||
x = x_pos;
|
x = x_old = x_pos;
|
||||||
y = y_pos;
|
y = y_old = y_pos;
|
||||||
width = dx = w;
|
width = dx = dxc = w;
|
||||||
height = dy = h;
|
height = dy = dyc = h;
|
||||||
pic_name = pic_name_old = image_name;
|
pic_name = pic_name_old = image_name;
|
||||||
shadow = shadow_mode;
|
shadow = shadow_mode;
|
||||||
shadow_w = SHADOW_OFFSET;
|
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
|
cc_paint_cache = false; //bg
|
||||||
keep_dx_aspect = false;
|
keep_dx_aspect = false;
|
||||||
keep_dy_aspect = false;
|
keep_dy_aspect = false;
|
||||||
|
need_init = true;
|
||||||
initCCItem();
|
initCCItem();
|
||||||
initParent(parent);
|
initParent(parent);
|
||||||
}
|
}
|
||||||
@@ -109,6 +109,7 @@ void CComponentsPicture::setPicture(const std::string& picture_name)
|
|||||||
{
|
{
|
||||||
if (pic_name == picture_name)
|
if (pic_name == picture_name)
|
||||||
return;
|
return;
|
||||||
|
need_init = true;
|
||||||
clearCache();
|
clearCache();
|
||||||
pic_name = picture_name;
|
pic_name = picture_name;
|
||||||
initCCItem();
|
initCCItem();
|
||||||
@@ -124,7 +125,10 @@ void CComponentsPicture::setPicture(const char* picture_name)
|
|||||||
|
|
||||||
void CComponentsPicture::setWidth(const int& w, bool keep_aspect)
|
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;
|
do_scale = true;
|
||||||
keep_dy_aspect = keep_aspect;
|
keep_dy_aspect = keep_aspect;
|
||||||
initCCItem();
|
initCCItem();
|
||||||
@@ -132,7 +136,10 @@ void CComponentsPicture::setWidth(const int& w, bool keep_aspect)
|
|||||||
|
|
||||||
void CComponentsPicture::setHeight(const int& h, 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;
|
do_scale = true;
|
||||||
keep_dx_aspect = keep_aspect;
|
keep_dx_aspect = keep_aspect;
|
||||||
initCCItem();
|
initCCItem();
|
||||||
@@ -140,10 +147,11 @@ void CComponentsPicture::setHeight(const int& h, bool keep_aspect)
|
|||||||
|
|
||||||
void CComponentsPicture::initCCItem()
|
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__);
|
dprintf(DEBUG_DEBUG, "[CComponentsPicture] %s - %d : no image file assigned...\n", __func__, __LINE__);
|
||||||
return;
|
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
|
//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);
|
string::size_type pos = pic_name.find("/", 0);
|
||||||
@@ -255,6 +263,7 @@ void CComponentsPicture::paintPicture()
|
|||||||
initPosition(&x_pic, &y_pic);
|
initPosition(&x_pic, &y_pic);
|
||||||
x_pic += fr_thickness;
|
x_pic += fr_thickness;
|
||||||
y_pic += fr_thickness;
|
y_pic += fr_thickness;
|
||||||
|
|
||||||
initCCItem();
|
initCCItem();
|
||||||
|
|
||||||
if (pic_name.empty()){
|
if (pic_name.empty()){
|
||||||
@@ -272,11 +281,13 @@ void CComponentsPicture::paintPicture()
|
|||||||
frameBuffer->SetTransparentDefault();
|
frameBuffer->SetTransparentDefault();
|
||||||
if (enable_cache){
|
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());
|
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{
|
}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());
|
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)
|
void CComponentsChannelLogo::setAltLogo(const std::string& picture_name)
|
||||||
{
|
{
|
||||||
|
if (alt_pic_name == picture_name)
|
||||||
|
return;
|
||||||
|
need_init = true;
|
||||||
alt_pic_name = picture_name;
|
alt_pic_name = picture_name;
|
||||||
channel_id = 0;
|
channel_id = 0;
|
||||||
channel_name = "";
|
channel_name = "";
|
||||||
@@ -368,7 +382,16 @@ void CComponentsChannelLogo::setAltLogo(const char* picture_name)
|
|||||||
|
|
||||||
void CComponentsChannelLogo::setChannel(const uint64_t& channelId, const std::string& channelName)
|
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;
|
channel_name = channelName;
|
||||||
int dummy;
|
int dummy;
|
||||||
|
|
||||||
|
@@ -58,6 +58,9 @@ class CComponentsPicture : public CComponentsItem
|
|||||||
///current original image dimensions
|
///current original image dimensions
|
||||||
int dx, dy;
|
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
|
///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;
|
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
|
///sets internal option for keeping aspect, see also setHeight(), setWidth(), default value = false
|
||||||
bool keep_dx_aspect;
|
bool keep_dx_aspect;
|
||||||
bool keep_dy_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,
|
void init( const int &x_pos, const int &y_pos, const int &w, const int &h,
|
||||||
const std::string& image_name,
|
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
|
///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);
|
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
|
///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
|
///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.
|
///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;};
|
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
|
///set channel id and/or channel name, NOTE: channel name is prefered
|
||||||
void setChannel(const uint64_t& channelId, const std::string& channelName);
|
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
|
///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);
|
void setAltLogo(const std::string& picture_name);
|
||||||
|
Reference in New Issue
Block a user