CSignalBar/CSignalBox: rework position and paint handling, use dyn fonts

This commit is contained in:
2013-08-30 22:17:08 +02:00
parent 6b25b6d530
commit bb3a5fa8ef
2 changed files with 143 additions and 103 deletions

View File

@@ -32,7 +32,7 @@
#include "signalbars.h" #include "signalbars.h"
#include <sstream> #include <sstream>
#define SB_MIN_HEIGHT 10 #define SB_MIN_HEIGHT 12
using namespace std; using namespace std;
@@ -49,52 +49,26 @@ CSignalBar::CSignalBar(const int& xpos, const int& ypos, const int& w, const int
x = xpos; x = xpos;
y = ypos; y = ypos;
width = w; width = w;
height = max(h, height); height = h;
initSBItems(); initSBItems();
} }
void CSignalBar::initVarSigBar()
{
initVarForm();
corner_rad = 0;
corner_type = 0;
append_h_offset = 4;
append_v_offset = 0;
height = SB_MIN_HEIGHT;
sb_item_height = height;
sb_scale_height = sb_item_height;
dy_font = CNeutrinoFonts::getInstance();
int dx = 0;
sb_font = *dy_font->getDynFont(dx, height);
sb_item_height = sb_font->getHeight();
sb_caption_color= COL_INFOBAR_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() void CSignalBar::initDimensions()
{ {
//set current required dimensions //set current required dimensions and font size
sb_item_height = max(height, SB_MIN_HEIGHT) - 2*fr_thickness;
sb_item_top = height/2 - sb_item_height/2;
if (sb_scale_height == -1)
sb_scale_height = sb_item_height;
int dx = 0; int dx = 0;
sb_font = *dy_font->getDynFont(dx, height); int dy = sb_item_height;
sb_vlbl_width = sb_font->getRenderWidth ("100%", true); sb_font = *dy_font->getDynFont(dx, dy);
sb_lbl_width = sb_font->getRenderWidth ("XXXXX", true);
sb_scale_width = width-sb_vlbl_width-sb_lbl_width-corner_rad; sb_vlbl_width = sb_font->getRenderWidth ("00%", true);
sb_item_height = max(sb_scale_height, sb_font->getHeight()); sb_lbl_width = sb_font->getRenderWidth ("XXXX"/*sb_name*/, true);
sb_scale_width = width - sb_vlbl_width - sb_lbl_width - 2*fr_thickness;
} }
void CSignalBar::initSBItems() void CSignalBar::initSBItems()
@@ -117,13 +91,29 @@ void CSignalBar::initSBItems()
initSBarName(); initSBarName();
} }
void CSignalBar::Refresh() void CSignalBar::initVarSigBar()
{ {
//get current value from frontend initVarForm();
sb_signal = sb_frontend->getSignalStrength(); corner_rad = 0;
corner_type = 0;
append_h_offset = 2;
append_v_offset = 0;
height = SB_MIN_HEIGHT;
//reinit items with current values sb_scale_height = -1;
initSBItems();
dy_font = CNeutrinoFonts::getInstance();
sb_caption_color= COL_INFOBAR_TEXT;
sb_lastsig = 0;
sb_signal = 0;
sb_frontend = NULL;
sb_scale = NULL;
sb_vlbl = NULL;
sb_lbl = NULL;
sb_name = "SIG";
} }
void CSignalBar::initSBarScale() void CSignalBar::initSBarScale()
@@ -136,8 +126,9 @@ void CSignalBar::initSBarScale()
} }
//move and set dimensions //move and set dimensions
int sb_y = height/2 - sb_scale_height/2 ; int scale_y = (sb_item_height/2 - sb_scale_height/2);
sb_scale->setDimensionsAll(append_v_offset, sb_y, sb_scale_width, sb_scale_height); sb_scale->setDimensionsAll(fr_thickness, scale_y, sb_scale_width, sb_scale_height/*sb_item_height*/);
sb_scale->setColorBody(col_body);
//add scale object to container //add scale object to container
if(!isAdded(sb_scale)) if(!isAdded(sb_scale))
@@ -155,16 +146,16 @@ void CSignalBar::initSBarValue()
} }
//move and set dimensions //move and set dimensions
int sb_y = height/2 - sb_item_height/2 ; int vlbl_x = sb_scale->getXPos() + sb_scale_width + append_h_offset;
sb_vlbl->setDimensionsAll(CC_APPEND, sb_y, sb_vlbl_width, sb_item_height); sb_vlbl->setDimensionsAll(vlbl_x/*CC_APPEND*/, sb_item_top, sb_vlbl_width, sb_item_height);
//set current text color //set current text and body color color
sb_vlbl->setTextColor(sb_caption_color); sb_vlbl->setTextColor(sb_caption_color);
sb_vlbl->setColorBody(col_body);
//add value label object to container //add value label object to container
if (!isAdded(sb_vlbl)) if (!isAdded(sb_vlbl))
addCCItem(sb_vlbl); addCCItem(sb_vlbl);
} }
void CSignalBar::initSBarName() void CSignalBar::initSBarName()
@@ -173,16 +164,18 @@ void CSignalBar::initSBarName()
if (sb_lbl == NULL){ if (sb_lbl == NULL){
sb_lbl = new CComponentsLabel(); sb_lbl = new CComponentsLabel();
//paint no backround //paint no backround
sb_lbl->doPaintBg(false); sb_lbl->doPaintBg(true);
sb_lbl->forceTextPaint();
} }
//move and set dimensions //move and set dimensions
int sb_y = sb_vlbl->getYPos() ; int lbl_x = width - sb_lbl_width - fr_thickness;
sb_lbl->setDimensionsAll(CC_APPEND, sb_y, sb_lbl_width, sb_item_height); sb_lbl->setDimensionsAll(lbl_x, sb_item_top, sb_lbl_width, sb_item_height);
sb_lbl->setText(sb_name, CTextBox::NO_AUTO_LINEBREAK, sb_font); sb_lbl->setText(sb_name, CTextBox::NO_AUTO_LINEBREAK | CTextBox::RIGHT, sb_font);
//set current text color //set current text and body color
sb_lbl->setTextColor(sb_caption_color); sb_lbl->setTextColor(sb_caption_color);
sb_lbl->setColorBody(col_body);
//add name label object to container //add name label object to container
if (!isAdded(sb_lbl)) if (!isAdded(sb_lbl))
@@ -190,7 +183,16 @@ void CSignalBar::initSBarName()
} }
void CSignalBar::Repaint() void CSignalBar::Refresh()
{
//get current value from frontend
sb_signal = sb_frontend->getSignalStrength();
//reinit items with current values
initSBItems();
}
void CSignalBar::paintScale()
{ {
//format signal values //format signal values
int sig; int sig;
@@ -204,7 +206,6 @@ void CSignalBar::Repaint()
if (sb_lastsig != sig) { if (sb_lastsig != sig) {
sb_lastsig = sig; sb_lastsig = sig;
sb_scale->setValues(sig, 100); sb_scale->setValues(sig, 100);
//string is required //string is required
ostringstream i_str; ostringstream i_str;
i_str << sig; i_str << sig;
@@ -224,6 +225,19 @@ void CSignalBar::Repaint()
} }
} }
void CSignalBar::paint(bool do_save_bg)
{
//initialize before and paint frame and body
if (!is_painted){
initSBItems();
paintForm(do_save_bg);
}
//paint current sig value
paintScale();
}
//******************************************************************************************************************************* //*******************************************************************************************************************************
CSignalNoiseRatioBar::CSignalNoiseRatioBar() CSignalNoiseRatioBar::CSignalNoiseRatioBar()
{ {
@@ -238,7 +252,7 @@ CSignalNoiseRatioBar::CSignalNoiseRatioBar(const int& xpos, const int& ypos, con
x = xpos; x = xpos;
y = ypos; y = ypos;
width = w; width = w;
height = max(h, height); height = h;
initSBItems(); initSBItems();
} }
@@ -268,7 +282,7 @@ CSignalBox::CSignalBox(const int& xpos, const int& ypos, const int& w, const int
x = xpos; x = xpos;
y = ypos; y = ypos;
width = w; width = w;
height = max(h, height); height = h;
sbx_bar_height = height/2; sbx_bar_height = height/2;
sbx_bar_width = width-2*corner_rad; sbx_bar_width = width-2*corner_rad;
@@ -292,7 +306,7 @@ void CSignalBox::initVarSigBox()
sbx_frontend = NULL; sbx_frontend = NULL;
sbar = NULL; sbar = NULL;
snrbar = NULL; snrbar = NULL;
height = 5* SB_MIN_HEIGHT; height = 3* SB_MIN_HEIGHT;
sbx_bar_height = height/2; sbx_bar_height = height/2;
sbx_bar_x = corner_rad; sbx_bar_x = corner_rad;
sbx_caption_color = COL_INFOBAR_TEXT; sbx_caption_color = COL_INFOBAR_TEXT;
@@ -301,30 +315,47 @@ void CSignalBox::initVarSigBox()
void CSignalBox::initSignalItems() void CSignalBox::initSignalItems()
{ {
//set current properties for items //set current properties for items
int cor_rad = corner_rad/2-fr_thickness; // int cor_rad = corner_rad/2-fr_thickness;
sbar->setDimensionsAll(sbx_bar_x, 0, sbx_bar_width, sbx_bar_height); // int corr_y = sbx_bar_height%2;
sbar->setCornerRadius(cor_rad); // int sb_h = sbx_bar_height - corr_y;
int sbar_h = sbx_bar_height - fr_thickness - append_v_offset/2;
int sbar_w = sbx_bar_width - 2*fr_thickness;
int sbar_x = sbx_bar_x + fr_thickness;
int scale_h = sbar_h * 76 / 100;
sbar->setDimensionsAll(sbar_x, fr_thickness, sbar_w, sbar_h);
sbar->setFrontEnd(sbx_frontend); sbar->setFrontEnd(sbx_frontend);
sbar->setCornerRadius(0);
sbar->setScaleHeight(scale_h);
snrbar->setDimensionsAll(sbx_bar_x, CC_APPEND, sbx_bar_width, sbx_bar_height); snrbar->setDimensionsAll(sbar_x, CC_APPEND, sbar_w, sbar_h);
snrbar->setCornerRadius(cor_rad);
snrbar->setFrontEnd(sbx_frontend); snrbar->setFrontEnd(sbx_frontend);
snrbar->setCornerRadius(0);
snrbar->setScaleHeight(scale_h);
} }
void CSignalBox::Refresh() void CSignalBox::paintScale()
{ {
//reinit properties of items
initSignalItems(); initSignalItems();
//refresh properties of items //repaint items
sbar->Refresh(); sbar->Refresh();
sbar->paint/*Scale*/(false);
snrbar->Refresh(); snrbar->Refresh();
snrbar->paint/*Scale*/(false);
} }
void CSignalBox::Repaint() void CSignalBox::paint(bool do_save_bg)
{ {
//repaint items //paint frame and body
sbar->Repaint(); if (!is_painted){
snrbar->Repaint(); initSignalItems();
paintForm(do_save_bg);
}
//paint current signal value
paintScale();
} }

View File

@@ -50,6 +50,10 @@ CSignalBar() is intended to show signal rate.
class CSignalBar : public CComponentsForm class CSignalBar : public CComponentsForm
{ {
public:
///refresh current item properties, use this before paintScale().
void Refresh();
protected: protected:
///object: current frontend ///object: current frontend
CFrontend *sb_frontend; CFrontend *sb_frontend;
@@ -66,12 +70,14 @@ class CSignalBar : public CComponentsForm
///property: text color, see also setTextColor() ///property: text color, see also setTextColor()
fb_pixel_t sb_caption_color; fb_pixel_t sb_caption_color;
///property: item top position
int sb_item_top;
///property: height of items ///property: height of items
int sb_item_height; int sb_item_height;
///property: height of scale
int sb_scale_height;
///property: width of progressbar ///property: width of progressbar
int sb_scale_width; int sb_scale_width;
///property: height of progressbar
int sb_scale_height;
///property: width of value caption ///property: width of value caption
int sb_vlbl_width; int sb_vlbl_width;
///property: width of caption ///property: width of caption
@@ -96,6 +102,9 @@ class CSignalBar : public CComponentsForm
///initialize all required objects at once, see also Refresh() ///initialize all required objects at once, see also Refresh()
void initSBItems(); void initSBItems();
///reinitialize current signal values and paint new values, required after Refresh()
void paintScale();
///property: contains the name of signal type in the caption object, see also setName() ///property: contains the name of signal type in the caption object, see also setName()
std::string sb_name; std::string sb_name;
@@ -120,11 +129,8 @@ class CSignalBar : public CComponentsForm
///returns the caption object, type = CComponentsLabel* ///returns the caption object, type = CComponentsLabel*
virtual CComponentsLabel* getLabelObject(){return sb_lbl;}; virtual CComponentsLabel* getLabelObject(){return sb_lbl;};
///refresh current item properties, use this before Repaint(). ///paint this items
void Refresh(); virtual void paint(bool do_save_bg);
///reinitialize current signal values and paint new values, required after Refresh()
virtual void Repaint();
}; };
/// Sub class of CSignalBar() /// Sub class of CSignalBar()
@@ -136,6 +142,10 @@ CSignalNoiseRatioBar() is intended to show signal noise ratio value.
class CSignalNoiseRatioBar : public CSignalBar class CSignalNoiseRatioBar : public CSignalBar
{ {
public:
///refresh current item properties, use this before paintScale().
void Refresh();
protected: protected:
///initialize all needed basic attributes and objects ///initialize all needed basic attributes and objects
void initVarSnrBar(); void initVarSnrBar();
@@ -144,9 +154,6 @@ class CSignalNoiseRatioBar : public CSignalBar
CSignalNoiseRatioBar(); CSignalNoiseRatioBar();
///basic component class constructor for signal noise ratio. ///basic component class constructor for signal noise ratio.
CSignalNoiseRatioBar(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref); 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. /// Class CSignalBox() provides CSignalBar(), CSignalNoiseRatioBar() scales at once.
@@ -192,8 +199,8 @@ void CSampleClass::showSNR()
{ {
if (signalbox == NULL){ if (signalbox == NULL){
signalbox = new CSignalBox(10, 100, 500, 38, frontend); signalbox = new CSignalBox(10, 100, 500, 38, frontend);
signalbox->setCornerRadius(0); // signalbox->setCornerRadius(0); //optional
// signalbox->setColorBody(COL_BLACK); // signalbox->setColorBody(COL_BLACK); //optional
signalbox->setColorBody(COL_MENUHEAD_PLUS_0); signalbox->setColorBody(COL_MENUHEAD_PLUS_0);
signalbox->doPaintBg(false); signalbox->doPaintBg(false);
//if you want to add the object to a CC-Container (e.g. CComponentsWindow()), remove this line: //if you want to add the object to a CC-Container (e.g. CComponentsWindow()), remove this line:
@@ -201,11 +208,10 @@ void CSampleClass::showSNR()
//and add this lines: //and add this lines:
// if (!isAdded(signalbox)) // if (!isAdded(signalbox))
// addCCItem(signalbox); // addCCItem(signalbox);
//Note: signal box object deallocate together with the CC-Container! //Note: signal box objects deallocate together with the CC-Container!
} }
else{ else{
signalbox->Refresh(); signalbox->paintScale();
signalbox->Repaint();
} }
} }
@@ -225,13 +231,14 @@ void CSampleClass::hide ()
class CSignalBox : public CComponentsForm class CSignalBox : public CComponentsForm
{ {
protected: private:
///object: current frontend ///object: current frontend
CFrontend *sbx_frontend; CFrontend *sbx_frontend;
///object: current signalbar ///object: current signalbar
CSignalBar *sbar; CSignalBar *sbar;
///object: current signal noise ratio bar ///object: current signal noise ratio bar
CSignalNoiseRatioBar *snrbar; CSignalNoiseRatioBar *snrbar;
///property: height of signalbars ///property: height of signalbars
int sbx_bar_height; int sbx_bar_height;
///property: width of signalbars ///property: width of signalbars
@@ -240,30 +247,32 @@ class CSignalBox : public CComponentsForm
int sbx_bar_x; int sbx_bar_x;
///property: text color, see also setTextColor() ///property: text color, see also setTextColor()
fb_pixel_t sbx_caption_color; fb_pixel_t sbx_caption_color;
///initialize all needed basic attributes and objects ///initialize all needed basic attributes and objects
void initVarSigBox(); void initVarSigBox();
///initialize general properties of signal items
void initSignalItems(); void initSignalItems();
///paint items with new values, required after Refresh()
void paintScale();
public: public:
///class constructor for signal noise ratio. ///class constructor for signal noise ratio.
CSignalBox(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref); CSignalBox(const int& xpos, const int& ypos, const int& w, const int& h, CFrontend *frontend_ref);
///returns the signal object, type = CSignalBar* ///returns the signal object, type = CSignalBar*
virtual CSignalBar* getScaleObject(){return sbar;}; CSignalBar* getScaleObject(){return sbar;};
///returns the signal noise ratio object, type = CSignalNoiseRatioBar* ///returns the signal noise ratio object, type = CSignalNoiseRatioBar*
virtual CSignalNoiseRatioBar* getLabelObject(){return snrbar;}; CSignalNoiseRatioBar* getLabelObject(){return snrbar;};
///sets the caption color of signalbars, see also property 'sbx_caption_color' ///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;}; void setTextColor(const fb_pixel_t& caption_color){ sbx_caption_color = caption_color;};
///get caption color of signalbars, see also property 'sbx_caption_color' ///get caption color of signalbars, see also property 'sbx_caption_color'
fb_pixel_t getTextColor(){return 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() ///paint items
void Repaint(); void paint(bool do_save_bg);
}; };
#endif #endif