CMenuWidget: rework cc modules implementation

- don't create header instance on every widget paint.
- remove parameters from hide(), not needed anymore
- add signal/slot OnBeforePaint(), OnAfterHide()
- try to fix infoclock handling
- add member ResetModules()
- allow separator to paint with gradient
This commit is contained in:
2015-11-18 19:35:48 +01:00
parent 523b273af8
commit 77518102f8
2 changed files with 98 additions and 55 deletions

View File

@@ -37,6 +37,7 @@
#include <driver/screen_max.h>
#include <gui/pluginlist.h>
#include <gui/widget/stringinput.h>
#include <gui/infoclock.h>
#include <driver/fade.h>
@@ -547,7 +548,7 @@ CMenuWidget::CMenuWidget()
preselected = -1;
details_line = NULL;
info_box = NULL;
show_details_line = true;
header = NULL;
nextShortcut = 1;
}
@@ -572,10 +573,10 @@ void CMenuWidget::Init(const std::string &Icon, const int mwidth, const mn_widge
mglobal = CMenuGlobal::getInstance(); //create CMenuGlobal instance only here
frameBuffer = CFrameBuffer::getInstance();
iconfile = Icon;
details_line = new CComponentsDetailLine();
show_details_line = true;
info_box = new CComponentsInfoBox();
details_line = NULL;
info_box = NULL;
header = NULL;
//handle select values
if(w_index > MN_WIDGET_ID_MAX){
//error
@@ -632,8 +633,26 @@ void CMenuWidget::move(int xoff, int yoff)
CMenuWidget::~CMenuWidget()
{
resetWidget(true);
delete details_line;
delete info_box;
ResetModules();
}
void CMenuWidget::ResetModules()
{
if (header){
header->hide();
delete header;
header = NULL;
}
if (details_line){
details_line->hide();
delete details_line;
details_line = NULL;
}
if (info_box){
info_box->kill();
delete info_box;
info_box = NULL;
}
}
void CMenuWidget::addItem(CMenuItem* menuItem, const bool defaultselected)
@@ -1039,6 +1058,10 @@ void CMenuWidget::hide()
if(savescreen && background)
restoreScreen();//FIXME
else {
if (header)
header->kill();
if (info_box)
info_box->kill();
frameBuffer->paintBackgroundBoxRel(x, y, full_width, full_height + fbutton_height);
//paintHint(-1);
}
@@ -1050,6 +1073,9 @@ void CMenuWidget::hide()
items[count]->init(-1, 0, 0, 0);
hint_painted = false;
washidden = true;
if (CInfoClock::getInstance()->isRun())
CInfoClock::getInstance()->enableInfoClock(!CInfoClock::getInstance()->isBlocked());
OnAfterHide();
}
void CMenuWidget::checkHints()
@@ -1193,14 +1219,28 @@ void CMenuWidget::initSelectable()
void CMenuWidget::paint()
{
OnBeforePaint();
if (header){
if ((bool)header->getCornerRadius() != (bool)g_settings.rounded_corners) //ensure reset if corner mode was changed
ResetModules();
}
if (CInfoClock::getInstance()->isRun())
CInfoClock::getInstance()->disableInfoClock();
calcSize();
CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8 /*, nameString.c_str()*/);
// paint head
CComponentsHeader header(x, y, width + sb_width, hheight, getName(), iconfile);
header.setShadowOnOff(CC_SHADOW_ON);
header.setOffset(10);
header.paint(CC_SAVE_SCREEN_NO);
if (header == NULL){
header = new CComponentsHeader(x, y, width + sb_width, hheight, getName(), iconfile);
header->enableShadow(CC_SHADOW_RIGHT);
header->setOffset(10);
}
header->setColorBody(COL_MENUHEAD_PLUS_0);
header->setColorShadow(COL_MENUCONTENTDARK_PLUS_0);
header->setCaptionColor(COL_MENUHEAD_TEXT);
header->enableColBodyGradient(g_settings.theme.menu_Head_gradient, COL_MENUCONTENT_PLUS_0);
header->paint(CC_SAVE_SCREEN_NO);
// paint body shadow
frameBuffer->paintBoxRel(x+SHADOW_OFFSET, y + hheight + SHADOW_OFFSET, width + sb_width, height - hheight + RADIUS_LARGE + (fbutton_count ? fbutton_height : 0), COL_MENUCONTENTDARK_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM);
@@ -1220,9 +1260,9 @@ void CMenuWidget::setMenuPos(const int& menu_width)
int scr_y = frameBuffer->getScreenY();
int scr_w = frameBuffer->getScreenWidth();
int scr_h = frameBuffer->getScreenHeight();
int real_h = full_height + fbutton_height + hint_height;
int x_old = x;
int y_old = y;
//configured positions
switch(g_settings.menu_pos)
{
@@ -1254,6 +1294,8 @@ void CMenuWidget::setMenuPos(const int& menu_width)
x = /*offx +*/ scr_x + scr_w - menu_width - 10;
break;
}
if (x_old != x || y_old != y)
ResetModules();
}
void CMenuWidget::paintItems()
@@ -1364,23 +1406,21 @@ void CMenuWidget::enableSaveScreen(bool enable)
void CMenuWidget::paintHint(int pos)
{
if (!g_settings.show_menu_hints)
if (!g_settings.show_menu_hints){
ResetModules(); //ensure clean up on changed setting
return;
}
if (pos < 0 && !hint_painted)
return;
info_box->enableGradient(g_settings.theme.menu_Hint_gradient != 0);
info_box->set2ndColor(COL_INFOBAR_SHADOW_PLUS_1); // COL_INFOBAR_SHADOW_PLUS_1 is default footer color
if (hint_painted) {
/* clear detailsline line */
if (details_line)
savescreen ? details_line->hide() : details_line->kill();
details_line->hide();
/* clear info box */
if ((info_box) && (pos < 0))
savescreen ? info_box->hide(true) : info_box->kill();
savescreen ? info_box->hide() : info_box->kill();
hint_painted = false;
}
if (pos < 0)
@@ -1390,7 +1430,7 @@ void CMenuWidget::paintHint(int pos)
if (!item->hintIcon && item->hint == NONEXISTANT_LOCALE && item->hintText.empty()) {
if (info_box) {
savescreen ? info_box->hide(false) : info_box->kill();
savescreen ? info_box->hide() : info_box->kill();
hint_painted = false;
}
return;
@@ -1413,35 +1453,38 @@ void CMenuWidget::paintHint(int pos)
int imarkh = iheight/2+1;
//init details line
if (details_line){
details_line->setXPos(xpos);
details_line->setYPos(ypos1a);
details_line->setYPosDown(ypos2a);
details_line->setHMarkTop(imarkh);
details_line->setHMarkDown(markh);
details_line->syncSysColors();
}
if (details_line == NULL)
details_line = new CComponentsDetailLine();
details_line->setXPos(xpos);
details_line->setYPos(ypos1a);
details_line->setYPosDown(ypos2a);
details_line->setHMarkTop(imarkh);
details_line->setHMarkDown(markh);
details_line->syncSysColors();
//init infobox
std::string str = item->hintText.empty() ? g_Locale->getText(item->hint) : item->hintText;
if (info_box){
info_box->setDimensionsAll(x, ypos2, iwidth, hint_height);
info_box->setFrameThickness(2);
info_box->removeLineBreaks(str);
info_box->setText(str, CTextBox::AUTO_WIDTH, g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT], COL_MENUCONTENT_TEXT);
info_box->setCorner(RADIUS_LARGE);
info_box->syncSysColors();
info_box->setColorBody(COL_MENUCONTENTDARK_PLUS_0);
info_box->setShadowOnOff(CC_SHADOW_ON);
info_box->setPicture(item->hintIcon ? item->hintIcon : "");
}
if (info_box == NULL)
info_box = new CComponentsInfoBox();
info_box->setDimensionsAll(x, ypos2, iwidth, hint_height);
info_box->setFrameThickness(2);
info_box->removeLineBreaks(str);
info_box->setText(str, CTextBox::AUTO_WIDTH, g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT], COL_MENUCONTENT_TEXT);
info_box->setCorner(RADIUS_LARGE);
info_box->setColorAll(COL_MENUCONTENT_PLUS_6, COL_MENUCONTENTDARK_PLUS_0, COL_MENUCONTENTDARK_PLUS_0);
info_box->enableShadow();
info_box->setPicture(item->hintIcon ? item->hintIcon : "");
info_box->enableColBodyGradient(g_settings.theme.menu_Hint_gradient, COL_INFOBAR_SHADOW_PLUS_1, g_settings.theme.menu_Hint_gradient_direction);// COL_INFOBAR_SHADOW_PLUS_1 is default footer color
//paint result
if (show_details_line)
details_line->paint(savescreen);
info_box->paint(savescreen);
if (details_line)
details_line->paint();
if (info_box)
info_box->paint(savescreen);
hint_painted = true;
hint_painted = info_box ? info_box->isPainted() : false;
}
void CMenuWidget::addKey(neutrino_msg_t key, CMenuTarget *menue, const std::string & action)
@@ -1564,7 +1607,7 @@ int CMenuOptionNumberChooser::exec(CMenuTarget*)
// give the observer a chance to modify the value
paint(true);
OnAfterChangeOption();
if (wantsRepaint)
res = menu_return::RETURN_REPAINT;
@@ -2254,8 +2297,8 @@ int CMenuSeparator::paint(bool selected)
frameBuffer->paintBoxRel(x,y, dx, height, item_bgcolor);
if ((type & LINE))
{
frameBuffer->paintHLineRel(x+10,dx-20,y+(height>>1), COL_MENUCONTENT_PLUS_3);
frameBuffer->paintHLineRel(x+10,dx-20,y+(height>>1)+1, COL_MENUCONTENT_PLUS_1);
int grad = g_settings.theme.menu_Separator_gradient_enable ? CC_COLGRAD_COL_DARK_LIGHT_DARK : CC_COLGRAD_OFF;
paintBoxRel(x+10, y+(height>>1), dx-20, 2, COL_MENUCONTENT_PLUS_3, 0, CORNER_NONE, grad, COL_MENUCONTENT_PLUS_0, CFrameBuffer::gradientHorizontal, CColorGradient::light);
}
if ((type & STRING))
{

View File

@@ -308,7 +308,7 @@ class CAbstractMenuOptionChooser : public CMenuItem
optionValue = NULL;
}
~CAbstractMenuOptionChooser(){}
sigc::signal<void> OnAfterChangeOption;
};
class CMenuOptionNumberChooser : public CAbstractMenuOptionChooser
@@ -444,7 +444,7 @@ class CMenuOptionChooser : public CAbstractMenuOptionChooser
int getWidth(void);
void setOptions(const struct keyval * const Options, const unsigned Number_Of_Options);
void setOptions(const struct keyval_ext * const Options, const unsigned Number_Of_Options);
sigc::signal<void> OnAfterChangeOption;
int paint(bool selected);
int exec(CMenuTarget* parent);
@@ -497,7 +497,7 @@ class CMenuGlobal
static CMenuGlobal* getInstance();
};
class CMenuWidget : public CMenuTarget
class CMenuWidget : public CMenuTarget, public CComponentsSignals
{
private:
mn_widget_id_t widget_index;
@@ -505,7 +505,7 @@ class CMenuWidget : public CMenuTarget
CComponentsDetailLine *details_line;
CComponentsInfoBox *info_box;
int hint_height;
bool show_details_line;
CComponentsHeader *header;
protected:
std::string nameString;
neutrino_locale_t name;
@@ -562,7 +562,7 @@ class CMenuWidget : public CMenuTarget
CMenuWidget(const std::string &Name, const std::string & Icon = "", const int mwidth = 30, const mn_widget_id_t &w_index = NO_WIDGET_ID);
CMenuWidget(const neutrino_locale_t Name, const std::string & Icon = "", const int mwidth = 30, const mn_widget_id_t &w_index = NO_WIDGET_ID);
~CMenuWidget();
void ResetModules();
virtual void addItem(CMenuItem* menuItem, const bool defaultselected = false);
enum
@@ -610,7 +610,7 @@ class CMenuWidget : public CMenuTarget
};
void addKey(neutrino_msg_t key, CMenuTarget *menue, const std::string &action);
void setFooter(const struct button_label *_fbutton_label, const int _fbutton_count, bool repaint = false);
void suppressDetailsLine(bool suppress = true){show_details_line = suppress ? false : true;};
void setNextShortcut(int sc) { nextShortcut = sc; };
int getNextShortcut() { return nextShortcut; };
};