CComponentsButton: simplify paint of button icon

Calculation of image aspect ratio now happens in picture object itself.
This commit is contained in:
2015-07-11 22:07:25 +02:00
parent 53a350d5af
commit b47a0ccaeb
2 changed files with 10 additions and 11 deletions

View File

@@ -143,23 +143,22 @@ void CComponentsButton::initIcon()
//initialize icon object //initialize icon object
if (cc_btn_icon_obj == NULL){ if (cc_btn_icon_obj == NULL){
int w_icon = 0;
int h_icon = 0;
int y_icon = 0; int y_icon = 0;
string::size_type pos = cc_btn_icon.find("/", 0); string::size_type pos = cc_btn_icon.find("/", 0);
if (pos == string::npos) if (pos == string::npos)
cc_btn_icon = frameBuffer->getIconBasePath() + "/" + cc_btn_icon + ".png"; cc_btn_icon = frameBuffer->getIconBasePath() + "/" + cc_btn_icon + ".png";
cc_btn_icon_obj = new CComponentsPicture(fr_thickness, y_icon, cc_btn_icon, this); cc_btn_icon_obj = new CComponentsPictureScalable(fr_thickness, y_icon, cc_btn_icon, this);
cc_btn_icon_obj->getSize(&w_icon, &h_icon);
if (h_icon > (height-2*fr_thickness)){ int h_icon = cc_btn_icon_obj->getHeight();
cc_btn_icon_obj->setHeight(height-2*fr_thickness);
uint8_t h_ratio = uint8_t(h_icon/cc_btn_icon_obj->getHeight()); //get required icon height
w_icon = w_icon/h_ratio; int h_max = height-2*fr_thickness;
cc_btn_icon_obj->setWidth(w_icon);
} //get current icon dimensions
if (h_icon > h_max)
cc_btn_icon_obj->setHeight(h_max, true);
y_icon = height/2 - cc_btn_icon_obj->getHeight()/2; y_icon = height/2 - cc_btn_icon_obj->getHeight()/2;

View File

@@ -47,7 +47,7 @@ class CComponentsButton : public CComponentsFrmChain
{ {
protected: protected:
///object: picture object ///object: picture object
CComponentsPicture *cc_btn_icon_obj; CComponentsPictureScalable *cc_btn_icon_obj;
///object: label object ///object: label object
CComponentsLabel *cc_btn_capt_obj; CComponentsLabel *cc_btn_capt_obj;