CComponentsPicture: fix icon size/scale handling

This commit is contained in:
2015-01-14 19:29:23 +01:00
parent 2dc47e0fe1
commit e8d46a8a55
2 changed files with 37 additions and 19 deletions

View File

@@ -113,22 +113,23 @@ void CComponentsPicture::initCCItem()
return;
}
//handle size
int w_pic = width;
int h_pic = height;
//check for path or name, set icon or image with full path
//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);
if (pos == string::npos)
do_scale = false;
if (!do_scale || (w_pic == 0 || w_pic == 0)){
if (!pic_name.empty())
frameBuffer->getIconSize(pic_name.c_str(), &width, &height);
}else{
g_PicViewer->getSize(pic_name.c_str(), &w_pic, &h_pic);
if (width != w_pic || height != h_pic)
g_PicViewer->rescaleImageDimensions(&w_pic, &h_pic, width, height);
//initial internal size
int w_pic = width;
int h_pic = height;
if (!do_scale){
//use image/icon size as object dimension values
frameBuffer->getIconSize(pic_name.c_str(), &width, &height);
}
else{
//if initialized dimension values = 0, set current object dimension values to real image size otherwise use defined size
g_PicViewer->getSize(pic_name.c_str(), (width == 0 ? &width : &w_pic), (height == 0 ? &height : &h_pic));
g_PicViewer->rescaleImageDimensions(&w_pic, &h_pic, width, height);
}
}
@@ -234,17 +235,18 @@ CComponentsChannelLogo::CComponentsChannelLogo( const int &x_pos, const int &y_p
void CComponentsChannelLogo::init(const uint64_t& channelId, const std::string& channelName, bool allow_scale)
{
alt_pic_name = "";
setChannel(channelId, channelName);
do_scale = allow_scale;
alt_pic_name = "";
}
void CComponentsChannelLogo::setAltLogo(const std::string& picture_name)
{
alt_pic_name = picture_name;
channel_id = 0;
channel_name = "";
has_logo = true;
initCCItem();
has_logo = !alt_pic_name.empty();
if (has_logo)
initCCItem();
}
void CComponentsChannelLogo::setAltLogo(const char* picture_name)
@@ -263,9 +265,18 @@ void CComponentsChannelLogo::setChannel(const uint64_t& channelId, const std::st
has_logo = g_PicViewer->GetLogoName(channel_id, channel_name, pic_name, &dummy, &dummy);
if (!has_logo)
if (!has_logo)//no logo was found, use altrenate icon or logo
pic_name = alt_pic_name;
//if logo or alternate image still not available, set has logo to false
has_logo = !pic_name.empty();
//refresh object
initCCItem();
//set has_logo to false if no dimensions were detected
if (width && height)
has_logo = true;
doPaintBg(false);
}

View File

@@ -86,7 +86,7 @@ class CComponentsPicture : public CComponentsItem
void SetTransparent(int t){ image_transparent = t; }
public:
///constructor for image objects, use this for scaled images, scaling dimensions are defined with parameters w (width) and h (height)
///constructor for image objects, use this for scaled images, scaling dimensions are defined with parameters w (width) and h (height), only values >0 causes scale of image
CComponentsPicture( const int &x_pos, const int &y_pos, const int &w, const int &h,
const std::string& image_name,
CComponentsForm *parent = NULL,
@@ -118,7 +118,14 @@ class CComponentsPicture : public CComponentsItem
///return height of component
virtual int getHeight();
virtual void doScale(bool scale = true){do_scale = scale;}
///set width of object and image, value >0 causes scale of image
virtual void setWidth(const int& w){CComponentsItem::setWidth(w), do_scale = true; initCCItem();}
///set height of object and image, value >0 causes scale of image
virtual void setHeight(const int& h){CComponentsItem::setHeight(h), do_scale = true; initCCItem();}
///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();}
///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();}
///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;};