From 4d7700aecedf475038d57e10f45ab2dd4bcf806f Mon Sep 17 00:00:00 2001 From: louis Date: Thu, 12 Feb 2015 18:50:58 +0100 Subject: [PATCH] plugin interface --- Makefile | 5 +- config.c | 70 +++++++- config.h | 17 +- designer.c | 60 +++++++ designer.h | 2 + displayplugin.c | 94 ++++++++++- displayplugin.h | 22 ++- dtd/displayplugin.dtd | 24 +++ dtd/functions.dtd | 10 ++ libcore/pixmapcontainer.c | 7 + libcore/pixmapcontainer.h | 1 + libtemplate/template.c | 20 ++- libtemplate/template.h | 9 +- libtemplate/templatepixmap.c | 22 +++ libtemplate/templatepixmap.h | 4 + libtemplate/templateview.c | 153 ++++++++++++++++-- libtemplate/templateview.h | 22 ++- libtemplate/templateviewelement.h | 2 +- libtemplate/templateviewgrid.c | 29 ++++ libtemplate/templateviewgrid.h | 25 +++ libtemplate/templateviewlist.h | 4 - libtemplate/xmlparser.c | 41 +++++ libtemplate/xmlparser.h | 2 + services.h | 82 ++++++---- skindesigner.c | 30 +++- skins/blackhole/themes/default/theme.xml | 1 + .../xmlfiles/plug-tvguideng-detail.xml | 15 ++ .../xmlfiles/plug-tvguideng-root.xml | 72 +++++++++ views/displaypluginview.c | 83 ++++++++++ views/displaypluginview.h | 33 ++++ views/view.c | 129 +++++++++++++++ views/view.h | 27 ++++ views/viewgrid.c | 74 +++++++++ views/viewgrid.h | 26 +++ 34 files changed, 1133 insertions(+), 84 deletions(-) create mode 100644 dtd/displayplugin.dtd create mode 100644 libtemplate/templateviewgrid.c create mode 100644 libtemplate/templateviewgrid.h create mode 100644 skins/blackhole/xmlfiles/plug-tvguideng-detail.xml create mode 100644 skins/blackhole/xmlfiles/plug-tvguideng-root.xml create mode 100644 views/displaypluginview.c create mode 100644 views/displaypluginview.h create mode 100644 views/viewgrid.c create mode 100644 views/viewgrid.h diff --git a/Makefile b/Makefile index 04242b8..686a2d5 100644 --- a/Makefile +++ b/Makefile @@ -81,12 +81,14 @@ OBJS = $(PLUGIN).o \ libtemplate/templateview.o \ libtemplate/templateviewelement.o \ libtemplate/templateviewlist.o \ + libtemplate/templateviewgrid.o \ libtemplate/templatepixmap.o \ libtemplate/templateviewtab.o \ libtemplate/templatefunction.o \ libtemplate/templateloopfunction.o \ libtemplate/xmlparser.o \ views/view.o \ + views/viewgrid.o \ views/viewhelpers.o \ views/displaychannelview.o \ views/displaymenurootview.o \ @@ -100,7 +102,8 @@ OBJS = $(PLUGIN).o \ views/displayreplayview.o \ views/displayreplayonpauseview.o \ views/displayvolumeview.o \ - views/displayaudiotracksview.o + views/displayaudiotracksview.o \ + views/displaypluginview.o ### The main target: diff --git a/config.c b/config.c index 8b018f7..b667876 100644 --- a/config.c +++ b/config.c @@ -288,23 +288,77 @@ cString cDesignerConfig::GetSkinRessourcePath(void) { return cString::sprintf("%s%s", *skinPath, osdSkin.c_str()); } -void cDesignerConfig::AddPlugin(string name, map < int, string > &menus) { - plugins.insert(pair< string, map < int, string > >(name, menus)); +void cDesignerConfig::AddPluginMenus(string name, map< int, string > menus) { + pluginMenus.insert(pair< string, map < int, string > >(name, menus)); } -void cDesignerConfig::InitPluginIterator(void) { - plugIt = plugins.begin(); +void cDesignerConfig::AddPluginViews(string name, + map< int, string > views, + map< int, map > viewElements, + map< int, map > viewGrids) { + pluginViews.insert(pair< string, map < int, string > >(name, views)); + pluginViewElements.insert(pair< string, map< int, map > >(name, viewElements)); + pluginViewGrids.insert(pair< string, map< int, map > >(name, viewGrids)); +} + +void cDesignerConfig::InitPluginMenuIterator(void) { + plugMenuIt = pluginMenus.begin(); } map *cDesignerConfig::GetPluginTemplates(string &name) { - if (plugIt == plugins.end()) + if (plugMenuIt == pluginMenus.end()) return NULL; - name = plugIt->first; - map *templates = &plugIt->second; - plugIt++; + name = plugMenuIt->first; + map *templates = &plugMenuIt->second; + plugMenuIt++; return templates; } +void cDesignerConfig::InitPluginViewIterator(void) { + plugViewIt = pluginViews.begin(); +} + +map *cDesignerConfig::GetPluginViews(string &name) { + if (plugViewIt == pluginViews.end()) + return NULL; + name = plugViewIt->first; + map *views = &plugViewIt->second; + plugViewIt++; + return views; +} + +int cDesignerConfig::GetPluginViewElementID(string pluginName, string viewElementName, int viewID) { + map < string, map< int, map > >::iterator hit = pluginViewElements.find(pluginName); + if (hit == pluginViewElements.end()) + return -1; + map< int, map >::iterator hit2 = (hit->second).find(viewID); + if (hit2 == (hit->second).end()) + return -1; + + map viewElements = hit2->second; + for (map ::iterator it = viewElements.begin(); it != viewElements.end(); it++) { + if (!(it->second).compare(viewElementName)) + return it->first; + } + return -1; +} + +int cDesignerConfig::GetPluginViewGridID(string pluginName, string viewGridName, int viewID) { + map < string, map< int, map > >::iterator hit = pluginViewGrids.find(pluginName); + if (hit == pluginViewGrids.end()) + return -1; + map< int, map >::iterator hit2 = (hit->second).find(viewID); + if (hit2 == (hit->second).end()) + return -1; + + map viewGrids = hit2->second; + for (map ::iterator it = viewGrids.begin(); it != viewGrids.end(); it++) { + if (!(it->second).compare(viewGridName)) + return it->first; + } + return -1; +} + cString cDesignerConfig::CheckSlashAtEnd(std::string path) { try { if (!(path.at(path.size()-1) == '/')) diff --git a/config.h b/config.h index a10ad5f..a3613f3 100644 --- a/config.h +++ b/config.h @@ -28,8 +28,12 @@ private: string fontSml; string osdLanguage; cGlobals *tmplGlobals; - map < string, map < int, string > > plugins; - map < string, map < int, string > >::iterator plugIt; + map < string, map < int, string > > pluginMenus; + map < string, map < int, string > >::iterator plugMenuIt; + map < string, map < int, string > > pluginViews; + map < string, map < int, string > >::iterator plugViewIt; + map < string, map< int, map > > pluginViewElements; + map < string, map< int, map > > pluginViewGrids; map < string, cSkinSetup* > skinSetups; map < string, cSkinSetup* >::iterator setupIt; vector < pair > skinSetupParameters; @@ -67,9 +71,14 @@ public: void SetOsdLanguage(void) { osdLanguage = Setup.OSDLanguage; }; bool OsdLanguageChanged(void); cString GetSkinRessourcePath(void); - void AddPlugin(string name, map < int, string > &menus); - void InitPluginIterator(void); + void AddPluginMenus(string name, map< int, string > menus); + void AddPluginViews(string name, map< int, string > views, map< int, map > viewElements, map< int, map > viewGrids); + void InitPluginMenuIterator(void); map *GetPluginTemplates(string &name); + void InitPluginViewIterator(void); + map *GetPluginViews(string &name); + int GetPluginViewElementID(string pluginName, string viewElementName, int viewID); + int GetPluginViewGridID(string pluginName, string viewGridName, int viewID); cString skinPath; cString logoPath; cString epgImagePath; diff --git a/designer.c b/designer.c index c279650..45797d8 100644 --- a/designer.c +++ b/designer.c @@ -107,6 +107,22 @@ cSkinDisplayMessage *cSkinDesigner::DisplayMessage(void) { return displayMessage; } +cSkinDisplayPlugin *cSkinDesigner::DisplayPlugin(string pluginName, int viewID) { + currentMenu = NULL; + if (useBackupSkin) + return NULL; + Init(); + cSkinDisplayPlugin *displayPlugin = NULL; + map< string, map >::iterator hit = pluginTemplates.find(pluginName); + if (hit == pluginTemplates.end()) + return NULL; + map ::iterator hit2 = (hit->second).find(viewID); + if (hit2 == (hit->second).end()) + return NULL; + return new cSkinDisplayPlugin(hit2->second); +} + + void cSkinDesigner::Reload(void) { dsyslog("skindesigner: forcing full reload of templates"); if (cOsd::IsOpen()) { @@ -236,6 +252,13 @@ void cSkinDesigner::DeleteTemplates(void) { delete audiotracksTemplate; audiotracksTemplate = NULL; } + for (map< string, map >::iterator plugs = pluginTemplates.begin(); plugs !=pluginTemplates.end(); plugs++) { + map plugTpls = plugs->second; + for (map ::iterator tpl = plugTpls.begin(); tpl != plugTpls.end(); tpl++) { + delete tpl->second; + } + } + pluginTemplates.clear(); } bool cSkinDesigner::LoadTemplates(void) { @@ -316,6 +339,33 @@ bool cSkinDesigner::LoadTemplates(void) { } audiotracksTemplate->Translate(); + config.InitPluginViewIterator(); + map *plugViews = NULL; + string plugName; + while ( plugViews = config.GetPluginViews(plugName) ) { + for (map ::iterator v = plugViews->begin(); v != plugViews->end(); v++) { + stringstream templateName; + templateName << "plug-" << plugName << "-" << v->second.c_str(); + cTemplate *plgTemplate = new cTemplate(vtDisplayPlugin, plugName, v->first); + plgTemplate->SetGlobals(globals); + ok = plgTemplate->ReadFromXML(templateName.str()); + if (!ok) { + esyslog("skindesigner: error reading plugin %s template", plugName.c_str()); + DeleteTemplates(); + return false; + } + plgTemplate->Translate(); + map< string, map >::iterator hit = pluginTemplates.find(plugName); + if (hit == pluginTemplates.end()) { + map plugTemplates; + plugTemplates.insert(pair(v->first, plgTemplate)); + pluginTemplates.insert(pair >(plugName, plugTemplates)); + } else { + (hit->second).insert(pair(v->first, plgTemplate)); + } + } + } + dsyslog("skindesigner: templates successfully validated and parsed"); return true; } @@ -327,6 +377,11 @@ void cSkinDesigner::CacheTemplates(void) { replayTemplate->PreCache(); volumeTemplate->PreCache(); audiotracksTemplate->PreCache(); + for (map< string, map >::iterator plugs = pluginTemplates.begin(); plugs != pluginTemplates.end(); plugs++) { + for (map ::iterator plugTplts = plugs->second.begin(); plugTplts != plugs->second.end(); plugTplts++) { + (plugTplts->second)->PreCache(); + } + } dsyslog("skindesigner: templates cached"); fontManager->CacheFonts(channelTemplate); fontManager->CacheFonts(menuTemplate); @@ -344,6 +399,11 @@ void cSkinDesigner::CacheTemplates(void) { replayTemplate->CacheImages(); volumeTemplate->CacheImages(); audiotracksTemplate->CacheImages(); + for (map< string, map >::iterator plugs = pluginTemplates.begin(); plugs != pluginTemplates.end(); plugs++) { + for (map ::iterator plugTplts = plugs->second.begin(); plugTplts != plugs->second.end(); plugTplts++) { + (plugTplts->second)->CacheImages(); + } + } imgCache->Debug(false); } diff --git a/designer.h b/designer.h index 5c51ebd..20abcb6 100644 --- a/designer.h +++ b/designer.h @@ -26,6 +26,7 @@ private: cTemplate *replayTemplate; cTemplate *volumeTemplate; cTemplate *audiotracksTemplate; + map< string, map > pluginTemplates; cSDDisplayMenu *currentMenu; void Init(void); void ReloadCaches(void); @@ -42,6 +43,7 @@ public: virtual cSkinDisplayVolume *DisplayVolume(void); virtual cSkinDisplayTracks *DisplayTracks(const char *Title, int NumTracks, const char * const *Tracks); virtual cSkinDisplayMessage *DisplayMessage(void); + virtual cSkinDisplayPlugin *DisplayPlugin(string pluginName, int viewID); void ActivateBackupSkin(void) { useBackupSkin = true; }; void Reload(void); void ListAvailableFonts(void); diff --git a/displayplugin.c b/displayplugin.c index c8661b9..ad5965f 100644 --- a/displayplugin.c +++ b/displayplugin.c @@ -1,7 +1,97 @@ #include "displayplugin.h" -cDisplayPlugin::cDisplayPlugin(cTemplate *menuTemplate) { +cSkinDisplayPlugin::cSkinDisplayPlugin(cTemplate *pluginTemplate) { + if (!pluginTemplate) { + doOutput = false; + return; + } else { + doOutput = true; + } + initial = true; + pluginView = new cDisplayPluginView(pluginTemplate->GetRootView()); + if (!pluginView->createOsd()) { + doOutput = false; + return; + } } -cDisplayPlugin::~cDisplayPlugin() { +cSkinDisplayPlugin::~cSkinDisplayPlugin(void) { + if (pluginView) { + delete pluginView; + pluginView = NULL; + } +} + +void cSkinDisplayPlugin::SetViewElementIntTokens(map *intTokens) { + if (pluginView) + pluginView->SetIntTokens(intTokens); +} + +void cSkinDisplayPlugin::SetViewElementStringTokens(map *stringTokens) { + if (pluginView) + pluginView->SetStringTokens(stringTokens); +} + +void cSkinDisplayPlugin::SetViewElementLoopTokens(map > > *loopTokens) { + if (pluginView) + pluginView->SetLoopTokens(loopTokens); +} + +void cSkinDisplayPlugin::DisplayViewElement(int id) { + if (!doOutput) { + return; + } + pluginView->DisplayViewElement(id); +} + +void cSkinDisplayPlugin::InitGrids(int viewGridID) { + if (!doOutput) { + return; + } + pluginView->InitGrids(viewGridID); +} + +void cSkinDisplayPlugin::SetGrid(int viewGridID, long gridID, + double x, double y, double width, double height, + map *intTokens, map *stringTokens) { + if (!doOutput) { + return; + } + pluginView->SetGrid(viewGridID, gridID, x, y, width, height, intTokens, stringTokens); +} + +void cSkinDisplayPlugin::SetGridCurrent(int viewGridID, long gridID, bool current) { + if (!doOutput) { + return; + } + pluginView->SetGridCurrent(viewGridID, gridID, current); +} + +void cSkinDisplayPlugin::DeleteGrid(int viewGridID, long gridID) { + if (!doOutput) { + return; + } + pluginView->DeleteGrid(viewGridID, gridID); +} + +void cSkinDisplayPlugin::DisplayGrids(int viewGridID) { + if (!doOutput) { + return; + } + pluginView->DisplayGrids(viewGridID); +} + +void cSkinDisplayPlugin::ClearGrids(int viewGridID) { + if (!doOutput) { + return; + } + pluginView->ClearGrids(viewGridID); +} + +void cSkinDisplayPlugin::Flush(void) { + if (initial) { + pluginView->DoStart(); + initial = false; + } + pluginView->Flush(); } \ No newline at end of file diff --git a/displayplugin.h b/displayplugin.h index bad6759..6fef255 100644 --- a/displayplugin.h +++ b/displayplugin.h @@ -2,12 +2,28 @@ #define __DISPLAYPLUGIN_H #include "libtemplate/template.h" +#include "views/displaypluginview.h" -class cDisplayPlugin { +class cSkinDisplayPlugin { private: + bool doOutput; + bool initial; + cDisplayPluginView *pluginView; public: - cDisplayPlugin(cTemplate *pluginTemplate); - virtual ~cDisplayPlugin(); + cSkinDisplayPlugin(void) {}; + cSkinDisplayPlugin(cTemplate *pluginTemplate); + virtual ~cSkinDisplayPlugin(void); + virtual void DisplayViewElement(int id); + virtual void SetViewElementIntTokens(map *intTokens); + virtual void SetViewElementStringTokens(map *stringTokens); + virtual void SetViewElementLoopTokens(map > > *loopTokens); + virtual void InitGrids(int viewGridID); + virtual void SetGrid(int viewGridID, long gridID, double x, double y, double width, double height, map *intTokens, map *stringTokens); + virtual void SetGridCurrent(int viewGridID, long gridID, bool current); + virtual void DeleteGrid(int viewGridID, long gridID); + virtual void DisplayGrids(int viewGridID); + virtual void ClearGrids(int viewGridID); + virtual void Flush(void); }; #endif //__DISPLAYPLUGIN_H diff --git a/dtd/displayplugin.dtd b/dtd/displayplugin.dtd new file mode 100644 index 0000000..df18160 --- /dev/null +++ b/dtd/displayplugin.dtd @@ -0,0 +1,24 @@ + + + + + + + + + + +%functions; diff --git a/dtd/functions.dtd b/dtd/functions.dtd index 27ba561..9e474e4 100644 --- a/dtd/functions.dtd +++ b/dtd/functions.dtd @@ -27,6 +27,16 @@ debug (true|false) #IMPLIED > + + + SetLayer(Layer); } +void cPixmapContainer::SetViewPort(int num, const cRect &rect) { + cMutexLock MutexLock(&mutex); + if (!pixmaps[num]) + return; + pixmaps[num]->SetViewPort(rect); +} + int cPixmapContainer::Width(int num) { if (checkRunning && !Running()) return 0; diff --git a/libcore/pixmapcontainer.h b/libcore/pixmapcontainer.h index 3b3105a..8fe1dfe 100644 --- a/libcore/pixmapcontainer.h +++ b/libcore/pixmapcontainer.h @@ -42,6 +42,7 @@ protected: void SetAlpha(int num, int Alpha); void SetTransparency(int num, int Transparency); void SetLayer(int num, int Layer); + void SetViewPort(int num, const cRect &rect); int Width(int num); int Height(int num); int DrawportWidth(int num); diff --git a/libtemplate/template.c b/libtemplate/template.c index ef7d677..01a7b28 100644 --- a/libtemplate/template.c +++ b/libtemplate/template.c @@ -4,11 +4,11 @@ // --- cTemplate ------------------------------------------------------------- -cTemplate::cTemplate(eViewType viewType) { +cTemplate::cTemplate(eViewType viewType, string pluginName, int viewID) { globals = NULL; rootView = NULL; this->viewType = viewType; - CreateView(); + CreateView(pluginName, viewID); } cTemplate::~cTemplate() { @@ -21,8 +21,8 @@ cTemplate::~cTemplate() { /******************************************************************* * Public Functions *******************************************************************/ -bool cTemplate::ReadFromXML(void) { - std::string xmlFile; +bool cTemplate::ReadFromXML(string xmlfile) { + string xmlFile; switch (viewType) { case vtDisplayChannel: xmlFile = "displaychannel.xml"; @@ -42,6 +42,9 @@ bool cTemplate::ReadFromXML(void) { case vtDisplayAudioTracks: xmlFile = "displayaudiotracks.xml"; break; + case vtDisplayPlugin: + xmlFile = xmlfile; + break; default: return false; } @@ -56,7 +59,7 @@ bool cTemplate::ReadFromXML(void) { //read additional plugin templates bool ok = true; if (viewType == vtDisplayMenu) { - config.InitPluginIterator(); + config.InitPluginMenuIterator(); map *plugTemplates = NULL; string plugName; while ( plugTemplates = config.GetPluginTemplates(plugName) ) { @@ -119,7 +122,7 @@ void cTemplate::Debug(void) { * Private Functions *******************************************************************/ -void cTemplate::CreateView(void) { +void cTemplate::CreateView(string pluginName, int viewID) { switch (viewType) { case vtDisplayChannel: rootView = new cTemplateViewChannel(); @@ -138,7 +141,10 @@ void cTemplate::CreateView(void) { break; case vtDisplayMessage: rootView = new cTemplateViewMessage(); - break; + break; + case vtDisplayPlugin: + rootView = new cTemplateViewPlugin(pluginName, viewID); + break; default: esyslog("skindesigner: unknown view %d", viewType); } diff --git a/libtemplate/template.h b/libtemplate/template.h index 2c1cfb2..79a824b 100644 --- a/libtemplate/template.h +++ b/libtemplate/template.h @@ -26,7 +26,8 @@ enum eViewType { vtDisplayReplay, vtDisplayVolume, vtDisplayAudioTracks, - vtDisplayMessage + vtDisplayMessage, + vtDisplayPlugin }; class cTemplate { @@ -37,13 +38,13 @@ private: protected: cGlobals *globals; cTemplateView *rootView; - void CreateView(void); + void CreateView(string pluginName, int viewID); void GetUsedFonts(cTemplateView *view, vector< pair > &usedFonts); void CacheImages(cTemplateView *view); public: - cTemplate(eViewType viewType); + cTemplate(eViewType viewType, string pluginName = "", int viewID = -1); virtual ~cTemplate(void); - bool ReadFromXML(void); + bool ReadFromXML(string xmlfile = ""); void SetGlobals(cGlobals *globals); cTemplateView *GetRootView(void) { return rootView; }; void Translate(void); diff --git a/libtemplate/templatepixmap.c b/libtemplate/templatepixmap.c index a1d032b..40e35a3 100644 --- a/libtemplate/templatepixmap.c +++ b/libtemplate/templatepixmap.c @@ -53,6 +53,28 @@ void cTemplatePixmap::SetY(int y) { parameters->SetYManually(y); } +void cTemplatePixmap::SetWidthPercent(double width) { + int absWidth = containerWidth * width; + cString pWidth = cString::sprintf("%d", absWidth); + parameters->SetWidthManually(*pWidth); +} + +void cTemplatePixmap::SetHeightPercent(double height) { + int absHeight = containerHeight * height; + cString pHeight = cString::sprintf("%d", absHeight); + parameters->SetHeightManually(*pHeight); +} + +void cTemplatePixmap::SetXPercent(double x) { + int absX = containerX + containerWidth * x; + parameters->SetXManually(absX); +} + +void cTemplatePixmap::SetYPercent(double y) { + int absY = containerY + containerHeight * y; + parameters->SetYManually(absY); +} + void cTemplatePixmap::ClearDynamicParameters(void) { parameters->ClearDynamicParameters(); } diff --git a/libtemplate/templatepixmap.h b/libtemplate/templatepixmap.h index 6cf3bd5..17bf7d3 100644 --- a/libtemplate/templatepixmap.h +++ b/libtemplate/templatepixmap.h @@ -47,6 +47,10 @@ public: void SetHeight(int height); void SetX(int x); void SetY(int y); + void SetWidthPercent(double width); + void SetHeightPercent(double height); + void SetXPercent(double x); + void SetYPercent(double y); void SetContainer(int x, int y, int w, int h); void SetGlobals(cGlobals *globals) { this->globals = globals; }; void AddFunction(string name, vector > ¶ms); diff --git a/libtemplate/templateview.c b/libtemplate/templateview.c index 4b1376a..753b242 100644 --- a/libtemplate/templateview.c +++ b/libtemplate/templateview.c @@ -1,3 +1,4 @@ +#include "../config.h" #include "templateview.h" // --- cTemplateView ------------------------------------------------------------- @@ -22,6 +23,10 @@ cTemplateView::~cTemplateView() { delete it->second; } + for (map < int, cTemplateViewGrid* >::iterator it = viewGrids.begin(); it != viewGrids.end(); it++) { + delete it->second; + } + for (vector < cTemplateViewTab* >::iterator it = viewTabs.begin(); it != viewTabs.end(); it++) { delete *it; } @@ -61,8 +66,9 @@ void cTemplateView::SetContainer(int x, int y, int width, int height) { cTemplateViewElement *cTemplateView::GetViewElement(eViewElement ve) { map < eViewElement, cTemplateViewElement* >::iterator hit = viewElements.find(ve); - if (hit == viewElements.end()) + if (hit == viewElements.end()) { return NULL; + } return hit->second; } @@ -78,6 +84,14 @@ cTemplateViewElement *cTemplateView::GetNextViewElement(void) { return viewElement; } +cTemplateViewGrid *cTemplateView::GetViewGrid(int gridID) { + map < int, cTemplateViewGrid* >::iterator hit = viewGrids.find(gridID); + if (hit == viewGrids.end()) { + return NULL; + } + return hit->second; +} + cTemplateViewList *cTemplateView::GetViewList(eViewList vl) { map < eViewList, cTemplateViewList* >::iterator hit = viewLists.find(vl); if (hit == viewLists.end()) @@ -224,7 +238,14 @@ bool cTemplateView::ValidViewList(const char *viewList) { set::iterator hit = viewListsAllowed.find(viewList); if (hit == viewListsAllowed.end()) return false; - return true; + return true; +} + +bool cTemplateView::ValidViewGrid(const char *viewGrid) { + set::iterator hit = viewGridsAllowed.find(viewGrid); + if (hit == viewGridsAllowed.end()) + return false; + return true; } bool cTemplateView::ValidFunction(const char *func) { @@ -428,6 +449,14 @@ void cTemplateView::PreCache(bool isSubview) { pixOffset += viewElement->GetNumPixmaps(); } + //Cache ViewGrids + for (map < int, cTemplateViewGrid* >::iterator it = viewGrids.begin(); it != viewGrids.end(); it++) { + cTemplateViewGrid *viewGrid = it->second; + viewGrid->SetGlobals(globals); + viewGrid->SetContainer(0, 0, osdWidth, osdHeight); + viewGrid->CalculateParameters(); + viewGrid->CalculatePixmapParameters(); + } //Cache ViewLists for (map < eViewList, cTemplateViewList* >::iterator it = viewLists.begin(); it != viewLists.end(); it++) { @@ -486,6 +515,12 @@ void cTemplateView::Debug(void) { viewList->Debug(); } + for (map < int, cTemplateViewGrid* >::iterator it = viewGrids.begin(); it != viewGrids.end(); it++) { + esyslog("skindesigner: ++++++++ ViewGrid %d:", it->first); + cTemplateViewGrid *viewGrid = it->second; + viewGrid->Debug(); + } + for (vector::iterator tab = viewTabs.begin(); tab != viewTabs.end(); tab++) { esyslog("skindesigner: ++++++++ ViewTab"); (*tab)->Debug(); @@ -516,6 +551,7 @@ void cTemplateView::SetFunctionDefinitions(void) { attributes.insert("debug"); attributes.insert("delay"); attributes.insert("fadetime"); + attributes.insert("name"); funcsAllowed.insert(pair< string, set >(name, attributes)); name = "area"; @@ -1095,7 +1131,6 @@ void cTemplateViewMenu::SetViewElements(void) { } void cTemplateViewMenu::SetViewLists(void) { - viewListsAllowed.insert("timerlist"); viewListsAllowed.insert("menuitems"); } @@ -1210,9 +1245,6 @@ string cTemplateViewMenu::GetViewElementName(eViewElement ve) { string cTemplateViewMenu::GetViewListName(eViewList vl) { string name; switch (vl) { - case vlTimerList: - name = "Timer List"; - break; case vlMenuItem: name = "Menu Item"; break; @@ -1335,9 +1367,7 @@ void cTemplateViewMenu::AddPixmap(string sViewElement, cTemplatePixmap *pix, vec void cTemplateViewMenu::AddViewList(string sViewList, cTemplateViewList *viewList) { eViewList vl = vlUndefined; - if (!sViewList.compare("timerlist")) { - vl = vlTimerList; - } else if (!sViewList.compare("menuitems")) { + if (!sViewList.compare("menuitems")) { vl = vlMenuItem; } @@ -1797,3 +1827,108 @@ void cTemplateViewAudioTracks::AddViewList(string sViewList, cTemplateViewList * viewList->SetGlobals(globals); viewLists.insert(pair< eViewList, cTemplateViewList*>(vl, viewList)); } + +/************************************************************************************ +* cTemplateViewPlugin +************************************************************************************/ + +cTemplateViewPlugin::cTemplateViewPlugin(string pluginName, int viewID) { + this->pluginName = pluginName; + this->viewID = viewID; + viewName = "displayplugin"; + //definition of allowed parameters for class itself + set attributes; + attributes.insert("x"); + attributes.insert("y"); + attributes.insert("width"); + attributes.insert("height"); + attributes.insert("fadetime"); + attributes.insert("scaletvx"); + attributes.insert("scaletvy"); + attributes.insert("scaletvwidth"); + attributes.insert("scaletvheight"); + funcsAllowed.insert(pair< string, set >(viewName, attributes)); + + attributes.clear(); + attributes.insert("x"); + attributes.insert("y"); + attributes.insert("width"); + attributes.insert("height"); + attributes.insert("name"); + funcsAllowed.insert(pair< string, set >("grid", attributes)); + + viewElementsAllowed.insert("viewelement"); + viewGridsAllowed.insert("grid"); +} + +cTemplateViewPlugin::~cTemplateViewPlugin() { +} + +void cTemplateViewPlugin::AddPixmap(string sViewElement, cTemplatePixmap *pix, vector > &viewElementattributes) { + eViewElement ve = veUndefined; + string viewElementName = ""; + bool found = false; + for (vector >::iterator it = viewElementattributes.begin(); it != viewElementattributes.end(); it++) { + if (!(it->first).compare("name")) { + viewElementName = it->second; + found = true; + break; + } + } + if (!found) { + esyslog("skindesigner: no name defined for plugin %s viewelement", pluginName.c_str()); + } + + int viewElementID = config.GetPluginViewElementID(pluginName, viewElementName, viewID); + + if (viewElementID == -1) { + esyslog("skindesigner: %s: unknown ViewElement in displayplugin: %s", pluginName.c_str(), viewElementName.c_str()); + return; + } + + pix->SetGlobals(globals); + + ve = (eViewElement)viewElementID; + map < eViewElement, cTemplateViewElement* >::iterator hit = viewElements.find(ve); + if (hit == viewElements.end()) { + cTemplateViewElement *viewElement = new cTemplateViewElement(); + viewElement->SetParameters(viewElementattributes); + viewElement->AddPixmap(pix); + viewElements.insert(pair< eViewElement, cTemplateViewElement*>(ve, viewElement)); + } else { + (hit->second)->AddPixmap(pix); + } +} + +void cTemplateViewPlugin::AddPixmapGrid(cTemplatePixmap *pix, vector > &gridAttributes) { + string gridName = ""; + bool found = false; + for (vector >::iterator it = gridAttributes.begin(); it != gridAttributes.end(); it++) { + if (!(it->first).compare("name")) { + gridName = it->second; + found = true; + break; + } + } + if (!found) { + esyslog("skindesigner: no name defined for plugin %s grid", pluginName.c_str()); + } + int gridID = config.GetPluginViewGridID(pluginName, gridName, viewID); + + if (gridID == -1) { + esyslog("skindesigner: %s: unknown Grid in displayplugin: %s", pluginName.c_str(), gridName.c_str()); + return; + } + + pix->SetGlobals(globals); + + map < int, cTemplateViewGrid* >::iterator hit = viewGrids.find(gridID); + if (hit == viewGrids.end()) { + cTemplateViewGrid *viewGrid = new cTemplateViewGrid(); + viewGrid->SetParameters(gridAttributes); + viewGrid->AddPixmap(pix); + viewGrids.insert(pair< int, cTemplateViewGrid*>(gridID, viewGrid)); + } else { + (hit->second)->AddPixmap(pix); + } +} diff --git a/libtemplate/templateview.h b/libtemplate/templateview.h index 1cd4289..7e0d43e 100644 --- a/libtemplate/templateview.h +++ b/libtemplate/templateview.h @@ -13,6 +13,7 @@ #include "templateviewelement.h" #include "templateviewlist.h" +#include "templateviewgrid.h" #include "templatepixmap.h" #include "templateviewtab.h" #include "templatefunction.h" @@ -50,6 +51,7 @@ protected: //basic view data structures map < eViewElement, cTemplateViewElement* > viewElements; map < eViewList, cTemplateViewList* > viewLists; + map < int, cTemplateViewGrid* > viewGrids; map < eSubView, cTemplateView* > subViews; vector< cTemplateViewTab* > viewTabs; map < string, map< int, cTemplateView*> > pluginViews; @@ -62,6 +64,7 @@ protected: set subViewsAllowed; set viewElementsAllowed; set viewListsAllowed; + set viewGridsAllowed; map < string, set < string > > funcsAllowed; void SetFunctionDefinitions(void); public: @@ -73,6 +76,7 @@ public: virtual void AddSubView(string sSubView, cTemplateView *subView) {}; virtual void AddPluginView(string plugName, int templNo, cTemplateView *plugView) {}; virtual void AddPixmap(string sViewElement, cTemplatePixmap *pix, vector > &viewElementattributes) {}; + virtual void AddPixmapGrid(cTemplatePixmap *pix, vector > &gridAttributes) {}; virtual void AddViewList(string sViewList, cTemplateViewList *viewList) {}; virtual void AddViewTab(cTemplateViewTab *viewTab) {}; //Setter Functions @@ -83,6 +87,8 @@ public: cTemplateViewElement *GetViewElement(eViewElement ve); void InitViewElementIterator(void); cTemplateViewElement *GetNextViewElement(void); + //access view grids + cTemplateViewGrid *GetViewGrid(int gridID); //access list elements cTemplateViewList *GetViewList(eViewList vl); void InitViewListIterator(void); @@ -110,7 +116,8 @@ public: //Checks for parsing template XML files bool ValidSubView(const char *subView); bool ValidViewElement(const char *viewElement); - bool ValidViewList(const char *viewList); + bool ValidViewList(const char *viewList); + bool ValidViewGrid(const char *viewGrid); bool ValidFunction(const char *func); bool ValidAttribute(const char *func, const char *att); //Caching @@ -204,4 +211,17 @@ public: void AddViewList(string sViewList, cTemplateViewList *viewList); }; +// --- cTemplateViewAudioTracks ------------------------------------------------------------- + +class cTemplateViewPlugin : public cTemplateView { +private: + string pluginName; + int viewID; +public: + cTemplateViewPlugin(string pluginName, int viewID); + virtual ~cTemplateViewPlugin(void); + void AddPixmap(string viewElement, cTemplatePixmap *pix, vector > &viewElementattributes); + void AddPixmapGrid(cTemplatePixmap *pix, vector > &gridAttributes); +}; + #endif //__TEMPLATEVIEW_H diff --git a/libtemplate/templateviewelement.h b/libtemplate/templateviewelement.h index 744c87a..ebddcd2 100644 --- a/libtemplate/templateviewelement.h +++ b/libtemplate/templateviewelement.h @@ -87,7 +87,7 @@ public: virtual ~cTemplateViewElement(void); void SetParameters(vector > ¶ms); bool CalculateParameters(void); - bool CalculatePixmapParameters(void); + virtual bool CalculatePixmapParameters(void); bool CalculatePixmapParametersList(int orientation, int numElements); int GetNumericParameter(eParamType type); void AddPixmap(cTemplatePixmap *pix) { viewPixmaps.push_back(pix); }; diff --git a/libtemplate/templateviewgrid.c b/libtemplate/templateviewgrid.c new file mode 100644 index 0000000..dc4af63 --- /dev/null +++ b/libtemplate/templateviewgrid.c @@ -0,0 +1,29 @@ +#include "templateviewgrid.h" +#include "../config.h" +#include "../libcore/helpers.h" + +cTemplateViewGrid::cTemplateViewGrid(void) : cTemplateViewElement() { +} + +cTemplateViewGrid::~cTemplateViewGrid(void) { +} + +bool cTemplateViewGrid::CalculatePixmapParameters(void) { + bool paramsValid = true; + int gridX = parameters->GetNumericParameter(ptX); + int gridY = parameters->GetNumericParameter(ptY); + int gridWidth = parameters->GetNumericParameter(ptWidth); + int gridHeight = parameters->GetNumericParameter(ptHeight); + + for (vector::iterator pix = viewPixmaps.begin(); pix != viewPixmaps.end(); pix++) { + (*pix)->SetContainer(gridX, gridY, gridWidth, gridHeight); + (*pix)->SetGlobals(globals); + paramsValid = paramsValid && (*pix)->CalculateParameters(); + } + return paramsValid; +} + +void cTemplateViewGrid::Debug(void) { + esyslog("skindesigner: --- Grid: "); + cTemplateViewElement::Debug(); +} \ No newline at end of file diff --git a/libtemplate/templateviewgrid.h b/libtemplate/templateviewgrid.h new file mode 100644 index 0000000..6b5c34a --- /dev/null +++ b/libtemplate/templateviewgrid.h @@ -0,0 +1,25 @@ +#ifndef __TEMPLATEVIEWGRID_H +#define __TEMPLATEVIEWGRID_H + +#include +#include +#include +#include +#include + +#include "templateviewelement.h" + +using namespace std; + +// --- cTemplateViewGrid ------------------------------------------------------------- + +class cTemplateViewGrid : public cTemplateViewElement { +private: +public: + cTemplateViewGrid(void); + ~cTemplateViewGrid(void); + bool CalculatePixmapParameters(void); + void Debug(void); +}; + +#endif //__TEMPLATEVIEWGRID_H \ No newline at end of file diff --git a/libtemplate/templateviewlist.h b/libtemplate/templateviewlist.h index b124a7c..5806745 100644 --- a/libtemplate/templateviewlist.h +++ b/libtemplate/templateviewlist.h @@ -19,10 +19,6 @@ using namespace std; enum eViewList { vlUndefined, - //DisplayChannel ViewLists - vlDvbDeviceInfoList, - //DisplayMenu ViewLists - vlTimerList, vlMenuItem }; diff --git a/libtemplate/xmlparser.c b/libtemplate/xmlparser.c index 0162780..e086ba4 100644 --- a/libtemplate/xmlparser.c +++ b/libtemplate/xmlparser.c @@ -195,6 +195,11 @@ bool cXmlParser::ParseView(void) { ParseViewElement(node->name, node->xmlChildrenNode, attribs); } else if (view->ValidViewList((const char*)node->name)) { ParseViewList(node); + } else if (view->ValidViewGrid((const char*)node->name)) { + xmlAttrPtr attr = node->properties; + vector > attribs; + ParseAttributes(attr, node, attribs); + ParseGrid(node->xmlChildrenNode, attribs); } else { return false; } @@ -844,6 +849,42 @@ void cXmlParser::ParseViewTab(xmlNodePtr parentNode, cTemplateView *subView) { subView->AddViewTab(viewTab); } +void cXmlParser::ParseGrid(xmlNodePtr node, vector > &attributes) { + if (!node) + return; + + if (!view) + return; + + while (node != NULL) { + + if (node->type != XML_ELEMENT_NODE) { + node = node->next; + continue; + } + + if (xmlStrcmp(node->name, (const xmlChar *) "area") && xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { + esyslog("skindesigner: invalid tag \"%s\"", node->name); + node = node->next; + continue; + } + + xmlAttrPtr attr = node->properties; + vector > attribs; + ParseAttributes(attr, node, attribs); + + cTemplatePixmap *pix = new cTemplatePixmap(); + if (!xmlStrcmp(node->name, (const xmlChar *) "areascroll")) { + pix->SetScrolling(); + } + pix->SetParameters(attribs); + ParseFunctionCalls(node->xmlChildrenNode, pix); + view->AddPixmapGrid(pix, attributes); + + node = node->next; + } +} + void cXmlParser::ParseFunctionCalls(xmlNodePtr node, cTemplatePixmap *pix) { if (!node) return; diff --git a/libtemplate/xmlparser.h b/libtemplate/xmlparser.h index 20f6763..8698196 100644 --- a/libtemplate/xmlparser.h +++ b/libtemplate/xmlparser.h @@ -15,6 +15,7 @@ #include "templateview.h" #include "templateviewlist.h" +#include "templateviewgrid.h" #include "templateviewtab.h" #include "../libcore/skinsetup.h" @@ -43,6 +44,7 @@ private: void ParseViewElement(const xmlChar * viewElement, xmlNodePtr node, vector > &attributes, cTemplateView *subView = NULL); void ParseViewList(xmlNodePtr parentNode, cTemplateView *subView = NULL); void ParseViewTab(xmlNodePtr parentNode, cTemplateView *subView); + void ParseGrid(xmlNodePtr node, vector > &attributes); void ParseFunctionCalls(xmlNodePtr node, cTemplatePixmap *pix); void ParseLoopFunctionCalls(xmlNodePtr node, cTemplateLoopFunction *loopFunc); bool ParseAttributes(xmlAttrPtr attr, xmlNodePtr node, vector > &attribs); diff --git a/services.h b/services.h index 203e715..ea2372b 100644 --- a/services.h +++ b/services.h @@ -13,55 +13,67 @@ using namespace std; // Data structure for service "RegisterPlugin" class RegisterPlugin { public: - RegisterPlugin(void) { - name = ""; - }; - void SetMenu(int key, string templateName) { - menus.insert(pair(key, templateName)); - } + RegisterPlugin(void) { + name = ""; + }; + void SetMenu(int key, string templateName) { + menus.insert(pair(key, templateName)); + } + void SetView(int key, string templateName) { + views.insert(pair(key, templateName)); + } + void SetViewElement(int view, int viewElement, string name) { + map< int, map >::iterator hit = viewElements.find(view); + if (hit == viewElements.end()) { + map vE; + vE.insert(pair(viewElement, name)); + viewElements.insert(pair >(view, vE)); + } else { + (hit->second).insert(pair(viewElement, name)); + } + } + void SetViewGrid(int view, int viewGrid, string name) { + map< int, map >::iterator hit = viewGrids.find(view); + if (hit == viewGrids.end()) { + map vG; + vG.insert(pair(viewGrid, name)); + viewGrids.insert(pair >(view, vG)); + } else { + (hit->second).insert(pair(viewGrid, name)); + } + } // in - string name; //name of plugin - map< int, string > menus; //menus as key -> templatename hashmap + string name; //name of plugin + map< int, string > menus; //menus as key -> templatename hashmap + map< int, string> views; //standalone views as key -> templatename hashmap + map< int, map > viewElements; //viewelements as key -> (viewelement, viewelementname) hashmap + map< int, map > viewGrids; //viewgrids as key -> (viewgrid, viewgridname) hashmap //out }; // Data structure for service "GetDisplayMenu" class GetDisplayMenu { public: - GetDisplayMenu(void) { - displayMenu = NULL; - }; + GetDisplayMenu(void) { + displayMenu = NULL; + }; // in //out - cSDDisplayMenu *displayMenu; + cSDDisplayMenu *displayMenu; }; -// Data structure for service "RegisterStandalonePlugin" -/* -class RegisterStandalonePlugin { -public: - RegisterStandalonePlugin(void) { - name = ""; - rootView = ""; - }; - void SetMenu(int key, string templateName) { - menus.insert(pair(key, templateName)); - } -// in - string name; //name of plugin - string rootView; //name of plugin - map< int, string > menus; //menus as key -> templatename hashmap -//out -}; -*/ // Data structure for service "GetDisplayPlugin" class GetDisplayPlugin { public: - GetDisplayPlugin(void) { - displayPlugin = NULL; - }; + GetDisplayPlugin(void) { + pluginName = ""; + viewID = -1; + displayPlugin = NULL; + }; // in + string pluginName; + int viewID; //out - cDisplayPlugin *displayPlugin; + cSkinDisplayPlugin *displayPlugin; }; -#endif //__SKINDESIGNERSERVICES_H \ No newline at end of file +#endif //__SKINDESIGNERSERVICES_H diff --git a/skindesigner.c b/skindesigner.c index b641cd8..dff54a7 100644 --- a/skindesigner.c +++ b/skindesigner.c @@ -162,13 +162,17 @@ bool cPluginSkinDesigner::Service(const char *Id, void *Data) { return false; if (strcmp(Id, "RegisterPlugin") == 0) { - RegisterPlugin* call = (RegisterPlugin*) Data; - if (call->menus.size() < 1) { - esyslog("skindesigner: error - plugin without menus registered"); + RegisterPlugin *call = (RegisterPlugin*) Data; + if (call->menus.size() < 1 && call->views.size() < 1) { + esyslog("skindesigner: error - plugin without menus or views registered"); return false; } - config.AddPlugin(call->name, call->menus); - dsyslog("skindesigner: plugin %s has registered %ld templates", call->name.c_str(), call->menus.size()); + config.AddPluginMenus(call->name, call->menus); + config.AddPluginViews(call->name, call->views, call->viewElements, call->viewGrids); + if (call->menus.size() > 0) + dsyslog("skindesigner: plugin %s has registered %ld menus", call->name.c_str(), call->menus.size()); + if (call->views.size() > 0) + dsyslog("skindesigner: plugin %s has registered %ld views", call->name.c_str(), call->views.size()); return true; } else if (strcmp(Id, "GetDisplayMenu") == 0) { GetDisplayMenu* call = (GetDisplayMenu*) Data; @@ -184,6 +188,22 @@ bool cPluginSkinDesigner::Service(const char *Id, void *Data) { } } return false; + } else if (strcmp(Id, "GetDisplayPlugin") == 0) { + GetDisplayPlugin* call = (GetDisplayPlugin*) Data; + if (call->pluginName.size() == 0 || call->viewID < 0) + return false; + cSkin *current = Skins.Current(); + for (vector::iterator skin = skins.begin(); skin != skins.end(); skin++) { + if (*skin == current) { + cSkinDisplayPlugin *displayPlugin = (*skin)->DisplayPlugin(call->pluginName, call->viewID); + if (displayPlugin) { + call->displayPlugin = displayPlugin; + return true; + } else + return false; + } + } + return false; } return false; diff --git a/skins/blackhole/themes/default/theme.xml b/skins/blackhole/themes/default/theme.xml index 753336b..4eb66a9 100644 --- a/skins/blackhole/themes/default/theme.xml +++ b/skins/blackhole/themes/default/theme.xml @@ -12,6 +12,7 @@ FFE2DA00 FF007FE2 FFFFFFFF + FF000000 FF999999 55FF0000 99000000 diff --git a/skins/blackhole/xmlfiles/plug-tvguideng-detail.xml b/skins/blackhole/xmlfiles/plug-tvguideng-detail.xml new file mode 100644 index 0000000..f7a0aab --- /dev/null +++ b/skins/blackhole/xmlfiles/plug-tvguideng-detail.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/skins/blackhole/xmlfiles/plug-tvguideng-root.xml b/skins/blackhole/xmlfiles/plug-tvguideng-root.xml new file mode 100644 index 0000000..342af31 --- /dev/null +++ b/skins/blackhole/xmlfiles/plug-tvguideng-root.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/views/displaypluginview.c b/views/displaypluginview.c new file mode 100644 index 0000000..89ff94c --- /dev/null +++ b/views/displaypluginview.c @@ -0,0 +1,83 @@ +#define __STL_CONFIG_H +#include "displaypluginview.h" + +cDisplayPluginView::cDisplayPluginView(cTemplateView *tmplView) : cView(tmplView) { + intTokens = NULL; + stringTokens = NULL; + loopTokens = NULL; + DeleteOsdOnExit(); + SetFadeTime(tmplView->GetNumericParameter(ptFadeTime)); +} + +cDisplayPluginView::~cDisplayPluginView() { + CancelSave(); + FadeOut(); +} + +bool cDisplayPluginView::createOsd(void) { + cRect osdSize = tmplView->GetOsdSize(); + bool ok = CreateOsd(cOsd::OsdLeft() + osdSize.X(), + cOsd::OsdTop() + osdSize.Y(), + osdSize.Width(), + osdSize.Height()); + return ok; +} + +void cDisplayPluginView::DisplayViewElement(int id) { + if (!intTokens || !stringTokens || !loopTokens) + return; + DrawViewElement((eViewElement)id, stringTokens, intTokens, loopTokens); +} + +void cDisplayPluginView::InitGrids(int viewGridID) { + map< int, cViewGrid* >::iterator hit = viewGrids.find(viewGridID); + if (hit != viewGrids.end()) { + delete hit->second; + viewGrids.erase(hit); + } + cTemplateViewGrid *tmplGrid = tmplView->GetViewGrid(viewGridID); + cViewGrid *grid = new cViewGrid(tmplGrid); + viewGrids.insert(pair< int, cViewGrid* >(viewGridID, grid)); +} + +void cDisplayPluginView::SetGrid(int viewGridID, long gridID, + double x, double y, double width, double height, + map *intTokens, map *stringTokens) { + map< int, cViewGrid* >::iterator hit = viewGrids.find(viewGridID); + if (hit != viewGrids.end()) + (hit->second)->SetGrid(gridID, x, y, width, height, intTokens, stringTokens); +} + +void cDisplayPluginView::SetGridCurrent(int viewGridID, long gridID, bool current) { + map< int, cViewGrid* >::iterator hit = viewGrids.find(viewGridID); + if (hit != viewGrids.end()) + (hit->second)->SetCurrent(gridID, current); +} + +void cDisplayPluginView::DeleteGrid(int viewGridID, long gridID) { + map< int, cViewGrid* >::iterator hit = viewGrids.find(viewGridID); + if (hit == viewGrids.end()) + return; + (hit->second)->Delete(gridID); +} + +void cDisplayPluginView::DisplayGrids(int viewGridID) { + map< int, cViewGrid* >::iterator hit = viewGrids.find(viewGridID); + if (hit == viewGrids.end()) + return; + (hit->second)->Render(); +} + +void cDisplayPluginView::ClearGrids(int viewGridID) { + map< int, cViewGrid* >::iterator hit = viewGrids.find(viewGridID); + if (hit == viewGrids.end()) + return; + (hit->second)->Clear(); +} + +void cDisplayPluginView::Action(void) { + SetInitFinished(); + FadeIn(); + DoFlush(); + cView::Action(); +} diff --git a/views/displaypluginview.h b/views/displaypluginview.h new file mode 100644 index 0000000..b170116 --- /dev/null +++ b/views/displaypluginview.h @@ -0,0 +1,33 @@ +#ifndef __DISPLAYPLUGINVIEW_H +#define __DISPLAYPLUGINVIEW_H + +#include +#include "../libtemplate/template.h" +#include "view.h" +#include "viewgrid.h" + +class cDisplayPluginView : public cView { +private: + map *intTokens; + map *stringTokens; + map > > *loopTokens; + map< int, cViewGrid* > viewGrids; + virtual void Action(void); +public: + cDisplayPluginView(cTemplateView *tmplView); + virtual ~cDisplayPluginView(); + bool createOsd(void); + void SetIntTokens(map *intTokens) { this->intTokens = intTokens; }; + void SetStringTokens(map *stringTokens) { this->stringTokens = stringTokens; }; + void SetLoopTokens(map > > *loopTokens) { this->loopTokens = loopTokens; }; + void DisplayViewElement(int id); + void InitGrids(int viewGridID); + void SetGrid(int viewGridID, long gridID, double x, double y, double width, double height, map *intTokens, map *stringTokens); + void SetGridCurrent(int viewGridID, long gridID, bool current); + void DeleteGrid(int viewGridID, long gridID); + void DisplayGrids(int viewGridID); + void ClearGrids(int viewGridID); + void DoStart(void) { Start(); }; + void Flush(void) { DoFlush(); }; +}; +#endif //__DISPLAYPLUGINVIEW_H diff --git a/views/view.c b/views/view.c index 2b9c4bf..1571d2e 100644 --- a/views/view.c +++ b/views/view.c @@ -837,3 +837,132 @@ void cViewListItem::SetListElementPosition(cTemplatePixmap *pix) { pix->SetY(y); } +/*********************************************************************** +* cGrid +************************************************************************/ + +cGrid::cGrid(cTemplateViewElement *tmplGrid) : cView(tmplGrid) { + dirty = true; + moved = true; + resized = true; + current = false; + x = 0.0; + y = 0.0; + width = 0.0; + height = 0.0; +} + +cGrid::~cGrid() { + +} + +void cGrid::Set(double x, double y, double width, double height, + map *intTokens, map *stringTokens) { + if ((width != this->width) || (height != this->height)) { + resized = true; + dirty = false; + } else { + resized = false; + } + this->x = x; + this->y = y; + this->width = width; + this->height = height; + moved = true; + if (intTokens) { + this->intTokens = *intTokens; + SetCurrent(current); + dirty = true; + } + if (stringTokens) { + this->stringTokens = *stringTokens; + dirty = true; + } +} + +void cGrid::SetCurrent(bool current) { + this->current = current; + if (!resized) + dirty = true; + intTokens.erase("current"); + intTokens.insert(pair("current", current)); +} + +void cGrid::Move(void) { + tmplItem->InitIterator(); + cTemplatePixmap *pix = NULL; + int pixCurrent = 0; + + while(pix = tmplItem->GetNextPixmap()) { + PositionPixmap(pix); + cRect pixViewPort = pix->GetPixmapSize(); + SetViewPort(pixCurrent, pixViewPort); + pixCurrent++; + } + dirty = false; + resized = false; + moved = false; +} + +void cGrid::Draw(void) { + if (tmplItem->DebugTokens()) { + DebugTokens("Grid", &stringTokens, &intTokens); + } + + tmplItem->InitIterator(); + cTemplatePixmap *pix = NULL; + int pixCurrent = 0; + + while(pix = tmplItem->GetNextPixmap()) { + PositionPixmap(pix); + if (!PixmapExists(pixCurrent)) { + pix->ParseDynamicParameters(&intTokens, true); + } else { + pix->ParseDynamicParameters(&intTokens, false); + } + if (!PixmapExists(pixCurrent) && pix->Ready() && pix->DoExecute() && !pix->Scrolling()) { + CreateViewPixmap(pixCurrent, pix); + } + //if pixmap still not valid, skip + if (!pix->Ready() && !pix->Scrolling()) { + pixCurrent++; + continue; + } + //if condition for pixmap set, check if cond is true + if (!pix->DoExecute()) { + pixCurrent++; + continue; + } + + pix->ClearDynamicFunctionParameters(); + pix->ParseDynamicFunctionParameters(&stringTokens, &intTokens); + //pix->Debug(); + DrawPixmap(pixCurrent, pix); + pixCurrent++; + } + dirty = false; + resized = false; + moved = false; +} + +void cGrid::Clear(void) { + int pixMax = NumPixmaps(); + for (int pixCurrent = 0; pixCurrent < pixMax; pixCurrent++) { + Fill(pixCurrent, clrTransparent); + } +} + +void cGrid::DeletePixmaps(void) { + int pixMax = NumPixmaps(); + for (int pixCurrent = 0; pixCurrent < pixMax; pixCurrent++) { + DestroyPixmap(pixCurrent); + } +} + +void cGrid::PositionPixmap(cTemplatePixmap *pix) { + pix->SetXPercent(x); + pix->SetYPercent(y); + pix->SetWidthPercent(width); + pix->SetHeightPercent(height); + pix->CalculateParameters(); +} diff --git a/views/view.h b/views/view.h index a793c31..7b5bd9b 100644 --- a/views/view.h +++ b/views/view.h @@ -70,4 +70,31 @@ public: void ClearListItem(void); }; +class cGrid : public cView { +protected: + bool dirty; + bool moved; + bool resized; + bool current; + double x; + double y; + double width; + double height; + map stringTokens; + map intTokens; + void PositionPixmap(cTemplatePixmap *pix); +public: + cGrid(cTemplateViewElement *tmplGrid); + virtual ~cGrid(); + bool Dirty(void) { return dirty; }; + bool Moved(void) { return moved; }; + bool Resized(void) { return resized; }; + void Set(double x, double y, double width, double height, map *intTokens, map *stringTokens); + void SetCurrent(bool current); + void Move(void); + void Draw(void); + void Clear(void); + void DeletePixmaps(void); +}; + #endif //__VIEW_H \ No newline at end of file diff --git a/views/viewgrid.c b/views/viewgrid.c new file mode 100644 index 0000000..6488ccd --- /dev/null +++ b/views/viewgrid.c @@ -0,0 +1,74 @@ +#include "viewgrid.h" + +using namespace std; + +cViewGrid::cViewGrid(cTemplateViewGrid *tmplGrid) { + this->tmplGrid = tmplGrid; +} + +cViewGrid::~cViewGrid() { + Clear(); +} + +void cViewGrid::SetGrid(long gridID, + double x, double y, double width, double height, + map *intTokens, map *stringTokens) { + map < long, cGrid* >::iterator hit = grids.find(gridID); + cGrid *grid; + if (hit == grids.end()) { + grid = new cGrid(tmplGrid); + grid->Set(x, y, width, height, intTokens, stringTokens); + grids.insert(pair(gridID, grid)); + } else { + (hit->second)->Set(x, y, width, height, intTokens, stringTokens); + } +} + +void cViewGrid::SetCurrent(long gridID, bool current) { + esyslog("skindesigner: setting %ld to current %d", gridID, current); + map::iterator hit = grids.find(gridID); + if (hit != grids.end()) + (hit->second)->SetCurrent(current); +} + +void cViewGrid::Delete(long gridID) { + map::iterator hit = grids.find(gridID); + if (hit == grids.end()) + return; + esyslog("skindesigner: deleting grid %ld", gridID); + delete (hit->second); + grids.erase(gridID); +} + +void cViewGrid::Clear(void) { + for (map < long, cGrid* >::iterator it = grids.begin(); it != grids.end(); it++) + delete it->second; + grids.clear(); +} + +void cViewGrid::Render(void) { + esyslog("skindesigner: rendering %ld grids", grids.size()); + for (map < long, cGrid* >::iterator it = grids.begin(); it != grids.end(); it++) { + cGrid *grid = it->second; + if (grid->Dirty()) { + if (grid->Moved()) { + grid->DeletePixmaps(); + } + esyslog("skindesigner: rendering grid %ld", it->first); + grid->Draw(); + } else if (grid->Resized()) { + esyslog("skindesigner: resizing grid %ld", it->first); + grid->DeletePixmaps(); + grid->Draw(); + } else if (grid->Moved()) { + esyslog("skindesigner: moving grid %ld", it->first); + grid->Move(); + } else { + esyslog("skindesigner: skipping grid %ld", it->first); + } + } +} + +void cViewGrid::Debug(void) { + +} \ No newline at end of file diff --git a/views/viewgrid.h b/views/viewgrid.h new file mode 100644 index 0000000..84209c3 --- /dev/null +++ b/views/viewgrid.h @@ -0,0 +1,26 @@ +#ifndef __VIEWGRID_H +#define __VIEWGRID_H + +#include "string" +#include "map" +#include "view.h" +#include "../libtemplate/templateviewgrid.h" + +using namespace std; + +class cViewGrid { +private: + cTemplateViewGrid *tmplGrid; + map < long, cGrid* > grids; +public: + cViewGrid(cTemplateViewGrid *tmplGrid); + virtual ~cViewGrid(); + void SetGrid(long gridID, double x, double y, double width, double height, map *intTokens, map *stringTokens); + void SetCurrent(long gridID, bool current); + void Delete(long gridID); + void Clear(void); + void Render(void); + void Debug(void); +}; + +#endif //__DISPLAYMENULISTVIEW_H \ No newline at end of file