diff options
-rw-r--r-- | displaymenu.c | 155 | ||||
-rw-r--r-- | displaymenu.h | 6 | ||||
-rw-r--r-- | displaytracks.c | 17 | ||||
-rw-r--r-- | displaytracks.h | 6 | ||||
-rw-r--r-- | menuitem.h | 5 |
5 files changed, 92 insertions, 97 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); diff --git a/displaymenu.h b/displaymenu.h index a90e2ce..e08b6f0 100644 --- a/displaymenu.h +++ b/displaymenu.h @@ -4,6 +4,8 @@ #include "nopacity.h" #include "menuitem.h" #include <vdr/thread.h> +#include <memory> +#include <vector> class cNopacityDisplayMenu : public cSkinDisplayMenu , cThread { private: @@ -15,15 +17,13 @@ private: int FrameTime; int FadeTime; bool initial; - bool initMenu; bool diskUsageDrawn; int lastDiskUsageState; int lastTimersState; bool timersDrawn; - int menuItemIndexLast; int currentNumItems; cList<cNopacityTimer> timers; - cList<cNopacityMenuItem> menuItems; + std::vector<std::unique_ptr<cNopacityMenuItem>> menuItems; int positionButtons[4]; cRect videoWindowRect; int currentFeed; diff --git a/displaytracks.c b/displaytracks.c index f403e26..536e85b 100644 --- a/displaytracks.c +++ b/displaytracks.c @@ -26,7 +26,7 @@ cNopacityDisplayTracks::~cNopacityDisplayTracks() { osd->DestroyPixmap(pixmapContainer); osd->DestroyPixmap(pixmapHeader); osd->DestroyPixmap(pixmapHeaderAudio); - menuItems.Clear(); + menuItems.clear(); delete osd; } @@ -118,6 +118,9 @@ void cNopacityDisplayTracks::DrawHeader(const char *Title) { void cNopacityDisplayTracks::SetItem(const char *Text, int Index, bool Current) { cNopacityMenuItem *item; item = new cNopacityTrackMenuItem(osd, imgCache, Text); + if ((int)menuItems.size() <= Index) + menuItems.resize(Index+4); + menuItems[Index].reset(item); item->SetCurrent(Current); item->SetFont(fontManager->trackText); item->SetGeometry(Index, menuItemHeight+4, 2, menuItemWidth, menuItemHeight, 4); @@ -125,18 +128,17 @@ void cNopacityDisplayTracks::SetItem(const char *Text, int Index, bool Current) item->CreatePixmapStatic(); if (config.GetValue("displayType") == dtGraphical) item->CreatePixmapForeground(); - menuItems.Add(item); item->Render(); } void cNopacityDisplayTracks::SetTrack(int Index, const char * const *Tracks) { cNopacityMenuItem *item; if (currentIndex >= 0) { - item = menuItems.Get(currentIndex); + item = menuItems[currentIndex].get(); item->SetCurrent(false); item->Render(); } - item = menuItems.Get(Index); + item = menuItems[Index].get(); item->SetCurrent(true); item->Render(); currentIndex = Index; @@ -183,8 +185,11 @@ void cNopacityDisplayTracks::Action(void) { pixmapContainer->SetAlpha(Alpha); pixmapHeader->SetAlpha(Alpha); pixmapHeaderAudio->SetAlpha(Alpha); - for (cNopacityMenuItem *item = menuItems.First(); Running() && item; item = menuItems.Next(item)) { - item->SetAlpha(Alpha); + for (auto i = menuItems.begin(); i != menuItems.end(); ++i) { + if (*i && Running()) { + cNopacityMenuItem *item = i->get(); + item->SetAlpha(Alpha); + } } cPixmap::Unlock(); if (Running()) diff --git a/displaytracks.h b/displaytracks.h index 05c5596..0442b9a 100644 --- a/displaytracks.h +++ b/displaytracks.h @@ -4,6 +4,8 @@ #include <vdr/skins.h> #include <vdr/thread.h> #include "menuitem.h" +#include <memory> +#include <vector> class cNopacityDisplayTracks : public cSkinDisplayTracks, cThread { private: @@ -22,7 +24,7 @@ private: cPixmap *pixmapHeader; cPixmap *pixmapHeaderAudio; cPixmap *pixmapIcon; - cList<cNopacityMenuItem> menuItems; + std::vector<std::unique_ptr<cNopacityMenuItem>> menuItems; virtual void Action(void); void SetItem(const char *Text, int Index, bool Current); void SetGeometry(void); @@ -37,4 +39,4 @@ public: }; -#endif //__NOPACITY_DISPLAYTRACKS_H
\ No newline at end of file +#endif //__NOPACITY_DISPLAYTRACKS_H @@ -5,7 +5,7 @@ #include <string> #include "imagecache.h" -class cNopacityMenuItem : public cListObject, public cThread { +class cNopacityMenuItem : public cThread { protected: cOsd *osd; cImageCache *imgCache; @@ -64,6 +64,9 @@ public: virtual void Render() = 0; }; +// avoid confusion between vdr swap() and std::swap() for std::unique_ptr<cNopacityMenuItem> +inline void swap(cNopacityMenuItem*& a, cNopacityMenuItem*& b) {std::swap(a,b);} + class cNopacityMainMenuItem : public cNopacityMenuItem { private: bool isSetup; |