CComponentsPicture: rework scale behavior

Scaling mode not longer only dependent from image name.
Now also evaluated parameters.
Image objects with defined dimensions will be scaled.
Icons without defined path and file type, will be scaled as before.


Origin commit data
------------------
Branch: ni/coolstream
Commit: f75f0ed6e3
Author: Thilo Graf <dbt@novatux.de>
Date: 2014-10-07 (Tue, 07 Oct 2014)



------------------
This commit was generated by Migit
This commit is contained in:
2014-10-07 22:03:49 +02:00
committed by [CST] Focus
parent 6c58364cd5
commit 4366ab349a
2 changed files with 28 additions and 18 deletions

View File

@@ -47,7 +47,7 @@ CComponentsPicture::CComponentsPicture( const int &x_pos, const int &y_pos, cons
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); 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, 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, 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, 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, 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,
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,
bool allow_scale)
{ {
//CComponents, CComponentsItem //CComponents, CComponentsItem
cc_item_type = CC_ITEMTYPE_PICTURE; 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 //CComponentsPicture
pic_name = image_name; pic_name = image_name;
is_icon = false;
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); g_PicViewer->getSupportedImageFormats(v_ext);
v_ext.resize(unique(v_ext.begin(), v_ext.end()) - v_ext.begin()); v_ext.resize(unique(v_ext.begin(), v_ext.end()) - v_ext.begin());
@@ -120,16 +121,17 @@ void CComponentsPicture::initCCItem()
//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);
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 //get current image size
getImageSize(&w_pic, &h_pic); getImageSize(&w_pic, &h_pic);
//for icons (names without explicit path) set dimensions of "this" to current image...//TODO: centering image/icon //for icons (names without explicit path) set dimensions of "this" to current image...//TODO: centering image/icon
if (is_icon){ if (!do_scale){
width = w_pic; width = max(w_pic, width);
height = max(h_pic, height); height = max(h_pic, height);
} }
else{ //defined values in constructor or defined via setters defined, have priority, value 0 is not allowed else{ //defined values in constructor or defined via setters defined, have priority, value 0 is not allowed
@@ -140,7 +142,7 @@ void CComponentsPicture::initCCItem()
} }
//resize/scale image if required, if no icon mode detected, use real image size //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) { 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; 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) 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); g_PicViewer->getSize(pic_name.c_str(), width_image, height_image);
else else
frameBuffer->getIconSize(pic_name.c_str(), width_image, height_image); 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()); dprintf(DEBUG_INFO, "[CComponentsPicture] %s: paint image file: pic_name=%s\n", __func__, pic_name.c_str());
if (cc_allow_paint){ if (cc_allow_paint){
frameBuffer->SetTransparent(image_transparent); frameBuffer->SetTransparent(image_transparent);
if (!is_icon) if (do_scale)
is_image_painted = g_PicViewer->DisplayImage(pic_name, x_pic, y_pic, width, height); is_image_painted = g_PicViewer->DisplayImage(pic_name, x_pic, y_pic, width, height);
else else
is_image_painted = frameBuffer->paintIcon(pic_name, x_pic, y_pic, height, 1, do_paint, paint_bg, col_body); is_image_painted = frameBuffer->paintIcon(pic_name, x_pic, y_pic, height, 1, do_paint, paint_bg, col_body);

View File

@@ -35,6 +35,9 @@
#include <string> #include <string>
#include <driver/pictureviewer/pictureviewer.h> #include <driver/pictureviewer/pictureviewer.h>
#define NO_SCALE false
#define SCALE true
//! Sub class of CComponentsItem. Shows box with image with assigned attributes. //! Sub class of CComponentsItem. Shows box with image with assigned attributes.
/*! /*!
Picture is usable as an object like each other CCItems. Picture is usable as an object like each other CCItems.
@@ -51,14 +54,16 @@ class CComponentsPicture : public CComponentsItem
///indicate that image was sucessful painted ///indicate that image was sucessful painted
bool is_image_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 ///sets that image may be painted, default = false
bool do_paint; bool do_paint;
///set the transparency of pictures (default = CFrameBuffer::TM_NONE) ///set the transparency of pictures (default = CFrameBuffer::TM_NONE)
int image_transparent; 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, 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,
CComponentsForm *parent, CComponentsForm *parent,
@@ -66,7 +71,8 @@ class CComponentsPicture : public CComponentsItem
fb_pixel_t color_frame, fb_pixel_t color_frame,
fb_pixel_t color_background, fb_pixel_t color_background,
fb_pixel_t color_shadow, fb_pixel_t color_shadow,
int transparent); int transparent,
bool allow_scale);
///initialize all required attributes ///initialize all required attributes
void initCCItem(); void initCCItem();
@@ -80,6 +86,7 @@ class CComponentsPicture : public CComponentsItem
void SetTransparent(int t){ image_transparent = t; } void SetTransparent(int t){ image_transparent = t; }
public: 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, CComponentsPicture( const int &x_pos, const int &y_pos, const int &w, const int &h,
const std::string& image_name, const std::string& image_name,
CComponentsForm *parent = NULL, CComponentsForm *parent = NULL,
@@ -89,6 +96,7 @@ class CComponentsPicture : public CComponentsItem
fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0,
int transparent = CFrameBuffer::TM_NONE); 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, CComponentsPicture( const int &x_pos, const int &y_pos,
const std::string& image_name, const std::string& image_name,
CComponentsForm *parent = NULL, CComponentsForm *parent = NULL,
@@ -98,9 +106,9 @@ class CComponentsPicture : public CComponentsItem
fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0,
int transparent = CFrameBuffer::TM_NONE); 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); 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); 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. ///return paint mode of internal image, true=image was painted, please do not to confuse with isPainted()! isPainted() is related to item itself.