CSignalBar: optimize caption handling

This commit is contained in:
2013-10-11 14:11:22 +02:00
parent b5483d4050
commit 517313cd82
2 changed files with 35 additions and 16 deletions

View File

@@ -57,18 +57,20 @@ CSignalBar::CSignalBar(const int& xpos, const int& ypos, const int& w, const int
void CSignalBar::initDimensions() void CSignalBar::initDimensions()
{ {
//set current required dimensions and font size //set current required dimensions and font size
sb_item_height = max(height, SB_MIN_HEIGHT) - 2*fr_thickness; sb_item_height = max(height, SB_MIN_HEIGHT) - 2*fr_thickness - append_h_offset;
sb_item_top = height/2 - sb_item_height/2; sb_item_top = height/2 - sb_item_height/2;
if (sb_scale_height == -1) if (sb_scale_height == -1)
sb_scale_height = sb_item_height; sb_scale_height = sb_item_height;
int dx = 0; //use value in % of signalbox width for scale, rest is reserved for caption
sb_scale_width = width*sb_scale_w_percent/100;
int dx = width - sb_scale_width;
int dy = sb_item_height; int dy = sb_item_height;
sb_font = *dy_font->getDynFont(dx, dy); sb_font = *dy_font->getDynFont(dx, dy);
sb_vlbl_width = sb_font->getRenderWidth ("00%", true); //use 15% for value and name label
sb_lbl_width = sb_font->getRenderWidth ("XXXX"/*sb_name*/, true); sb_vlbl_width = sb_lbl_width = dx /2;
sb_scale_width = width - sb_vlbl_width - sb_lbl_width - 2*fr_thickness;
} }
void CSignalBar::initSBItems() void CSignalBar::initSBItems()
@@ -97,11 +99,11 @@ void CSignalBar::initVarSigBar()
corner_rad = 0; corner_rad = 0;
corner_type = 0; corner_type = 0;
append_h_offset = 2; append_h_offset = 2;
append_v_offset = 0; append_v_offset = 2;
height = SB_MIN_HEIGHT; height = SB_MIN_HEIGHT;
sb_scale_height = -1; sb_scale_height = -1;
sb_scale_w_percent = 60;
dy_font = CNeutrinoFonts::getInstance(); dy_font = CNeutrinoFonts::getInstance();
sb_caption_color= COL_INFOBAR_TEXT; sb_caption_color= COL_INFOBAR_TEXT;
@@ -127,7 +129,7 @@ void CSignalBar::initSBarScale()
//move and set dimensions //move and set dimensions
int scale_y = (sb_item_height/2 - sb_scale_height/2); 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->setDimensionsAll(fr_thickness, scale_y, sb_scale_width, sb_scale_height);
sb_scale->setColorBody(col_body); sb_scale->setColorBody(col_body);
//add scale object to container //add scale object to container
@@ -146,8 +148,10 @@ void CSignalBar::initSBarValue()
} }
//move and set dimensions //move and set dimensions
int vlbl_x = sb_scale->getXPos() + sb_scale_width + append_h_offset; int vlbl_x = sb_scale->getXPos() + sb_scale_width + append_v_offset;
sb_vlbl->setDimensionsAll(vlbl_x/*CC_APPEND*/, sb_item_top, sb_vlbl_width, sb_item_height); int vlbl_h = sb_scale->getHeight();
int vlbl_y = sb_item_height/2 + sb_item_top - vlbl_h/2 - append_h_offset;
sb_vlbl->setDimensionsAll(vlbl_x, vlbl_y, sb_vlbl_width, vlbl_h);
//set current text and body color color //set current text and body color color
sb_vlbl->setTextColor(sb_caption_color); sb_vlbl->setTextColor(sb_caption_color);
@@ -163,15 +167,17 @@ void CSignalBar::initSBarName()
//create name label object with basic properties //create name label object with basic properties
if (sb_lbl == NULL){ if (sb_lbl == NULL){
sb_lbl = new CComponentsLabel(); sb_lbl = new CComponentsLabel();
//paint no backround sb_lbl->doPaintBg(false);
sb_lbl->doPaintBg(true); sb_lbl->setText(sb_name, CTextBox::NO_AUTO_LINEBREAK/* | CTextBox::RIGHT*/, sb_font);
sb_lbl->forceTextPaint(); sb_lbl->forceTextPaint();
sb_lbl->doPaintTextBoxBg(true);
} }
//move and set dimensions //move and set dimensions
int lbl_x = width - sb_lbl_width - fr_thickness; int lbl_x = sb_vlbl->getXPos()+ sb_vlbl->getWidth();
sb_lbl->setDimensionsAll(lbl_x, sb_item_top, sb_lbl_width, sb_item_height); int lbl_h = sb_vlbl->getHeight();
sb_lbl->setText(sb_name, CTextBox::NO_AUTO_LINEBREAK | CTextBox::RIGHT, sb_font); int lbl_y = sb_item_height/2 + sb_item_top - lbl_h/2 - append_h_offset;
sb_lbl->setDimensionsAll(lbl_x, lbl_y, sb_lbl_width, lbl_h);
//set current text and body color //set current text and body color
sb_lbl->setTextColor(sb_caption_color); sb_lbl->setTextColor(sb_caption_color);
@@ -310,6 +316,7 @@ void CSignalBox::initVarSigBox()
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;
sbx_scale_w_percent = 60;
} }
void CSignalBox::initSignalItems() void CSignalBox::initSignalItems()
@@ -329,11 +336,13 @@ void CSignalBox::initSignalItems()
sbar->setFrontEnd(sbx_frontend); sbar->setFrontEnd(sbx_frontend);
sbar->setCorner(0); sbar->setCorner(0);
sbar->setScaleHeight(scale_h); sbar->setScaleHeight(scale_h);
sbar->setScaleWidth(sbx_scale_w_percent);
snrbar->setDimensionsAll(sbar_x, CC_APPEND, sbar_w, sbar_h); snrbar->setDimensionsAll(sbar_x, CC_APPEND, sbar_w, sbar_h);
snrbar->setFrontEnd(sbx_frontend); snrbar->setFrontEnd(sbx_frontend);
snrbar->setCorner(0); snrbar->setCorner(0);
snrbar->setScaleHeight(scale_h); snrbar->setScaleHeight(scale_h);
snrbar->setScaleWidth(sbx_scale_w_percent);
} }
void CSignalBox::paintScale() void CSignalBox::paintScale()

View File

@@ -87,6 +87,9 @@ class CSignalBar : public CComponentsForm
int sb_lastsig; int sb_lastsig;
///current signal value ///current signal value
uint16_t sb_signal; uint16_t sb_signal;
///allowed width of scale bar from full width in %, rest used by caption, default value = 60% of width, use setScaleWidth() to set this value
short sb_scale_w_percent;
///initialize all needed basich attributes and objects ///initialize all needed basich attributes and objects
void initVarSigBar(); void initVarSigBar();
@@ -121,6 +124,8 @@ class CSignalBar : public CComponentsForm
virtual void setTextColor(const fb_pixel_t& caption_color){ sb_caption_color = caption_color;}; virtual void setTextColor(const fb_pixel_t& caption_color){ sb_caption_color = caption_color;};
///assigns the height of scale ///assigns the height of scale
virtual void setScaleHeight(const int& scale_height){sb_scale_height = scale_height;}; virtual void setScaleHeight(const int& scale_height){sb_scale_height = scale_height;};
///assigns the width of scale
virtual void setScaleWidth(const short & scale_width_percent){sb_scale_w_percent = scale_width_percent;};
///assigns the name of signal value in the caption object, see also sb_name ///assigns the name of signal value in the caption object, see also sb_name
virtual void setName(const std::string& name){sb_name = name;}; virtual void setName(const std::string& name){sb_name = name;};
@@ -248,6 +253,9 @@ class CSignalBox : public CComponentsForm
///property: text color, see also setTextColor() ///property: text color, see also setTextColor()
fb_pixel_t sbx_caption_color; fb_pixel_t sbx_caption_color;
///allowed width of scale bar from full width in %, rest used by caption, default value = 60% of width, use setScaleWidth() to set this value
short sbx_scale_w_percent;
///initialize all needed basic attributes and objects ///initialize all needed basic attributes and objects
void initVarSigBox(); void initVarSigBox();
///initialize general properties of signal items ///initialize general properties of signal items
@@ -270,7 +278,9 @@ class CSignalBox : public CComponentsForm
///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;};
///assigns the width of scale
void setScaleWidth(const short & scale_width_percent){sbx_scale_w_percent = scale_width_percent;};
///paint items ///paint items
void paint(bool do_save_bg); void paint(bool do_save_bg);
}; };