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 <sstream>
#define SB_MIN_HEIGHT 10
#define SB_MIN_HEIGHT 12
using namespace std;
@@ -49,52 +49,26 @@ CSignalBar::CSignalBar(const int& xpos, const int& ypos, const int& w, const int
x = xpos;
y = ypos;
width = w;
height = max(h, height);
height = h;
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()
{
//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;
sb_font = *dy_font->getDynFont(dx, height);
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());
int dy = sb_item_height;
sb_font = *dy_font->getDynFont(dx, dy);
sb_vlbl_width = sb_font->getRenderWidth ("00%", true);
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()
@@ -117,13 +91,29 @@ void CSignalBar::initSBItems()
initSBarName();
}
void CSignalBar::Refresh()
void CSignalBar::initVarSigBar()
{
//get current value from frontend
sb_signal = sb_frontend->getSignalStrength();
initVarForm();
corner_rad = 0;
corner_type = 0;
append_h_offset = 2;
append_v_offset = 0;
height = SB_MIN_HEIGHT;
//reinit items with current values
initSBItems();
sb_scale_height = -1;
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()
@@ -136,8 +126,9 @@ void CSignalBar::initSBarScale()
}
//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);
int scale_y = (sb_item_height/2 - sb_scale_height/2);
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
if(!isAdded(sb_scale))
@@ -155,16 +146,16 @@ void CSignalBar::initSBarValue()
}
//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);
int vlbl_x = sb_scale->getXPos() + sb_scale_width + append_h_offset;
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->setColorBody(col_body);
//add value label object to container
if (!isAdded(sb_vlbl))
addCCItem(sb_vlbl);
}
void CSignalBar::initSBarName()
@@ -173,16 +164,18 @@ void CSignalBar::initSBarName()
if (sb_lbl == NULL){
sb_lbl = new CComponentsLabel();
//paint no backround
sb_lbl->doPaintBg(false);
sb_lbl->doPaintBg(true);
sb_lbl->forceTextPaint();
}
//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);
int lbl_x = width - sb_lbl_width - fr_thickness;
sb_lbl->setDimensionsAll(lbl_x, sb_item_top, sb_lbl_width, sb_item_height);
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->setColorBody(col_body);
//add name label object to container
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
int sig;
@@ -204,7 +206,6 @@ void CSignalBar::Repaint()
if (sb_lastsig != sig) {
sb_lastsig = sig;
sb_scale->setValues(sig, 100);
//string is required
ostringstream i_str;
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()
{
@@ -238,7 +252,7 @@ CSignalNoiseRatioBar::CSignalNoiseRatioBar(const int& xpos, const int& ypos, con
x = xpos;
y = ypos;
width = w;
height = max(h, height);
height = h;
initSBItems();
}
@@ -268,7 +282,7 @@ CSignalBox::CSignalBox(const int& xpos, const int& ypos, const int& w, const int
x = xpos;
y = ypos;
width = w;
height = max(h, height);
height = h;
sbx_bar_height = height/2;
sbx_bar_width = width-2*corner_rad;
@@ -292,7 +306,7 @@ void CSignalBox::initVarSigBox()
sbx_frontend = NULL;
sbar = NULL;
snrbar = NULL;
height = 5* SB_MIN_HEIGHT;
height = 3* SB_MIN_HEIGHT;
sbx_bar_height = height/2;
sbx_bar_x = corner_rad;
sbx_caption_color = COL_INFOBAR_TEXT;
@@ -301,30 +315,47 @@ void CSignalBox::initVarSigBox()
void CSignalBox::initSignalItems()
{
//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);
sbar->setCornerRadius(cor_rad);
// int corr_y = sbx_bar_height%2;
// 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->setCornerRadius(0);
sbar->setScaleHeight(scale_h);
snrbar->setDimensionsAll(sbx_bar_x, CC_APPEND, sbx_bar_width, sbx_bar_height);
snrbar->setCornerRadius(cor_rad);
snrbar->setDimensionsAll(sbar_x, CC_APPEND, sbar_w, sbar_h);
snrbar->setFrontEnd(sbx_frontend);
snrbar->setCornerRadius(0);
snrbar->setScaleHeight(scale_h);
}
void CSignalBox::Refresh()
void CSignalBox::paintScale()
{
//reinit properties of items
initSignalItems();
//refresh properties of items
//repaint items
sbar->Refresh();
sbar->paint/*Scale*/(false);
snrbar->Refresh();
snrbar->paint/*Scale*/(false);
}
void CSignalBox::Repaint()
void CSignalBox::paint(bool do_save_bg)
{
//repaint items
sbar->Repaint();
snrbar->Repaint();
//paint frame and body
if (!is_painted){
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
{
public:
///refresh current item properties, use this before paintScale().
void Refresh();
protected:
///object: current frontend
CFrontend *sb_frontend;
@@ -66,12 +70,14 @@ class CSignalBar : public CComponentsForm
///property: text color, see also setTextColor()
fb_pixel_t sb_caption_color;
///property: item top position
int sb_item_top;
///property: height of items
int sb_item_height;
///property: height of scale
int sb_scale_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
@@ -96,6 +102,9 @@ class CSignalBar : public CComponentsForm
///initialize all required objects at once, see also Refresh()
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()
std::string sb_name;
@@ -120,11 +129,8 @@ class CSignalBar : public CComponentsForm
///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();
///paint this items
virtual void paint(bool do_save_bg);
};
/// Sub class of CSignalBar()
@@ -136,6 +142,10 @@ CSignalNoiseRatioBar() is intended to show signal noise ratio value.
class CSignalNoiseRatioBar : public CSignalBar
{
public:
///refresh current item properties, use this before paintScale().
void Refresh();
protected:
///initialize all needed basic attributes and objects
void initVarSnrBar();
@@ -144,9 +154,6 @@ class CSignalNoiseRatioBar : public CSignalBar
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.
@@ -192,8 +199,8 @@ void CSampleClass::showSNR()
{
if (signalbox == NULL){
signalbox = new CSignalBox(10, 100, 500, 38, frontend);
signalbox->setCornerRadius(0);
// signalbox->setColorBody(COL_BLACK);
// signalbox->setCornerRadius(0); //optional
// signalbox->setColorBody(COL_BLACK); //optional
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:
@@ -201,11 +208,10 @@ void CSampleClass::showSNR()
//and add this lines:
// if (!isAdded(signalbox))
// addCCItem(signalbox);
//Note: signal box object deallocate together with the CC-Container!
//Note: signal box objects deallocate together with the CC-Container!
}
else{
signalbox->Refresh();
signalbox->Repaint();
signalbox->paintScale();
}
}
@@ -225,13 +231,14 @@ void CSampleClass::hide ()
class CSignalBox : public CComponentsForm
{
protected:
private:
///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
@@ -240,30 +247,32 @@ class CSignalBox : public CComponentsForm
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();
///initialize general properties of signal items
void initSignalItems();
///paint items with new values, required after Refresh()
void paintScale();
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;};
CSignalBar* getScaleObject(){return sbar;};
///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'
void setTextColor(const fb_pixel_t& caption_color){ sbx_caption_color = caption_color;};
///get 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();
///paint items
void paint(bool do_save_bg);
};
#endif