neutrino: improve menu width calculation

calculate menu width in paint() instead of addItem()
this allows to cahnge the width of a menu later on dynamically

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@308 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
seife
2010-02-08 20:47:37 +00:00
parent d6180e4ab2
commit 292891db1f
2 changed files with 11 additions and 10 deletions

View File

@@ -105,13 +105,13 @@ void CMenuWidget::Init(const std::string & Icon, const int mwidth, const int /*m
frameBuffer = CFrameBuffer::getInstance(); frameBuffer = CFrameBuffer::getInstance();
iconfile = Icon; iconfile = Icon;
selected = -1; selected = -1;
needed_width = 0; /* is set in addItem() */ min_width = 0;
width = 0; /* is set in paint() */ width = 0; /* is set in paint() */
if (mwidth > 100) /* warn about abuse until we found all offenders... */ if (mwidth > 100) /* warn about abuse until we found all offenders... */
fprintf(stderr, "CMenuWidget::Init (%s) (%s) mwidth over 100%%: %d\n", nameString.c_str(), Icon.c_str(), mwidth); fprintf(stderr, "CMenuWidget::Init (%s) (%s) mwidth over 100%%: %d\n", nameString.c_str(), Icon.c_str(), mwidth);
else else
needed_width = frameBuffer->getScreenWidth() * mwidth / 100; min_width = frameBuffer->getScreenWidth() * mwidth / 100;
/* set the max height to 9/10 of usable screen height /* set the max height to 9/10 of usable screen height
debatable, if the callers need a possibility to set this */ debatable, if the callers need a possibility to set this */
@@ -144,11 +144,6 @@ void CMenuWidget::addItem(CMenuItem* menuItem, const bool defaultselected)
{ {
if (defaultselected) if (defaultselected)
selected = items.size(); selected = items.size();
int tmpw = menuItem->getWidth() + 10 + 10; /* 10 pixels to the left and right of the text */
if (tmpw > needed_width) {
//fprintf(stderr, "CMenuWidget::addItem: increase width from %d to %d '%s' offx: %d\n", needed_width, tmpw, menuItem->iconName.c_str(), offx);
needed_width = tmpw;
}
items.push_back(menuItem); items.push_back(menuItem);
} }
@@ -449,8 +444,14 @@ void CMenuWidget::paint()
CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8 /*, l_name*/); //FIXME menu name CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8 /*, l_name*/); //FIXME menu name
height=wanted_height; height = wanted_height;
width = needed_width; width = min_width;
for (unsigned int i= 0; i< items.size(); i++) {
int tmpw = items[i]->getWidth() + 10 + 10; /* 10 pixels to the left and right of the text */
if (tmpw > width)
width = tmpw;
}
if(height > ((int)frameBuffer->getScreenHeight() - 10)) if(height > ((int)frameBuffer->getScreenHeight() - 10))
height = frameBuffer->getScreenHeight() - 10; height = frameBuffer->getScreenHeight() - 10;

View File

@@ -331,7 +331,7 @@ class CMenuWidget : public CMenuTarget
std::vector<unsigned int> page_start; std::vector<unsigned int> page_start;
std::string iconfile; std::string iconfile;
int needed_width; int min_width;
int width; int width;
int height; int height;
int wanted_height; int wanted_height;