CComponentsButton: rework position handling for buttons and code comments

Origin commit data
------------------
Commit: 7d82da09ae
Author: Thilo Graf <dbt@novatux.de>
Date: 2013-06-03 (Mon, 03 Jun 2013)
This commit is contained in:
2013-06-03 22:01:11 +02:00
parent cbdfda6992
commit 9cb86caf96
2 changed files with 70 additions and 21 deletions

View File

@@ -33,6 +33,7 @@
#include "cc_frm_button.h"
#define FRAME_TH 3
#define H_SPACE 4
using namespace std;
@@ -91,8 +92,16 @@ void CComponentsButton::initIcon()
addCCItem(cc_btn_icon_obj);
}
//get first icon dimensions
int icon_w = 0, icon_h = 0;
frameBuffer->getIconSize(cc_btn_icon.c_str(), &icon_w, &icon_h);
//position of icon default centered
int icon_x = width/2-icon_w/2;
//set properties to picture object
if (cc_btn_icon_obj){
cc_btn_icon_obj->setDimensionsAll(this->getRealXPos(), this->getRealYPos(), height/*-2*fr_thickness*/, height-2*fr_thickness);
cc_btn_icon_obj->setDimensionsAll(icon_x, 0, icon_w, height);
cc_btn_icon_obj->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER);
cc_btn_icon_obj->doPaintBg(false);
}
@@ -106,13 +115,19 @@ void CComponentsButton::initCaption()
addCCItem(cc_btn_capt_obj);
}
int cap_x = this->getRealXPos()+(width/2)-(cc_btn_text_w/2);
int cap_h = height/*-2*fr_thickness*/;
int cap_y = this->getRealYPos();
int cap_x = (width/2)-(cc_btn_text_w/2); //text position is default centered
int cap_h = height;
int cap_y = 0 ;
if (cc_btn_icon_obj)
cap_x = this->getRealXPos()+cc_btn_icon_obj->getWidth();
//if we have a icon, then we must calculate centered position for booth items together
if (cc_btn_icon_obj){
int face_w = cc_btn_icon_obj->getWidth() + H_SPACE + cc_btn_text_w + 2*fr_thickness;
int face_x = width/2 - face_w/2;
cc_btn_icon_obj->setXPos(face_x);
cap_x = face_x + cc_btn_icon_obj->getWidth() + H_SPACE;
}
//set properties to label object
if (cc_btn_capt_obj){
cc_btn_capt_obj->setDimensionsAll(cap_x, cap_y, width-cap_x, cap_h);
cc_btn_capt_obj->setTextColor(this->cc_item_enabled ? COL_MENUCONTENT : COL_MENUCONTENTINACTIVE);

View File

@@ -31,26 +31,42 @@
#include "cc_frm.h"
#include <string>
//! Sub class of CComponentsForm.
/*!
Shows a button box with caption and optional icon.
*/
class CComponentsButton : public CComponentsForm
{
protected:
void initVarButton();
///caption and icon properties
std::string cc_btn_capt; //text
std::string cc_btn_icon; //icon name, only icons supported, to find in gui/widget/icons.h
fb_pixel_t cc_btn_capt_col; //text color
Font* cc_btn_font; //text font
int cc_btn_text_w, cc_btn_text_h; //width and height of text, too long text will be truncated
///icon and text objects
///object: picture object
CComponentsPicture *cc_btn_icon_obj;
///object: label object
CComponentsLabel *cc_btn_capt_obj;
///initialize of objects
///initialize all required attributes and objects
void initVarButton();
///property: button text
std::string cc_btn_capt;
///property: icon name, only icons supported, to find in gui/widget/icons.h
std::string cc_btn_icon;
///property: text color
fb_pixel_t cc_btn_capt_col;
///object: text font
Font* cc_btn_font;
///property: label object width, too long text will be truncated
int cc_btn_text_w;
///property: label object heigth
int cc_btn_text_h;
///initialize picture object
void initIcon();
///initialize label object
void initCaption();
///initialize picture and label object
void initCCBtnItems();
public:
@@ -60,11 +76,17 @@ class CComponentsButton : public CComponentsForm
bool selected = false, bool enabled = true, bool has_shadow = CC_SHADOW_OFF,
fb_pixel_t color_frame = COL_LIGHT_GRAY, fb_pixel_t color_body = COL_MENUCONTENT_PLUS_0, fb_pixel_t color_shadow = COL_MENUCONTENTDARK_PLUS_0);
///set text color
virtual void setButtonTextColor(fb_pixel_t caption_color){cc_btn_capt_col = caption_color;};
///paint button object
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
};
///sub classes for button objects with most needed params, and predefined color buttons, but functionality is the same as in CComponentsButton
//! Sub class of CComponentsButton.
/*!
Shows a button box with caption and prepared red icon.
*/
class CComponentsButtonRed : public CComponentsButton
{
public:
@@ -78,6 +100,10 @@ class CComponentsButtonRed : public CComponentsButton
};
};
//! Sub class of CComponentsButton.
/*!
Shows a button box with caption and prepared green icon.
*/
class CComponentsButtonGreen : public CComponentsButton
{
public:
@@ -91,6 +117,10 @@ class CComponentsButtonGreen : public CComponentsButton
};
};
//! Sub class of CComponentsButton.
/*!
Shows a button box with caption and prepared yellow icon.
*/
class CComponentsButtonYellow : public CComponentsButton
{
public:
@@ -104,6 +134,10 @@ class CComponentsButtonYellow : public CComponentsButton
};
};
//! Sub class of CComponentsButton.
/*!
Shows a button box with caption and prepared blue icon.
*/
class CComponentsButtonBlue : public CComponentsButton
{
public: