1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
#include "../config.h"
#include "view.h"
// --- cView -------------------------------------------------------------
cView::cView(void) {
globals = NULL;
viewName = NULL;
attribs = new cViewAttribs((int)eViewAttribs::count);
numViewElements = 0;
viewElements = NULL;
viewElementsHorizontal = NULL;
fader = NULL;
shifter = NULL;
shifting = false;
currentTvFrame = NULL;
newTvFrame = NULL;
menuInit = false;
}
cView::~cView() {
for (int i=0; i< numViewElements; i++)
delete viewElements[i];
delete[] viewElements;
if (viewElementsHorizontal) {
for (int i=0; i< numViewElements; i++)
delete viewElementsHorizontal[i];
delete[] viewElementsHorizontal;
}
delete attribs;
free(viewName);
delete fader;
delete shifter;
shifting = false;
sdOsd.DeleteOsd();
}
/*******************************************************************
* Public Functions
*******************************************************************/
bool cView::ReadFromXML(void) {
const char *xmlFile;
switch (viewId) {
case eViewType::DisplayChannel:
xmlFile = "displaychannel.xml";
break;
case eViewType::DisplayMenu:
xmlFile = "displaymenu.xml";
break;
case eViewType::DisplayMessage:
xmlFile = "displaymessage.xml";
break;
case eViewType::DisplayReplay:
xmlFile = "displayreplay.xml";
break;
case eViewType::DisplayVolume:
xmlFile = "displayvolume.xml";
break;
case eViewType::DisplayTracks:
xmlFile = "displayaudiotracks.xml";
break;
default:
return false;
}
cXmlParser parser;
parser.SetOsd(&sdOsd);
if (!parser.ReadView(this, xmlFile)) {
return false;
}
if (!parser.ParseView()) {
return false;
}
//read additional plugin menu templates
bool ok = true;
if (viewId == eViewType::DisplayMenu) {
plgManager->InitPluginMenuIterator();
map <int,skindesignerapi::sPlugMenu> *plugMenus = NULL;
string plugName = "";
int plugId = -1;
while ( plugMenus = plgManager->GetPluginMenus(plugName, plugId) ) {
for (map <int,skindesignerapi::sPlugMenu>::iterator it = plugMenus->begin(); it != plugMenus->end(); it++) {
int templateNumber = it->first;
int menuType = it->second.type;
cString templateName = cString::sprintf("plug-%s-%s", plugName.c_str(), it->second.tplname.c_str());
if (parser.ReadPluginView(*templateName)) {
ok = parser.ParsePluginView(plugName, plugId, templateNumber, menuType);
} else {
dsyslog("skindesigner: template %s for plugin %s not available", *templateName, plugName.c_str());
}
}
}
}
return ok;
}
void cView::SetGlobals(cGlobals *globals) {
this->globals = globals;
attribs->SetGlobals(globals);
for (int i=0; i < numViewElements; ++i) {
if (viewElements[i]) {
viewElements[i]->SetGlobals(globals);
}
if (viewElementsHorizontal && viewElementsHorizontal[i]) {
viewElementsHorizontal[i]->SetGlobals(globals);
}
}
}
void cView::SetContainer(int x, int y, int width, int height) {
container.SetX(x);
container.SetY(y);
container.SetWidth(width);
container.SetHeight(height);
}
void cView::SetAttributes(vector<stringpair> &attributes) {
attribs->Set(attributes);
}
void cView::AddViewElement(const char *sViewElement, cViewElement *viewElement) {
int id = ViewElementId(sViewElement);
if (id == ATTR_UNKNOWN)
return;
viewElement->SetId(id);
viewElement->SetTokenContainer();
eOrientation orientation = viewElement->Orientation();
if (viewElementsHorizontal && orientation == eOrientation::horizontal) {
viewElementsHorizontal[id] = viewElement;
} else {
viewElements[id] = viewElement;
}
}
bool cView::ValidViewElement(const char *viewElement) {
if (ViewElementId(viewElement) != ATTR_UNKNOWN)
return true;
return false;
}
bool cView::ValidViewList(const char *viewList) {
if (!strcmp(viewList, "menuitems"))
return true;
return false;
}
void cView::PreCache(void) {
bool rootView = (container.Width() == 0) ? true : false;
if (rootView) {
SetContainer(0, 0, cOsd::OsdWidth(), cOsd::OsdHeight());
attribs->SetContainer(0, 0, cOsd::OsdWidth(), cOsd::OsdHeight());
attribs->Cache();
rootView = true;
}
//set frame for scaling tv picture
tvFrame = attribs->TvFrame();
//cache viewelements
int contX = rootView ? 0 : ((attribs->X() > -1) ? attribs->X() : 0);
int contY = rootView ? 0 : ((attribs->Y() > -1) ? attribs->Y() : 0);
for (int i=0; i < numViewElements; i++) {
if (!viewElements[i])
continue;
if (FadeTime() > 0 || ShiftTime() > 0)
viewElements[i]->SetAnimatedView();
viewElements[i]->SetContainer(contX, contY, attribs->Width(), attribs->Height());
viewElements[i]->Cache();
}
if (viewElementsHorizontal) {
for (int i=0; i < numViewElements; i++) {
if (!viewElementsHorizontal[i])
continue;
if (FadeTime() > 0 || ShiftTime() > 0)
viewElementsHorizontal[i]->SetAnimatedView();
viewElementsHorizontal[i]->SetContainer(contX, contY, attribs->Width(), attribs->Height());
viewElementsHorizontal[i]->Cache();
}
}
//cleanup viewelements
for (int i=0; i < numViewElements; i++) {
if (!viewElements[i])
continue;
if (!viewElements[i]->Execute()) {
delete viewElements[i];
viewElements[i] = NULL;
}
}
if (viewElementsHorizontal) {
for (int i=0; i < numViewElements; i++) {
if (!viewElementsHorizontal[i])
continue;
if (!viewElementsHorizontal[i]->Execute()) {
delete viewElementsHorizontal[i];
viewElementsHorizontal[i] = NULL;
}
}
}
//set viewelement objects for each view
SetViewElementObjects();
}
bool cView::Init(void) {
int osdX = attribs->X();
int osdY = attribs->Y();
int osdWidth = attribs->Width();
int osdHeight = attribs->Height();
return sdOsd.CreateOsd(osdX, osdY, osdWidth, osdHeight);
}
void cView::Clear(int ve, bool forceClearBackground) {
if (!viewElements[ve])
return;
viewElements[ve]->Clear(forceClearBackground);
}
void cView::Render(int ve, bool force) {
if (!viewElements[ve])
return;
if (viewElements[ve]->Parse(force))
viewElements[ve]->Render();
}
void cView::Close(void) {
delete fader;
fader = NULL;
delete shifter;
shifter = NULL;
if (initFinished && ShiftTime() > 0) {
cRect shiftbox = CoveredArea();
cPoint ref = cPoint(shiftbox.X(), shiftbox.Y());
cPoint end = ShiftStart(shiftbox);
shifter = new cAnimation((cShiftable*)this, end, ref, false);
shifter->Shift();
delete shifter;
shifter = NULL;
} else if (initFinished && FadeTime() > 0) {
fader = new cAnimation((cFadable*)this, false);
fader->Fade();
delete fader;
fader = NULL;
}
UnScaleTv();
ClearVariables();
for (int i=0; i < numViewElements; i++) {
if (!viewElements[i])
continue;
viewElements[i]->Close();
}
sdOsd.Flush();
sdOsd.DeleteOsd();
}
int cView::FadeTime(void) {
return attribs->FadeTime();
}
void cView::SetTransparency(int transparency, bool force) {
for (int i = 0; i < numViewElements; i++) {
if (viewElements[i] && (!viewElements[i]->Fading() || force)) {
viewElements[i]->SetTransparency(transparency);
}
}
}
int cView::ShiftTime(void) {
return attribs->ShiftTime();
}
int cView::ShiftMode(void) {
return attribs->ShiftMode();
}
void cView::SetPosition(cPoint &position, cPoint &reference, bool force) {
for (int i = 0; i < numViewElements; i++) {
if (viewElements[i] && (!viewElements[i]->Shifting() || force)) {
viewElements[i]->SetPosition(position, reference);
}
}
}
void cView::Flush(void) {
if (init) {
init = false;
StartAnimation();
menuInit = true;
//LockFlush was set at startup of view to avoid display
//of not positioned pixmaps for shifting and fading
sdOsd.UnlockFlush();
}
if (menuInit) {
ScaleTv();
WakeViewElements();
menuInit = false;
}
sdOsd.Flush();
}
void cView::Debug(void) {
esyslog("skindesigner: ---> view %s", viewName);
attribs->Debug();
for (int i=0; i < numViewElements; i++) {
if (!viewElements[i])
continue;
esyslog("skindesigner: debugging ve %d", i);
viewElements[i]->Debug(true);
}
}
/*******************************************************************
* Protected Functions
*******************************************************************/
void cView::ClearVariables(void) {
init = true;
initFinished = false;
newTvFrame = NULL;
currentTvFrame = NULL;
menuInit = false;
}
int cView::ViewElementId(const char *name) {
map<string, int>::iterator hit = viewElementNames.find(name);
if (hit != viewElementNames.end())
return (int)hit->second;
return ATTR_UNKNOWN;
}
void cView::StartAnimation(void) {
if (ShiftTime() > 0) {
cRect shiftbox = CoveredArea();
cPoint ref = cPoint(shiftbox.X(), shiftbox.Y());
cPoint start = ShiftStart(shiftbox);
SetPosition(start, ref);
shifter = new cAnimation((cShiftable*)this, start, ref, true);
shifter->Start();
} else if (FadeTime() > 0) {
if (fader)
return;
SetTransparency(100);
sdOsd.Flush();
fader = new cAnimation((cFadable*)this, true);
fader->Start();
}
initFinished = true;
}
void cView::WakeViewElements(void) {
for (int i = 0; i < numViewElements; i++) {
if (viewElements[i]) {
viewElements[i]->WakeUp();
}
}
if (!viewElementsHorizontal)
return;
for (int i = 0; i < numViewElements; i++) {
if (viewElementsHorizontal[i]) {
viewElementsHorizontal[i]->WakeUp();
}
}
}
cPoint cView::ShiftStart(cRect &shiftbox) {
eShiftType type = (eShiftType)attribs->ShiftType();
cPoint start;
if (type == eShiftType::none) {
start = attribs->ShiftStartpoint();
} else if (type == eShiftType::left) {
start.SetX(-shiftbox.Width());
start.SetY(shiftbox.Y());
} else if (type == eShiftType::right) {
start.SetX(attribs->Width());
start.SetY(shiftbox.Y());
} else if (type == eShiftType::top) {
start.SetX(shiftbox.X());
start.SetY(-shiftbox.Height());
} else if (type == eShiftType::bottom) {
start.SetX(shiftbox.X());
start.SetY(attribs->Height());
}
return start;
}
cRect cView::CoveredArea(void) {
cRect unionArea;
for (int i = 0; i < numViewElements; i++) {
if (viewElements[i] && !viewElements[i]->Shifting()) {
unionArea.Combine(viewElements[i]->CoveredArea());
}
}
return unionArea;
}
void cView::ScaleTv(void) {
bool scale = false;
if (newTvFrame) {
if (currentTvFrame) {
if (*newTvFrame != *currentTvFrame) {
scale = true;
}
} else {
scale = true;
}
currentTvFrame = newTvFrame;
} else {
if (tvFrame != cRect::Null) {
scale = true;
currentTvFrame = &tvFrame;
}
}
if (currentTvFrame && scale) {
DoScaleTv(currentTvFrame);
}
}
void cView::UnScaleTv(void) {
if (currentTvFrame) {
DoScaleTv(&cRect::Null);
currentTvFrame = NULL;
}
}
void cView::DoScaleTv(const cRect *frame) {
if (*frame == cRect::Null) {
cDevice::PrimaryDevice()->ScaleVideo(cRect::Null);
} else {
cRect scalingWindow = cDevice::PrimaryDevice()->CanScaleVideo(*frame);
if (scalingWindow != cRect::Null) {
cDevice::PrimaryDevice()->ScaleVideo(scalingWindow);
}
}
}
|