diff --git a/src/gui/components/Makefile.am b/src/gui/components/Makefile.am index 8aec4d2ba..b4b58ec39 100644 --- a/src/gui/components/Makefile.am +++ b/src/gui/components/Makefile.am @@ -28,6 +28,7 @@ libneutrino_gui_components_a_SOURCES = \ cc_detailsline.cpp \ cc_frm_button.cpp \ cc_frm.cpp \ + cc_frm_chain.cpp \ cc_frm_clock.cpp \ cc_frm_footer.cpp \ cc_frm_header.cpp \ diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index efae3aae5..54e612954 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -44,6 +44,7 @@ Basic attributes and member functions for component sub classes #include "cc_frm.h" #include "cc_frm_button.h" +#include "cc_frm_chain.h" #include "cc_frm_clock.h" #include "cc_frm_signalbars.h" #include "cc_frm_slider.h" diff --git a/src/gui/components/cc_frm.cpp b/src/gui/components/cc_frm.cpp index ce7418d78..a7c4c6bce 100644 --- a/src/gui/components/cc_frm.cpp +++ b/src/gui/components/cc_frm.cpp @@ -151,6 +151,12 @@ void CComponentsForm::addCCItem(CComponentsItem* cc_Item) #endif } +void CComponentsForm::addCCItem(const std::vector cc_Items) +{ + for (size_t i= 0; i< cc_Items.size(); i++) + addCCItem(cc_Items[i]); +} + int CComponentsForm::getCCItemId(CComponentsItem* cc_Item) { if (cc_Item){ @@ -297,6 +303,15 @@ void CComponentsForm::paintCCItems() int xpos = cc_item->getXPos(); int ypos = cc_item->getYPos(); + //check item for corrupt position, skip current item if found problems + //TODO: need a solution with possibility for scrolling + if (ypos > height || xpos > width){ + printf("[CComponentsForm] %s: [form: %d] [item-index %d] [type=%d] WARNING: item position is out of form size:\ndefinied x=%d, defined width=%d \ndefinied y=%d, defined height=%d \n", + __func__, cc_item_index, cc_item->getIndex(), cc_item->getItemType(), xpos, width, ypos, height); + if (this->cc_item_type != CC_ITEMTYPE_FRM_CHAIN) + continue; + } + //set required x-position to item: //append vertical if (xpos == CC_APPEND){ diff --git a/src/gui/components/cc_frm.h b/src/gui/components/cc_frm.h index 6b2bd31cc..1dbbd2c2a 100644 --- a/src/gui/components/cc_frm.h +++ b/src/gui/components/cc_frm.h @@ -57,6 +57,7 @@ class CComponentsForm : public CComponentsItem void paint(bool do_save_bg = CC_SAVE_SCREEN_YES); void hide(bool no_restore = false); virtual void addCCItem(CComponentsItem* cc_Item); + virtual void addCCItem(const std::vector cc_items); virtual void insertCCItem(const uint& cc_item_id, CComponentsItem* cc_Item); virtual void removeCCItem(const uint& cc_item_id); virtual void removeCCItem(CComponentsItem* cc_Item); diff --git a/src/gui/components/cc_frm_chain.cpp b/src/gui/components/cc_frm_chain.cpp new file mode 100644 index 000000000..6603b18bf --- /dev/null +++ b/src/gui/components/cc_frm_chain.cpp @@ -0,0 +1,126 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Classes for generic GUI-related components. + Copyright (C) 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, see . +*/ + +#include +#include +#include "cc_frm_chain.h" + +using namespace std; + +//------------------------------------------------------------------------------------------------------- +//sub class CComponentsFrmChain +CComponentsFrmChain::CComponentsFrmChain( const int& x_pos, const int& y_pos, const int& w, const int& h, + const std::vector *v_items, + bool horizontal, + bool dynamic_width, + bool dynamic_height, + bool has_shadow, + fb_pixel_t& color_frame, + fb_pixel_t& color_body, + fb_pixel_t& color_shadow) +{ + initVarChain(x_pos, y_pos, w, h, v_items, horizontal, dynamic_width, dynamic_height, has_shadow, color_frame, color_body, color_shadow); +} + + +void CComponentsFrmChain::initVarChain( const int& x_pos, const int& y_pos, const int& w, const int& h, + const std::vector *v_items, + bool horizontal, + bool dynamic_width, + bool dynamic_height, + bool has_shadow, + fb_pixel_t& color_frame, + fb_pixel_t& color_body, + fb_pixel_t& color_shadow) +{ + cc_item_type = CC_ITEMTYPE_FRM_CHAIN; + corner_rad = 0; + + x = x_pos; + y = y_pos; + width = w; + height = h; + + shadow = has_shadow; + col_frame = color_frame; + col_body = color_body; + col_shadow = color_shadow; + + chn_horizontal = horizontal; + chn_dyn_height = dynamic_height; + chn_dyn_width = dynamic_width; + + if (v_items){ + addCCItem(*v_items); + initCChainItems(); + } +} + +void CComponentsFrmChain::initCChainItems() +{ + if (!v_cc_items.empty()){ + if (chn_dyn_height) + height = 0; + if (chn_dyn_width) + width = 0; + } + + for (size_t i= 0; i< v_cc_items.size(); i++){ + //set general start position for all items + if (i == 0) + v_cc_items[i]->setPos(0, 0); + + //set arrangement with required direction + if (chn_horizontal){ + if (i > 0) + v_cc_items[i]->setPos(CC_APPEND, 0); + } + else{ + if (i > 0) + v_cc_items[i]->setPos(0, CC_APPEND); + } + + //assign size + if (chn_horizontal){ + //assign dynamic width + if (chn_dyn_width) + width += v_cc_items[i]->getWidth(); + //assign dynamic height + if (chn_dyn_height) + height = max(v_cc_items[i]->getHeight(), height); + else + v_cc_items[i]->setHeight(height); + } + else{ + //assign dynamic height + if (chn_dyn_height) + height += v_cc_items[i]->getHeight(); + //assign dynamic width + if (chn_dyn_width) + width = max(v_cc_items[i]->getWidth(), width); + else + v_cc_items[i]->setWidth(width); + } + } +} + diff --git a/src/gui/components/cc_frm_chain.h b/src/gui/components/cc_frm_chain.h new file mode 100644 index 000000000..d18461f06 --- /dev/null +++ b/src/gui/components/cc_frm_chain.h @@ -0,0 +1,78 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Classes for generic GUI-related components. + Copyright (C) 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, see . +*/ + +#ifndef __CC_FORM_CHAIN_H__ +#define __CC_FORM_CHAIN_H__ + + +#include +#include "cc_frm.h" + + +//! Sub class of CComponentsForm. Creates a dynamic form with chained items. +/*! +Paint chained cc-items on screen. +You can set default form parameters like position, size, colors etc. and additional values +to display with defined direction. +*/ + +class CComponentsFrmChain : public CComponentsForm +{ + private: + ///property: defined arrangement mode of items, can be vertical or horizontal + int chn_horizontal; + + ///property: defines height from sum of all contained items + bool chn_dyn_height; + ///property: defines width from sum of all contained items + bool chn_dyn_width; + + ///init all required variables + void initVarChain( const int& x_pos, const int& y_pos, const int& w, const int& h, + const std::vector *v_items, + bool horizontal, + bool dynamic_width, + bool dynamic_height, + bool has_shadow, + fb_pixel_t& color_frame, + fb_pixel_t& color_body, + fb_pixel_t& color_shadow); + + void initCChainItems(); + protected: + + + public: + CComponentsFrmChain( const int& x_pos = 1, const int& y_pos = 1, const int& w = 720, const int& h = 32, + const std::vector *v_items = NULL, + bool horizontal = true, + bool dynamic_width = false, + bool dynamic_height = false, + bool has_shadow = CC_SHADOW_OFF, + fb_pixel_t& color_frame = COL_MENUCONTENT_PLUS_6, + fb_pixel_t& color_body = COL_MENUHEAD_PLUS_0, + fb_pixel_t& color_shadow = COL_MENUCONTENTDARK_PLUS_0); +// ~CComponentsSlider(); //inherited from CComponentsForm +}; + +#endif diff --git a/src/gui/components/cc_types.h b/src/gui/components/cc_types.h index 89e85e3d1..401c3c44d 100644 --- a/src/gui/components/cc_types.h +++ b/src/gui/components/cc_types.h @@ -43,6 +43,7 @@ typedef enum CC_ITEMTYPE_SHAPE_CIRCLE, CC_ITEMTYPE_PIP, CC_ITEMTYPE_FRM, + CC_ITEMTYPE_FRM_CHAIN, CC_ITEMTYPE_FRM_CLOCK, CC_ITEMTYPE_FRM_HEADER, CC_ITEMTYPE_FOOTER,