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
int iw = 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);
cch_icon_obj->setWidth(iw);
cch_icon_obj->setHeight(ih);

View File

@@ -42,12 +42,12 @@ using namespace std;
//-------------------------------------------------------------------------------------------------------
//sub class CComponentsPicture from CComponentsItem
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,
bool has_shadow,
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,
@@ -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);
}
void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w, const int &h,
const string& image_name,
CComponentsForm *parent,
@@ -72,25 +73,20 @@ void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w,
//CComponents
x = x_pos;
y = y_pos;
height = h;
width = w;
height = h;
pic_name = image_name;
shadow = has_shadow;
shadow_w = SHADOW_OFFSET;
col_frame = color_frame;
col_body = color_background;
col_shadow = color_shadow;
//CComponentsPicture
pic_name = image_name;
do_scale = allow_scale;
is_image_painted= false;
do_paint = true;
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();
initParent(parent);
}
@@ -112,65 +108,66 @@ void CComponentsPicture::setPicture(const char* picture_name)
void CComponentsPicture::initCCItem()
{
if (pic_name.empty()){
dprintf(DEBUG_NORMAL, "[CComponentsPicture] %s: no image file assigned...\n", __func__);
return;
}
//handle size
int w_pic = width;
int h_pic = height;
if (pic_name.empty())
return;
//check for path or name, set icon or image with full path
string::size_type pos = pic_name.find("/", 0);
if (pos == string::npos)
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());
//get current image size
getImageSize(&w_pic, &h_pic);
//for icons (names without explicit path) set dimensions of "this" to current image...//TODO: centering image/icon
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) {
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);
width = w_pic;
height = h_pic;
}
}
}
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;
*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;
*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)
g_PicViewer->getSize(pic_name.c_str(), width_image, height_image);
else
initCCItem();
if (do_scale){
*width_image = width;
*height_image = height;
}else{
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()
{
@@ -217,8 +214,7 @@ CComponentsChannelLogo::CComponentsChannelLogo( const int &x_pos, const int &y_p
"", parent, has_shadow,
color_frame, color_background, color_shadow, transparent)
{
setChannel(channelId, channelName);
alt_pic_name = "";
init(channelId, channelName, SCALE);
}
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,
color_frame, color_background, color_shadow, transparent)
{
setChannel(channelId, channelName);
alt_pic_name = "";
init(channelId, channelName, NO_SCALE);
}
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)
{
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
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.
virtual inline bool isPicPainted(){return is_image_painted;};
///handle image size
void getImageSize(int* width_image, int *height_image);
///paint item
virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
///hide item
@@ -137,6 +143,8 @@ class CComponentsChannelLogo : public CComponentsPicture
///indicates that logo is available, after paint or new instance, value = false
bool has_logo;
void init(const uint64_t& channelId, const std::string& channelName, bool allow_scale);
public:
CComponentsChannelLogo( const int &x_pos, const int &y_pos, const int &w, const int &h,
const std::string& channelName = "",