diff --git a/src/gui/components/Makefile.am b/src/gui/components/Makefile.am index c650d933b..2c78d799a 100644 --- a/src/gui/components/Makefile.am +++ b/src/gui/components/Makefile.am @@ -26,6 +26,7 @@ noinst_LIBRARIES = libneutrino_gui_components.a libneutrino_gui_components_a_SOURCES = \ cc_base.cpp \ cc_detailsline.cpp \ + cc_frm_button.cpp \ cc_frm.cpp \ cc_frm_header.cpp \ cc_frm_icons.cpp \ diff --git a/src/gui/components/cc_frm_button.cpp b/src/gui/components/cc_frm_button.cpp new file mode 100644 index 000000000..7895f00a0 --- /dev/null +++ b/src/gui/components/cc_frm_button.cpp @@ -0,0 +1,143 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Classes for generic GUI-related components. + Copyright (C) 2012, 2013, 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, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "cc_frm_button.h" + +#define FRAME_TH 3 + +using namespace std; + +CComponentsButton::CComponentsButton( const int x_pos, const int y_pos, const int w, const int h, + const std::string& caption, const std::string& icon_name, + bool selected, bool enabled, bool has_shadow, + fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) +{ + initVarButton(); + cc_btn_icon = icon_name; + cc_btn_capt = caption; + cc_btn_capt_col = COL_MENUCONTENT; + cc_btn_text_w = cc_btn_font->getRenderWidth(cc_btn_capt, true); + cc_btn_text_h = cc_btn_font->getHeight(); + + x = x_pos; + y = y_pos; + width = max(w, cc_btn_text_w); + height = max(h, cc_btn_text_h); + shadow = has_shadow; + shadow_w = SHADOW_OFFSET; + col_frame = color_frame; + col_body = color_body; + col_shadow = color_shadow; + cc_item_enabled = enabled; + cc_item_selected = selected; + fr_thickness = FRAME_TH; +} + +void CComponentsButton::initVarButton() +{ + initVarForm(); + cc_item_type = CC_ITEMTYPE_BUTTON; + cc_btn_icon_obj = NULL; + cc_btn_capt_obj = NULL; + cc_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]; + cc_btn_icon = ""; + cc_btn_capt = ""; + cc_btn_text_w = 0; + cc_btn_text_h = 0; +} + +void CComponentsButton::initIcon() +{ + //init cch_icon_obj only if an icon available + if (cc_btn_icon.empty()) { + if (cc_btn_icon_obj) + delete cc_btn_icon_obj; + cc_btn_icon_obj = NULL; + return; + } + + if (cc_btn_icon_obj == NULL){ + cc_btn_icon_obj = new CComponentsPicture(0, 0, 0, 0, cc_btn_icon); + + addCCItem(cc_btn_icon_obj); + } + + 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->setPictureAlign(CC_ALIGN_HOR_CENTER | CC_ALIGN_VER_CENTER); + cc_btn_icon_obj->doPaintBg(false); + } +} + +void CComponentsButton::initCaption() +{ + if (cc_btn_capt_obj == NULL){ + cc_btn_capt_obj = new CComponentsLabel(); + + 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(); + + if (cc_btn_icon_obj) + cap_x = this->getRealXPos()+(width/2)-(cc_btn_icon_obj->getWidth()+cc_btn_text_w)/2+cc_btn_icon_obj->getWidth(); + + 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); + cc_btn_capt_obj->setText(cc_btn_capt, CTextBox::NO_AUTO_LINEBREAK, cc_btn_font); + cc_btn_capt_obj->doPaintBg(false); + + //corner of text item + cc_btn_capt_obj->setCornerRadius(corner_rad-fr_thickness); + cc_btn_capt_obj->setCornerType(corner_type); + } +} + +void CComponentsButton::initCCBtnItems() +{ + initIcon(); + + initCaption(); +} + + +void CComponentsButton::paint(bool do_save_bg) +{ + //prepare items before paint + initCCBtnItems(); + + //paint form contents + paintForm(do_save_bg); +} diff --git a/src/gui/components/cc_frm_button.h b/src/gui/components/cc_frm_button.h new file mode 100644 index 000000000..b7cac5f2c --- /dev/null +++ b/src/gui/components/cc_frm_button.h @@ -0,0 +1,121 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Classes for generic GUI-related components. + Copyright (C) 2012, 2013, 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, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __CC_BUTTONS_H__ +#define __CC_BUTTONS_H__ + +#include "config.h" +#include "cc.h" +#include "cc_frm.h" +#include + + +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 + CComponentsPicture *cc_btn_icon_obj; + CComponentsLabel *cc_btn_capt_obj; + + ///initialize of objects + void initIcon(); + void initCaption(); + void initCCBtnItems(); + + public: + ///basic constructor for button object with most needed params, no button icon is definied here + CComponentsButton( const int x_pos, const int y_pos, const int w, const int h, + const std::string& caption, const std::string& icon_name, + 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); + + virtual void setButtonTextColor(fb_pixel_t caption_color){cc_btn_capt_col = caption_color;}; + 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 +class CComponentsButtonRed : public CComponentsButton +{ + public: + CComponentsButtonRed( const int x_pos, const int y_pos, const int w, const int h, + const std::string& caption, + 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) + :CComponentsButton(x_pos, y_pos, w, h, caption, NEUTRINO_ICON_BUTTON_RED, selected, enabled, has_shadow, color_frame, color_body, color_shadow) + { + cc_item_type = CC_ITEMTYPE_BUTTON_RED; + }; +}; + +class CComponentsButtonGreen : public CComponentsButton +{ + public: + CComponentsButtonGreen( const int x_pos, const int y_pos, const int w, const int h, + const std::string& caption, + 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) + :CComponentsButton(x_pos, y_pos, w, h, caption, NEUTRINO_ICON_BUTTON_GREEN, selected, enabled, has_shadow, color_frame, color_body, color_shadow) + { + cc_item_type = CC_ITEMTYPE_BUTTON_GREEN; + }; +}; + +class CComponentsButtonYellow : public CComponentsButton +{ + public: + CComponentsButtonYellow( const int x_pos, const int y_pos, const int w, const int h, + const std::string& caption, + 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) + :CComponentsButton(x_pos, y_pos, w, h, caption, NEUTRINO_ICON_BUTTON_YELLOW, selected, enabled, has_shadow, color_frame, color_body, color_shadow) + { + cc_item_type = CC_ITEMTYPE_BUTTON_YELLOW; + }; +}; + +class CComponentsButtonBlue : public CComponentsButton +{ + public: + CComponentsButtonBlue( const int x_pos, const int y_pos, const int w, const int h, + const std::string& caption, + 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) + :CComponentsButton(x_pos, y_pos, w, h, caption, NEUTRINO_ICON_BUTTON_BLUE, selected, enabled, has_shadow, color_frame, color_body, color_shadow) + { + cc_item_type = CC_ITEMTYPE_BUTTON_BLUE; + }; +}; + + +#endif /*__CC_BUTTONS_H__*/ diff --git a/src/gui/components/cc_types.h b/src/gui/components/cc_types.h index 3ba4d1c14..daef3f517 100644 --- a/src/gui/components/cc_types.h +++ b/src/gui/components/cc_types.h @@ -15,7 +15,7 @@ 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 - Library General Public License for more details. + General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the @@ -45,6 +45,11 @@ typedef enum CC_ITEMTYPE_FRM_WINDOW, CC_ITEMTYPE_LABEL, CC_ITEMTYPE_PROGRESSBAR, + CC_ITEMTYPE_BUTTON, + CC_ITEMTYPE_BUTTON_RED, + CC_ITEMTYPE_BUTTON_GREEN, + CC_ITEMTYPE_BUTTON_YELLOW, + CC_ITEMTYPE_BUTTON_BLUE, CC_ITEMTYPES }CC_ITEMTYPES_T;