diff --git a/src/gui/components/cc_item_picture.cpp b/src/gui/components/cc_item_picture.cpp index 56905219f..fb68ee7b2 100644 --- a/src/gui/components/cc_item_picture.cpp +++ b/src/gui/components/cc_item_picture.cpp @@ -47,7 +47,7 @@ CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos, cons 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); + init(x_pos, y_pos, w, h, image_path, parent, has_shadow, color_frame, color_background, color_shadow, transparent, SCALE); } CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos, @@ -56,14 +56,15 @@ CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos, 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, 0, 0, image_name, parent, has_shadow, color_frame, color_background, color_shadow, transparent); + 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, 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, + bool allow_scale) { //CComponents, CComponentsItem cc_item_type = CC_ITEMTYPE_PICTURE; @@ -81,12 +82,12 @@ void CComponentsPicture::init( const int &x_pos, const int &y_pos, const int &w, //CComponentsPicture pic_name = image_name; - is_icon = false; 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()); @@ -114,23 +115,24 @@ void CComponentsPicture::initCCItem() //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); - is_icon = (pos == string::npos); + if (pos == string::npos) + do_scale = false; - dprintf(DEBUG_INFO, "[CComponentsPicture] %s: detected image file: is_icon: %d (pos= %d), pic_name=%s\n", __func__, is_icon, pos, pic_name.c_str()); + 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 (is_icon){ - width = w_pic; - height = max(h_pic, height); + 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) @@ -140,7 +142,7 @@ void CComponentsPicture::initCCItem() } //resize/scale image if required, if no icon mode detected, use real image size - if (!is_icon){ + if (do_scale){ if (width != w_pic || height != h_pic) { g_PicViewer->rescaleImageDimensions(&w_pic, &h_pic, width, height); width = w_pic; @@ -164,7 +166,7 @@ void CComponentsPicture::initPosition(int *x_position, int *y_position) void CComponentsPicture::getImageSize(int* width_image, int *height_image) { - if (!is_icon) + if (do_scale) g_PicViewer->getSize(pic_name.c_str(), width_image, height_image); else frameBuffer->getIconSize(pic_name.c_str(), width_image, height_image); @@ -184,7 +186,7 @@ void CComponentsPicture::paintPicture() dprintf(DEBUG_INFO, "[CComponentsPicture] %s: paint image file: pic_name=%s\n", __func__, pic_name.c_str()); if (cc_allow_paint){ frameBuffer->SetTransparent(image_transparent); - if (!is_icon) + if (do_scale) is_image_painted = g_PicViewer->DisplayImage(pic_name, x_pic, y_pic, width, height); else is_image_painted = frameBuffer->paintIcon(pic_name, x_pic, y_pic, height, 1, do_paint, paint_bg, col_body); diff --git a/src/gui/components/cc_item_picture.h b/src/gui/components/cc_item_picture.h index b332ca92b..00cf5d10c 100644 --- a/src/gui/components/cc_item_picture.h +++ b/src/gui/components/cc_item_picture.h @@ -35,6 +35,9 @@ #include #include +#define NO_SCALE false +#define SCALE true + //! Sub class of CComponentsItem. Shows box with image with assigned attributes. /*! Picture is usable as an object like each other CCItems. @@ -51,14 +54,16 @@ class CComponentsPicture : public CComponentsItem ///indicate that image was sucessful painted bool is_image_painted; - ///image is defined only by name without full path, handling as icon, not as scalable image, default = false - bool is_icon; + ///sets that image may be painted, default = false bool do_paint; ///set the transparency of pictures (default = CFrameBuffer::TM_NONE) int image_transparent; + ///set internel paint mode to allow/disallow scale an image, value is assigned with constructor, if defined dimensions w and h = 0, then image scale is enabled + bool do_scale; + void init( const int &x_pos, const int &y_pos, const int &w, const int &h, const std::string& image_name, CComponentsForm *parent, @@ -66,7 +71,8 @@ class CComponentsPicture : public CComponentsItem fb_pixel_t color_frame, fb_pixel_t color_background, fb_pixel_t color_shadow, - int transparent); + int transparent, + bool allow_scale); ///initialize all required attributes void initCCItem(); @@ -80,6 +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) CComponentsPicture( const int &x_pos, const int &y_pos, const int &w, const int &h, const std::string& image_name, CComponentsForm *parent = NULL, @@ -89,6 +96,7 @@ class CComponentsPicture : public CComponentsItem fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0, int transparent = CFrameBuffer::TM_NONE); + ///constructor for image objects, use this for non scaled images, dimensions are defined by image size CComponentsPicture( const int &x_pos, const int &y_pos, const std::string& image_name, CComponentsForm *parent = NULL, @@ -98,9 +106,9 @@ class CComponentsPicture : public CComponentsItem fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0, int transparent = CFrameBuffer::TM_NONE); - ///sets an image name (unscaled icons only), full image path or url to an iamge file (scalable) + ///sets an image name (unscaled icons only), full image path or url to an image file virtual void setPicture(const std::string& picture_name); - ///sets an image name (unscaled icons only), full image path or url to an iamge file (scalable) + ///sets an image name (unscaled icons only), full image path or url to an image file virtual void setPicture(const char* picture_name); ///return paint mode of internal image, true=image was painted, please do not to confuse with isPainted()! isPainted() is related to item itself.