helpbox: some reworks ...

* rename line_space to line_height
* separators uses half line height
* add getLineHeight() function
* small cleanups


Origin commit data
------------------
Commit: ce82966c75
Author: vanhofen <vanhofen@gmx.de>
Date: 2016-12-04 (Sun, 04 Dec 2016)

Origin message was:
------------------
- helpbox: some reworks ...

* rename line_space to line_height
* separators uses half line height
* add getLineHeight() function
* small cleanups
This commit is contained in:
vanhofen
2016-12-04 22:08:44 +01:00
parent 7e4147bacd
commit 3a692877a6
2 changed files with 46 additions and 51 deletions

View File

@@ -26,7 +26,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include <gui/widget/helpbox.h> #include <gui/widget/helpbox.h>
@@ -36,16 +35,13 @@ using namespace std;
Helpbox::Helpbox( const string& Title, Helpbox::Helpbox( const string& Title,
const string& Default_Text, const string& Default_Text,
const int& text_mode, const int& text_mode,
const int& line_space, const int& line_height,
Font* default_font_text, Font* default_font_text,
const char* Icon): const char* Icon):
CComponentsWindowMax( Title, CComponentsWindowMax( Title,
Icon, Icon,
NULL, NULL,
CC_SHADOW_ON, CC_SHADOW_ON)
COL_MENUCONTENT_PLUS_6,
COL_MENUCONTENT_PLUS_0,
COL_SHADOW_PLUS_0)
{ {
page = 0; page = 0;
hbox_y = 1; hbox_y = 1;
@@ -53,18 +49,17 @@ Helpbox::Helpbox( const string& Title,
ccw_footer->setButtonLabel(NEUTRINO_ICON_BUTTON_HOME, LOCALE_MESSAGEBOX_BACK); ccw_footer->setButtonLabel(NEUTRINO_ICON_BUTTON_HOME, LOCALE_MESSAGEBOX_BACK);
hbox_font = default_font_text; hbox_font = default_font_text;
if (default_font_text == NULL) if (hbox_font == NULL)
hbox_font = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO]; hbox_font = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO];
if (!Default_Text.empty()) if (!Default_Text.empty())
addLine(Default_Text.c_str(), Default_Text, text_mode, line_space, HELPBOX_DEFAULT_LINE_INDENT ,hbox_font); addLine(Default_Text.c_str(), Default_Text, text_mode, line_height, HELPBOX_DEFAULT_LINE_INDENT, hbox_font);
//ensure hided channellist, because shared RC_ok //ensure hided channellist, because shared RC_ok
CNeutrinoApp::getInstance()->allowChannelList(false); CNeutrinoApp::getInstance()->allowChannelList(false);
} }
void Helpbox::addLine(const std::string& icon, const std::string& text, const int& text_mode, const int& line_height, const int& line_indent, Font* font_text)
void Helpbox::addLine(const std::string& icon, const std::string& text, const int& text_mode, const int& line_space, const int& line_indent, Font* font_text)
{ {
CComponentsItem *pre_item = !ccw_body->empty() ? ccw_body->back() : NULL; //get the last current item CComponentsItem *pre_item = !ccw_body->empty() ? ccw_body->back() : NULL; //get the last current item
@@ -73,12 +68,11 @@ void Helpbox::addLine(const std::string& icon, const std::string& text, const in
hbox_y = pre_item->getYPos() + pre_item->getHeight(); hbox_y = pre_item->getYPos() + pre_item->getHeight();
} }
int h_line = line_space;
Font* font = hbox_font; Font* font = hbox_font;
if (font_text){ if (font_text)
h_line = max(h_line, font_text->getHeight());
font = font_text; font = font_text;
}
int h_line = getLineHeight(line_height, font);
CComponentsFrmChain *line = new CComponentsFrmChain(line_indent, hbox_y, 0, h_line); CComponentsFrmChain *line = new CComponentsFrmChain(line_indent, hbox_y, 0, h_line);
if ((hbox_y + h_line)>ccw_body->getHeight()){ if ((hbox_y + h_line)>ccw_body->getHeight()){
@@ -88,7 +82,7 @@ void Helpbox::addLine(const std::string& icon, const std::string& text, const in
line->setPageNumber(page); line->setPageNumber(page);
int w_body = ccw_body->getWidth(); int w_body = ccw_body->getWidth();
line->setWidth(w_body - line_indent - 40); line->setWidth(w_body - 2*line_indent);
line->setXPos(line_indent); line->setXPos(line_indent);
line->setColorBody(ccw_body->getColorBody()); line->setColorBody(ccw_body->getColorBody());
@@ -105,7 +99,7 @@ void Helpbox::addLine(const std::string& icon, const std::string& text, const in
if (!text.empty()){ if (!text.empty()){
int x_text = w_picon + (picon ? 10 : 0); int x_text = w_picon + (picon ? 10 : 0);
CComponentsText * txt = new CComponentsText(x_text, 0, line->getWidth()-x_text, line_space, text, text_mode, font); CComponentsText * txt = new CComponentsText(x_text, 0, line->getWidth()-x_text, line_height, text, text_mode, font);
#if 0 //"contrast agent", if you want to see where the text items are drawn. #if 0 //"contrast agent", if you want to see where the text items are drawn.
txt->setColorBody(COL_RED); txt->setColorBody(COL_RED);
txt->doPaintBg(true); txt->doPaintBg(true);
@@ -115,10 +109,7 @@ void Helpbox::addLine(const std::string& icon, const std::string& text, const in
addWindowItem(line); addWindowItem(line);
} }
void Helpbox::addSeparatorLine(const int& line_height, const int& line_indent)
void Helpbox::addSeparatorLine(const int& line_space, const int& line_indent)
{ {
CComponentsItem *pre_item = !ccw_body->empty() ? ccw_body->back() : NULL; //get the last current item CComponentsItem *pre_item = !ccw_body->empty() ? ccw_body->back() : NULL; //get the last current item
@@ -127,13 +118,11 @@ void Helpbox::addSeparatorLine(const int& line_space, const int& line_indent)
hbox_y = pre_item->getYPos() + pre_item->getHeight(); hbox_y = pre_item->getYPos() + pre_item->getHeight();
} }
int h_line = line_space; CComponentsFrmChain *line = new CComponentsFrmChain(line_indent, hbox_y, 0, getLineHeight(line_height, hbox_font, true));
CComponentsFrmChain *line = new CComponentsFrmChain(line_indent, hbox_y, 0, h_line);
line->setPageNumber(page); line->setPageNumber(page);
int w_body = ccw_body->getWidth(); int w_body = ccw_body->getWidth();
line->setWidth(w_body - line_indent - 40); line->setWidth(w_body - 2*line_indent);
line->setXPos(line_indent); line->setXPos(line_indent);
line->setColorBody(ccw_body->getColorBody()); line->setColorBody(ccw_body->getColorBody());
@@ -151,7 +140,7 @@ void Helpbox::addSeparatorLine(const int& line_space, const int& line_indent)
addWindowItem(line); addWindowItem(line);
} }
void Helpbox::addSeparator(const int& line_space) void Helpbox::addSeparator(const int& line_height)
{ {
CComponentsItem *pre_item = !ccw_body->empty() ? ccw_body->back() : NULL; //get the last current item CComponentsItem *pre_item = !ccw_body->empty() ? ccw_body->back() : NULL; //get the last current item
@@ -160,7 +149,7 @@ void Helpbox::addSeparator(const int& line_space)
hbox_y = pre_item->getYPos() + pre_item->getHeight(); hbox_y = pre_item->getYPos() + pre_item->getHeight();
} }
CComponentsFrmChain *line = new CComponentsFrmChain(0, hbox_y, 0, line_space); CComponentsFrmChain *line = new CComponentsFrmChain(0, hbox_y, 0, getLineHeight(line_height, hbox_font, true));
line->setPageNumber(page); line->setPageNumber(page);
int w_body = ccw_body->getWidth(); int w_body = ccw_body->getWidth();
@@ -170,29 +159,21 @@ void Helpbox::addSeparator(const int& line_space)
addWindowItem(line); addWindowItem(line);
} }
void Helpbox::addLine(const char *icon, const char *text, const int& text_mode, const int& line_height, const int& line_indent, Font* font_text)
void Helpbox::addLine(const char *icon, const char *text, const int& text_mode, const int& line_space, const int& line_indent, Font* font_text)
{ {
addLine(icon, std::string(text), text_mode, line_space, line_indent, font_text); addLine(icon, std::string(text), text_mode, line_height, line_indent, font_text);
} }
void Helpbox::addLine(const char *text, const int& text_mode, const int& line_height, const int& line_indent, Font* font_text)
void Helpbox::addLine(const char *text, const int& text_mode, const int& line_space, const int& line_indent, Font* font_text)
{ {
addLine("", std::string(text), text_mode, line_space, line_indent, font_text); addLine("", std::string(text), text_mode, line_height, line_indent, font_text);
} }
void Helpbox::addLine(const std::string& text, const int& text_mode, const int& line_space, const int& line_indent, Font* font_text) void Helpbox::addLine(const std::string& text, const int& text_mode, const int& line_height, const int& line_indent, Font* font_text)
{ {
addLine("", text, text_mode, line_space, line_indent, font_text); addLine("", text, text_mode, line_height, line_indent, font_text);
} }
void Helpbox::addPagebreak(void) void Helpbox::addPagebreak(void)
{ {
page ++; page ++;
@@ -200,3 +181,15 @@ void Helpbox::addPagebreak(void)
hbox_y = 1; hbox_y = 1;
} }
int Helpbox::getLineHeight(int line_height, Font* font_text, bool separator)
{
if (font_text == NULL)
return 0; // should not happen
int h = max(line_height, font_text->getHeight());
if (separator)
return h/2; // separators uses half height
return h;
}

View File

@@ -29,8 +29,8 @@
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#define HELPBOX_DEFAULT_LINE_HEIGHT 35 #define HELPBOX_DEFAULT_LINE_HEIGHT 0 // use font height as default
#define HELPBOX_DEFAULT_LINE_INDENT 10 #define HELPBOX_DEFAULT_LINE_INDENT OFFSET_INNER_MID
class Helpbox : public CComponentsWindowMax class Helpbox : public CComponentsWindowMax
{ {
@@ -39,13 +39,15 @@ private:
//start position of items on page //start position of items on page
int hbox_y; int hbox_y;
int getLineHeight(int line_height, Font* font_text, bool separator = false);
///default font ///default font
Font* hbox_font; Font* hbox_font;
public: public:
Helpbox( const std::string& Title, Helpbox( const std::string& Title,
const std::string& Default_Text = std::string(), const std::string& Default_Text = std::string(),
const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH, const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH,
const int& line_space = HELPBOX_DEFAULT_LINE_HEIGHT, const int& line_height = HELPBOX_DEFAULT_LINE_HEIGHT,
Font* font_text = NULL, Font* font_text = NULL,
const char* Icon = NEUTRINO_ICON_INFO); const char* Icon = NEUTRINO_ICON_INFO);
@@ -54,37 +56,37 @@ public:
void addLine( const std::string& text, void addLine( const std::string& text,
const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH, const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH,
const int& line_space = HELPBOX_DEFAULT_LINE_HEIGHT, const int& line_height = HELPBOX_DEFAULT_LINE_HEIGHT,
const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT, const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT,
Font* font_text = NULL); Font* font_text = NULL);
void addLine( const char *text, void addLine( const char *text,
const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH, const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH,
const int& line_space = HELPBOX_DEFAULT_LINE_HEIGHT, const int& line_height = HELPBOX_DEFAULT_LINE_HEIGHT,
const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT, const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT,
Font* font_text = NULL); Font* font_text = NULL);
void addLine( const std::string& icon, void addLine( const std::string& icon,
const std::string& text, const std::string& text,
const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH, const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH,
const int& line_space = HELPBOX_DEFAULT_LINE_HEIGHT, const int& line_height = HELPBOX_DEFAULT_LINE_HEIGHT,
const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT, const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT,
Font* font_text = NULL); Font* font_text = NULL);
void addLine( const char *icon, void addLine( const char *icon,
const char *text, const char *text,
const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH, const int& text_mode = CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH,
const int& line_space = HELPBOX_DEFAULT_LINE_HEIGHT, const int& line_height = HELPBOX_DEFAULT_LINE_HEIGHT,
const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT, const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT,
Font* font_text = NULL); Font* font_text = NULL);
///adds a separator as horizontal line, arg 'line_space' defines the space of full separator height, the separator line itself has a defined height of 2px and is centered within line space. ///adds a separator as horizontal line, arg 'line_height' defines the space of full separator height, the separator line itself has a defined height of 2px and is centered within line space.
///arg 'line_indent' defines begin of line from left border within body object. ///arg 'line_indent' defines begin of line from left border within body object.
///arg 'enable_gradient' enable/disable gradient, Note: default = true, but gradient is only effected, if global/theme gradient settings are enabled! ///arg 'enable_gradient' enable/disable gradient, Note: default = true, but gradient is only effected, if global/theme gradient settings are enabled!
void addSeparatorLine( const int& line_space = HELPBOX_DEFAULT_LINE_HEIGHT, void addSeparatorLine( const int& line_height = HELPBOX_DEFAULT_LINE_HEIGHT,
const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT); const int& line_indent = HELPBOX_DEFAULT_LINE_INDENT);
///adds a simple empty separator as horizontal space, arg 'line_space' defines the space of full separator height ///adds a simple empty separator as horizontal space, arg 'line_height' defines the space of full separator height
void addSeparator( const int& line_space = HELPBOX_DEFAULT_LINE_HEIGHT); void addSeparator( const int& line_height = HELPBOX_DEFAULT_LINE_HEIGHT);
void addPagebreak(); void addPagebreak();