plugin interface

This commit is contained in:
louis
2015-02-12 18:50:58 +01:00
parent 00ac852820
commit 4d7700aece
34 changed files with 1133 additions and 84 deletions

83
views/displaypluginview.c Normal file
View File

@@ -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<string,int> *intTokens, map<string,string> *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();
}

33
views/displaypluginview.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef __DISPLAYPLUGINVIEW_H
#define __DISPLAYPLUGINVIEW_H
#include <vdr/thread.h>
#include "../libtemplate/template.h"
#include "view.h"
#include "viewgrid.h"
class cDisplayPluginView : public cView {
private:
map<string,int> *intTokens;
map<string,string> *stringTokens;
map<string,vector<map<string,string> > > *loopTokens;
map< int, cViewGrid* > viewGrids;
virtual void Action(void);
public:
cDisplayPluginView(cTemplateView *tmplView);
virtual ~cDisplayPluginView();
bool createOsd(void);
void SetIntTokens(map<string,int> *intTokens) { this->intTokens = intTokens; };
void SetStringTokens(map<string,string> *stringTokens) { this->stringTokens = stringTokens; };
void SetLoopTokens(map<string,vector<map<string,string> > > *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<string,int> *intTokens, map<string,string> *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

View File

@@ -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 <string,int> *intTokens, map <string,string> *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<string,int>("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();
}

View File

@@ -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 <string,string> stringTokens;
map <string,int> 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 <string,int> *intTokens, map <string,string> *stringTokens);
void SetCurrent(bool current);
void Move(void);
void Draw(void);
void Clear(void);
void DeletePixmaps(void);
};
#endif //__VIEW_H

74
views/viewgrid.c Normal file
View File

@@ -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<string,int> *intTokens, map<string,string> *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<long,cGrid*>(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<long,cGrid*>::iterator hit = grids.find(gridID);
if (hit != grids.end())
(hit->second)->SetCurrent(current);
}
void cViewGrid::Delete(long gridID) {
map<long,cGrid*>::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) {
}

26
views/viewgrid.h Normal file
View File

@@ -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<string,int> *intTokens, map<string,string> *stringTokens);
void SetCurrent(long gridID, bool current);
void Delete(long gridID);
void Clear(void);
void Render(void);
void Debug(void);
};
#endif //__DISPLAYMENULISTVIEW_H