vdr 2.7.2
osddemo.c
Go to the documentation of this file.
1/*
2 * osddemo.c: A plugin for the Video Disk Recorder
3 *
4 * See the README file for copyright information and how to reach the author.
5 *
6 * $Id: osddemo.c 4.5 2020/10/14 20:32:41 kls Exp $
7 */
8
9#include <vdr/osd.h>
10#include <vdr/plugin.h>
11
12static const char *VERSION = "2.4.1";
13static const char *DESCRIPTION = "Demo of arbitrary OSD setup";
14static const char *MAINMENUENTRY = "Osd Demo";
15
16// --- DrawEllipses ----------------------------------------------------------
17
18void DrawEllipse(cOsd *Osd, int x1, int y1, int x2, int y2, int Quadrants)
19{
20 Osd->DrawRectangle(x1 + 2, y1 + 2, x2 - 2, y2 - 2, clrGreen);
21 Osd->DrawEllipse(x1 + 3, y1 + 3, x2 - 3, y2 - 3, clrRed, Quadrants);
22}
23
25{
26 int xa = 0;
27 int ya = 0;
28 int xb = Osd->Width() - 1;
29 int yb = Osd->Height() - 1;
30 int x0 = xa;
31 int x5 = xb;
32 int x1 = x0 + (xb - xa) / 5;
33 int x2 = x0 + (xb - xa) * 2 / 5;
34 int x3 = x0 + (xb - xa) * 3 / 5;
35 int x4 = x0 + (xb - xa) * 4 / 5;
36 int y0 = ya;
37 int y4 = yb;
38 int y2 = (y0 + y4) / 2;
39 int y1 = (y0 + y2) / 2;
40 int y3 = (y2 + y4) / 2;
41 Osd->DrawRectangle(xa, ya, xb, yb, clrGray50);
42 DrawEllipse(Osd, x4, y0, x5, y4, 0);
43 DrawEllipse(Osd, x2, y1, x3, y2, 1);
44 DrawEllipse(Osd, x1, y1, x2, y2, 2);
45 DrawEllipse(Osd, x1, y2, x2, y3, 3);
46 DrawEllipse(Osd, x2, y2, x3, y3, 4);
47 DrawEllipse(Osd, x3, y1, x4, y3, 5);
48 DrawEllipse(Osd, x1, y0, x3, y1, 6);
49 DrawEllipse(Osd, x0, y1, x1, y3, 7);
50 DrawEllipse(Osd, x1, y3, x3, y4, 8);
51 DrawEllipse(Osd, x3, y0, x4, y1, -1);
52 DrawEllipse(Osd, x0, y0, x1, y1, -2);
53 DrawEllipse(Osd, x0, y3, x1, y4, -3);
54 DrawEllipse(Osd, x3, y3, x4, y4, -4);
55 Osd->Flush();
56}
57
58// --- DrawSlopes ------------------------------------------------------------
59
60void DrawSlope(cOsd *Osd, int x1, int y1, int x2, int y2, int Type)
61{
62 Osd->DrawRectangle(x1 + 2, y1 + 2, x2 - 2, y2 - 2, clrGreen);
63 Osd->DrawSlope(x1 + 3, y1 + 3, x2 - 3, y2 - 3, clrRed, Type);
64}
65
66void DrawSlopes(cOsd *Osd)
67{
68 int xa = 0;
69 int ya = 0;
70 int xb = Osd->Width() - 1;
71 int yb = Osd->Height() - 1;
72 int x0 = xa;
73 int x4 = xb;
74 int x2 = (x0 + x4) / 2;
75 int x1 = (x0 + x2) / 2;
76 int x3 = (x2 + x4) / 2;
77 int y0 = ya;
78 int y3 = yb;
79 int y2 = (y0 + y3) / 2;
80 int y1 = (y0 + y2) / 2;
81 Osd->DrawRectangle(xa, ya, xb, yb, clrGray50);
82 DrawSlope(Osd, x0, y0, x2, y1, 0);
83 DrawSlope(Osd, x2, y0, x4, y1, 1);
84 DrawSlope(Osd, x0, y1, x2, y2, 2);
85 DrawSlope(Osd, x2, y1, x4, y2, 3);
86 DrawSlope(Osd, x0, y2, x1, y3, 4);
87 DrawSlope(Osd, x1, y2, x2, y3, 5);
88 DrawSlope(Osd, x2, y2, x3, y3, 6);
89 DrawSlope(Osd, x3, y2, x4, y3, 7);
90 Osd->Flush();
91}
92
93// --- DrawImages ------------------------------------------------------------
94
96 int image;
98 };
99
100#define NUMOSDIMAGES 16
101#define NUMOSDIMAGEVARIANTS 8
102
103void DrawImages(cOsd *Osd)
104{
105 // Create images:
107 for (int i = 0; i < NUMOSDIMAGEVARIANTS; i++) {
108 images[i] = new cImage(cSize(
109 i == 0 || i == 1 ? Osd->MaxPixmapSize().Width() + 1 : rand() % Osd->Width(),
110 i == 0 || i == 2 ? Osd->MaxPixmapSize().Height() + 1 : rand() % Osd->Height()));
111 for (int x = 0; x < images[i]->Width(); x++) {
112 for (int y = 0; y < images[i]->Height(); y++) {
113 images[i]->SetPixel(cPoint(x, y),
114 (!x || !y || x == images[i]->Width() - 1 || y == images[i]->Height() - 1) ? clrWhite :
115 (x > images[i]->Width() / 2 ?
116 (y > images[i]->Height() / 2 ? clrBlue : clrGreen) :
117 (y > images[i]->Height() / 2 ? clrRed : clrYellow)));
118 }
119 }
120 }
121 // Store images:
122 tOsdImageRef osdImages[NUMOSDIMAGES];
123 for (int i = 0; i < NUMOSDIMAGES; i++) {
124 osdImages[i].image = cOsdProvider::StoreImage(*images[i % NUMOSDIMAGEVARIANTS]);
125 osdImages[i].size.Set(images[i % NUMOSDIMAGEVARIANTS]->Size());
126 }
127 // Delete images:
128 for (int i = 0; i < NUMOSDIMAGEVARIANTS; i++)
129 delete images[i];
130 // Draw images:
131 for (int i = 0; i < NUMOSDIMAGES; i++)
132 Osd->DrawImage(cPoint(rand() % (Osd->Width() + osdImages[i].size.Width()), rand() % (Osd->Height() + osdImages[i].size.Height())).Shifted(-osdImages[i].size.Width(), -osdImages[i].size.Height()), osdImages[i].image);
133 // Drop image references:
134 for (int i = 0; i < NUMOSDIMAGES; i++)
135 cOsdProvider::DropImage(osdImages[i].image);
136 Osd->Flush();
137}
138
139// --- DrawEllipseAlignments -------------------------------------------------
140
142{
144 int xa = 0;
145 int ya = 0;
146 int xb = Osd->Width() - 1;
147 int yb = Osd->Height() - 1;
148 Osd->DrawRectangle(xa, ya, xb, yb, clrBlack);
149 int d = 50;
150 int a = d / 2 + 1;
151 int t = a * 2;
152 int n = 30;
153 for (int i = 0; i < n; i++) {
154 Osd->DrawRectangle(a, t, a + d - 1, t + d - 1, clrGreen);
155 Osd->DrawEllipse(a, t - d / 2, a + d - 1, t, clrGreen, 6);
156 Osd->DrawEllipse(a, t + d, a + d - 1, t + d + d / 2, clrGreen, 8);
157 Osd->DrawText(a + d / 3, t + d / 3, itoa(d), clrRed, clrGreen, Font);
158 a += d + 5;
159 d++;
160 }
161 d = 50;
162 a = d * 3;
163 n = 20;
164 for (int i = 0; i < n; i++) {
165 Osd->DrawRectangle(t, a, t + d - 1, a + d - 1, clrGreen);
166 Osd->DrawEllipse(t - d / 2, a, t, a + d - 1, clrGreen, 7);
167 Osd->DrawEllipse(t + d, a, t + d + d / 2, a + d - 1, clrGreen, 5);
168 Osd->DrawText(t + d / 3, a + d / 3, itoa(d), clrRed, clrGreen, Font);
169 a += d + 5;
170 d++;
171 }
172 d = 50;
173 a = d * 3;
174 t = d * 5;
175 n = 30;
176 for (int i = 0; i < n; i++) {
177 Osd->DrawRectangle(a, t, a + d - 1, t + d - 1, clrGreen);
178 Osd->DrawEllipse(a, t - d, a + d - 1, t, clrGreen, 2);
179 Osd->DrawEllipse(a, t + d, a + d - 1, t + d + d, clrGreen, 3);
180 Osd->DrawText(a + d / 3, t + d / 3, itoa(d), clrRed, clrGreen, Font);
181 a += d + 5;
182 d++;
183 }
184 d = 50;
185 a = d * 3;
186 t = d * 9;
187 n = 30;
188 for (int i = 0; i < n; i++) {
189 Osd->DrawRectangle(a, t, a + d - 1, t + d - 1, clrGreen);
190 Osd->DrawEllipse(a, t - d, a + d - 1, t, clrGreen, 1);
191 Osd->DrawEllipse(a, t + d, a + d - 1, t + d + d, clrGreen, 4);
192 Osd->DrawText(a + d / 3, t + d / 3, itoa(d), clrRed, clrGreen, Font);
193 a += d + 5;
194 d++;
195 }
196 d = 50;
197 a = d * 12;
198 t = d * 5;
199 n = 20;
200 for (int i = 0; i < n; i++) {
201 Osd->DrawRectangle(t, a, t + d - 1, a + d - 1, clrGreen);
202 Osd->DrawEllipse(t - d, a, t, a + d - 1, clrGreen, 2);
203 Osd->DrawEllipse(t + d, a, t + d + d, a + d - 1, clrGreen, 1);
204 Osd->DrawText(t + d / 3, a + d / 3, itoa(d), clrRed, clrGreen, Font);
205 a += d + 5;
206 d++;
207 }
208 d = 50;
209 a = d * 12;
210 t = d * 9;
211 n = 20;
212 for (int i = 0; i < n; i++) {
213 Osd->DrawRectangle(t, a, t + d - 1, a + d - 1, clrGreen);
214 Osd->DrawEllipse(t - d, a, t, a + d - 1, clrGreen, 3);
215 Osd->DrawEllipse(t + d, a, t + d + d, a + d - 1, clrGreen, 4);
216 Osd->DrawText(t + d / 3, a + d / 3, itoa(d), clrRed, clrGreen, Font);
217 a += d + 5;
218 d++;
219 }
220 Osd->Flush();
221 delete Font;
222}
223
224// --- cLineGame -------------------------------------------------------------
225
226class cLineGame : public cOsdObject {
227private:
229 int x;
230 int y;
232public:
233 cLineGame(void);
234 virtual ~cLineGame();
235 virtual void Show(void);
236 virtual eOSState ProcessKey(eKeys Key);
237 };
238
240{
241 osd = NULL;
242 x = y = 0;
243 color = clrRed;
244}
245
247{
248 delete osd;
249}
250
252{
254 if (osd) {
255 int x1 = cOsd::OsdWidth() - 1;
256 int y1 = cOsd::OsdHeight() - 1;
257 while (x1 > 0 && y1 > 0) {
258 tArea Area = { 0, 0, x1, y1, 4 };
259 if (osd->CanHandleAreas(&Area, 1) == oeOk) {
260 osd->SetAreas(&Area, 1);
261 osd->DrawRectangle(0, 0, osd->Width() - 1, osd->Height() - 1, clrGray50);
262 osd->Flush();
263 x = osd->Width() / 2;
264 y = osd->Height() / 2;
265 break;
266 }
267 x1 = x1 * 9 / 10;
268 y1 = y1 * 9 / 10;
269 }
270 }
271}
272
274{
275 eOSState state = cOsdObject::ProcessKey(Key);
276 if (state == osUnknown) {
277 const int d = 4;
278 switch (Key & ~k_Repeat) {
279 case kUp: y = max(0, y - d); break;
280 case kDown: y = min(osd->Height() - d, y + d); break;
281 case kLeft: x = max(0, x - d); break;
282 case kRight: x = min(osd->Width() - d, x + d); break;
283 case kRed: color = clrRed; break;
284 case kGreen: color = clrGreen; break;
285 case kYellow: color = clrYellow; break;
286 case kBlue: color = clrBlue; break;
287 case k1: DrawEllipses(osd);
288 return osContinue;
289 case k2: DrawSlopes(osd);
290 return osContinue;
291 case kBack:
292 case kOk: return osEnd;
293 default: return state;
294 }
295 osd->DrawRectangle(x, y, x + d - 1, y + d - 1, color);
296 osd->Flush();
297 state = osContinue;
298 }
299 return state;
300}
301
302// --- cTrueColorDemo --------------------------------------------------------
303
304class cTrueColorDemo : public cOsdObject, public cThread {
305private:
312 bool SetArea(void);
313 virtual void Action(void);
314 cPixmap *CreateTextPixmap(const char *s, int Line, int Layer, tColor ColorFg, tColor ColorBg, const cFont *Font);
315public:
316 cTrueColorDemo(void);
317 virtual ~cTrueColorDemo();
318 virtual void Show(void);
319 virtual eOSState ProcessKey(eKeys Key);
320 };
321
323{
324 osd = NULL;
325 clockwise = true;
326 destroyablePixmap = NULL;
327 toggleablePixmap = NULL;
328}
329
331{
332 Cancel(3);
333 delete osd;
334}
335
336cPixmap *cTrueColorDemo::CreateTextPixmap(const char *s, int Line, int Layer, tColor ColorFg, tColor ColorBg, const cFont *Font)
337{
338 const int h = Font->Height(s);
339 int w = Font->Width(s);
340 cPixmap *Pixmap = osd->CreatePixmap(Layer, cRect((osd->Width() - w) / 2, Line, w, h));
341 if (Pixmap) {
342 Pixmap->Clear();
343 Pixmap->SetAlpha(0);
344 Pixmap->DrawText(cPoint(0, 0), s, ColorFg, ColorBg, Font, w);
345 }
346 return Pixmap;
347}
348
350{
351 cPixmap *FadeInPixmap = NULL;
352 cPixmap *FadeOutPixmap = NULL;
353 cPixmap *MovePixmap = NULL;
354 cPixmap *NextPixmap = NULL;
355 cPixmap *TilePixmap = NULL;
356 cPixmap *ScrollPixmap = NULL;
357 cPixmap *AnimPixmap = NULL;
360 cFont *LrgFont = cFont::CreateFont(Setup.FontOsd, osd->Height() / 10);
361 int FrameTime = 40; // ms
362 int FadeTime = 1000; // ms
363 int MoveTime = 4000; // ms
364 int TileTime = 6000; // ms
365 int ScrollWaitTime = 1000; // ms
366 int ScrollLineTime = 200; // ms
367 int ScrollTotalTime = 8000; // ms
368 uint64_t Start = 0;
369 uint64_t ScrollStartTime = 0;
370 int ScrollLineNumber = 0;
371 cPoint MoveStart, MoveEnd;
372 cPoint TileStart, TileEnd;
373 cPoint ScrollStart, ScrollEnd;
374 int Line = osd->Height() / 20;
375 int StartLine = Line;
376 cPoint OldCursor;
377 int State = 0;
378 while (Running()) {
380 bool Animated = false;
381 uint64_t Now = cTimeMs::Now();
382 if (FadeInPixmap) {
383 double t = min(double(Now - Start) / FadeTime, 1.0);
384 int Alpha = t * ALPHA_OPAQUE;
385 FadeInPixmap->SetAlpha(Alpha);
386 if (t >= 1)
387 FadeInPixmap = NULL;
388 Animated = true;
389 }
390 if (FadeOutPixmap) {
391 double t = min(double(Now - Start) / FadeTime, 1.0);
392 int Alpha = ALPHA_OPAQUE - t * ALPHA_OPAQUE;
393 FadeOutPixmap->SetAlpha(Alpha);
394 if (t >= 1)
395 FadeOutPixmap = NULL;
396 Animated = true;
397 }
398 if (MovePixmap) {
399 double t = min(double(Now - Start) / MoveTime, 1.0);
400 int x = MoveStart.X() + t * (MoveEnd.X() - MoveStart.X());
401 int y = MoveStart.Y() + t * (MoveEnd.Y() - MoveStart.Y());
402 cRect r = MovePixmap->ViewPort();
403 r.SetPoint(x, y);
404 MovePixmap->SetViewPort(r);
405 if (t >= 1)
406 MovePixmap = NULL;
407 Animated = true;
408 }
409 if (TilePixmap) {
410 double t = min(double(Now - Start) / TileTime, 1.0);
411 int x = TileStart.X() + t * (TileEnd.X() - TileStart.X());
412 int y = TileStart.Y() + t * (TileEnd.Y() - TileStart.Y());
413 TilePixmap->SetDrawPortPoint(cPoint(x, y));
414 if (t >= 1) {
415 destroyablePixmap = TilePixmap;
416 TilePixmap = NULL;
417 }
418 Animated = true;
419 }
420 if (ScrollPixmap) {
421 if (int(Now - Start) > ScrollWaitTime) {
422 if (ScrollStartTime) {
423 double t = min(double(Now - ScrollStartTime) / ScrollLineTime, 1.0);
424 int x = ScrollStart.X() + t * (ScrollEnd.X() - ScrollStart.X());
425 int y = ScrollStart.Y() + t * (ScrollEnd.Y() - ScrollStart.Y());
426 ScrollPixmap->SetDrawPortPoint(cPoint(x, y));
427 if (t >= 1) {
428 if (int(Now - Start) < ScrollTotalTime) {
429 cRect r = ScrollPixmap->DrawPort();
430 r.SetPoint(-r.X(), -r.Y());
431 ScrollPixmap->Pan(cPoint(0, 0), r);
432 cString s = cString::sprintf("Line %d", ++ScrollLineNumber);
433 ScrollPixmap->DrawRectangle(cRect(0, ScrollPixmap->ViewPort().Height(), ScrollPixmap->DrawPort().Width(), ScrollPixmap->DrawPort().Height()), clrTransparent);
434 ScrollPixmap->DrawText(cPoint(0, ScrollPixmap->ViewPort().Height()), s, clrYellow, clrTransparent, OsdFont);
435 ScrollStartTime = Now;
436 }
437 else {
438 FadeOutPixmap = ScrollPixmap;
439 ScrollPixmap = NULL;
441 }
442 }
443 }
444 else
445 ScrollStartTime = Now;
446 }
447 Animated = true;
448 }
449 if (AnimPixmap) {
450 int d = AnimPixmap->ViewPort().Height();
451 if (clockwise)
452 d = -d;
453 cPoint p = AnimPixmap->DrawPort().Point().Shifted(0, d);
454 if (clockwise && p.Y() <= -AnimPixmap->DrawPort().Height())
455 p.SetY(0);
456 else if (!clockwise && p.Y() > 0)
457 p.SetY(-(AnimPixmap->DrawPort().Height() - AnimPixmap->ViewPort().Height()));
458 AnimPixmap->SetDrawPortPoint(p);
459 }
460 if (!Animated) {
461 switch (State) {
462 case 0: {
463 FadeInPixmap = CreateTextPixmap("VDR", Line, 1, clrYellow, clrTransparent, LrgFont);
464 if (FadeInPixmap)
465 Line += FadeInPixmap->DrawPort().Height();
467 State++;
468 }
469 break;
470 case 1: {
471 FadeInPixmap = CreateTextPixmap("Video Disk Recorder", Line, 3, clrYellow, clrTransparent, OsdFont);
472 if (FadeInPixmap)
473 Line += FadeInPixmap->DrawPort().Height();
475 State++;
476 }
477 break;
478 case 2: {
479 FadeInPixmap = CreateTextPixmap("True Color OSD Demo", Line, 1, clrYellow, clrTransparent, OsdFont);
480 if (FadeInPixmap)
481 Line += FadeInPixmap->DrawPort().Height();
483 State++;
484 }
485 break;
486 case 3: {
487 NextPixmap = CreateTextPixmap("Millions of colors", Line, 1, clrYellow, clrTransparent, LrgFont);
488 if (NextPixmap) {
489 FadeInPixmap = NextPixmap;
491 StartLine = Line;
492 Line += NextPixmap->DrawPort().Height();
493 }
494 State++;
495 }
496 break;
497 case 4: {
498 Line += osd->Height() / 10;
499 int w = osd->Width() / 2;
500 int h = osd->Height() - Line - osd->Height() / 10;
501 cImage Image(cSize(w, h));
502 for (int y = 0; y < h; y++) {
503 for (int x = 0; x < w; x++)
504 Image.SetPixel(cPoint(x, y), HsvToColor(360 * double(x) / w, 1 - double(y) / h, 1) | 0xDF000000);
505 }
506 if (cPixmap *Pixmap = osd->CreatePixmap(2, cRect((osd->Width() - w) / 2, Line, w, h))) {
507 Pixmap->DrawImage(cPoint(0, 0), Image);
508 toggleablePixmap = Pixmap;
509 }
510 State++;
511 }
512 break;
513 case 5: {
514 if (NextPixmap) {
515 MovePixmap = NextPixmap;
516 MoveStart = MovePixmap->ViewPort().Point();
517 MoveEnd.Set(osd->Width() - MovePixmap->ViewPort().Width(), osd->Height() - MovePixmap->ViewPort().Height());
519 }
520 State++;
521 }
522 break;
523 case 6: {
524 TilePixmap = CreateTextPixmap("Tiled Pixmaps", StartLine, 1, clrRed, clrWhite, OsdFont);
525 if (TilePixmap) {
526 TilePixmap->SetViewPort(TilePixmap->ViewPort().Grown(TilePixmap->DrawPort().Width(), TilePixmap->DrawPort().Height()));
527 TilePixmap->SetAlpha(200);
528 TilePixmap->SetTile(true);
529 TileStart = TilePixmap->DrawPort().Point();
530 TileEnd = TileStart.Shifted(TilePixmap->ViewPort().Width(), TilePixmap->ViewPort().Height());
531 MovePixmap = TilePixmap;
532 MoveStart = MovePixmap->ViewPort().Point();
533 MoveEnd.Set(10, osd->Height() - MovePixmap->ViewPort().Height() - 10);
535 }
536 State++;
537 }
538 break;
539 case 7: {
540 const char *Text = "Scrolling Pixmaps";
541 int w = OsdFont->Width(Text);
542 int h = OsdFont->Height();
543 if (cPixmap *Pixmap = osd->CreatePixmap(2, cRect((osd->Width() - w) / 2, StartLine, w, 2 * h), cRect(0, 0, w, 3 * h))) {
544 Pixmap->Clear();
545 Pixmap->DrawText(cPoint(0, 0), Text, clrYellow, clrTransparent, OsdFont);
546 cString s = cString::sprintf("Line %d", ++ScrollLineNumber);
547 Pixmap->DrawText(cPoint(0, Pixmap->ViewPort().Height()), s, clrYellow, clrTransparent, OsdFont);
548 ScrollPixmap = Pixmap;
549 ScrollStart.Set(0, 0);
550 ScrollEnd.Set(0, -h);
552 }
553 State++;
554 }
555 break;
556 case 8: {
557 const char *Text = "Animation";
558 const int Size = SmlFont->Width(Text) + 10;
559 const int NumDots = 12;
560 const int AnimFrames = NumDots;
561 int Rows = min(osd->MaxPixmapSize().Height() / Size, AnimFrames);
562 int Cols = (AnimFrames + Rows - 1) / Rows;
563 // Temporarily using pixmap layer 0 to have the text alpha blended:
564 AnimPixmap = osd->CreatePixmap(0, cRect((osd->Width() - Size) / 2, StartLine, Size, Size), cRect(0, 0, Size * Cols, Size * Rows));
565 if (AnimPixmap) {
566 AnimPixmap->SetAlpha(0);
567 AnimPixmap->Clear();
568 const int Diameter = Size / 5;
569 for (int Frame = 0; Frame < AnimFrames; Frame++) {
570 int x0 = Frame / Rows * Size;
571 int y0 = Frame % Rows * Size;
572 AnimPixmap->DrawEllipse(cRect(x0, y0, Size, Size), 0xDDFFFFFF);
573 int xc = x0 + Size / 2 - Diameter / 2;
574 int yc = y0 + Size / 2 - Diameter / 2;
575 int Color = 0xFF;
576 int Delta = Color / NumDots / 3;
577 for (int a = 0; a < NumDots; a++) {
578 double t = 2 * M_PI * (Frame + a) / NumDots;
579 int x = xc + ((Size - Diameter) / 2 - 5) * cos(t);
580 int y = yc + ((Size - Diameter) / 2 - 5) * sin(t);
581 AnimPixmap->DrawEllipse(cRect(x, y, Diameter, Diameter), ArgbToColor(0xFF, Color, Color, Color));
582 Color -= Delta;
583 }
584 AnimPixmap->DrawText(cPoint(x0, y0), Text, clrBlack, clrTransparent, SmlFont, Size, Size, taCenter);
585 }
586 AnimPixmap->SetLayer(3); // now setting the actual pixmap layer
587 FadeInPixmap = AnimPixmap;
589 OldCursor = cursor = AnimPixmap->ViewPort().Point();
590 cursorLimits.Set(0, 0, osd->Width(), osd->Height());
593 cursorLimits.Grow(-10, -10);
595 }
596 State++;
597 }
598 break;
599 case 9: {
601 if (cursor != OldCursor) {
602 MovePixmap = AnimPixmap;
603 MoveStart = MovePixmap->ViewPort().Point();
604 MoveEnd = OldCursor = cursor;
605 MoveTime = 500;
607 }
608 }
609 break;
610 }
611 }
612 osd->Flush();
614 int Delta = cTimeMs::Now() - Now;
615 if (Delta < FrameTime)
616 cCondWait::SleepMs(FrameTime - Delta);
617 }
618 destroyablePixmap = NULL;
619 toggleablePixmap = NULL;
620 delete OsdFont;
621 delete SmlFont;
622 delete LrgFont;
623}
624
626{
627 if (osd) {
628 tArea Area = { 0, 0, cOsd::OsdWidth() - 1, cOsd::OsdHeight() - 1, 32 };
629 return osd->SetAreas(&Area, 1) == oeOk;
630 }
631 return false;
632}
633
635{
637 if (osd) {
638 if (SetArea()) {
639 osd->DrawRectangle(0, 0, osd->Width() - 1, osd->Height() - 1, clrGray50);
640 osd->Flush();
641 Start();
642 }
643 }
644}
645
647{
648 eOSState state = cOsdObject::ProcessKey(Key);
649 if (state == osUnknown) {
652 const int d = 80;
653 switch (Key & ~k_Repeat) {
654 case kUp: cursor.SetY(max(cursorLimits.Top(), cursor.Y() - d)); clockwise = false; break;
655 case kDown: cursor.SetY(min(cursorLimits.Bottom(), cursor.Y() + d)); clockwise = true; break;
656 case kLeft: cursor.SetX(max(cursorLimits.Left(), cursor.X() - d)); clockwise = false; break;
657 case kRight: cursor.SetX(min(cursorLimits.Right(), cursor.X() + d)); clockwise = true; break;
658 case kRed: if (destroyablePixmap) {
660 destroyablePixmap = NULL;
661 }
662 break;
663 case kGreen: if (toggleablePixmap)
665 break;
666 case k1: Cancel(3);
667 SetArea();
669 break;
670 case k2: Cancel(3);
671 SetArea();
673 break;
674 case k3: Cancel(3);
675 SetArea();
677 break;
678 case k4: Cancel(3);
679 SetArea();
681 return osContinue;
682 case kBack:
683 case kOk: return osEnd;
684 default: return state;
685 }
686 state = osContinue;
687 }
688 return state;
689}
690
691// --- cPluginOsddemo --------------------------------------------------------
692
693class cPluginOsddemo : public cPlugin {
694private:
695 // Add any member variables or functions you may need here.
696public:
697 cPluginOsddemo(void);
698 virtual ~cPluginOsddemo();
699 virtual const char *Version(void) { return VERSION; }
700 virtual const char *Description(void) { return DESCRIPTION; }
701 virtual const char *CommandLineHelp(void);
702 virtual bool ProcessArgs(int argc, char *argv[]);
703 virtual bool Start(void);
704 virtual void Housekeeping(void);
705 virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
706 virtual cOsdObject *MainMenuAction(void);
707 virtual cMenuSetupPage *SetupMenu(void);
708 virtual bool SetupParse(const char *Name, const char *Value);
709 };
710
712{
713 // Initialize any member variables here.
714 // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
715 // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
716}
717
719{
720 // Clean up after yourself!
721}
722
724{
725 // Return a string that describes all known command line options.
726 return NULL;
727}
728
729bool cPluginOsddemo::ProcessArgs(int argc, char *argv[])
730{
731 // Implement command line argument processing here if applicable.
732 return true;
733}
734
736{
737 // Start any background activities the plugin shall perform.
738 return true;
739}
740
742{
743 // Perform any cleanup or other regular tasks.
744}
745
747{
748 // Perform the action when selected from the main VDR menu.
750 return new cTrueColorDemo;
751 return new cLineGame;
752}
753
755{
756 // Return a setup menu in case the plugin supports one.
757 return NULL;
758}
759
760bool cPluginOsddemo::SetupParse(const char *Name, const char *Value)
761{
762 // Parse your own setup parameters and store their values.
763 return false;
764}
765
766VDRPLUGINCREATOR(cPluginOsddemo); // Don't touch this!
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
Definition thread.c:72
virtual int Width(void) const
Returns the original character width as requested when the font was created, or 0 if the default widt...
Definition skincurses.c:23
virtual int Height(void) const
Returns the height of this font in pixel (all characters have the same height).
Definition skincurses.c:26
Definition font.h:37
virtual int Width(void) const =0
Returns the original character width as requested when the font was created, or 0 if the default widt...
static cFont * CreateFont(const char *Name, int CharHeight, int CharWidth=0)
Creates a new font object with the given Name and makes its characters CharHeight pixels high.
Definition font.c:429
virtual int Height(void) const =0
Returns the height of this font in pixel (all characters have the same height).
Definition osd.h:419
int Height(void) const
Definition osd.h:436
int Width(void) const
Definition osd.h:435
void SetPixel(const cPoint &Point, tColor Color)
Sets the pixel at the given Point to Color.
Definition osd.h:442
virtual void Show(void)
Definition osddemo.c:251
cOsd * osd
Definition osddemo.c:228
cLineGame(void)
Definition osddemo.c:239
tColor color
Definition osddemo.c:231
virtual ~cLineGame()
Definition osddemo.c:246
virtual eOSState ProcessKey(eKeys Key)
Definition osddemo.c:273
virtual eOSState ProcessKey(eKeys Key)
Definition osdbase.h:82
static void DropImage(int ImageHandle)
Drops the image referenced by the given ImageHandle.
Definition osd.c:2391
static int StoreImage(const cImage &Image)
Stores the given Image for later use with DrawImage() on an OSD or pixmap.
Definition osd.c:2384
static bool SupportsTrueColor(void)
Returns true if the current OSD provider is able to handle a true color OSD.
Definition osd.c:2345
static cOsd * NewOsd(int Left, int Top, uint Level=OSD_LEVEL_DEFAULT)
Returns a pointer to a newly created cOsd object, which will be located at the given coordinates.
Definition osd.c:2290
The cOsd class is the interface to the "On Screen Display".
Definition osd.h:753
virtual const cSize & MaxPixmapSize(void) const
Returns the maximum possible size of a pixmap this OSD can create.
Definition osd.c:1972
virtual void DrawImage(const cPoint &Point, const cImage &Image)
Draws the given Image on this OSD at the given Point.
Definition osd.c:2172
int Width(void)
Definition osd.h:844
static int OsdHeight(void)
Definition osd.h:831
virtual eOsdError SetAreas(const tArea *Areas, int NumAreas)
Sets the sub-areas to the given areas.
Definition osd.c:2092
virtual void DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants=0)
Draws a filled ellipse defined by the upper left (x1, y1) and lower right (x2, y2) corners with the g...
Definition osd.c:2246
virtual void DestroyPixmap(cPixmap *Pixmap)
Destroys the given Pixmap, which has previously been created by a call to CreatePixmap().
Definition osd.c:1989
virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas)
Checks whether the OSD can display the given set of sub-areas.
Definition osd.c:2070
static int OsdTop(void)
Definition osd.h:829
virtual cPixmap * CreatePixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort=cRect::Null)
Creates a new true color pixmap on this OSD (see cPixmap for details).
Definition osd.c:1977
virtual void Flush(void)
Actually commits all data to the OSD hardware.
Definition osd.c:2266
virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
Draws a filled rectangle defined by the upper left (x1, y1) and lower right (x2, y2) corners with the...
Definition osd.c:2236
static int OsdLeft(void)
Definition osd.h:828
virtual void DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type)
Draws a "slope" into the rectangle defined by the upper left (x1, y1) and lower right (x2,...
Definition osd.c:2256
static int OsdWidth(void)
Definition osd.h:830
int Height(void)
Definition osd.h:845
virtual void DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width=0, int Height=0, int Alignment=taDefault)
Draws the given string at coordinates (x, y) with the given foreground and background color and font.
Definition osd.c:2226
Definition osd.h:459
const cRect & DrawPort(void) const
Returns the pixmap's draw port, which is relative to the view port.
Definition osd.h:548
virtual void SetViewPort(const cRect &Rect)
Sets the pixmap's view port to the given Rect.
Definition osd.c:1068
static void Unlock(void)
Definition osd.h:540
virtual void Clear(void)=0
Clears the pixmap's draw port by setting all pixels to be fully transparent.
const cRect & ViewPort(void) const
Returns the pixmap's view port, which is relative to the OSD's origin.
Definition osd.h:544
virtual void Pan(const cPoint &Dest, const cRect &Source=cRect::Null)=0
Does the same as Scroll(), but also shifts the draw port accordingly, so that the view port doesn't g...
virtual void DrawRectangle(const cRect &Rect, tColor Color)=0
Draws a filled rectangle with the given Color.
virtual void SetDrawPortPoint(const cPoint &Point, bool Dirty=true)
Sets the pixmap's draw port to the given Point.
Definition osd.c:1085
static void Lock(void)
All public member functions of cPixmap set locks as necessary to make sure they are thread-safe (unle...
Definition osd.h:534
virtual void SetLayer(int Layer)
Sets the layer of this pixmap to the given value.
Definition osd.c:1024
virtual void DrawEllipse(const cRect &Rect, tColor Color, int Quadrants=0)=0
Draws a filled ellipse with the given Color that fits into the given rectangle.
virtual void DrawText(const cPoint &Point, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width=0, int Height=0, int Alignment=taDefault)=0
Draws the given string at Point with the given foreground and background color and font.
virtual void SetAlpha(int Alpha)
Sets the alpha value of this pixmap to the given value.
Definition osd.c:1046
virtual void SetTile(bool Tile)
Sets the tile property of this pixmap to the given value.
Definition osd.c:1057
int Layer(void) const
Definition osd.h:541
virtual const char * MainMenuEntry(void)
Definition osddemo.c:705
virtual bool ProcessArgs(int argc, char *argv[])
Definition osddemo.c:729
virtual bool Start(void)
Definition osddemo.c:735
cPluginOsddemo(void)
Definition osddemo.c:711
virtual ~cPluginOsddemo()
Definition osddemo.c:718
virtual const char * CommandLineHelp(void)
Definition osddemo.c:723
virtual void Housekeeping(void)
Definition osddemo.c:741
virtual cOsdObject * MainMenuAction(void)
Definition osddemo.c:746
virtual const char * Description(void)
Definition osddemo.c:700
virtual cMenuSetupPage * SetupMenu(void)
Definition osddemo.c:754
virtual const char * Version(void)
Definition osddemo.c:699
virtual bool SetupParse(const char *Name, const char *Value)
Definition osddemo.c:760
const char * Name(void)
Definition plugin.h:36
Definition osd.h:306
void SetY(int Y)
Definition osd.h:321
int Y(void) const
Definition osd.h:319
int X(void) const
Definition osd.h:318
void Set(int X, int Y)
Definition osd.h:322
void SetX(int X)
Definition osd.h:320
cPoint Shifted(int Dx, int Dy) const
Definition osd.h:326
Definition osd.h:352
int Top(void) const
Definition osd.h:370
const cPoint & Point(void) const
Definition osd.h:373
void SetPoint(int X, int Y)
Definition osd.h:377
int Height(void) const
Definition osd.h:368
int Left(void) const
Definition osd.h:369
int Bottom(void) const
Definition osd.h:372
int Y(void) const
Definition osd.h:366
void SetRight(int Right)
Definition osd.h:387
int X(void) const
Definition osd.h:365
void Grow(int Dx, int Dy)
Grows the rectangle by the given number of pixels in either direction.
Definition osd.c:892
int Right(void) const
Definition osd.h:371
void SetBottom(int Bottom)
Definition osd.h:388
int Width(void) const
Definition osd.h:367
cRect Grown(int Dw, int Dh) const
Definition osd.h:396
void Set(int X, int Y, int Width, int Height)
Definition osd.h:375
int FontOsdSize
Definition config.h:341
int FontSmlSize
Definition config.h:342
char FontOsd[MAXFONTNAME]
Definition config.h:335
char FontSml[MAXFONTNAME]
Definition config.h:336
Definition osd.h:330
int Height(void) const
Definition osd.h:342
int Width(void) const
Definition osd.h:341
void Set(int Width, int Height)
Definition osd.h:345
static cString sprintf(const char *fmt,...) __attribute__((format(printf
Definition tools.c:1188
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
Definition thread.c:304
bool Running(void)
Returns false if a derived cThread object shall leave its Action() function.
Definition thread.h:101
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
Definition thread.c:354
static uint64_t Now(void)
Definition tools.c:762
cRect cursorLimits
Definition osddemo.c:308
virtual void Show(void)
Definition osddemo.c:634
cTrueColorDemo(void)
Definition osddemo.c:322
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
Definition osddemo.c:349
virtual ~cTrueColorDemo()
Definition osddemo.c:330
cPoint cursor
Definition osddemo.c:307
virtual eOSState ProcessKey(eKeys Key)
Definition osddemo.c:646
cPixmap * destroyablePixmap
Definition osddemo.c:310
cPixmap * CreateTextPixmap(const char *s, int Line, int Layer, tColor ColorFg, tColor ColorBg, const cFont *Font)
Definition osddemo.c:336
bool SetArea(void)
Definition osddemo.c:625
cPixmap * toggleablePixmap
Definition osddemo.c:311
cSetup Setup
Definition config.c:372
uint32_t tColor
Definition font.h:30
eKeys
Definition keys.h:16
@ kRight
Definition keys.h:23
@ k3
Definition keys.h:28
@ kRed
Definition keys.h:24
@ kUp
Definition keys.h:17
@ kDown
Definition keys.h:18
@ kGreen
Definition keys.h:25
@ k1
Definition keys.h:28
@ kLeft
Definition keys.h:22
@ kBlue
Definition keys.h:27
@ k2
Definition keys.h:28
@ kYellow
Definition keys.h:26
@ k4
Definition keys.h:28
@ kBack
Definition keys.h:21
@ k_Repeat
Definition keys.h:61
@ kOk
Definition keys.h:20
tColor HsvToColor(double H, double S, double V)
Converts the given Hue (0..360), Saturation (0..1) and Value (0..1) to an RGB tColor value.
Definition osd.c:19
#define ALPHA_OPAQUE
Definition osd.h:26
@ taCenter
Definition osd.h:158
@ oeOk
Definition osd.h:44
@ clrGray50
Definition osd.h:33
#define LOCK_PIXMAPS
Definition osd.h:707
tColor ArgbToColor(uint8_t A, uint8_t R, uint8_t G, uint8_t B)
Definition osd.h:58
eOSState
Definition osdbase.h:18
@ osEnd
Definition osdbase.h:34
@ osContinue
Definition osdbase.h:19
@ osUnknown
Definition osdbase.h:18
static const char * VERSION
Definition osddemo.c:12
static const char * DESCRIPTION
Definition osddemo.c:13
void DrawSlope(cOsd *Osd, int x1, int y1, int x2, int y2, int Type)
Definition osddemo.c:60
void DrawEllipseAlignments(cOsd *Osd)
Definition osddemo.c:141
#define NUMOSDIMAGES
Definition osddemo.c:100
#define NUMOSDIMAGEVARIANTS
Definition osddemo.c:101
void DrawSlopes(cOsd *Osd)
Definition osddemo.c:66
void DrawEllipse(cOsd *Osd, int x1, int y1, int x2, int y2, int Quadrants)
Definition osddemo.c:18
void DrawImages(cOsd *Osd)
Definition osddemo.c:103
void DrawEllipses(cOsd *Osd)
Definition osddemo.c:24
static const char * MAINMENUENTRY
Definition osddemo.c:14
#define VDRPLUGINCREATOR(PluginClass)
Definition plugin.h:18
#define clrBlue
Definition skincurses.c:41
#define clrTransparent
Definition skincurses.c:36
#define clrBlack
Definition skincurses.c:37
#define clrWhite
Definition skincurses.c:44
#define clrGreen
Definition skincurses.c:39
#define clrRed
Definition skincurses.c:38
#define clrYellow
Definition skincurses.c:40
static const cCursesFont Font
Definition skincurses.c:31
Definition osd.h:298
cSize size
Definition osddemo.c:97
#define LOCK_THREAD
Definition thread.h:167
cString itoa(int n)
Definition tools.c:447
T min(T a, T b)
Definition tools.h:63
T max(T a, T b)
Definition tools.h:64