From 9d014d20398a6af1b1b483c084bc15637147c7fc Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sat, 3 May 2014 19:00:28 +0200 Subject: [PATCH] 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. --- src/gui/components/cc_frm_button.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/components/cc_frm_button.cpp b/src/gui/components/cc_frm_button.cpp index d73ea48d5..120ee3ee8 100644 --- a/src/gui/components/cc_frm_button.cpp +++ b/src/gui/components/cc_frm_button.cpp @@ -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); } }