* CHintBox / CHintBoxExt: better draw

- Correct calculation of box width in CHintBoxExt
- Text display in CHintBox and CHintBoxExt centered


git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@2058 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
micha-bbg
2012-01-14 05:35:53 +00:00
parent 2105867ec5
commit 2ddfd01562
5 changed files with 25 additions and 9 deletions

View File

@@ -80,7 +80,7 @@ DText::DText(const char *text)
void DText::init() void DText::init()
{ {
m_width = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(m_text, true); // UTF-8 m_width = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(m_text, true); // UTF-8
m_height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); m_height = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
} }

View File

@@ -60,6 +60,8 @@ void CHintBox::init(const char * const Caption, const char * const Text, const i
char * begin; char * begin;
char * pos; char * pos;
int nw; int nw;
int scrollWidth = 0;
int maxLineWidth = 0;
message = strdup(Text); message = strdup(Text);
@@ -68,6 +70,7 @@ void CHintBox::init(const char * const Caption, const char * const Text, const i
theight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); theight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight();
fheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); fheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
height = theight + fheight; height = theight + fheight;
textStartX = 0;
caption = Caption; caption = Caption;
@@ -98,9 +101,10 @@ void CHintBox::init(const char * const Caption, const char * const Text, const i
unsigned int additional_width; unsigned int additional_width;
if (entries_per_page < line.size()) if (entries_per_page < line.size())
additional_width = 20 + 15; scrollWidth = 15;
else else
additional_width = 20 + 0; scrollWidth = 0;
additional_width = 20 + scrollWidth;
if (Icon != NULL) if (Icon != NULL)
{ {
@@ -118,7 +122,9 @@ void CHintBox::init(const char * const Caption, const char * const Text, const i
for (std::vector<char *>::const_iterator it = line.begin(); it != line.end(); it++) for (std::vector<char *>::const_iterator it = line.begin(); it != line.end(); it++)
{ {
nw = additional_width + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(*it, true); // UTF-8 int w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(*it, true); // UTF-8
maxLineWidth = std::max(maxLineWidth, w);
nw = additional_width + w;
if (nw > width) if (nw > width)
width = nw; width = nw;
} }
@@ -126,6 +132,7 @@ void CHintBox::init(const char * const Caption, const char * const Text, const i
/* make sure we don't overflow the usable area */ /* make sure we don't overflow the usable area */
if (nw > (int)CFrameBuffer::getInstance()->getScreenWidth()) if (nw > (int)CFrameBuffer::getInstance()->getScreenWidth())
width = CFrameBuffer::getInstance()->getScreenWidth(); width = CFrameBuffer::getInstance()->getScreenWidth();
textStartX = (width - scrollWidth - maxLineWidth) / 2;
window = NULL; window = NULL;
} }
@@ -195,7 +202,7 @@ void CHintBox::refresh(void)
int ypos = theight + (fheight >> 1); int ypos = theight + (fheight >> 1);
for (std::vector<char *>::const_iterator it = line.begin() + (entries_per_page * current_page); ((it != line.end()) && (count > 0)); it++, count--) for (std::vector<char *>::const_iterator it = line.begin() + (entries_per_page * current_page); ((it != line.end()) && (count > 0)); it++, count--)
window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_MENU], 10, (ypos += fheight), width, *it, (CFBWindow::color_t)COL_MENUCONTENT, 0, true); // UTF-8 window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_MENU], textStartX, (ypos += fheight), width, *it, (CFBWindow::color_t)COL_MENUCONTENT, 0, true); // UTF-8
if (entries_per_page < line.size()) if (entries_per_page < line.size())
{ {

View File

@@ -51,6 +51,7 @@ class CHintBox
int width; int width;
int height; int height;
int textStartX;
int fheight; int fheight;
int theight; int theight;

View File

@@ -105,6 +105,9 @@ void CHintBoxExt::init(const neutrino_locale_t Caption, const int Width, const c
m_fheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); m_fheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight();
m_height = m_theight + m_fheight; m_height = m_theight + m_fheight;
m_maxEntriesPerPage = 0; m_maxEntriesPerPage = 0;
int maxLineWidth = 0;
int scrollWidth = 0;
textStartX = 0;
m_caption = Caption; m_caption = Caption;
@@ -126,6 +129,7 @@ void CHintBoxExt::init(const neutrino_locale_t Caption, const int Width, const c
if ((*item)->getType() == Drawable::DTYPE_PAGEBREAK) if ((*item)->getType() == Drawable::DTYPE_PAGEBREAK)
pagebreak = true; pagebreak = true;
} }
maxLineWidth = std::max(maxLineWidth, lineWidth);
if (lineWidth > maxWidth) if (lineWidth > maxWidth)
maxWidth = lineWidth; maxWidth = lineWidth;
m_height += maxHeight; m_height += maxHeight;
@@ -168,10 +172,12 @@ void CHintBoxExt::init(const neutrino_locale_t Caption, const int Width, const c
m_pages = page + 1; m_pages = page + 1;
unsigned int additional_width; unsigned int additional_width;
if (m_startEntryOfPage.size() > 1) if (has_scrollbar())
additional_width = 20 + 15; scrollWidth = 15;
else else
additional_width = 20 + 0; scrollWidth = 0;
additional_width = 30 + scrollWidth;
m_width += additional_width;
if (Icon != NULL) if (Icon != NULL)
{ {
@@ -185,6 +191,7 @@ void CHintBoxExt::init(const neutrino_locale_t Caption, const int Width, const c
if (nw > m_width) if (nw > m_width)
m_width = nw; m_width = nw;
textStartX = (m_width - scrollWidth - maxLineWidth) / 2;
m_window = NULL; m_window = NULL;
} }
@@ -258,7 +265,7 @@ void CHintBoxExt::refresh(bool toround)
it != m_lines.begin() + m_startEntryOfPage[m_currentPage+1] it != m_lines.begin() + m_startEntryOfPage[m_currentPage+1]
&& it != m_lines.end(); it++) && it != m_lines.end(); it++)
{ {
int xPos = 10; int xPos = textStartX;
int maxHeight = 0; int maxHeight = 0;
for (std::vector<Drawable*>::iterator d = it->begin();d!=it->end();d++) for (std::vector<Drawable*>::iterator d = it->begin();d!=it->end();d++)
{ {

View File

@@ -55,6 +55,7 @@ class CHintBoxExt
int m_width; int m_width;
int m_height; int m_height;
int textStartX;
int m_fheight; int m_fheight;
int m_theight; int m_theight;