timerlist: use CListHelpers

remove duplicated code and use CListHelpers::UpDownKey().
Some variable types had to be changed to avoid typecasts, as
a result (int) casts to foo.size() had to be added :-)
This commit is contained in:
Stefan Seyfried
2016-01-16 18:18:50 +01:00
committed by svenhoefer
parent edf7d48e04
commit ed7eaafbcb
3 changed files with 19 additions and 52 deletions

View File

@@ -458,7 +458,7 @@ void CTimerList::updateEvents(void)
height = theight+listmaxshow*fheight*2+footerHeight; // recalc height height = theight+listmaxshow*fheight*2+footerHeight; // recalc height
} }
if (selected==timerlist.size() && !(timerlist.empty())) if (!timerlist.empty() && selected == (int)timerlist.size())
{ {
selected=timerlist.size()-1; selected=timerlist.size()-1;
liststart = (selected/listmaxshow)*listmaxshow; liststart = (selected/listmaxshow)*listmaxshow;
@@ -519,58 +519,22 @@ int CTimerList::show()
loop=false; loop=false;
} }
else if ((msg == CRCInput::RC_up || msg == (unsigned int)g_settings.key_pageup) && !(timerlist.empty())) else if (!timerlist.empty() &&
(msg == CRCInput::RC_up || (int)msg == g_settings.key_pageup ||
msg == CRCInput::RC_down || (int)msg == g_settings.key_pagedown))
{ {
int step = 0;
int prev_selected = selected; int prev_selected = selected;
int oldliststart = liststart;
step = (msg == (unsigned int)g_settings.key_pageup) ? listmaxshow : 1; // browse or step 1 selected = UpDownKey(timerlist, msg, listmaxshow, selected);
selected -= step; if (selected < 0) /* UpDownKey error */
if((prev_selected-step) < 0) // because of uint selected = prev_selected;
selected = timerlist.size() - 1; liststart = (selected / listmaxshow) * listmaxshow;
if (oldliststart != liststart)
paintItem(prev_selected - liststart);
unsigned int oldliststart = liststart;
liststart = (selected/listmaxshow)*listmaxshow;
if (oldliststart!=liststart)
{
paint(); paint();
} else {
else paintItem(prev_selected - liststart);
{
paintItem(selected - liststart); paintItem(selected - liststart);
} }
paintFoot();
}
else if ((msg == CRCInput::RC_down || msg == (unsigned int)g_settings.key_pagedown) && !(timerlist.empty()))
{
unsigned int step = 0;
int prev_selected = selected;
step = (msg == (unsigned int)g_settings.key_pagedown) ? listmaxshow : 1; // browse or step 1
selected += step;
if(selected >= timerlist.size())
{
if (((timerlist.size() / listmaxshow) + 1) * listmaxshow == timerlist.size() + listmaxshow) // last page has full entries
selected = 0;
else
selected = ((step == listmaxshow) && (selected < (((timerlist.size() / listmaxshow) + 1) * listmaxshow))) ? (timerlist.size() - 1) : 0;
}
paintItem(prev_selected - liststart);
unsigned int oldliststart = liststart;
liststart = (selected/listmaxshow)*listmaxshow;
if (oldliststart!=liststart)
{
paint();
}
else
{
paintItem(selected - liststart);
}
paintFoot(); paintFoot();
} }
else if ((msg == CRCInput::RC_right || msg == CRCInput::RC_ok || msg==CRCInput::RC_blue) && !(timerlist.empty())) else if ((msg == CRCInput::RC_right || msg == CRCInput::RC_ok || msg==CRCInput::RC_blue) && !(timerlist.empty()))
@@ -719,7 +683,7 @@ void CTimerList::paintItem(int pos)
//selected item //selected item
frameBuffer->paintBoxRel(x,ypos, real_width, 2*fheight, bgcolor, RADIUS_MID); frameBuffer->paintBoxRel(x,ypos, real_width, 2*fheight, bgcolor, RADIUS_MID);
if (liststart+pos<timerlist.size()) if (liststart + pos < (int)timerlist.size())
{ {
CTimerd::responseGetTimer & timer = timerlist[liststart+pos]; CTimerd::responseGetTimer & timer = timerlist[liststart+pos];
char zAlarmTime[25] = {0}; char zAlarmTime[25] = {0};

View File

@@ -36,6 +36,7 @@
#include <timerdclient/timerdtypes.h> #include <timerdclient/timerdtypes.h>
#include <gui/widget/menue.h> #include <gui/widget/menue.h>
#include <gui/widget/listhelpers.h>
#include <driver/framebuffer.h> #include <driver/framebuffer.h>
@@ -43,7 +44,7 @@
class CTimerdClient; class CTimerdClient;
class CTimerList : public CMenuTarget class CTimerList : public CMenuTarget, public CListHelpers
{ {
private: private:
CFrameBuffer *frameBuffer; CFrameBuffer *frameBuffer;
@@ -54,8 +55,8 @@ class CTimerList : public CMenuTarget
int fheight; // fontheight content int fheight; // fontheight content
int theight; // fontheight titel int theight; // fontheight titel
int footerHeight; int footerHeight;
unsigned int selected; int selected;
unsigned int liststart; int liststart;
unsigned int listmaxshow; unsigned int listmaxshow;
bool visible; bool visible;

View File

@@ -24,6 +24,7 @@
#include <global.h> #include <global.h>
#include <gui/bouquetlist.h> #include <gui/bouquetlist.h>
#include <libupnpclient/upnpclient.h> #include <libupnpclient/upnpclient.h>
#include <timerdclient/timerdtypes.h>
static int upDownKey(int size, neutrino_msg_t msg, int lines, int sel) static int upDownKey(int size, neutrino_msg_t msg, int lines, int sel)
{ {
@@ -83,3 +84,4 @@ updown_t(std::vector<CZapitBouquet*>);
updown_t(std::vector<CZapitChannel*>); updown_t(std::vector<CZapitChannel*>);
updown_t(std::vector<CChannelEvent>); updown_t(std::vector<CChannelEvent>);
updown_t(std::vector<CUPnPDevice>); updown_t(std::vector<CUPnPDevice>);
updown_t(std::vector<CTimerd::responseGetTimer>);