summaryrefslogtreecommitdiff
path: root/displaymenu.c
diff options
context:
space:
mode:
authorSoeren Moch <smoch@web.de>2021-02-28 23:18:59 +0100
committerkamel5 <vdr.kamel5 (at) gmx (dot) net>2021-03-10 16:32:14 +0100
commitb249d2003fb6d02e8127b7744af2f2b09be8010e (patch)
tree756fae2cef5f8eb1752f3df9497e68370499f3c2 /displaymenu.c
parent88dd896bf6843e7738f5457e8d990a947871ea9a (diff)
downloadskin-nopacity-b249d2003fb6d02e8127b7744af2f2b09be8010e.tar.gz
skin-nopacity-b249d2003fb6d02e8127b7744af2f2b09be8010e.tar.bz2
Convert menuItems from cList to std::vector
This allows to access menu items in arbitrary order. This is required to learn remote control keys in the remote plugin. Also clear Tabs when creating menu to avoid uninitialized use. Signed-off-by: Soeren Moch <smoch@web.de>
Diffstat (limited to 'displaymenu.c')
-rw-r--r--displaymenu.c155
1 files changed, 70 insertions, 85 deletions
diff --git a/displaymenu.c b/displaymenu.c
index a97bc93..7056b75 100644
--- a/displaymenu.c
+++ b/displaymenu.c
@@ -17,12 +17,10 @@ cNopacityDisplayMenu::cNopacityDisplayMenu(cImageCache *imgCache) {
FadeTime = config.GetValue("menuFadeTime");
FrameTime = FadeTime / 10;
initial = true;
- initMenu = true;
diskUsageDrawn = false;
timersDrawn = false;
lastDiskUsageState = -1;
lastTimersState = -1;
- menuItemIndexLast = -1;
currentNumItems = 0;
detailView = NULL;
SetButtonPositions();
@@ -34,6 +32,7 @@ cNopacityDisplayMenu::cNopacityDisplayMenu(cImageCache *imgCache) {
menuView->DrawHeaderLogo();
menuView->DrawBorderDecoration();
currentFeed = 0;
+ SetTabs(0);
}
cNopacityDisplayMenu::~cNopacityDisplayMenu() {
@@ -41,7 +40,7 @@ cNopacityDisplayMenu::~cNopacityDisplayMenu() {
while (Active())
cCondWait::SleepMs(10);
delete menuView;
- menuItems.Clear();
+ menuItems.clear();
if (detailView) {
delete detailView;
}
@@ -211,9 +210,7 @@ void cNopacityDisplayMenu::Clear(void) {
delete detailView;
detailView = NULL;
}
- menuItemIndexLast = -1;
- initMenu = true;
- menuItems.Clear();
+ menuItems.clear();
}
void cNopacityDisplayMenu::SetMenuCategory(eMenuCategory MenuCategory) {
@@ -266,11 +263,7 @@ void cNopacityDisplayMenu::SetMenuCategory(eMenuCategory MenuCategory) {
void cNopacityDisplayMenu::SetTitle(const char *Title) {
//resetting menuitems if no call to clear
- if (!initMenu) {
- initMenu = true;
- menuItemIndexLast = -1;
- menuItems.Clear();
- }
+ menuItems.clear();
int left = 5;
menuView->DestroyHeaderIcon();
if (Title) {
@@ -369,9 +362,12 @@ bool cNopacityDisplayMenu::SetItemEvent(const cEvent *Event, int Index, bool Cur
if (!config.GetValue("narrowScheduleMenu"))
return false;
- if ((initMenu)&&(Index > menuItemIndexLast)) {
+ if ((int)menuItems.size() <= Index)
+ menuItems.resize(currentNumItems);
+ if (!menuItems[Index]) {
cNopacityMenuItem *item = new cNopacityScheduleMenuItem(osd, imgCache, Event, Channel, TimerMatch, Selectable, MenuCategory(), &videoWindowRect);
cPoint itemSize;
+ menuItems[Index].reset(item);
menuView->GetMenuItemSize(MenuCategory(), &itemSize);
item->SetFont(fontManager->menuItemSchedule);
item->SetFontSmall(fontManager->menuItemScheduleSmall);
@@ -389,9 +385,7 @@ bool cNopacityDisplayMenu::SetItemEvent(const cEvent *Event, int Index, bool Cur
}
item->CreatePixmapStatic();
item->CreatePixmapTextScroller(textWidth);
- menuItems.Add(item);
item->Render();
- menuItemIndexLast = Index;
if (initial) {
if (FadeTime) {
item->SetAlpha(0);
@@ -400,7 +394,7 @@ bool cNopacityDisplayMenu::SetItemEvent(const cEvent *Event, int Index, bool Cur
}
}
} else {
- cNopacityMenuItem *item = menuItems.Get(Index);
+ cNopacityMenuItem *item = menuItems[Index].get();
item->SetCurrent(Current);
item->Render();
}
@@ -410,9 +404,12 @@ bool cNopacityDisplayMenu::SetItemEvent(const cEvent *Event, int Index, bool Cur
bool cNopacityDisplayMenu::SetItemTimer(const cTimer *Timer, int Index, bool Current, bool Selectable) {
if (!config.GetValue("narrowTimerMenu"))
return false;
- if ((initMenu)&&(Index > menuItemIndexLast)) {
+ if ((int)menuItems.size() <= Index)
+ menuItems.resize(currentNumItems);
+ if (!menuItems[Index]) {
cNopacityMenuItem *item = new cNopacityTimerMenuItem(osd, imgCache, Timer, Selectable, &videoWindowRect);
cPoint itemSize;
+ menuItems[Index].reset(item);
menuView->GetMenuItemSize(MenuCategory(), &itemSize);
item->SetFont(fontManager->menuItemTimers);
item->SetFontSmall(fontManager->menuItemTimersSmall);
@@ -430,9 +427,7 @@ bool cNopacityDisplayMenu::SetItemTimer(const cTimer *Timer, int Index, bool Cur
}
item->CreatePixmapStatic();
item->CreatePixmapTextScroller(textWidth);
- menuItems.Add(item);
item->Render();
- menuItemIndexLast = Index;
if (initial) {
if (FadeTime) {
item->SetAlpha(0);
@@ -441,7 +436,7 @@ bool cNopacityDisplayMenu::SetItemTimer(const cTimer *Timer, int Index, bool Cur
}
}
} else {
- cNopacityMenuItem *item = menuItems.Get(Index);
+ cNopacityMenuItem *item = menuItems[Index].get();
item->SetCurrent(Current);
item->Render();
}
@@ -451,9 +446,12 @@ bool cNopacityDisplayMenu::SetItemTimer(const cTimer *Timer, int Index, bool Cur
bool cNopacityDisplayMenu::SetItemChannel(const cChannel *Channel, int Index, bool Current, bool Selectable, bool WithProvider) {
if (!config.GetValue("narrowChannelMenu"))
return false;
- if ((initMenu)&&(Index > menuItemIndexLast)) {
+ if ((int)menuItems.size() <= Index)
+ menuItems.resize(currentNumItems);
+ if (!menuItems[Index]) {
cNopacityMenuItem *item = new cNopacityChannelMenuItem(osd, imgCache, Channel, Selectable, &videoWindowRect);
cPoint itemSize;
+ menuItems[Index].reset(item);
menuView->GetMenuItemSize(MenuCategory(), &itemSize);
item->SetFont(fontManager->menuItemChannel);
item->SetFontSmall(fontManager->menuItemChannelSmall);
@@ -470,9 +468,7 @@ bool cNopacityDisplayMenu::SetItemChannel(const cChannel *Channel, int Index, bo
if (config.GetValue("displayType") == dtGraphical) {
item->CreatePixmapForeground();
}
- menuItems.Add(item);
item->Render();
- menuItemIndexLast = Index;
if (initial) {
if (FadeTime) {
item->SetAlpha(0);
@@ -481,7 +477,7 @@ bool cNopacityDisplayMenu::SetItemChannel(const cChannel *Channel, int Index, bo
}
}
} else {
- cNopacityMenuItem *item = menuItems.Get(Index);
+ cNopacityMenuItem *item = menuItems[Index].get();
item->SetCurrent(Current);
item->Render();
}
@@ -492,12 +488,15 @@ bool cNopacityDisplayMenu::SetItemRecording(const cRecording *Recording, int Ind
int Level, int Total, int New) {
if (!config.GetValue("narrowRecordingMenu"))
return false;
- if ((initMenu)&&(Index > menuItemIndexLast)) {
+ if ((int)menuItems.size() <= Index)
+ menuItems.resize(currentNumItems);
+ if (!menuItems[Index]) {
bool isFolder = false;
if (Total > 0)
isFolder = true;
cNopacityMenuItem *item = new cNopacityRecordingMenuItem(osd, imgCache, Recording, Selectable, isFolder, Level, Total, New, &videoWindowRect);
cPoint itemSize;
+ menuItems[Index].reset(item);
menuView->GetMenuItemSize(MenuCategory(), &itemSize);
item->SetFont(fontManager->menuItemRecordings);
item->SetFontSmall(fontManager->menuItemRecordingsSmall);
@@ -516,9 +515,7 @@ bool cNopacityDisplayMenu::SetItemRecording(const cRecording *Recording, int Ind
if (config.GetValue("displayType") == dtGraphical) {
item->CreatePixmapForeground();
}
- menuItems.Add(item);
item->Render();
- menuItemIndexLast = Index;
if (initial) {
if (FadeTime) {
item->SetAlpha(0);
@@ -527,7 +524,7 @@ bool cNopacityDisplayMenu::SetItemRecording(const cRecording *Recording, int Ind
}
}
} else {
- cNopacityMenuItem *item = menuItems.Get(Index);
+ cNopacityMenuItem *item = menuItems[Index].get();
item->SetCurrent(Current);
item->Render();
}
@@ -546,61 +543,47 @@ void cNopacityDisplayMenu::SetItem(const char *Text, int Index, bool Current, bo
tabItems[i+MaxTabs] = 0;
}
SplitItem(Text, strItems, tabItems);
- if (initMenu) {
- if (Index > menuItemIndexLast) {
- cNopacityMenuItem *item;
- cPoint itemSize;
- if (((MenuCategory() == mcMain)&&(config.GetValue("narrowMainMenu"))) || ((MenuCategory() == mcSetup)&&(config.GetValue("narrowSetupMenu")))){
- MainOrSetup = true;
- bool isSetup = (MenuCategory() == mcSetup)?true:false;
- item = new cNopacityMainMenuItem(osd, imgCache, Text, Selectable, isSetup);
- menuView->GetMenuItemSize(MenuCategory(), &itemSize);
- item->SetFont(fontManager->menuItemLarge);
- if (config.GetValue("useMenuIcons"))
- hasIcons = true;
- } else {
- item = new cNopacityDefaultMenuItem(osd, imgCache, Text, Selectable);
- menuView->GetMenuItemSize(mcUnknown, &itemSize);
- item->SetFont(fontManager->menuItemDefault);
- }
- int spaceTop = menuView->GetMenuTop(currentNumItems, itemSize.Y());
- item->SetGeometry(Index, spaceTop, menuView->GetMenuItemLeft(itemSize.X()), itemSize.X(), itemSize.Y(), geoManager->menuSpace);
- item->SetCurrent(Current);
- item->SetTabs(strItems, tabItems, MaxTabs);
- item->CreateText();
- int textWidth = item->CheckScrollable(hasIcons);
- item->CreatePixmapBackground();
- if (config.GetValue("displayType") == dtGraphical && MainOrSetup) {
- item->CreatePixmapForeground();
- }
- item->CreatePixmapStatic();
- if (textWidth > 0)
- item->CreatePixmapTextScroller(textWidth);
- menuItems.Add(item);
- item->Render();
- menuItemIndexLast = Index;
- if (initial) {
- if (FadeTime) {
- item->SetAlpha(0);
- item->SetAlphaIcon(0);
- item->SetAlphaText(0);
- }
- }
+ if ((int)menuItems.size() <= Index)
+ menuItems.resize(MaxItems());
+ menuItems[Index].reset();
+ if (*Text != '\0') {
+ cNopacityMenuItem *item;
+ cPoint itemSize;
+ if (((MenuCategory() == mcMain)&&(config.GetValue("narrowMainMenu"))) || ((MenuCategory() == mcSetup)&&(config.GetValue("narrowSetupMenu")))){
+ MainOrSetup = true;
+ bool isSetup = (MenuCategory() == mcSetup)?true:false;
+ item = new cNopacityMainMenuItem(osd, imgCache, Text, Selectable, isSetup);
+ menuItems[Index].reset(item);
+ menuView->GetMenuItemSize(MenuCategory(), &itemSize);
+ item->SetFont(fontManager->menuItemLarge);
+ if (config.GetValue("useMenuIcons"))
+ hasIcons = true;
} else {
- //adjust Current if item was added twice
- cNopacityMenuItem *item = menuItems.Get(Index);
- item->SetCurrent(Current);
- item->Render();
+ item = new cNopacityDefaultMenuItem(osd, imgCache, Text, Selectable);
+ menuItems[Index].reset(item);
+ menuView->GetMenuItemSize(mcUnknown, &itemSize);
+ item->SetFont(fontManager->menuItemDefault);
}
- } else {
- //redraw item when switching through menu
- cNopacityMenuItem *item = menuItems.Get(Index);
- if (item) {
- item->SetTabs(strItems, tabItems, MaxTabs);
- item->SetCurrent(Current);
- if ((MenuCategory() != mcMain) && (MenuCategory() != mcSetup))
- item->CheckScrollable(false);
- item->Render();
+ int spaceTop = menuView->GetMenuTop(currentNumItems, itemSize.Y());
+ item->SetGeometry(Index, spaceTop, menuView->GetMenuItemLeft(itemSize.X()), itemSize.X(), itemSize.Y(), geoManager->menuSpace);
+ item->SetCurrent(Current);
+ item->SetTabs(strItems, tabItems, MaxTabs);
+ item->CreateText();
+ int textWidth = item->CheckScrollable(hasIcons);
+ item->CreatePixmapBackground();
+ if (config.GetValue("displayType") == dtGraphical && MainOrSetup) {
+ item->CreatePixmapForeground();
+ }
+ item->CreatePixmapStatic();
+ if (textWidth > 0)
+ item->CreatePixmapTextScroller(textWidth);
+ item->Render();
+ if (initial) {
+ if (FadeTime) {
+ item->SetAlpha(0);
+ item->SetAlphaIcon(0);
+ item->SetAlphaText(0);
+ }
}
}
SetEditableWidth(menuView->GetEditableWidth());
@@ -713,7 +696,6 @@ void cNopacityDisplayMenu::Flush(void) {
if (FadeTime)
Start();
}
- initMenu = false;
initial = false;
osd->Flush();
cDevice::PrimaryDevice()->ScaleVideo(videoWindowRect);
@@ -727,10 +709,13 @@ void cNopacityDisplayMenu::Action(void) {
double t = std::min(double(Now - Start) / FadeTime, 1.0);
int Alpha = t * ALPHA_OPAQUE;
menuView->SetPixmapAlpha(Alpha);
- for (cNopacityMenuItem *item = menuItems.First(); Running() && item; item = menuItems.Next(item)) {
- item->SetAlpha(Alpha);
- item->SetAlphaIcon(Alpha);
- item->SetAlphaText(Alpha);
+ for (auto i = menuItems.begin(); i != menuItems.end(); ++i) {
+ if (*i && Running()) {
+ cNopacityMenuItem *item = i->get();
+ item->SetAlpha(Alpha);
+ item->SetAlphaIcon(Alpha);
+ item->SetAlphaText(Alpha);
+ }
}
for (cNopacityTimer *t = timers.First(); Running() && t; t = timers.Next(t))
t->SetAlpha(Alpha);