CCButtonSelect: outsource button select handling into own class

This commit is contained in:
2017-06-15 01:01:54 +02:00
parent 9e2c5cb939
commit 4d753d7437
7 changed files with 165 additions and 83 deletions

View File

@@ -18,6 +18,7 @@ noinst_LIBRARIES = libneutrino_gui_components.a
libneutrino_gui_components_a_SOURCES = \
cc_base.cpp \
cc_button_select.cpp \
cc_detailsline.cpp \
cc_draw.cpp \
cc_extra.cpp \

View File

@@ -0,0 +1,74 @@
/*
Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components.
Copyright (C) 2017, Thilo Graf 'dbt'
License: GPL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "cc_button_select.h"
CCButtonSelect::CCButtonSelect(CComponentsFrmChain *chain_obj)
{
chain = chain_obj;
}
CComponentsFrmChain* CCButtonSelect::getButtonChainObject()
{
return chain;
}
CComponentsButton* CCButtonSelect::getSelectedButtonObject()
{
CComponentsButton* ret = static_cast<CComponentsButton*>(chain->getSelectedItemObject());
return ret;
}
int CCButtonSelect::getSelectedButton()
{
if (chain)
return chain->getSelectedItem();
return -1;
}
void CCButtonSelect::setSelectedButton(size_t item_id,
const fb_pixel_t& fr_col,
const fb_pixel_t& sel_fr_col,
const fb_pixel_t& bg_col,
const fb_pixel_t& sel_bg_col,
const fb_pixel_t& text_col,
const fb_pixel_t& sel_text_col,
const int& frame_width,
const int& sel_frame_width)
{
if (chain){
for (size_t i= 0; i< chain->size(); i++){
CComponentsButton *btn = static_cast<CComponentsButton*>(chain->getCCItem(i));
btn->setButtonTextColor(text_col);
}
fb_pixel_t sel_col = fr_col;
if (chain->size() > 1)
sel_col = sel_fr_col; //TODO: make it configurable
chain->setSelectedItem(item_id, sel_col, fr_col, sel_bg_col, bg_col, frame_width, sel_frame_width);
getSelectedButtonObject()->setButtonTextColor(sel_text_col);
}
}

View File

@@ -0,0 +1,81 @@
/*
Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components.
Copyright (C) 2017, Thilo Graf 'dbt'
License: GPL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CC_BTN_SEL_H__
#define __CC_BTN_SEL_H__
#include "cc_frm_button.h"
/*!
Class for inheritation of button select handling inside other CComponentsForm objects and their derivations
*/
class CCButtonSelect
{
protected:
CComponentsFrmChain *chain;
public:
CCButtonSelect(CComponentsFrmChain *chain_obj = NULL);
///returns selected button object, return value as pointer to object, NULL means nothing is selected
CComponentsButton* getSelectedButtonObject();
///returns pointer to internal button container
CComponentsFrmChain* getButtonChainObject();
///returns id of select button, return value as int, -1 = nothing is selected
int getSelectedButton();
/**Select a definied button inside button chain object
* @param[in] item_id
* @li optional: expects type size_t
* @param[in] fr_col
* @li optional: expects type fb_pixel_t, as default frame color
* @param[in] sel_fr_col
* @li optional: expects type fb_pixel_t, as selected frame color
* @param[in] bg_col
* @li optional: expects type fb_pixel_t, as default background color
* @param[in] sel_bg_col
* @li optional: expects type fb_pixel_t, as selected background color
* @param[in] text_col
* @li optional: expects type fb_pixel_t, as default text color
* @param[in] sel_text_col
* @li optional: expects type fb_pixel_t, as selected text color
* @param[in] frame_width
* @li optional: expects type int, default = 1
* @param[in] sel_frame_width
* @li optional: expects type int, default = 1
*/
void setSelectedButton(size_t item_id,
const fb_pixel_t& fr_col = COL_MENUCONTENTSELECTED_PLUS_2,
const fb_pixel_t& sel_fr_col = COL_MENUCONTENTSELECTED_PLUS_0,
const fb_pixel_t& bg_col = COL_MENUCONTENT_PLUS_0,
const fb_pixel_t& sel_bg_col = COL_MENUCONTENTSELECTED_PLUS_0,
const fb_pixel_t& text_col = COL_MENUCONTENT_TEXT,
const fb_pixel_t& sel_text_col = COL_MENUCONTENTSELECTED_TEXT,
const int& frame_width = 1,
const int& sel_frame_width = 1);
};
#endif //__CC_BTN_SEL_H__

View File

@@ -28,7 +28,7 @@
#include "config.h"
#include "cc_base.h"
#include "cc_item.h"
#include "cc_frm_scrollbar.h"
class CComponentsForm : public CComponentsItem
{

View File

@@ -35,7 +35,7 @@ using namespace std;
//-------------------------------------------------------------------------------------------------------
//sub class CComponentsFooter inherit from CComponentsHeader
CComponentsFooter::CComponentsFooter(CComponentsForm* parent)
CComponentsFooter::CComponentsFooter(CComponentsForm* parent):CCButtonSelect()
{
//CComponentsFooter
initVarFooter(1, 1, 0, 0, 0, parent, CC_SHADOW_OFF, COL_FRAME_PLUS_0, COL_MENUFOOT_PLUS_0, COL_SHADOW_PLUS_0);
@@ -47,7 +47,7 @@ CComponentsFooter::CComponentsFooter( const int& x_pos, const int& y_pos, const
int shadow_mode,
fb_pixel_t color_frame,
fb_pixel_t color_body,
fb_pixel_t color_shadow )
fb_pixel_t color_shadow ):CCButtonSelect()
{
//CComponentsFooter
initVarFooter(x_pos, y_pos, w, h, buttons, parent, shadow_mode, color_frame, color_body, color_shadow);
@@ -95,7 +95,6 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const
corner_type = CORNER_BOTTOM;
ccf_enable_button_bg = false /*g_settings.theme.Button_gradient*/; //TODO: not implemented at the moment
chain = NULL;
addContextButton(buttons);
initCCItems();
@@ -323,43 +322,6 @@ void CComponentsFooter::enableButtonBg(bool enable)
}
}
void CComponentsFooter::setSelectedButton(size_t item_id,
const fb_pixel_t& fr_col, const fb_pixel_t& sel_fr_col,
const fb_pixel_t& bg_col, const fb_pixel_t& sel_bg_col,
const fb_pixel_t& text_col, const fb_pixel_t& sel_text_col,
const int& frame_width,
const int& sel_frame_width)
{
if (chain){
for (size_t i= 0; i< chain->size(); i++){
CComponentsButton *btn = static_cast<CComponentsButton*>(chain->getCCItem(i));
btn->setButtonTextColor(text_col);
}
fb_pixel_t sel_col = fr_col;
if (chain->size() > 1)
sel_col = sel_fr_col; //TODO: make it configurable
chain->setSelectedItem(item_id, sel_col, fr_col, sel_bg_col, bg_col, frame_width, sel_frame_width);
getSelectedButtonObject()->setButtonTextColor(sel_text_col);
}
}
int CComponentsFooter::getSelectedButton()
{
int ret = -1;
if (chain)
ret = chain->getSelectedItem();
return ret;
}
CComponentsButton* CComponentsFooter::getSelectedButtonObject()
{
CComponentsButton* ret = static_cast<CComponentsButton*>(chain->getSelectedItemObject());
return ret;
}
void CComponentsFooter::paintButtons(const int& x_pos,
const int& y_pos,
const int& w,

View File

@@ -26,6 +26,8 @@
#include "cc_frm_header.h"
#include "cc_frm_button.h"
#include "cc_button_select.h"
#include <global.h>
#include <gui/widget/buttons.h> //for compatibility with 'button_label' type
@@ -39,7 +41,7 @@ to add button labels known by older button handler, to find in gui/widget/button
functionality. Why limited ?: old parameter 'struct button_label' doesn't provide newer parameters.
Missing parameters are filled with default values and must be assigned afterward, if required.
*/
class CComponentsFooter : public CComponentsHeader
class CComponentsFooter : public CComponentsHeader, public CCButtonSelect
{
private:
void initVarFooter( const int& x_pos, const int& y_pos, const int& w, const int& h,
@@ -67,9 +69,6 @@ class CComponentsFooter : public CComponentsHeader
///init default fonts for size modes
virtual void initDefaultFonts();
///container for button objects
CComponentsFrmChain *chain;
public:
CComponentsFooter(CComponentsForm *parent = NULL);
CComponentsFooter( const int& x_pos, const int& y_pos, const int& w, const int& h = 0,
@@ -114,40 +113,6 @@ class CComponentsFooter : public CComponentsHeader
///disables background of buttons
void disableButtonBg(){enableButtonBg(false);}
/**Select a definied button inside button chain object
* @param[in] item_id
* @li optional: exepts type size_t
* @param[in] fr_col
* @li optional: exepts type fb_pixel_t, as default frame color
* @param[in] sel_fr_col
* @li optional: exepts type fb_pixel_t, as selected frame color
* @param[in] bg_col
* @li optional: exepts type fb_pixel_t, as default background color
* @param[in] sel_bg_col
* @li optional: exepts type fb_pixel_t, as selected background color
* @param[in] text_col
* @li optional: exepts type fb_pixel_t, as default text color
* @param[in] sel_text_col
* @li optional: exepts type fb_pixel_t, as selected text color
* @param[in] frame_width
* @li optional: exepts type int, default = 1
* @param[in] sel_frame_width
* @li optional: exepts type int, default = 2
*/
void setSelectedButton(size_t item_id,
const fb_pixel_t& fr_col = COL_MENUCONTENTSELECTED_PLUS_2,
const fb_pixel_t& sel_fr_col = COL_MENUCONTENTSELECTED_PLUS_0,
const fb_pixel_t& bg_col = COL_MENUCONTENT_PLUS_0,
const fb_pixel_t& sel_bg_col = COL_MENUCONTENTSELECTED_PLUS_0,
const fb_pixel_t& text_col = COL_MENUCONTENT_TEXT,
const fb_pixel_t& sel_text_col = COL_MENUCONTENTSELECTED_TEXT,
const int& frame_width = 1,
const int& sel_frame_width = 1);
///returns id of select button, return value as int, -1 = nothing is selected
int getSelectedButton();
///returns selected button object, return value as pointer to object, NULL means nothing is selected
CComponentsButton* getSelectedButtonObject();
/*!
Sets a new text to an already predefined button.
1st parameter 'btn_id' accepts current id of an already defined button. 2nd parameter sets the new text as std::string
@@ -164,10 +129,6 @@ class CComponentsFooter : public CComponentsHeader
///property: set font for label caption, parameter as font object, value NULL causes usage of dynamic font
void setButtonFont(Font* font){ccf_btn_font = font;};
///returns pointer to internal button container
CComponentsFrmChain* getButtonChainObject(){return chain;};
///this is a nearly methode similar with the older button handler find in gui/widget/buttons.h, some parameters are different, but require minimalized input
///this member sets some basic parameters and will paint concurrently on execute, explicit call of paint() is not required
void paintButtons( const int& x_pos,
@@ -196,4 +157,6 @@ class CComponentsFooter : public CComponentsHeader
void disbaleButtonShadow(){enableButtonShadow(CC_SHADOW_OFF);}
};
#endif

View File

@@ -34,6 +34,7 @@ struct gradientData_t;
class Font;
class CComponentsForm;
class CComponentsScrollBar;
class CCButtonSelect;
///cc item types
typedef enum