gui/pluginlist: drop custom menu implementation

(but use the menu-hint as plugin-description)
This commit is contained in:
martii
2014-03-02 23:00:30 +01:00
committed by svenhoefer
parent eb206ae523
commit cf43a6f2a6
3 changed files with 58 additions and 351 deletions

View File

@@ -57,332 +57,80 @@
#include <driver/fade.h>
#include <zapit/client/zapittools.h>
#include <system/helpers.h>
#include "plugins.h"
/* for alexW images with old drivers:
* #define USE_VBI_INTERFACE 1
*/
#ifdef USE_VBI_INTERFACE
#define AVIA_VBI_START_VTXT 1
#define AVIA_VBI_STOP_VTXT 2
#endif
#include <daemonc/remotecontrol.h>
extern CPlugins * g_PluginList; /* neutrino.cpp */
extern CRemoteControl * g_RemoteControl; /* neutrino.cpp */
CPluginList::CPluginList(const neutrino_locale_t Name, const uint32_t listtype)
CPluginList::CPluginList(const neutrino_locale_t Title, const uint32_t listtype)
{
frameBuffer = CFrameBuffer::getInstance();
name = Name;
title = Title;
pluginlisttype = listtype;
selected = 0;
width = w_max( 500, 0 );
height = h_max( 526, 50 ); // 2*25 pixel frei
theight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight();
//
fheight1 = g_Font[SNeutrinoSettings::FONT_TYPE_GAMELIST_ITEMLARGE]->getHeight();
fheight2 = g_Font[SNeutrinoSettings::FONT_TYPE_GAMELIST_ITEMSMALL]->getHeight();
fheight = fheight1 + fheight2 + 2;
//
listmaxshow = (height-theight-0)/fheight;
height = theight+0+listmaxshow*fheight; // recalc height
x=getScreenStartX( width );
y=getScreenStartY( height );
liststart = 0;
width = w_max (40, 10);
selected = -1;
number = -1;
}
CPluginList::~CPluginList()
int CPluginList::run()
{
for(unsigned int count=0;count<pluginlist.size();count++)
{
delete pluginlist[count];
g_PluginList->startPlugin(number);
if (!g_PluginList->getScriptOutput().empty()) {
hide();
ShowMsg(LOCALE_PLUGINS_RESULT, g_PluginList->getScriptOutput(), CMessageBox::mbrBack, CMessageBox::mbBack, NEUTRINO_ICON_SHELL);
}
pluginlist.clear();
return menu_return::RETURN_REPAINT;
}
int CPluginList::exec(CMenuTarget* parent, const std::string & /*actionKey*/)
int CPluginList::exec(CMenuTarget* parent, const std::string &actionKey)
{
neutrino_msg_t msg;
neutrino_msg_data_t data;
int res = menu_return::RETURN_REPAINT;
if (parent)
{
parent->hide();
}
//scan4plugins here!
for(unsigned int count=0;count<pluginlist.size();count++)
{
delete pluginlist[count];
}
pluginlist.clear();
number = -1;
if (actionKey != "")
number = atoi(actionKey.c_str());
pluginitem* tmp = new pluginitem();
tmp->name = g_Locale->getText(LOCALE_MENU_BACK);
pluginlist.push_back(tmp);
for(unsigned int count=0;count < (unsigned int)g_PluginList->getNumberOfPlugins();count++)
{
if ((g_PluginList->getType(count) & pluginlisttype) && !g_PluginList->isHidden(count))
{
tmp = new pluginitem();
tmp->number = count;
tmp->name = g_PluginList->getName(count);
tmp->desc = g_PluginList->getDescription(count);
if (tmp->desc == "")
tmp->desc = "---";
pluginlist.push_back(tmp);
}
}
COSDFader fader(g_settings.menu_Content_alpha);
fader.StartFadeIn();
paint();
uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]);
bool loop=true;
while (loop)
{
g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );
if ( msg <= CRCInput::RC_MaxRC )
timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]);
if((msg == NeutrinoMessages::EVT_TIMER) && (data == fader.GetTimer())) {
if(fader.Fade()) {
loop = false;
}
}
else if ( ( msg == CRCInput::RC_timeout ) ||
( msg == (neutrino_msg_t)g_settings.key_channelList_cancel ) )
{
if(fader.StartFadeOut()) {
timeoutEnd = CRCInput::calcTimeoutEnd( 1 );
msg = 0;
} else
loop=false;
}
else if ( msg == (neutrino_msg_t)g_settings.key_channelList_pageup )
{
if ((int(selected)-int(listmaxshow))<0)
selected=0;
else
selected -= listmaxshow;
liststart = (selected/listmaxshow)*listmaxshow;
paintItems();
}
else if ( msg == (neutrino_msg_t)g_settings.key_channelList_pagedown )
{
selected+=listmaxshow;
if (selected>pluginlist.size()-1)
selected=pluginlist.size()-1;
liststart = (selected/listmaxshow)*listmaxshow;
paintItems();
}
else if ( msg == CRCInput::RC_up )
{
int prevselected=selected;
if(selected==0)
{
selected = pluginlist.size()-1;
}
else
selected--;
paintItem(prevselected - liststart);
unsigned int oldliststart = liststart;
liststart = (selected/listmaxshow)*listmaxshow;
if(oldliststart!=liststart)
{
paintItems();
}
else
{
paintItem(selected - liststart);
}
}
else if ( msg == CRCInput::RC_down )
{
int prevselected=selected;
selected = (selected+1)%pluginlist.size();
paintItem(prevselected - liststart);
unsigned int oldliststart = liststart;
liststart = (selected/listmaxshow)*listmaxshow;
if(oldliststart!=liststart)
{
paintItems();
}
else
{
paintItem(selected - liststart);
}
}
else if ( msg == CRCInput::RC_ok )
{
if(selected==0)
{
loop=false;
}
else
{//exec the plugin :))
if (pluginSelected() == close)
{
loop=false;
}
}
}
else if( (msg== CRCInput::RC_red) ||
(msg==CRCInput::RC_green) ||
(msg==CRCInput::RC_yellow) ||
(msg==CRCInput::RC_blue) ||
(CRCInput::isNumeric(msg)) )
{
g_RCInput->postMsg(msg, data);
loop=false;
}
else if ( msg == CRCInput::RC_setup )
{
loop = false;
res = menu_return::RETURN_EXIT_ALL;
}
else if ( CNeutrinoApp::getInstance()->handleMsg(msg, data) & messages_return::cancel_all )
{
loop = false;
res = menu_return::RETURN_EXIT_ALL;
}
}
hide();
fader.Stop();
return res;
}
void CPluginList::hide()
{
frameBuffer->paintBackgroundBoxRel(x,y, width+15,height);
}
void CPluginList::paintItem(int pos)
{
int ypos = (y+theight) + pos*fheight;
int itemheight = fheight;
fb_pixel_t color = COL_MENUCONTENT_TEXT;
fb_pixel_t bgcolor = COL_MENUCONTENT_PLUS_0;
if (liststart+pos==selected)
{
color = COL_MENUCONTENTSELECTED_TEXT;
bgcolor = COL_MENUCONTENTSELECTED_PLUS_0;
}
if(liststart+pos==0)
{ //back is half-height...
itemheight = (fheight / 2) + 3;
frameBuffer->paintBoxRel(x , ypos + itemheight , width , 15, COL_MENUCONTENT_PLUS_0);
frameBuffer->paintBoxRel(x + 10, ypos + itemheight + 5, width - 20, 1, COL_MENUCONTENT_PLUS_5);
frameBuffer->paintBoxRel(x + 10, ypos + itemheight + 6, width - 20, 1, COL_MENUCONTENT_PLUS_2);
}
else if(liststart==0)
{
ypos -= (fheight / 2) - 15;
//if(pos==(int)listmaxshow-1)
// frameBuffer->paintBoxRel(x,ypos+itemheight, width, (fheight / 2)-15, COL_MENUCONTENT_PLUS_0);
}
//frameBuffer->paintBoxRel(x, ypos, width, itemheight, bgcolor);
if(liststart+pos < pluginlist.size())
{
frameBuffer->paintBoxRel(x, ypos, width, itemheight, bgcolor, RADIUS_LARGE);
pluginitem* actplugin = pluginlist[liststart+pos];
g_Font[SNeutrinoSettings::FONT_TYPE_GAMELIST_ITEMLARGE]->RenderString(x+10, ypos+fheight1+3, width-20, actplugin->name, color, 0, true); // UTF-8
g_Font[SNeutrinoSettings::FONT_TYPE_GAMELIST_ITEMSMALL]->RenderString(x+20, ypos+fheight, width-20, actplugin->desc, color, 0, true); // UTF-8
}
}
void CPluginList::paintHead()
{
int h_width = width;
if (listmaxshow < pluginlist.size())
h_width += 15;
CComponentsHeaderLocalized header(x, y, h_width, theight, name);
if (number > -1)
return run();
const char *icon = "";
if (pluginlisttype == CPlugins::P_TYPE_GAME)
header.setIcon(NEUTRINO_ICON_GAMES);
icon = NEUTRINO_ICON_GAMES;
else
header.setIcon(NEUTRINO_ICON_SHELL);
icon = NEUTRINO_ICON_SHELL;
header.paint(CC_SAVE_SCREEN_NO);
}
CMenuWidget m(title, icon, width);
m.setSelected(selected);
m.addIntroItems();
void CPluginList::paint()
{
hide();
width = w_max( 500, 0 );
height = h_max( 526, 50 ); // 2*25 pixel frei
listmaxshow = (height-theight-0)/fheight;
if (pluginlist.size() < listmaxshow)
listmaxshow = pluginlist.size();
height = theight+0+listmaxshow*fheight; // recalc height
x=getScreenStartX( width );
y=getScreenStartY( height );
int nop = g_PluginList->getNumberOfPlugins();
liststart = (selected/listmaxshow)*listmaxshow;
int shortcut = 1;
paintHead();
paintItems();
}
void CPluginList::paintItems()
{
if(listmaxshow < pluginlist.size())
{
// Scrollbar
int nrOfPages = ((pluginlist.size()-1) / listmaxshow)+1;
int currPage = (liststart/listmaxshow) +1;
float blockHeight = (height-theight-4-RADIUS_LARGE)/nrOfPages;
frameBuffer->paintBoxRel(x, y+theight, width+15, height-theight, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM);
frameBuffer->paintBoxRel(x+width, y+theight, 15, height-theight-RADIUS_LARGE, COL_MENUCONTENT_PLUS_1);
frameBuffer->paintBoxRel(x+ width +2, y+theight+2+int((currPage-1)*blockHeight) , 11, int(blockHeight), COL_MENUCONTENT_PLUS_3);
} else
frameBuffer->paintBoxRel(x, y+theight, width, height-theight, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM);
for(unsigned int count=0;count<listmaxshow;count++)
{
paintItem(count);
for(int count = 0; count < nop; count++) {
if ((g_PluginList->getType(count) & pluginlisttype) && !g_PluginList->isHidden(count)) {
CMenuForwarder *f = new CMenuForwarder(std::string(g_PluginList->getName(count)), true, "", this, to_string(count).c_str(), CRCInput::convertDigitToKey(shortcut++));
//TODO: use hint-icons; header-icons are to small
f->setHint("", g_PluginList->getDescription(count));
m.addItem(f);
}
}
m.exec(NULL, "");
m.hide();
selected = m.getSelected();
return menu_return::RETURN_REPAINT;
}
CPluginList::result_ CPluginList::pluginSelected()
CPluginChooser::CPluginChooser(const neutrino_locale_t Name, const uint32_t listtype, std::string &selectedFile) : CPluginList(Name, listtype)
{
hide();
g_PluginList->startPlugin(pluginlist[selected]->number);
if (!g_PluginList->getScriptOutput().empty())
{
ShowMsg(LOCALE_PLUGINS_RESULT, g_PluginList->getScriptOutput(), CMessageBox::mbrBack,CMessageBox::mbBack,NEUTRINO_ICON_SHELL);
}
paint();
return resume;
selectedFilePtr = &selectedFile;
}
CPluginChooser::CPluginChooser(const neutrino_locale_t Name, const uint32_t listtype, char* pluginname)
: CPluginList(Name, listtype), selected_plugin(pluginname)
int CPluginChooser::run()
{
if (number > -1)
*selectedFilePtr = g_PluginList->getFileName(number);
return menu_return::RETURN_EXIT;
}
CPluginList::result_ CPluginChooser::pluginSelected()
{
strcpy(selected_plugin,g_PluginList->getFileName(pluginlist[selected]->number));
return CPluginList::close;
}

View File

@@ -43,71 +43,28 @@
class CPluginList : public CMenuTarget
{
public:
enum result_
{
close = 0,
resume = 1
} result;
private:
CFrameBuffer *frameBuffer;
struct pluginitem
{
int number;
std::string name; // UTF-8 encoded
std::string desc; // UTF-8 encoded
};
unsigned int liststart;
unsigned int listmaxshow;
int key;
neutrino_locale_t name;
neutrino_locale_t title;
uint32_t pluginlisttype;
int fheight; // Fonthoehe Channellist-Inhalt
int theight; // Fonthoehe Channellist-Titel
int fheight1,fheight2;
int width;
int height;
int x;
int y;
void paintItem(int pos);
void paintItems();
void paint();
void paintHead();
int width;
protected:
unsigned int selected;
std::vector<pluginitem *> pluginlist;
virtual CPluginList::result_ pluginSelected();
int selected;
int number;
public:
CPluginList(const neutrino_locale_t Name, const uint32_t listtype);
virtual ~CPluginList();
void hide();
CPluginList(const neutrino_locale_t Title, const uint32_t listtype);
int exec(CMenuTarget* parent, const std::string & actionKey);
virtual int run ();
};
class CPluginChooser : public CPluginList
{
private:
char* selected_plugin;
protected:
CPluginList::result_ pluginSelected();
std::string *selectedFilePtr;
public:
CPluginChooser(const neutrino_locale_t Name, const uint32_t listtype, char* pluginname);
CPluginChooser(const neutrino_locale_t Name, const uint32_t listtype, std::string &selectedFile);
int run ();
};
#endif

View File

@@ -65,6 +65,7 @@
#include <system/settings.h>
#include <system/fsmounter.h>
#include <system/helpers.h>
#include <global.h>
#include <neutrino.h>
@@ -1223,12 +1224,12 @@ int CTimerList::newTimer()
CStringInputSMS timerSettings_msg(LOCALE_TIMERLIST_MESSAGE, &timerNew_message, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-.,:!?/ ");
CMenuForwarder *m9 = new CMenuForwarder(LOCALE_TIMERLIST_MESSAGE, false, timerNew_message, &timerSettings_msg );
strcpy(timerNew.pluginName,"---");
std::string timerNew_pluginName("---");
CPluginChooser plugin_chooser(LOCALE_TIMERLIST_PLUGIN, CPlugins::P_TYPE_SCRIPT | CPlugins::P_TYPE_TOOL
#if ENABLE_LUA
| CPlugins::P_TYPE_LUA
#endif
, timerNew.pluginName);
, timerNew_pluginName);
CMenuForwarder *m10 = new CMenuForwarder(LOCALE_TIMERLIST_PLUGIN, false, timerNew.pluginName, &plugin_chooser);
@@ -1258,7 +1259,8 @@ int CTimerList::newTimer()
notifier2.changeNotify(NONEXISTANT_LOCALE, NULL);
int ret=timerSettings.exec(this,"");
strncpy(timerNew.message, timerNew_message.c_str(), sizeof(timerNew.message));
cstrncpy(timerNew.pluginName, timerNew_pluginName, sizeof(timerNew.pluginName));
cstrncpy(timerNew.message, timerNew_message, sizeof(timerNew.message));
// delete dynamic created objects
for (unsigned int count=0; count<toDelete.size(); count++)