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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
#include "textwindow.h"
#include "config.h"
#include "imagecache.h"
#include "imageloader.h"
#include "helpers.h"
#include <sstream>
cNopacityTextWindow::cNopacityTextWindow(cOsd *osd, cFont *font, cRect *vidWin) : cThread("TextWindow") {
this->osd = osd;
this->font = font;
this->fontHeader = NULL;
this->vidWin = vidWin;
pixmapBackground = NULL;
pixmap = NULL;
scaledWindow = false;
posterWidth = 0;
posterHeight = 0;
hasManualPoster = false;
manualPosterPath = "";
hasPoster = false;
}
cNopacityTextWindow::cNopacityTextWindow(cOsd *osd, cFont *font, cFont *fontHeader) : cThread("TextWindow") {
this->osd = osd;
this->font = font;
this->fontHeader = fontHeader;
this->vidWin = NULL;
pixmapBackground = NULL;
pixmap = NULL;
scaledWindow = false;
posterWidth = 0;
posterHeight = 0;
hasManualPoster = false;
manualPosterPath = "";
hasPoster = false;
}
cNopacityTextWindow::~cNopacityTextWindow(void) {
Cancel(-1);
while (Active())
cCondWait::SleepMs(10);
if (pixmapBackground) {
osd->DestroyPixmap(pixmapBackground);
pixmapBackground = NULL;
}
if (pixmap) {
osd->DestroyPixmap(pixmap);
pixmap = NULL;
}
if ((config.GetValue("scalePicture") == 2) && scaledWindow) {
cRect vidWinNew = cDevice::PrimaryDevice()->CanScaleVideo(oldVidWin);
if (vidWinNew != cRect::Null) {
vidWin->SetX(vidWinNew.X());
vidWin->SetY(vidWinNew.Y());
vidWin->SetWidth(vidWinNew.Width());
vidWin->SetHeight(vidWinNew.Height());
}
}
}
bool cNopacityTextWindow::SetManualPoster(const cRecording *recording, bool fullscreen) {
cString posterFound;
cImageLoader imgLoader;
hasManualPoster = imgLoader.SearchRecordingPoster(recording->FileName(), posterFound);
if (hasManualPoster) {
manualPosterPath = posterFound;
int posterWidthOrig = config.GetValue("posterWidth");
int posterHeightOrig = config.GetValue("posterHeight");
if (!fullscreen) {
posterHeight = geometry->Height() - 5;
posterWidth = posterWidthOrig * ((double)posterHeight / (double)posterHeightOrig);
} else {
posterWidth = geometry->Width() / 4;
posterHeight = posterHeightOrig * ((double)posterWidth / (double)posterWidthOrig);
}
return true;
}
return false;
}
void cNopacityTextWindow::SetPoster(const cEvent *event, const cRecording *recording, bool fullscreen) {
if (!event && !recording)
return;
hasPoster = false;
posterHeight = 0;
posterWidth = 0;
static cPlugin *pScraper = GetScraperPlugin();
if (pScraper && (config.GetValue("scraperInfo") == 1)) {
posterScraper2Vdr.event = event;
posterScraper2Vdr.recording = recording;
if (pScraper->Service("GetPoster", &posterScraper2Vdr)) {
int posterWidthOrig = posterScraper2Vdr.poster.width;
int posterHeightOrig = posterScraper2Vdr.poster.height;
if (!(posterWidthOrig == 0 || posterHeightOrig == 0)) {
if (!fullscreen) {
posterHeight = geometry->Height() - 5;
posterWidth = posterWidthOrig * ((double)posterHeight / (double)posterHeightOrig);
} else {
posterWidth = geometry->Width() / 4;
posterHeight = posterHeightOrig * ((double)posterWidth / (double)posterWidthOrig);
}
hasPoster = true;
}
}
}
}
bool cNopacityTextWindow::SetTextScroller(int border, int left) {
int lineHeight = font->Height();
bool scrolling = false;
drawportHeight = geometry->Height();
if (!(hasPoster || hasManualPoster)) {
drawTextTall = false;
drawTextFull = true;
twTextTall.Set("", font, 5);
twTextFull.Set(*text, font, geometry->Width() - 2*border);
int pixmapTotalHeight = lineHeight * (twTextFull.Lines()+1);
if ((pixmapTotalHeight - (lineHeight/2)) > drawportHeight) {
drawportHeight = pixmapTotalHeight;
scrolling = true;
}
} else {
cTextWrapper test;
int widthTall = geometry->Width() - 2 * border - left;
test.Set(*text, font, widthTall);
int linesTotal = test.Lines();
int textHeight = linesTotal * lineHeight;
if (textHeight > posterHeight) {
drawTextTall = true;
drawTextFull = true;
int lineSplit = posterHeight / lineHeight + 1;
std::stringstream textTall;
std::stringstream textFull;
for (int line = 0; line < linesTotal; line++) {
bool lineWrap = false;
if (font->Width(test.GetLine(line)) < (widthTall - 100))
lineWrap = true;
if (line < lineSplit) {
textTall << test.GetLine(line);
if (lineWrap)
textTall << "\n";
else
textTall << " ";
} else {
textFull << test.GetLine(line);
if (lineWrap)
textFull << "\n";
else
textFull << " ";
}
}
twTextTall.Set(textTall.str().c_str(), font, widthTall);
twTextFull.Set(textFull.str().c_str(), font, geometry->Width() - 2*border);
scrolling = true;
drawportHeight = lineHeight * (twTextTall.Lines() + twTextFull.Lines() + 1);
} else {
scrolling = false;
drawTextTall = true;
drawTextFull = false;
twTextTall.Set(*text, font, geometry->Width() - 2*border - left);
twTextFull.Set("", font, 5);
}
}
return scrolling;
}
void cNopacityTextWindow::CreatePixmap(void) {
cPixmap::Lock();
pixmapBackground = osd->CreatePixmap(4, cRect(geometry->X()-1, geometry->Y()-1, geometry->Width()+2, geometry->Height()+2));
pixmap = osd->CreatePixmap(5, cRect(geometry->X(), geometry->Y(), geometry->Width(), geometry->Height()),
cRect(0, 0, geometry->Width(), drawportHeight));
pixmapBackground->Fill(Theme.Color(clrMenuBorder));
pixmapBackground->DrawRectangle(cRect(1, 1, geometry->Width(), geometry->Height()), clrBlack);
pixmap->Fill(Theme.Color(clrMenuBack));
if (config.GetValue("animation") && config.GetValue("menuEPGWindowFadeTime"))
SetAlpha();
cPixmap::Unlock();
}
void cNopacityTextWindow::CreatePixmapFullScreen(void) {
pixmapBackground = osd->CreatePixmap(4, cRect(geometry->X()-1, geometry->Y()-1, geometry->Width()+2, geometry->Height()+2));
pixmap = osd->CreatePixmap(5, cRect(geometry->X(), geometry->Y(), geometry->Width(), geometry->Height()));
pixmapBackground->Fill(Theme.Color(clrMenuBorder));
pixmapBackground->DrawRectangle(cRect(1, 1, geometry->Width(), geometry->Height()), Theme.Color(clrMenuTextWindow));
pixmap->Fill(clrTransparent);
}
void cNopacityTextWindow::SetAlpha(int Alpha) {
if (pixmapBackground) pixmapBackground->SetAlpha(Alpha);
if (pixmap) pixmap->SetAlpha(Alpha);
}
void cNopacityTextWindow::DrawText(int border, int left) {
int lineHeight = font->Height();
int currentLineHeight = lineHeight/2;
tColor clrFontBack = (config.GetValue("displayType") != dtFlat)?(clrTransparent):(Theme.Color(clrMenuBack));
cPixmap::Lock();
if (drawTextTall) {
for (int i=0; (i < twTextTall.Lines()) && Running(); i++) {
pixmap->DrawText(cPoint(border + left, currentLineHeight), twTextTall.GetLine(i), Theme.Color(clrMenuFontDetailViewText), clrFontBack, font);
currentLineHeight += lineHeight;
}
}
if (drawTextFull) {
for (int i=0; (i < twTextFull.Lines()) && Running(); i++) {
pixmap->DrawText(cPoint(border, currentLineHeight), twTextFull.GetLine(i), Theme.Color(clrMenuFontDetailViewText), clrFontBack, font);
currentLineHeight += lineHeight;
}
}
cPixmap::Unlock();
}
void cNopacityTextWindow::SetEvent(const cEvent *event) {
if (!event)
return;
CreatePixmapFullScreen();
int border = config.GetValue("borderDetailedEPG");
int width = geometry->Width();
int height = geometry->Height();
int widthTextHeader = width - 2 * border;
int widthText = widthTextHeader;
int y = border;
cImageLoader imgLoader;
bool epgImageFound = false;
if (hasPoster) {
int posterX = width - posterWidth - border;
if (imgLoader.LoadPoster(posterScraper2Vdr.poster.path.c_str(), posterWidth, posterHeight)) {
pixmap->DrawImage(cPoint(posterX, border), imgLoader.GetImage());
widthTextHeader -= posterWidth + border;
}
} else if (imgLoader.LoadEPGImage(event->EventID())) {
epgImageFound = true;
pixmap->DrawImage(cPoint(width - config.GetValue("epgImageWidth") - border, y), imgLoader.GetImage());
widthTextHeader -= config.GetValue("epgImageWidth") + border;
}
//Title
y = DrawTextWrapper(event->Title(), widthTextHeader, y, border, fontHeader, Theme.Color(clrMenuFontDetailViewHeaderTitle), height);
//Short Text
y = DrawTextWrapper(event->ShortText(), widthTextHeader, y, border, font, Theme.Color(clrMenuFontDetailViewHeader), height);
y += fontHeader->Height();
//Description
if (hasPoster && (y < (border + posterHeight))) {
int heightNarrow = border + posterHeight - y;
DrawTextWrapperFloat(event->Description(),
widthTextHeader, widthText, y, heightNarrow,
border, font, Theme.Color(clrMenuFontDetailViewText), height);
} else if (epgImageFound && (y < (border + config.GetValue("epgImageHeight")))) {
y = border + config.GetValue("epgImageHeight");
DrawTextWrapper(event->Description(), widthText, y, border, font, Theme.Color(clrMenuFontDetailViewText), height);
} else {
DrawTextWrapper(event->Description(), widthText, y, border, font, Theme.Color(clrMenuFontDetailViewText), height);
}
}
void cNopacityTextWindow::SetRecording(const cRecording *recording) {
if (!recording)
return;
CreatePixmapFullScreen();
int border = config.GetValue("borderDetailedRecordings");
int width = geometry->Width();
int height = geometry->Height();
int widthTextHeader = width - 2 * border;
int widthText = widthTextHeader;
int y = border;
//Image
cImageLoader imgLoader;
bool recImageFound = false;
if (hasManualPoster) {
if (imgLoader.LoadPoster(*manualPosterPath, posterWidth, posterHeight)) {
int posterX = width - posterWidth - border;
pixmap->DrawImage(cPoint(posterX, border), imgLoader.GetImage());
widthTextHeader -= posterWidth + border;
}
} else if (hasPoster) {
int posterX = width - posterWidth - border;
if (imgLoader.LoadPoster(posterScraper2Vdr.poster.path.c_str(), posterWidth, posterHeight)) {
pixmap->DrawImage(cPoint(posterX, border), imgLoader.GetImage());
widthTextHeader -= posterWidth + border;
}
} else if (imgLoader.LoadRecordingImage(recording->FileName())) {
pixmap->DrawImage(cPoint(width - config.GetValue("epgImageWidth") - border, y), imgLoader.GetImage());
widthTextHeader -= config.GetValue("epgImageWidth") + border;
recImageFound = true;
}
const cRecordingInfo *info = recording->Info();
if (!info)
return;
cString recTitle;
if (info->Title())
recTitle = info->Title();
else
recTitle = recording->Name();
//Title
y = DrawTextWrapper(*recTitle, widthTextHeader, y, border, fontHeader, Theme.Color(clrMenuFontDetailViewHeaderTitle), height);
//Short Text
if (!isempty(info->ShortText())) {
y = DrawTextWrapper(info->ShortText(), widthTextHeader, y, border, font, Theme.Color(clrMenuFontDetailViewHeader), height);
}
y += fontHeader->Height();
//Description
if ((hasPoster || hasManualPoster) && (y < (border + posterHeight))) {
int heightNarrow = border + posterHeight - y;
DrawTextWrapperFloat(recording->Info()->Description(),
widthTextHeader, widthText, y, heightNarrow,
border, font, Theme.Color(clrMenuFontDetailViewText), height);
} else if (recImageFound && (y < (border + config.GetValue("epgImageHeight")))) {
y = border + config.GetValue("epgImageHeight");
DrawTextWrapper(recording->Info()->Description(), widthText, y, border, font, Theme.Color(clrMenuFontDetailViewText), height);
} else {
DrawTextWrapper(recording->Info()->Description(), widthText, y, border, font, Theme.Color(clrMenuFontDetailViewText), height);
}
}
int cNopacityTextWindow::DrawTextWrapper(const char *text, int width, int top, int x,
const cFont *font, tColor color, int maxHeight) {
cTextWrapper wrapper;
int lineHeight = font->Height();
wrapper.Set(text, font, width);
int y = top;
for (int i=0; i < wrapper.Lines(); i++) {
if (y + 2*lineHeight > maxHeight) {
pixmap->DrawText(cPoint(x, y), "...", color, clrTransparent, font);
y += 2*lineHeight;
break;
}
pixmap->DrawText(cPoint(x, y), wrapper.GetLine(i), color, clrTransparent, font);
y += lineHeight;
}
return y;
}
void cNopacityTextWindow::DrawTextWrapperFloat(const char *text, int widthSmall, int widthFull,
int top, int heightNarrow, int x, const cFont *font,
tColor color, int maxHeight) {
if (!text)
return;
int lineHeight = font->Height();
int numLinesNarrow = heightNarrow / lineHeight + 1;
splitstring s(text);
std::vector<std::string> flds = s.split('\n', 1);
if (flds.size() < 1)
return;
int y = top;
int linesDrawn = 0;
bool drawNarrow = true;
for (unsigned int i = 0; i < flds.size(); i++) {
if (!flds[i].size()) {
//empty line
linesDrawn++;
y += lineHeight;
} else {
cTextWrapper wrapper;
if (drawNarrow) {
wrapper.Set((flds[i].c_str()), font, widthSmall);
int newLines = wrapper.Lines();
//check if wrapper fits completely into narrow area
if (linesDrawn + newLines < numLinesNarrow) {
y = DrawTextWrapper(flds[i].c_str(), widthSmall, y, x, font, color, maxHeight);
linesDrawn += newLines;
} else {
//this wrapper has to be splitted
std::stringstream sstrTextTall;
std::stringstream sstrTextFull;
for (int line = 0; line < wrapper.Lines(); line++) {
if (line + linesDrawn < numLinesNarrow) {
sstrTextTall << wrapper.GetLine(line) << " ";
} else {
sstrTextFull << wrapper.GetLine(line) << " ";
}
}
y = DrawTextWrapper(sstrTextTall.str().c_str(), widthSmall, y, x, font, color, maxHeight);
y = DrawTextWrapper(sstrTextFull.str().c_str(), widthFull, y, x, font, color, maxHeight);
drawNarrow = false;
}
} else {
if (y > maxHeight)
break;
y = DrawTextWrapper(flds[i].c_str(), widthFull, y, x, font, color, maxHeight);
}
}
}
}
void cNopacityTextWindow::DrawPoster(int border) {
int posterY = font->Height() / 2;
cImageLoader imgLoader;
if (hasManualPoster) {
if (imgLoader.LoadPoster(*manualPosterPath, posterWidth, posterHeight)) {
pixmap->DrawImage(cPoint(border, posterY), imgLoader.GetImage());
}
} else if (imgLoader.LoadPoster(posterScraper2Vdr.poster.path.c_str(), posterWidth, posterHeight)) {
pixmap->DrawImage(cPoint(border, posterY), imgLoader.GetImage());
}
}
void cNopacityTextWindow::DoSleep(int duration) {
int sleepSlice = 10;
for (int i = 0; Running() && (i*sleepSlice < duration); i++)
cCondWait::SleepMs(sleepSlice);
}
void cNopacityTextWindow::ScaleVideoWindow(void) {
oldVidWin.SetX(vidWin->X());
oldVidWin.SetY(vidWin->Y());
oldVidWin.SetWidth(vidWin->Width());
oldVidWin.SetHeight(vidWin->Height());
cRect availableRect(vidWin->X(), vidWin->Y(), vidWin->Width(), vidWin->Height() - geometry->Height());
cRect vidWinNew = cDevice::PrimaryDevice()->CanScaleVideo(availableRect);
if (vidWinNew != cRect::Null) {
vidWin->SetX(vidWinNew.X());
vidWin->SetY(vidWinNew.Y());
vidWin->SetWidth(vidWinNew.Width());
vidWin->SetHeight(vidWinNew.Height());
scaledWindow = true;
}
}
void cNopacityTextWindow::Action(void) {
if (! *text)
return;
int initialSleepTime = (initial) ? config.GetValue("menuFadeTime") : 0;
DoSleep(initialSleepTime + config.GetValue("menuInfoTextDelay") * 1000);
if (config.GetValue("scalePicture") == 2) {
ScaleVideoWindow();
}
int border = 5;
int left = 0;
if (hasPoster || hasManualPoster)
left = 10 + posterWidth;
bool scrolling = false;
if (Running()) {
scrolling = SetTextScroller(border, left);
CreatePixmap();
}
if (Running()) {
DrawText(border, left);
}
if (Running() && (hasPoster || hasManualPoster)) {
DrawPoster(border);
}
//FadeIn
if (config.GetValue("menuEPGWindowFadeTime")) {
int FadeTime = config.GetValue("menuEPGWindowFadeTime");
int FadeFrameTime = FadeTime / 10;
uint64_t Start = cTimeMs::Now();
while (Running()) {
uint64_t Now = cTimeMs::Now();
double t = std::min(double(Now - Start) / FadeTime, 1.0);
int Alpha = t * ALPHA_OPAQUE;
cPixmap::Lock();
SetAlpha(Alpha);
cPixmap::Unlock();
if (Running())
osd->Flush();
int Delta = cTimeMs::Now() - Now;
if (Running() && (Delta < FadeFrameTime))
cCondWait::SleepMs(FadeFrameTime - Delta);
if ((int)(Now - Start) > FadeTime)
break;
}
}
if (scrolling && Running()) {
int scrollDelay = config.GetValue("menuInfoScrollDelay") * 1000;
DoSleep(scrollDelay);
int drawPortY;
int FrameTime = 0;
if (config.GetValue("menuInfoScrollSpeed") == 1)
FrameTime = 50;
else if (config.GetValue("menuInfoScrollSpeed") == 2)
FrameTime = 30;
else if (config.GetValue("menuInfoScrollSpeed") == 3)
FrameTime = 15;
int maxY = pixmap->DrawPort().Height() - pixmap->ViewPort().Height();
bool doSleep = false;
while (Running()) {
uint64_t Now = cTimeMs::Now();
cPixmap::Lock();
drawPortY = pixmap->DrawPort().Y();
drawPortY -= 1;
cPixmap::Unlock();
if (std::abs(drawPortY) > maxY) {
doSleep = true;
DoSleep(scrollDelay);
drawPortY = 0;
}
cPixmap::Lock();
if (Running())
pixmap->SetDrawPortPoint(cPoint(0, drawPortY));
cPixmap::Unlock();
if (doSleep) {
doSleep = false;
DoSleep(scrollDelay);
}
int Delta = cTimeMs::Now() - Now;
if (Running())
osd->Flush();
if (Running() && (Delta < FrameTime))
cCondWait::SleepMs(FrameTime - Delta);
}
}
}
|