Try to rework footer

* try to fix enableButtonShadow(), seems an init is missing
* shadow fixed
This commit is contained in:
2016-09-24 00:52:59 +02:00
parent eb78743e4a
commit 2e631fd0ce
9 changed files with 152 additions and 81 deletions

View File

@@ -101,7 +101,7 @@ void CComponentsButton::initVarButton( const int& x_pos, const int& y_pos, const
width = w; width = w;
height = h; height = h;
shadow = shadow_mode; shadow = shadow_mode;
shadow_w = shadow ? OFFSET_SHADOW/2 : 0; //buttons are mostly small elements, so these elements should have a reasonable shadow width shadow_w = shadow != CC_SHADOW_OFF ? OFFSET_SHADOW/2 : 0; //buttons are mostly small elements, so these elements should have a reasonable shadow width
cc_body_gradient_enable = CC_COLGRAD_OFF/*g_settings.gradiant*/; //TODO: gradient is prepared for use but disabled at the moment till some other parts of gui parts are provide gradient cc_body_gradient_enable = CC_COLGRAD_OFF/*g_settings.gradiant*/; //TODO: gradient is prepared for use but disabled at the moment till some other parts of gui parts are provide gradient
setColBodyGradient(cc_body_gradient_enable/*CColorGradient::gradientLight2Dark*/, CFrameBuffer::gradientVertical, CColorGradient::light); setColBodyGradient(cc_body_gradient_enable/*CColorGradient::gradientLight2Dark*/, CFrameBuffer::gradientVertical, CColorGradient::light);
@@ -195,24 +195,34 @@ void CComponentsButton::initCaption()
x_cap += cc_btn_icon_obj ? cc_btn_icon_obj->getWidth() : 0; x_cap += cc_btn_icon_obj ? cc_btn_icon_obj->getWidth() : 0;
int w_cap = width - w_frame - append_x_offset - x_cap - w_frame; int w_cap = width - w_frame - append_x_offset - x_cap - w_frame;
int h_cap = height*65/100 /*- 2*fr_thickness*/; int h_cap = (height*75/100) - 2*w_frame;
/*NOTE: /*NOTE:
paint of centered text in y direction without y_offset paint of centered text in y direction without y_offset
looks unlovely displaced in y direction especially besides small icons and inside small areas, looks unlovely displaced in y direction especially besides small icons and inside small areas,
but text render isn't wrong here, because capitalized chars or long chars like e. 'q', 'y' are considered! but text render isn't wrong here, because capitalized chars or long chars like e. 'q', 'y' are considered!
Therefore we here need other icons or a hack, that considers some different height values. Therefore we here need other icons or a hack, that considers some different height values.
*/ */
int y_cap = height/2 - h_cap/2 + w_frame/2; int y_cap = height/2 - h_cap/2;
cc_btn_capt_obj->setDimensionsAll(x_cap, y_cap, w_cap, h_cap); cc_btn_capt_obj->setDimensionsAll(x_cap, y_cap, w_cap, h_cap);
//text and font //text and font
if (cc_btn_font == NULL) Font* def_font = *cc_btn_dy_font->getDynFont(w_cap, h_cap, cc_btn_capt);
cc_btn_font = *cc_btn_dy_font->getDynFont(w_cap, h_cap, cc_btn_capt); if (cc_btn_font == NULL){
/* use dynamic font as default font if no font defined */
cc_btn_font = def_font;
}else{
/* if button dimension too small, use dynamic font as default font size, this ignores possible defined font
* Otherwise definied font will be used.
*/
if (cc_btn_font->getHeight() > h_cap){
cc_btn_font = def_font;
}
}
cc_btn_capt_obj->setText(cc_btn_capt, CTextBox::NO_AUTO_LINEBREAK, cc_btn_font); cc_btn_capt_obj->setText(cc_btn_capt, CTextBox::NO_AUTO_LINEBREAK, cc_btn_font);
cc_btn_capt_obj->forceTextPaint(); //here required; cc_btn_capt_obj->forceTextPaint(); //here required;
cc_btn_capt_obj->getCTextBoxObject()->setTextBorderWidth(0,0);
//set color //set color
cc_btn_capt_obj->setTextColor(this->cc_item_enabled ? cc_btn_capt_col : cc_btn_capt_disable_col); cc_btn_capt_obj->setTextColor(this->cc_item_enabled ? cc_btn_capt_col : cc_btn_capt_disable_col);
@@ -280,3 +290,9 @@ void CComponentsButton::paint(bool do_save_bg)
//paint form contents //paint form contents
paintForm(do_save_bg); paintForm(do_save_bg);
} }
void CComponentsButton::enableShadow(int mode, const int& shadow_width, bool force_paint)
{
clear();
initVarButton(x, y, width, height, cc_btn_capt, cc_btn_icon, cc_parent, cc_item_selected, cc_item_enabled, mode, col_frame, col_body, col_shadow);
}

View File

@@ -195,6 +195,12 @@ class CComponentsButton : public CComponentsFrmChain, public CCTextScreen
inline virtual void setButtonAlias(const int& alias_value){cc_btn_alias = alias_value;}; inline virtual void setButtonAlias(const int& alias_value){cc_btn_alias = alias_value;};
///returns an alias value from button object, see also cc_btn_alias ///returns an alias value from button object, see also cc_btn_alias
inline virtual int getButtonAlias(){return cc_btn_alias;}; inline virtual int getButtonAlias(){return cc_btn_alias;};
/**1st parameter requires defines CC_SHADOW_ON (default), CC_SHADOW_OFF, CC_SHADOW_BOTTOM or CC_SHADOW_RIGHT, see also cc_types.h
* 2nd parameter defines shadow width, default = defined by system
* 3rd parameter forces paint of shadow layer, default = false, Note: default shadow will paint only on first paint, use 3rd parameter=true ignores this
*/
void enableShadow(int mode = CC_SHADOW_ON, const int& shadow_width = -1, bool force_paint = false);
}; };
//! Sub class of CComponentsButton. //! Sub class of CComponentsButton.

View File

@@ -69,10 +69,13 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
width = w == 0 ? frameBuffer->getScreenWidth(true) : w; width = w == 0 ? frameBuffer->getScreenWidth(true) : w;
//init footer height //init footer height
initCaptionFont();
height = max(h, cch_font->getHeight()); height = max(h, cch_font->getHeight());
shadow = shadow_mode; shadow = shadow_mode;
ccf_enable_button_shadow = false ; ccf_enable_button_shadow = false ;
ccf_button_shadow_width = 0;
ccf_button_shadow_force_paint = false;
col_frame = color_frame; col_frame = color_frame;
col_body = color_body; col_body = color_body;
col_shadow = color_shadow; col_shadow = color_shadow;
@@ -85,7 +88,7 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
corner_type = CORNER_BOTTOM; corner_type = CORNER_BOTTOM;
ccf_enable_button_bg = false /*g_settings.theme.Button_gradient*/; //TODO: not implemented at the moment ccf_enable_button_bg = false /*g_settings.theme.Button_gradient*/; //TODO: not implemented at the moment
ccf_btn_font = NULL; ccf_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT];
chain = NULL; chain = NULL;
addContextButton(buttons); addContextButton(buttons);
@@ -95,43 +98,76 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
void CComponentsFooter::setButtonLabels(const struct button_label_s * const content, const size_t& label_count, const int& chain_width, const int& label_width) void CComponentsFooter::setButtonLabels(const struct button_label_s * const content, const size_t& label_count, const int& chain_width, const int& label_width)
{ {
//define required total width of button group, minimal width is >0, sensless values are nonsens! /* clean up before init*/
int w_chain = chain_width > 0 ? chain_width : width;//TODO: alow and handle only with rational values >0, exit here if (chain)
if (w_chain < 100){ chain->clear();
dprintf(DEBUG_NORMAL, "[CComponentsFooter] [%s - %d] stupid width of chain: width = %d, values < 100 are nonsens, buttons not painted!\n", __func__, __LINE__, w_chain);
return; /* set general available full basic space for button chain,
* in this case this is footer width
*/
int w_chain = width - 2*cch_offset;
/* calculate current available space for button container depends
* of already enbedded footer objects.
* If already existing some items then subtract those width from footer width.
* ...so we have the possible usable size for button container.
*/
if(!v_cc_items.empty()){ //FIXME: footer container seems always not empty here, so here j initialized with = 1. I dont't know where it comes from! dbt!
for (size_t j= 1; j< size(); j++)
w_chain -= getCCItem(j)->getWidth();
} }
//consider context button group on the right side of footer, if exist then subtract result from chain_width of button container /* On defined parameter chain_width
if (cch_btn_obj) * calculate current available space for button container depends
w_chain -= cch_btn_obj->getWidth(); * of passed chain with parameter
* Consider that chain_width is not too large.
*/
if (chain_width > 0 && chain_width <= w_chain){
if (chain_width <= w_chain){
w_chain = chain_width;
}
}
//calculate required position of button container /* initialize button container (chain object): this contains all passed (as interleaved) button label items,
//consider icon (inherited) width, if exist then set evaluated result as x position for button label container and ... * With this container we can work inside footer as primary container (in this context '=this') and the parent for the button label container (chain object).
int x_chain = 0; * Button label container (chain object) itself is concurrent to the parent object for button objects.
*/
int x_chain = width/2 - w_chain/2;
if (cch_icon_obj) if (cch_icon_obj)
x_chain = (cch_icon_obj->getXPos() + cch_offset + cch_icon_obj->getWidth()); x_chain = cch_offset+cch_icon_obj->getWidth()+cch_offset;
//... reduce also total width for button label container
w_chain -= x_chain;
//initialize container (chain object) as button label container: this contains all passed (as interleaved) button label items, with this container we can work inside
//footer as primary container (in this context '=this') and the parent for the button label container (chain object),
//button label container (chain object) itself is concurrent the parent object for button objects.
if (chain == NULL){ if (chain == NULL){
chain = new CComponentsFrmChain(x_chain, CC_CENTERED, w_chain, height, 0, CC_DIR_X, this, CC_SHADOW_OFF, COL_FRAME_PLUS_0, col_body); chain = new CComponentsFrmChain(x_chain, 0, w_chain, height, 0, CC_DIR_X, this, CC_SHADOW_OFF, COL_MENUCONTENT_PLUS_6, col_body);
chain->setAppendOffset(0, 0);
chain->setCorner(this->corner_rad, this->corner_type); chain->setCorner(this->corner_rad, this->corner_type);
chain->doPaintBg(false); chain->doPaintBg(false);
} }
if (!chain->empty())
chain->clear();
//calculate default static width of button labels inside button object container related to available width of chain object /* Calculate usable width of button labels inside button object container
int w_btn_fix = chain->getWidth() / label_count; * related to available width of chain object and passed
int w_btn_min = min(label_width, w_btn_fix); * label_width parameter.
* Parameter is used as minimal value and will be reduced
* if it is too large.
* Too small label_width parameter will be compensated by
* button objects itself.
*/
int w_offset = int((label_count-1)*cch_offset);
int w_btn = chain->getWidth()/label_count - w_offset;
if (label_width){
int w_label = label_width;
int w_defined = int(label_width*label_count);
int w_max = chain->getWidth() - w_offset;
while (w_defined > w_max){
w_label--;
w_defined = int(w_label*label_count) - w_offset;
}
w_btn = w_label;
}
int w_used = 0; /* generate button objects passed from button label content
* with default width to chain object.
//generate and add button objects passed from button label content with default width to chain object. */
vector<CComponentsItem*> v_btns;
int h_btn = height*85/100;
for (size_t i= 0; i< label_count; i++){ for (size_t i= 0; i< label_count; i++){
string txt = content[i].text; string txt = content[i].text;
string icon_name = string(content[i].button); string icon_name = string(content[i].button);
@@ -142,14 +178,14 @@ void CComponentsFooter::setButtonLabels(const struct button_label_s * const cont
continue; continue;
} }
CComponentsButton *btn = new CComponentsButton(0, CC_CENTERED, w_btn_min, (ccf_enable_button_bg ? height-2*fr_thickness : height)- 2*shadow_w, txt, icon_name, NULL, false, true, ccf_enable_button_shadow); CComponentsButton *btn = new CComponentsButton(0, CC_CENTERED, w_btn, /*(ccf_enable_button_bg ? */h_btn-2*fr_thickness/* : height)*/-ccf_button_shadow_width, txt, icon_name, NULL, false, true, ccf_enable_button_shadow);
btn->setButtonFont(ccf_btn_font);
btn->doPaintBg(ccf_enable_button_bg); btn->doPaintBg(ccf_enable_button_bg);
btn->setButtonDirectKey(content[i].directKey); btn->setButtonDirectKey(content[i].directKey);
btn->setButtonDirectKeyA(content[i].directKeyAlt); btn->setButtonDirectKeyA(content[i].directKeyAlt);
btn->setButtonResult(content[i].btn_result); btn->setButtonResult(content[i].btn_result);
btn->setButtonAlias(content[i].btn_alias); btn->setButtonAlias(content[i].btn_alias);
btn->setButtonFont(ccf_btn_font);
//set button frames to icon color, predefined for available color buttons //set button frames to icon color, predefined for available color buttons
if (btn_auto_frame_col){ if (btn_auto_frame_col){
@@ -165,32 +201,35 @@ void CComponentsFooter::setButtonLabels(const struct button_label_s * const cont
btn->setColorFrame(f_col); btn->setColorFrame(f_col);
} }
chain->addCCItem(btn); v_btns.push_back(btn);
//set x position of next button object if (w_btn < btn->getWidth()){
if (i != 0) btn->setWidth(w_btn);
btn->setXPos(CC_APPEND); btn->setButtonFont(NULL);
//collect used button width inside chain object
w_used += btn->getWidth();
} }
//calculate offset between button objects inside chain object dprintf(DEBUG_NORMAL, "[CComponentsFooter] [%s - %d] button %s [%u] btn->getWidth() = %d w_btn = %d, (chain->getWidth() = %d)\n", __func__, __LINE__, txt.c_str(), i, btn->getWidth(), w_btn, chain->getWidth());
int w_rest = max(w_chain - w_used, 0); }
int btn_offset = w_rest / chain->size();
chain->setAppendOffset(btn_offset, 0);
dprintf(DEBUG_INFO, "[CComponentsFooter] [%s - %d] btn_offset = %d, w_rest = %d, w_chain = %d, w_used = %d, chain->size() = %u\n", __func__, __LINE__, btn_offset, w_rest, w_chain, w_used, chain->size());
//set x position of 1st button object inside chain, this is centering button objects inside chain /* add generated button objects to chain object.
int x_1st_btn = btn_offset/2; */
chain->getCCItem(0)->setXPos(x_1st_btn); if (!v_btns.empty()){
/*add all buttons into button container*/
chain->addCCItem(v_btns);
//check used width of generated buttons, if required then use dynamic font, and try to fit buttons into chain container, dynamic font is used if ccf_btn_font==NULL /* set position of labels, as centered inside button container*/
//NOTE: user should be set not too small window size and not too large fontsize, at some point this possibility will be depleted and it's no more space for readable caption int w_chain_used = 0;
if (w_used > width && ccf_btn_font != NULL){ for (size_t a= 0; a< chain->size(); a++)
chain->clear(); w_chain_used += chain->getCCItem(a)->getWidth();
ccf_btn_font = NULL; w_chain_used += (chain->size()-1)*cch_offset;
setButtonLabels(content, label_count, chain_width, label_width);
int x_btn = chain->getWidth()/2 - w_chain_used/2;
chain->getCCItem(0)->setXPos(x_btn);
for (size_t c= 1; c< chain->size(); c++){
x_btn += chain->getCCItem(c-1)->getWidth()+ cch_offset;
chain->getCCItem(c)->setXPos(x_btn);
}
} }
} }
@@ -360,8 +399,10 @@ void CComponentsFooter::setButtonText(const uint& btn_id, const std::string& tex
void CComponentsFooter::enableButtonShadow(int mode, const int& shadow_width, bool force_paint) void CComponentsFooter::enableButtonShadow(int mode, const int& shadow_width, bool force_paint)
{ {
ccf_enable_button_shadow = mode; ccf_enable_button_shadow = mode;
ccf_button_shadow_width = shadow_width;
ccf_button_shadow_force_paint = force_paint;
if (chain){ if (chain){
for(size_t i=0; i<chain->size(); i++) for(size_t i=0; i<chain->size(); i++)
chain->enableShadow(mode, shadow_width, force_paint); chain->getCCItem(i)->enableShadow(ccf_enable_button_shadow, ccf_button_shadow_width, ccf_button_shadow_force_paint);
} }
} }

View File

@@ -72,8 +72,12 @@ class CComponentsFooter : public CComponentsHeader
///show button with background, default false ///show button with background, default false
bool ccf_enable_button_bg; bool ccf_enable_button_bg;
///enable button with shadow, default false ///enable button with shadow mode, default CC_SHADOW_OFF
bool ccf_enable_button_shadow; int ccf_enable_button_shadow;
///set button shadow button width
int ccf_button_shadow_width;
///set button shadow button repaint mode
bool ccf_button_shadow_force_paint;
///enable/disable button frame in icon color, predefined for red, green, yellow and blue, default disabled ///enable/disable button frame in icon color, predefined for red, green, yellow and blue, default disabled
bool btn_auto_frame_col; bool btn_auto_frame_col;
@@ -183,7 +187,7 @@ class CComponentsFooter : public CComponentsHeader
virtual void setSizeMode(const int& size_mode){cch_size_mode = size_mode; initCCItems();} virtual void setSizeMode(const int& size_mode){cch_size_mode = size_mode; initCCItems();}
///enable and sets shadow properties for embedded buttons ///enable and sets shadow properties for embedded buttons
void enableButtonShadow(int mode = CC_SHADOW_ON, const int& shadow_width = RADIUS_SMALL, bool force_paint = false); void enableButtonShadow(int mode = CC_SHADOW_ON, const int& shadow_width = OFFSET_SHADOW/2, bool force_paint = false);
///disable shadow for embedded buttons ///disable shadow for embedded buttons
void disbaleButtonShadow(){enableButtonShadow(CC_SHADOW_OFF);} void disbaleButtonShadow(){enableButtonShadow(CC_SHADOW_OFF);}
}; };

View File

@@ -119,8 +119,8 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen
CComponentsHeader(CComponentsForm *parent = NULL); CComponentsHeader(CComponentsForm *parent = NULL);
CComponentsHeader( const int& x_pos, const int& y_pos, const int& w, const int& h = 0, CComponentsHeader( const int& x_pos, const int& y_pos, const int& w, const int& h = 0,
const std::string& caption = "", const std::string& caption = std::string(),
const std::string& = "", const std::string& = std::string(),
const int& buttons = 0, const int& buttons = 0,
CComponentsForm *parent = NULL, CComponentsForm *parent = NULL,
int shadow_mode = CC_SHADOW_OFF, int shadow_mode = CC_SHADOW_OFF,

View File

@@ -247,11 +247,11 @@ void CComponentsPicture::initPosition(int *x_position, int *y_position)
} }
void CComponentsPicture::getSize(int* width_image, int *height_image) // void CComponentsPicture::getSize(int* width_image, int *height_image)
{ // {
*width_image = width; // *width_image = width;
*height_image = height; // *height_image = height;
} // }
int CComponentsPicture::getWidth() int CComponentsPicture::getWidth()
{ {

View File

@@ -144,12 +144,12 @@ class CComponentsPicture : public CComponentsItem
///returns current assigned image name ///returns current assigned image name
std::string getPictureName(){return pic_name;} std::string getPictureName(){return pic_name;}
///handle image size // ///handle image size
virtual void getSize(int* width_image, int *height_image); // void getSize(int* width_image, int *height_image);
///return width of component ///return width of item
virtual int getWidth(); int getWidth();
///return height of component ///return height of item
virtual int getHeight(); int getHeight();
///set width of object and image, value >0 causes scale of image, parameter keep_aspect = true causes scaling of height with same aspect, default = false ///set width of object and image, value >0 causes scale of image, parameter keep_aspect = true causes scaling of height with same aspect, default = false
virtual void setWidth(const int& w, bool keep_aspect = false); virtual void setWidth(const int& w, bool keep_aspect = false);

View File

@@ -370,9 +370,10 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
#endif #endif
else if (actionKey == "button"){ else if (actionKey == "button"){
if (button == NULL){ if (button == NULL){
button = new CComponentsButtonRed(100, 100, 100, 50, "Test"); button = new CComponentsButtonRed(100, 100, 100, 50, "Test", NULL, false, true, CC_SHADOW_OFF);
button->enableShadow(); button->enableShadow();
} }else
button->disableShadow();
if (!button->isPainted()){ if (!button->isPainted()){
@@ -560,7 +561,7 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
footer->setIcon(NEUTRINO_ICON_INFO); footer->setIcon(NEUTRINO_ICON_INFO);
//add button labels with conventional button label struct //add button labels with conventional button label struct
footer->setButtonLabels(TestButtons, TestButtonsCount, 0, footer->getWidth()/6); footer->setButtonLabels(TestButtons, TestButtonsCount, 0, footer->getWidth()/TestButtonsCount);
//also possible: use directly button name and as 2nd parameter string or locale as text //also possible: use directly button name and as 2nd parameter string or locale as text
// footer->setButtonLabel(NULL, "Test", 0, 250); // footer->setButtonLabel(NULL, "Test", 0, 250);

View File

@@ -97,6 +97,8 @@ void CMsgBox::init(const int& Height, const int& ShowButtons, const msg_result_t
height = min(MAX_WINDOW_HEIGHT, height); height = min(MAX_WINDOW_HEIGHT, height);
width = min(MAX_WINDOW_WIDTH, width); width = min(MAX_WINDOW_WIDTH, width);
shadow = CC_SHADOW_ON;
//set result //set result
if (Default_result != mbrNone) if (Default_result != mbrNone)
result = default_result = Default_result; result = default_result = Default_result;
@@ -175,8 +177,9 @@ void CMsgBox::initButtons()
ccw_footer->setButtonLabels(v_buttons, 0, 125); ccw_footer->setButtonLabels(v_buttons, 0, 125);
//show buttons with background //show buttons with background and shadow
ccw_footer->enableButtonBg(btn_enable_bg); ccw_footer->enableButtonBg(btn_enable_bg);
ccw_footer->enableButtonShadow(CC_SHADOW_ON, OFFSET_SHADOW/2, true);
//set position of meassage window and refresh window properties //set position of meassage window and refresh window properties
setCenterPos(); setCenterPos();