mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 15:32:59 +02:00
CCButtonSelect: outsource button select handling into own class
This commit is contained in:
@@ -18,6 +18,7 @@ noinst_LIBRARIES = libneutrino_gui_components.a
|
|||||||
|
|
||||||
libneutrino_gui_components_a_SOURCES = \
|
libneutrino_gui_components_a_SOURCES = \
|
||||||
cc_base.cpp \
|
cc_base.cpp \
|
||||||
|
cc_button_select.cpp \
|
||||||
cc_detailsline.cpp \
|
cc_detailsline.cpp \
|
||||||
cc_draw.cpp \
|
cc_draw.cpp \
|
||||||
cc_extra.cpp \
|
cc_extra.cpp \
|
||||||
|
74
src/gui/components/cc_button_select.cpp
Normal file
74
src/gui/components/cc_button_select.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
81
src/gui/components/cc_button_select.h
Normal file
81
src/gui/components/cc_button_select.h
Normal 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__
|
@@ -28,7 +28,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "cc_base.h"
|
#include "cc_base.h"
|
||||||
#include "cc_item.h"
|
#include "cc_item.h"
|
||||||
#include "cc_frm_scrollbar.h"
|
|
||||||
|
|
||||||
class CComponentsForm : public CComponentsItem
|
class CComponentsForm : public CComponentsItem
|
||||||
{
|
{
|
||||||
|
@@ -35,7 +35,7 @@ using namespace std;
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------
|
||||||
//sub class CComponentsFooter inherit from CComponentsHeader
|
//sub class CComponentsFooter inherit from CComponentsHeader
|
||||||
CComponentsFooter::CComponentsFooter(CComponentsForm* parent)
|
CComponentsFooter::CComponentsFooter(CComponentsForm* parent):CCButtonSelect()
|
||||||
{
|
{
|
||||||
//CComponentsFooter
|
//CComponentsFooter
|
||||||
initVarFooter(1, 1, 0, 0, 0, parent, CC_SHADOW_OFF, COL_FRAME_PLUS_0, COL_MENUFOOT_PLUS_0, COL_SHADOW_PLUS_0);
|
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,
|
int shadow_mode,
|
||||||
fb_pixel_t color_frame,
|
fb_pixel_t color_frame,
|
||||||
fb_pixel_t color_body,
|
fb_pixel_t color_body,
|
||||||
fb_pixel_t color_shadow )
|
fb_pixel_t color_shadow ):CCButtonSelect()
|
||||||
{
|
{
|
||||||
//CComponentsFooter
|
//CComponentsFooter
|
||||||
initVarFooter(x_pos, y_pos, w, h, buttons, parent, shadow_mode, color_frame, color_body, color_shadow);
|
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;
|
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
|
||||||
chain = NULL;
|
|
||||||
|
|
||||||
addContextButton(buttons);
|
addContextButton(buttons);
|
||||||
initCCItems();
|
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,
|
void CComponentsFooter::paintButtons(const int& x_pos,
|
||||||
const int& y_pos,
|
const int& y_pos,
|
||||||
const int& w,
|
const int& w,
|
||||||
|
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include "cc_frm_header.h"
|
#include "cc_frm_header.h"
|
||||||
#include "cc_frm_button.h"
|
#include "cc_frm_button.h"
|
||||||
|
#include "cc_button_select.h"
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <gui/widget/buttons.h> //for compatibility with 'button_label' type
|
#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.
|
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.
|
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:
|
private:
|
||||||
void initVarFooter( const int& x_pos, const int& y_pos, const int& w, const int& h,
|
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
|
///init default fonts for size modes
|
||||||
virtual void initDefaultFonts();
|
virtual void initDefaultFonts();
|
||||||
|
|
||||||
///container for button objects
|
|
||||||
CComponentsFrmChain *chain;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CComponentsFooter(CComponentsForm *parent = NULL);
|
CComponentsFooter(CComponentsForm *parent = NULL);
|
||||||
CComponentsFooter( const int& x_pos, const int& y_pos, const int& w, const int& h = 0,
|
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
|
///disables background of buttons
|
||||||
void disableButtonBg(){enableButtonBg(false);}
|
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.
|
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
|
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
|
///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;};
|
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 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
|
///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,
|
void paintButtons( const int& x_pos,
|
||||||
@@ -196,4 +157,6 @@ class CComponentsFooter : public CComponentsHeader
|
|||||||
void disbaleButtonShadow(){enableButtonShadow(CC_SHADOW_OFF);}
|
void disbaleButtonShadow(){enableButtonShadow(CC_SHADOW_OFF);}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -34,6 +34,7 @@ struct gradientData_t;
|
|||||||
class Font;
|
class Font;
|
||||||
class CComponentsForm;
|
class CComponentsForm;
|
||||||
class CComponentsScrollBar;
|
class CComponentsScrollBar;
|
||||||
|
class CCButtonSelect;
|
||||||
|
|
||||||
///cc item types
|
///cc item types
|
||||||
typedef enum
|
typedef enum
|
||||||
|
Reference in New Issue
Block a user