- menu: add possibility to add a footer to the menus; fix alignment of menus

add footer-keys to testmenu

  (some of this code is based on code by martii; thx)
This commit is contained in:
svenhoefer
2014-04-11 00:26:52 +02:00
parent 9dc59ec556
commit 4fba818cc2
3 changed files with 78 additions and 13 deletions

View File

@@ -655,6 +655,21 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey)
} }
return res; return res;
} }
else if (actionKey == "footer_key"){
neutrino_msg_t msg;
neutrino_msg_data_t data;
CHintBox * hintBox = new CHintBox(LOCALE_MESSAGEBOX_INFO, "Footer-Key pressed. Press EXIT to return");
hintBox->paint();
while (1)
{
g_RCInput->getMsg(&msg, &data, 100);
if (msg == CRCInput::RC_home)
break;
}
delete hintBox;
return res;
}
return showTestMenu(); return showTestMenu();
@@ -689,6 +704,16 @@ int CTestMenu::showTestMenu()
f_bi->setHint(NEUTRINO_ICON_HINT_IMAGEINFO, LOCALE_MENU_HINT_BUILDINFO); f_bi->setHint(NEUTRINO_ICON_HINT_IMAGEINFO, LOCALE_MENU_HINT_BUILDINFO);
w_test.addItem(f_bi); w_test.addItem(f_bi);
//footer buttons
static const struct button_label footerButtons[2] = {
{ NEUTRINO_ICON_BUTTON_RED, LOCALE_COLORCHOOSER_RED },
{ NEUTRINO_ICON_BUTTON_GREEN, LOCALE_COLORCHOOSER_GREEN }
};
w_test.setFooter(footerButtons, 2);
w_test.addKey(CRCInput::RC_red, this, "footer_key");
w_test.addKey(CRCInput::RC_green, this, "footer_key");
//exit //exit
return w_test.exec(NULL, "");; return w_test.exec(NULL, "");;
} }

View File

@@ -334,6 +334,7 @@ CMenuWidget::CMenuWidget()
from_wizard = false; from_wizard = false;
fade = true; fade = true;
sb_width = 0; sb_width = 0;
sb_height = 0;
savescreen = false; savescreen = false;
background = NULL; background = NULL;
preselected = -1; preselected = -1;
@@ -407,6 +408,9 @@ void CMenuWidget::Init(const std::string & Icon, const int mwidth, const mn_widg
has_hints = false; has_hints = false;
hint_painted = false; hint_painted = false;
hint_height = 0; hint_height = 0;
fbutton_count = 0;
fbutton_labels = NULL;
fbutton_height = 0;
} }
void CMenuWidget::move(int xoff, int yoff) void CMenuWidget::move(int xoff, int yoff)
@@ -869,7 +873,7 @@ void CMenuWidget::calcSize()
for (unsigned int i= 0; i< items.size(); i++) { for (unsigned int i= 0; i< items.size(); i++) {
int item_height=items[i]->getHeight(); int item_height=items[i]->getHeight();
heightCurrPage+=item_height; heightCurrPage+=item_height;
if(heightCurrPage > (height-hheight)) { if(heightCurrPage > (height-hheight-fbutton_height)) {
page_start.push_back(i); page_start.push_back(i);
total_pages++; total_pages++;
heightCurrPage=item_height; heightCurrPage=item_height;
@@ -901,18 +905,29 @@ void CMenuWidget::calcSize()
width = frameBuffer->getScreenWidth(); width = frameBuffer->getScreenWidth();
// shrink menu if less items // shrink menu if less items
if(hheight+itemHeightTotal < height) if (hheight + itemHeightTotal + fbutton_height < height)
height=hheight+itemHeightTotal; height = hheight + itemHeightTotal + fbutton_height;
//scrollbar width //scrollbar
sb_width=0; sb_width=0;
if(total_pages > 1) if(total_pages > 1)
sb_width=15; sb_width=15;
sb_height=itemHeightTotal;
full_width = /*ConnectLineBox_Width+*/width+sb_width+SHADOW_OFFSET; full_width = /*ConnectLineBox_Width+*/width+sb_width+SHADOW_OFFSET;
full_height = height+RADIUS_LARGE+SHADOW_OFFSET*2 /*+hint_height+INFO_BOX_Y_OFFSET*/; full_height = height+RADIUS_LARGE+SHADOW_OFFSET*2 /*+hint_height+INFO_BOX_Y_OFFSET*/;
/* + ConnectLineBox_Width for the hintbox connection line
* + center_offset for symmetry
* + 20 for setMenuPos calculates 10 pixels border left and right */
int center_offset = (g_settings.menu_pos == MENU_POS_CENTER) ? ConnectLineBox_Width : 0;
int max_possible = (int)frameBuffer->getScreenWidth() - ConnectLineBox_Width - center_offset - 20;
if (full_width > max_possible)
{
width = max_possible - sb_width - SHADOW_OFFSET;
full_width = max_possible + center_offset; /* symmetry in MENU_POS_CENTER case */
}
setMenuPos(width - sb_width); setMenuPos(width + sb_width);
} }
void CMenuWidget::paint() void CMenuWidget::paint()
@@ -929,11 +944,13 @@ void CMenuWidget::paint()
// paint body shadow // paint body shadow
frameBuffer->paintBoxRel(x+SHADOW_OFFSET, y + hheight + SHADOW_OFFSET, width + sb_width, height - hheight + RADIUS_LARGE, COL_MENUCONTENTDARK_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM); frameBuffer->paintBoxRel(x+SHADOW_OFFSET, y + hheight + SHADOW_OFFSET, width + sb_width, height - hheight + RADIUS_LARGE, COL_MENUCONTENTDARK_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM);
// paint body background // paint body background
frameBuffer->paintBoxRel(x ,y+hheight, width + sb_width, height-hheight + RADIUS_LARGE ,COL_MENUCONTENT_PLUS_0 ,RADIUS_LARGE, CORNER_BOTTOM); frameBuffer->paintBoxRel(x, y + hheight, width + sb_width, height - hheight + RADIUS_LARGE - fbutton_height, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, (fbutton_count ? 0 /*CORNER_NONE*/ : CORNER_BOTTOM));
item_start_y = y+hheight; item_start_y = y+hheight;
paintItems(); paintItems();
washidden = false; washidden = false;
if (fbutton_count)
::paintButtons(x, y + height + RADIUS_LARGE - fbutton_height, width + sb_width, fbutton_count, fbutton_labels, width, fbutton_height);
} }
void CMenuWidget::setMenuPos(const int& menu_width) void CMenuWidget::setMenuPos(const int& menu_width)
@@ -943,12 +960,14 @@ void CMenuWidget::setMenuPos(const int& menu_width)
int scr_w = frameBuffer->getScreenWidth(); int scr_w = frameBuffer->getScreenWidth();
int scr_h = frameBuffer->getScreenHeight(); int scr_h = frameBuffer->getScreenHeight();
int real_h = full_height + hint_height;
//configured positions //configured positions
switch(g_settings.menu_pos) switch(g_settings.menu_pos)
{ {
case MENU_POS_CENTER: case MENU_POS_CENTER:
x = offx + scr_x + ((scr_w - menu_width ) >> 1 ); x = offx + scr_x + ((scr_w - menu_width ) >> 1 );
y = offy + scr_y + ((scr_h - height - hint_height) >> 1 ); y = offy + scr_y + ((scr_h - real_h) >> 1 );
break; break;
case MENU_POS_TOP_LEFT: case MENU_POS_TOP_LEFT:
@@ -962,12 +981,12 @@ void CMenuWidget::setMenuPos(const int& menu_width)
break; break;
case MENU_POS_BOTTOM_LEFT: case MENU_POS_BOTTOM_LEFT:
y = offy + scr_y + scr_h - height - hint_height - 10; y = offy + scr_y + scr_h - real_h - 10;
x = offx + scr_x + 10; x = offx + scr_x + 10;
break; break;
case MENU_POS_BOTTOM_RIGHT: case MENU_POS_BOTTOM_RIGHT:
y = offy + scr_y + scr_h - height - hint_height - 10; y = offy + scr_y + scr_h - real_h - 10;
x = offx + scr_x + scr_w - menu_width - 10; x = offx + scr_x + scr_w - menu_width - 10;
break; break;
} }
@@ -987,12 +1006,11 @@ void CMenuWidget::paintItems()
// Scrollbar // Scrollbar
if(total_pages>1) if(total_pages>1)
{ {
int item_height=height-(item_start_y-y); frameBuffer->paintBoxRel(x+ width,item_start_y, sb_width, sb_height, COL_MENUCONTENT_PLUS_1, RADIUS_MIN);
frameBuffer->paintBoxRel(x+ width,item_start_y, 15, item_height, COL_MENUCONTENT_PLUS_1, RADIUS_MIN); frameBuffer->paintBoxRel(x+ width +2, item_start_y+ 2+ current_page*(sb_height-4)/total_pages, sb_width-4, (sb_height-4)/total_pages, COL_MENUCONTENT_PLUS_3, RADIUS_MIN);
frameBuffer->paintBoxRel(x+ width +2, item_start_y+ 2+ current_page*(item_height-4)/total_pages, 11, (item_height-4)/total_pages, COL_MENUCONTENT_PLUS_3, RADIUS_MIN);
/* background of menu items, paint every time because different items can have /* background of menu items, paint every time because different items can have
* different height and this might leave artifacts otherwise after changing pages */ * different height and this might leave artifacts otherwise after changing pages */
frameBuffer->paintBoxRel(x,item_start_y, width,item_height, COL_MENUCONTENT_PLUS_0); frameBuffer->paintBoxRel(x,item_start_y, width, sb_height, COL_MENUCONTENT_PLUS_0);
} }
int ypos=item_start_y; int ypos=item_start_y;
for (int count = 0; count < (int)items.size(); count++) for (int count = 0; count < (int)items.size(); count++)
@@ -1168,6 +1186,21 @@ void CMenuWidget::addKey(neutrino_msg_t key, CMenuTarget *menue, const std::stri
keyActionMap[key].action = action; keyActionMap[key].action = action;
} }
void CMenuWidget::setFooter(const struct button_label *_fbutton_labels, const int _fbutton_count, bool repaint)
{
fbutton_count = _fbutton_count;
fbutton_labels = _fbutton_labels;
fbutton_height = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight() + 6; // init min buttonbar height
int h = 0, w = 0;
for (int i = 0; i < fbutton_count; i++) {
frameBuffer->getIconSize(fbutton_labels[i].button, &w, &h);
fbutton_height = std::max(fbutton_height, h + 4);
}
if (repaint)
paint();
}
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
CMenuOptionNumberChooser::CMenuOptionNumberChooser( const neutrino_locale_t Name, CMenuOptionNumberChooser::CMenuOptionNumberChooser( const neutrino_locale_t Name,
int * const OptionValue, int * const OptionValue,

View File

@@ -39,6 +39,7 @@
#include <driver/framebuffer.h> #include <driver/framebuffer.h>
#include <driver/rcinput.h> #include <driver/rcinput.h>
#include <system/localize.h> #include <system/localize.h>
#include <gui/widget/buttons.h>
#include <gui/widget/icons.h> #include <gui/widget/icons.h>
#include <gui/color.h> #include <gui/color.h>
#include <gui/components/cc.h> #include <gui/components/cc.h>
@@ -652,12 +653,17 @@ class CMenuWidget : public CMenuTarget
int selected; int selected;
int iconOffset; int iconOffset;
int sb_width; int sb_width;
int sb_height;
fb_pixel_t *background; fb_pixel_t *background;
int full_width, full_height; int full_width, full_height;
bool savescreen; bool savescreen;
bool has_hints; // is any items has hints bool has_hints; // is any items has hints
bool hint_painted; // is hint painted bool hint_painted; // is hint painted
int fbutton_height;
int fbutton_count;
const struct button_label *fbutton_labels;
unsigned int item_start_y; unsigned int item_start_y;
unsigned int current_page; unsigned int current_page;
unsigned int total_pages; unsigned int total_pages;
@@ -719,6 +725,7 @@ class CMenuWidget : public CMenuTarget
MENU_POS_BOTTOM_RIGHT MENU_POS_BOTTOM_RIGHT
}; };
void addKey(neutrino_msg_t key, CMenuTarget *menue, const std::string &action); 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);
}; };
class CPINProtection class CPINProtection