CComponentsPicture: simplify item init, adapt getHeight/getWidth members

Members getHeight/getWidth returns now image related values dependent of
scale mode
This commit is contained in:
2014-10-12 22:38:10 +02:00
parent 20180b5b83
commit 8227638c06
3 changed files with 59 additions and 51 deletions

View File

@@ -205,7 +205,7 @@ void CComponentsHeader::initIcon()
//get dimensions of header icon //get dimensions of header icon
int iw = 0; int iw = 0;
int ih = 0; int ih = 0;
cch_icon_obj->getImageSize(&iw, &ih); cch_icon_obj->getSize(&iw, &ih);
dprintf(DEBUG_INFO, "[CComponentsHeader]\n [%s - %d] init icon size: iw = %d, ih = %d\n", __func__, __LINE__, iw, ih); dprintf(DEBUG_INFO, "[CComponentsHeader]\n [%s - %d] init icon size: iw = %d, ih = %d\n", __func__, __LINE__, iw, ih);
cch_icon_obj->setWidth(iw); cch_icon_obj->setWidth(iw);
cch_icon_obj->setHeight(ih); cch_icon_obj->setHeight(ih);

View File

@@ -42,12 +42,12 @@ using namespace std;
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
//sub class CComponentsPicture from CComponentsItem //sub class CComponentsPicture from CComponentsItem
CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos, const int &w, const int &h, CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos, const int &w, const int &h,
const std::string& image_path, const std::string& image_name,
CComponentsForm *parent, CComponentsForm *parent,
bool has_shadow, bool has_shadow,
fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow, int transparent) fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow, int transparent)
{ {
init(x_pos, y_pos, w, h, image_path, parent, has_shadow, color_frame, color_background, color_shadow, transparent, SCALE); init(x_pos, y_pos, w, h, image_name, parent, has_shadow, color_frame, color_background, color_shadow, transparent, SCALE);
} }
CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos, CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos,
@@ -59,6 +59,7 @@ CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos,
init(x_pos, y_pos, 0, 0, image_name, parent, has_shadow, color_frame, color_background, color_shadow, transparent, NO_SCALE); init(x_pos, y_pos, 0, 0, image_name, parent, has_shadow, color_frame, color_background, color_shadow, transparent, NO_SCALE);
} }
void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w, const int &h, void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w, const int &h,
const string& image_name, const string& image_name,
CComponentsForm *parent, CComponentsForm *parent,
@@ -72,25 +73,20 @@ void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w,
//CComponents //CComponents
x = x_pos; x = x_pos;
y = y_pos; y = y_pos;
width = w;
height = h; height = h;
width = w; pic_name = image_name;
shadow = has_shadow; shadow = has_shadow;
shadow_w = SHADOW_OFFSET; shadow_w = SHADOW_OFFSET;
col_frame = color_frame; col_frame = color_frame;
col_body = color_background; col_body = color_background;
col_shadow = color_shadow; col_shadow = color_shadow;
do_scale = allow_scale;
//CComponentsPicture
pic_name = image_name;
is_image_painted= false; is_image_painted= false;
do_paint = true; do_paint = true;
image_transparent = transparent; image_transparent = transparent;
do_scale = allow_scale;
g_PicViewer->getSupportedImageFormats(v_ext);
v_ext.resize(unique(v_ext.begin(), v_ext.end()) - v_ext.begin());
initCCItem(); initCCItem();
initParent(parent); initParent(parent);
} }
@@ -112,64 +108,65 @@ void CComponentsPicture::setPicture(const char* picture_name)
void CComponentsPicture::initCCItem() void CComponentsPicture::initCCItem()
{ {
if (pic_name.empty()){
dprintf(DEBUG_NORMAL, "[CComponentsPicture] %s: no image file assigned...\n", __func__);
return;
}
//handle size //handle size
int w_pic = width; int w_pic = width;
int h_pic = height; int h_pic = height;
if (pic_name.empty())
return;
//check for path or name, set icon or image with full path //check for path or name, set icon or image with full path
string::size_type pos = pic_name.find("/", 0); string::size_type pos = pic_name.find("/", 0);
if (pos == string::npos) if (pos == string::npos)
do_scale = false; do_scale = false;
dprintf(DEBUG_INFO, "[CComponentsPicture] %s: detected image file: do_scale: %d (pos= %d), pic_name=%s\n", __func__, do_scale, pos, pic_name.c_str()); if (!do_scale || (w_pic == 0 || w_pic == 0)){
if (!pic_name.empty())
//get current image size frameBuffer->getIconSize(pic_name.c_str(), &width, &height);
getImageSize(&w_pic, &h_pic); }else{
g_PicViewer->getSize(pic_name.c_str(), &w_pic, &h_pic);
//for icons (names without explicit path) set dimensions of "this" to current image...//TODO: centering image/icon if (width != w_pic || height != h_pic)
if (!do_scale){
width = max(w_pic, width);
height = max(h_pic, height);
}
else{ //defined values in constructor or defined via setters defined, have priority, value 0 is not allowed
if (width == 0)
width = w_pic;
if (height == 0)
height = h_pic;
}
//resize/scale image if required, if no icon mode detected, use real image size
if (do_scale){
if (width != w_pic || height != h_pic) {
g_PicViewer->rescaleImageDimensions(&w_pic, &h_pic, width, height); g_PicViewer->rescaleImageDimensions(&w_pic, &h_pic, width, height);
width = w_pic;
height = h_pic;
}
} }
} }
void CComponentsPicture::initPosition(int *x_position, int *y_position) void CComponentsPicture::initPosition(int *x_position, int *y_position)
{ {
//using of real x/y values to paint images if this picture object is bound in a parent form
*x_position = x; *x_position = x;
*y_position = y; *y_position = y;
if (cc_parent){ if (cc_parent){ //using of real x/y values to paint images if this picture object is bound in a parent form
*x_position = cc_xr; *x_position = cc_xr;
*y_position = cc_yr; *y_position = cc_yr;
} }
} }
void CComponentsPicture::getImageSize(int* width_image, int *height_image) void CComponentsPicture::getSize(int* width_image, int *height_image)
{ {
if (do_scale) initCCItem();
g_PicViewer->getSize(pic_name.c_str(), width_image, height_image); if (do_scale){
else *width_image = width;
*height_image = height;
}else{
frameBuffer->getIconSize(pic_name.c_str(), width_image, height_image); frameBuffer->getIconSize(pic_name.c_str(), width_image, height_image);
}
}
int CComponentsPicture::getWidth()
{
int w, h;
getSize(&w, &h);
return w;
}
int CComponentsPicture::getHeight()
{
int w, h;
getSize(&w, &h);
return h;
} }
void CComponentsPicture::paintPicture() void CComponentsPicture::paintPicture()
@@ -217,8 +214,7 @@ CComponentsChannelLogo::CComponentsChannelLogo( const int &x_pos, const int &y_p
"", parent, has_shadow, "", parent, has_shadow,
color_frame, color_background, color_shadow, transparent) color_frame, color_background, color_shadow, transparent)
{ {
setChannel(channelId, channelName); init(channelId, channelName, SCALE);
alt_pic_name = "";
} }
CComponentsChannelLogo::CComponentsChannelLogo( const int &x_pos, const int &y_pos, CComponentsChannelLogo::CComponentsChannelLogo( const int &x_pos, const int &y_pos,
@@ -231,11 +227,15 @@ CComponentsChannelLogo::CComponentsChannelLogo( const int &x_pos, const int &y_p
"", parent, has_shadow, "", parent, has_shadow,
color_frame, color_background, color_shadow, transparent) color_frame, color_background, color_shadow, transparent)
{ {
setChannel(channelId, channelName); init(channelId, channelName, NO_SCALE);
alt_pic_name = "";
} }
void CComponentsChannelLogo::init(const uint64_t& channelId, const std::string& channelName, bool allow_scale)
{
setChannel(channelId, channelName);
do_scale = allow_scale;
alt_pic_name = "";
}
void CComponentsChannelLogo::setAltLogo(const std::string& picture_name) void CComponentsChannelLogo::setAltLogo(const std::string& picture_name)
{ {
alt_pic_name = picture_name; alt_pic_name = picture_name;

View File

@@ -111,12 +111,18 @@ class CComponentsPicture : public CComponentsItem
///sets an image name (unscaled icons only), full image path or url to an image file ///sets an image name (unscaled icons only), full image path or url to an image file
virtual void setPicture(const char* picture_name); virtual void setPicture(const char* picture_name);
///handle image size
virtual void getSize(int* width_image, int *height_image);
///return width of component
virtual int getWidth();
///return height of component
virtual int getHeight();
virtual void doScale(bool scale = true){do_scale = scale;}
///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;};
///handle image size
void getImageSize(int* width_image, int *height_image);
///paint item ///paint item
virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
///hide item ///hide item
@@ -137,6 +143,8 @@ class CComponentsChannelLogo : public CComponentsPicture
///indicates that logo is available, after paint or new instance, value = false ///indicates that logo is available, after paint or new instance, value = false
bool has_logo; bool has_logo;
void init(const uint64_t& channelId, const std::string& channelName, bool allow_scale);
public: public:
CComponentsChannelLogo( const int &x_pos, const int &y_pos, const int &w, const int &h, CComponentsChannelLogo( const int &x_pos, const int &y_pos, const int &w, const int &h,
const std::string& channelName = "", const std::string& channelName = "",