CComponentsButton: ensure matching icons inside button

Some icons can be too large for defined button height, so it's required to
scale icons. Scaling happens inside cc_btn_icon_obj during its init.
This commit is contained in:
2014-05-03 19:00:28 +02:00
parent 75bf3aa276
commit 9d014d2039

View File

@@ -135,7 +135,19 @@ void CComponentsButton::initIcon()
//initialize icon object
if (cc_btn_icon_obj == NULL){
cc_btn_icon_obj = new CComponentsPicture(fr_thickness, CC_CENTERED, 0, 0, cc_btn_icon, CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, this);
int w_icon = 0;
int h_icon = 0;
frameBuffer->getIconSize(cc_btn_icon.c_str(), &w_icon, &h_icon);
int h_max = height-2*fr_thickness;
if (h_icon > h_max){
int ratio = h_icon/h_max;
cc_btn_icon = frameBuffer->getIconBasePath() + cc_btn_icon;
cc_btn_icon += ".png";
w_icon = w_icon*ratio;
}
cc_btn_icon_obj = new CComponentsPicture(fr_thickness, CC_CENTERED, w_icon, h_max, cc_btn_icon, CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER, this);
cc_btn_icon_obj->doPaintBg(false);
}
}