diff --git a/src/gui/widget/Makefile.am b/src/gui/widget/Makefile.am index 608af6216..24ef50127 100644 --- a/src/gui/widget/Makefile.am +++ b/src/gui/widget/Makefile.am @@ -22,7 +22,7 @@ if BOXTYPE_TRIPLE INCLUDES += -I$(top_srcdir)/lib/libtriple endif -noinst_LIBRARIES = libneutrino_gui_widget.a libneutrino_gui_widget2.a +noinst_LIBRARIES = libneutrino_gui_widget.a libneutrino_gui_widget2.a libneutrino_gui_widget_a_SOURCES = \ buttons.cpp \ @@ -38,6 +38,7 @@ libneutrino_gui_widget_a_SOURCES = \ messagebox.cpp \ mountchooser.cpp \ msgbox.cpp \ + signalbars.cpp \ stringinput.cpp \ stringinput_ext.cpp \ textbox.cpp diff --git a/src/gui/widget/signalbars.cpp b/src/gui/widget/signalbars.cpp new file mode 100644 index 000000000..1a0dc3564 --- /dev/null +++ b/src/gui/widget/signalbars.cpp @@ -0,0 +1,321 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Class for signalbar based up CComponent classes. + 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, 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 "signalbars.h" +#include + +#define SB_MIN_HEIGHT 10 + +using namespace std; + +CSignalBar::CSignalBar() +{ + initVarSigBar(); +} + +CSignalBar::CSignalBar(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref) +{ + initVarSigBar(); + sb_frontend = frontend_ref; + x = xpos; + y = ypos; + width = w; + height = max(h, height); + + initSBItems(); +} + +void CSignalBar::initVarSigBar() +{ + initVarForm(); + corner_rad = 0; + corner_type = 0; + append_h_offset = 4; + append_v_offset = 0; + + sb_font = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]; + sb_item_height = sb_font->getHeight(); + height = sb_item_height; + sb_scale_height = SB_MIN_HEIGHT; + sb_caption_color= COL_MENUCONTENT_TEXT; + + initDimensions(); + + sb_lastsig = 0; + sb_signal = 0; + + sb_frontend = NULL; + sb_scale = NULL; + sb_vlbl = NULL; + sb_lbl = NULL; + sb_name = "SIG"; +} + +void CSignalBar::initDimensions() +{ + //set current required dimensions + sb_vlbl_width = sb_font->getRenderWidth ("100%", true); + sb_lbl_width = sb_font->getRenderWidth ("XXXXX", true); + sb_scale_width = width-sb_vlbl_width-sb_lbl_width-corner_rad; + sb_item_height = max(sb_scale_height, sb_font->getHeight()); + height = max(height, sb_item_height); +} + +void CSignalBar::initSBItems() +{ + if (cc_parent){ + //use backround color of parent form if signalbar is embedded + col_body = cc_parent->getColorBody(); + + //and set required color for text to name label + CSignalBox *sbx = static_cast(cc_parent); + sb_caption_color = sbx->getTextColor(); + } + + //reinit dimensions + initDimensions(); + + //init items scale, value and name + initSBarScale(); + initSBarValue(); + initSBarName(); +} + +void CSignalBar::Refresh() +{ + //get current value from frontend + sb_signal = sb_frontend->getSignalStrength(); + + //reinit items with current values + initSBItems(); +} + +void CSignalBar::initSBarScale() +{ + //create scale object if required + if (sb_scale == NULL){ + sb_scale = new CProgressBar(); + //we want colored scale! + sb_scale->setBlink(); + } + + //move and set dimensions + int sb_y = height/2 - sb_scale_height/2 ; + sb_scale->setDimensionsAll(append_v_offset, sb_y, sb_scale_width, sb_scale_height); + + //add scale object to container + if(!isAdded(sb_scale)) + addCCItem(sb_scale); + +} + +void CSignalBar::initSBarValue() +{ + //create value label object with basic properties + if (sb_vlbl == NULL){ + sb_vlbl = new CComponentsLabel(); + sb_vlbl->doPaintBg(false); + sb_vlbl->setText("0%", CTextBox::NO_AUTO_LINEBREAK, sb_font); + } + + //move and set dimensions + int sb_y = height/2 - sb_item_height/2 ; + sb_vlbl->setDimensionsAll(CC_APPEND, sb_y, sb_vlbl_width, sb_item_height); + + //set current text color + sb_vlbl->setTextColor(sb_caption_color); + + //add value label object to container + if (!isAdded(sb_vlbl)) + addCCItem(sb_vlbl); + +} + +void CSignalBar::initSBarName() +{ + //create name label object with basic properties + if (sb_lbl == NULL){ + sb_lbl = new CComponentsLabel(); + //paint no backround + sb_lbl->doPaintBg(false); + } + + //move and set dimensions + int sb_y = sb_vlbl->getYPos() ; + sb_lbl->setDimensionsAll(CC_APPEND, sb_y, sb_lbl_width, sb_item_height); + sb_lbl->setText(sb_name, CTextBox::NO_AUTO_LINEBREAK, sb_font); + + //set current text color + sb_lbl->setTextColor(sb_caption_color); + + //add name label object to container + if (!isAdded(sb_lbl)) + addCCItem(sb_lbl); +} + + +void CSignalBar::Repaint() +{ + //format signal values + int sig; + sig = (sb_signal & 0xFFFF) * 100 / 65535; + + //exit if value too small + if(sig < 5) + return; + + //assign current value to scale object and paint new value + if (sb_lastsig != sig) { + sb_lastsig = sig; + sb_scale->setValues(sig, 100); + + //string is required + ostringstream i_str; + i_str << sig; + string percent(i_str.str()); + percent += "%"; + sb_vlbl->setText(percent, CTextBox::NO_AUTO_LINEBREAK | CTextBox::CENTER, sb_font); + + //we must force paint backround, because of changing values + sb_vlbl->doPaintBg(true); + sb_vlbl->forceTextPaint(); + sb_vlbl->doPaintTextBoxBg(true); + sb_vlbl->setColorBody(col_body); + + //repaint labels + for(size_t i=0; iv_cc_items.size(); i++) + v_cc_items[i]->paint(false); + } +} + +//******************************************************************************************************************************* +CSignalNoiseRatioBar::CSignalNoiseRatioBar() +{ + initVarSnrBar(); +} + +CSignalNoiseRatioBar::CSignalNoiseRatioBar(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref) +{ + initVarSnrBar(); + sb_frontend = frontend_ref; + x = xpos; + y = ypos; + width = w; + height = max(h, height); + + initSBItems(); +} + +void CSignalNoiseRatioBar::initVarSnrBar() +{ + initVarSigBar(); + sb_name = "SNR"; +} + +void CSignalNoiseRatioBar::Refresh() +{ + //get current value from frontend + sb_signal = sb_frontend->getSignalNoiseRatio(); + + //reinit items with current values + initSBItems(); +} + + +//********************************************************************************************************************** +CSignalBox::CSignalBox(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref) +{ + initVarSigBox(); + + sbx_frontend = frontend_ref; + x = xpos; + y = ypos; + width = w; + height = max(h, height); + + sbx_bar_height = height/2; + sbx_bar_width = width-2*corner_rad; + + sbar = new CSignalBar(sbx_bar_x, 0, sbx_bar_width, sbx_bar_height, sbx_frontend); + sbar->doPaintBg(false); + addCCItem(sbar); + + snrbar = new CSignalNoiseRatioBar(sbx_bar_x, CC_APPEND, sbx_bar_width, sbx_bar_height, sbx_frontend); + snrbar->doPaintBg(false); + addCCItem(snrbar); + + initSignalItems(); +} + +void CSignalBox::initVarSigBox() +{ + initVarForm(); + corner_rad = 0; + + sbx_frontend = NULL; + sbar = NULL; + snrbar = NULL; + height = 5* SB_MIN_HEIGHT; + sbx_bar_height = height/2; + sbx_bar_x = corner_rad; + sbx_caption_color = COL_MENUCONTENT_TEXT; +} + +void CSignalBox::initSignalItems() +{ + //set current properties for items + int cor_rad = corner_rad/2-fr_thickness; + + sbar->setDimensionsAll(sbx_bar_x, 0, sbx_bar_width, sbx_bar_height); + sbar->setCornerRadius(cor_rad); + sbar->setFrontEnd(sbx_frontend); + + snrbar->setDimensionsAll(sbx_bar_x, CC_APPEND, sbx_bar_width, sbx_bar_height); + snrbar->setCornerRadius(cor_rad); + snrbar->setFrontEnd(sbx_frontend); +} + +void CSignalBox::Refresh() +{ + //reinit properties of items + initSignalItems(); + + //refresh properties of items + sbar->Refresh(); + snrbar->Refresh(); +} + +void CSignalBox::Repaint() +{ + //repaint items + sbar->Repaint(); + snrbar->Repaint(); +} diff --git a/src/gui/widget/signalbars.h b/src/gui/widget/signalbars.h new file mode 100644 index 000000000..85501f2cd --- /dev/null +++ b/src/gui/widget/signalbars.h @@ -0,0 +1,267 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Class for signalbar based up CComponent classes. + 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, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __SIGNALBARS_H__ +#define __SIGNALBARS_H__ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include + + +/// Basic class for signalbars +/*! +Basic attributes and member functions for items. +These class provides basic attributes and members to show frontend values in signalbars. +CSignalBar() and their sub classes based up CComponentsForm() and are usable like other CComponentsItems() + +CSignalBar() is intended to show signal rate. +*/ + +class CSignalBar : public CComponentsForm +{ + protected: + ///object: current frontend + CFrontend *sb_frontend; + ///object: scale bar + CProgressBar *sb_scale; + ///object: value caption + CComponentsLabel *sb_vlbl; + ///object: caption for signal name + CComponentsLabel *sb_lbl; + ///object: current font + Font *sb_font; + ///property: text color, see also setTextColor() + fb_pixel_t sb_caption_color; + + ///property: height of items + int sb_item_height; + ///property: width of progressbar + int sb_scale_width; + ///property: height of progressbar + int sb_scale_height; + ///property: width of value caption + int sb_vlbl_width; + ///property: width of caption + int sb_lbl_width; + + ///cache last assingned signal value + int sb_lastsig; + ///current signal value + uint16_t sb_signal; + + ///initialize all needed basich attributes and objects + void initVarSigBar(); + ///initianlize position and dimensions of signalbar container + void initDimensions(); + ///initialize scale object + void initSBarScale(); + ///initialize value caption object, this contains the value of current frontend data, signal or noise rate + void initSBarValue(); + ///initialize caption object, this contains the unit (e.g %) or name of value (e.g. SIG) + void initSBarName(); + + ///initialize all required objects at once, see also Refresh() + void initSBItems(); + + ///property: contains the name of signal type in the caption object, see also setName() + std::string sb_name; + + public: + CSignalBar(); + ///basic component class constructor for signal. + CSignalBar(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref); + + ///assigns the current used frontend, simplified a tuner object, see frontend_c.h + virtual void setFrontEnd(CFrontend *frontend_ref){sb_frontend = frontend_ref;}; + ///assigns font for caption + virtual void setTextFont(Font* font_text){sb_font = font_text;}; + ///sets the caption color, see also property 'sb_caption_color' + virtual void setTextColor(const fb_pixel_t& caption_color){ sb_caption_color = caption_color;}; + ///assigns the height of scale + virtual void setScaleHeight(const int& scale_height){sb_scale_height = scale_height;}; + ///assigns the name of signal value in the caption object, see also sb_name + virtual void setName(const std::string& name){sb_name = name;}; + + ///returns the scale object, type = CProgressBar* + virtual CProgressBar* getScaleObject(){return sb_scale;}; + ///returns the caption object, type = CComponentsLabel* + virtual CComponentsLabel* getLabelObject(){return sb_lbl;}; + + ///refresh current item properties, use this before Repaint(). + void Refresh(); + ///reinitialize current signal values and paint new values, required after Refresh() + virtual void Repaint(); + +}; + +/// Sub class of CSignalBar() +/*! +This class use basic attributes and members from CSignalBar() to show frontend values. + +CSignalNoiseRatioBar() is intended to show signal noise ratio value. +*/ + +class CSignalNoiseRatioBar : public CSignalBar +{ + protected: + ///initialize all needed basic attributes and objects + void initVarSnrBar(); + + public: + CSignalNoiseRatioBar(); + ///basic component class constructor for signal noise ratio. + CSignalNoiseRatioBar(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref); + + ///refresh current item properties, use this before repaintSignalBar(). + void Refresh(); +}; + +/// Class CSignalBox() provides CSignalBar(), CSignalNoiseRatioBar() scales at once. +/*! +Provides basic attributes and member functions for CComponentItems in +additional of CSignalBar()- and CSignalNoiseRatioBar()-objects. + + +To add a signalbox object to your code add this to a header file: +#include + +class CSampleClass +{ + private: + //other stuff; + CSignalBox * signalbox; + + public: + CSampleClass(); + ~CSampleClass(); + void showSNR(); + + //other stuff; + +}; + + +//add this to your costructor into the code file: +CSampleClass::CSampleClass() +{ + //other stuff; + signalbox = NULL; +} + +CStreamInfo2::~CStreamInfo2 () +{ + //other stuff to clean; + delete signalbox; + //other stuff to clean; +} + +void CSampleClass::showSNR() +{ + if (signalbox == NULL){ + signalbox = new CSignalBox(10, 100, 500, 38, frontend); + signalbox->setCornerRadius(0); +// signalbox->setColorBody(COL_BLACK); + signalbox->setColorBody(COL_MENUHEAD_PLUS_0); + signalbox->doPaintBg(false); +//if you want to add the object to a CC-Container (e.g. CComponentsWindow()), remove this line: + signalbox->paint(false); +//and add this lines: +// if (!isAdded(signalbox)) +// addCCItem(signalbox); +//Note: signal box object deallocate together with the CC-Container! + } + else{ + signalbox->Refresh(); + signalbox->Repaint(); + } + } + +void CSampleClass::hide () +{ + //other code; + +//Note: not required if signalbox is added to a CC-Container! + signalbox->hide(true); + delete signalbox; + signalbox = NULL; + + //other code; +} + +*/ + +class CSignalBox : public CComponentsForm +{ + protected: + ///object: current frontend + CFrontend *sbx_frontend; + ///object: current signalbar + CSignalBar *sbar; + ///object: current signal noise ratio bar + CSignalNoiseRatioBar *snrbar; + ///property: height of signalbars + int sbx_bar_height; + ///property: width of signalbars + int sbx_bar_width; + ///property: x position of signalbars + int sbx_bar_x; + ///property: text color, see also setTextColor() + fb_pixel_t sbx_caption_color; + ///initialize all needed basic attributes and objects + void initVarSigBox(); + + void initSignalItems(); + + public: + ///class constructor for signal noise ratio. + CSignalBox(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref); + + ///returns the signal object, type = CSignalBar* + virtual CSignalBar* getScaleObject(){return sbar;}; + ///returns the signal noise ratio object, type = CSignalNoiseRatioBar* + virtual CSignalNoiseRatioBar* getLabelObject(){return snrbar;}; + + ///sets the caption color of signalbars, see also property 'sbx_caption_color' + void setTextColor(const fb_pixel_t& caption_color){ sbx_caption_color = caption_color;}; + ///sets the caption color of signalbars, see also property 'sbx_caption_color' + fb_pixel_t getTextColor(){return sbx_caption_color;}; + + ///refresh all current snr value, use this before paint(). + void Refresh(); + + ///paint items with new values, required after Refresh() + void Repaint(); +}; + +#endif