vdr  2.4.7
skincurses.c
Go to the documentation of this file.
1 /*
2  * skincurses.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: skincurses.c 4.6 2020/05/11 10:23:15 kls Exp $
7  */
8 
9 #include <ncurses.h>
10 #include <vdr/osd.h>
11 #include <vdr/plugin.h>
12 #include <vdr/skins.h>
13 #include <vdr/videodir.h>
14 
15 static const char *VERSION = "2.4.2";
16 static const char *DESCRIPTION = trNOOP("A text only skin");
17 static const char *MAINMENUENTRY = NULL;
18 
19 // --- cCursesFont -----------------------------------------------------------
20 
21 class cCursesFont : public cFont {
22 public:
23  virtual int Width(void) const { return 1; }
24  virtual int Width(uint c) const { return 1; }
25  virtual int Width(const char *s) const { return s ? Utf8StrLen(s) : 0; }
26  virtual int Height(void) const { return 1; }
27  virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {}
28  virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {}
29  };
30 
31 static const cCursesFont Font = cCursesFont(); // w/o the '= cCursesFont()' gcc 4.6 complains - can anybody explain why this is necessary?
32 
33 // --- cCursesOsd ------------------------------------------------------------
34 
35 #define clrBackground COLOR_BLACK
36 #define clrTransparent clrBackground
37 #define clrBlack clrBackground
38 #define clrRed COLOR_RED
39 #define clrGreen COLOR_GREEN
40 #define clrYellow COLOR_YELLOW
41 #define clrBlue COLOR_BLUE
42 #define clrMagenta COLOR_MAGENTA
43 #define clrCyan COLOR_CYAN
44 #define clrWhite COLOR_WHITE
45 
46 static int clrMessage[] = {
47  clrBlack,
48  clrCyan,
49  clrBlack,
50  clrGreen,
51  clrBlack,
52  clrYellow,
53  clrWhite,
54  clrRed
55  };
56 
57 static int ScOsdWidth = 50;
58 static int ScOsdHeight = 20;
59 
60 class cCursesOsd : public cOsd {
61 private:
62  WINDOW *savedRegion;
64  void SetColor(int colorFg, int colorBg = clrBackground);
65 public:
66  cCursesOsd(int Left, int Top);
67  virtual ~cCursesOsd();
68  virtual void SaveRegion(int x1, int y1, int x2, int y2);
69  virtual void RestoreRegion(void);
70  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);
71  virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color);
72  virtual void Flush(void);
73  };
74 
75 cCursesOsd::cCursesOsd(int Left, int Top)
76 :cOsd(Left, Top, 0)
77 {
78  savedRegion = NULL;
79 
80  start_color();
81  leaveok(stdscr, true);
82  refresh(); // to react on changes to screen size
83 
84  int begy, begx;
85  int maxy, maxx;
86  getmaxyx(stdscr, maxy, maxx);
87  getbegyx(stdscr, begy, begx);
88  ScOsdWidth = maxx - begx;
89  ScOsdHeight = maxy - begy;
90 }
91 
93 {
94  erase();
95  Flush();
96 }
97 
98 void cCursesOsd::SetColor(int colorFg, int colorBg)
99 {
100  int color = (colorBg << 16) | colorFg | 0x80000000;
101  int i = colorPairs.IndexOf(color);
102  if (i < 0) {
103  colorPairs.Append(color);
104  i = colorPairs.Size() - 1;
105  init_pair(i + 1, colorFg, colorBg);
106  }
107  attrset(COLOR_PAIR(i + 1));
108 }
109 
110 void cCursesOsd::SaveRegion(int x1, int y1, int x2, int y2)
111 {
112  if (savedRegion) {
113  delwin(savedRegion);
114  savedRegion = NULL;
115  }
116  savedRegion = newwin(y2 - y1 + 1, x2 - x1 + 1, y1, x1);
117  if (savedRegion)
118  copywin(stdscr, savedRegion, y1, x1, 0, 0, y2 - y1, x2 - x1, false);
119 }
120 
122 {
123  if (savedRegion) {
124  overwrite(savedRegion, stdscr);
125  delwin(savedRegion);
126  savedRegion = NULL;
127  }
128 }
129 
130 void cCursesOsd::DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width, int Height, int Alignment)
131 {
132  int w = Font->Width(s);
133  int h = Font->Height();
134  if (Width || Height) {
135  int cw = Width ? Width : w;
136  int ch = Height ? Height : h;
137  DrawRectangle(x, y, x + cw - 1, y + ch - 1, ColorBg);
138  if (Width) {
139  if ((Alignment & taLeft) != 0)
140  ;
141  else if ((Alignment & taRight) != 0) {
142  if (w < Width)
143  x += Width - w;
144  }
145  else { // taCentered
146  if (w < Width)
147  x += (Width - w) / 2;
148  }
149  }
150  if (Height) {
151  if ((Alignment & taTop) != 0)
152  ;
153  else if ((Alignment & taBottom) != 0) {
154  if (h < Height)
155  y += Height - h;
156  }
157  else { // taCentered
158  if (h < Height)
159  y += (Height - h) / 2;
160  }
161  }
162  }
163  SetColor(ColorFg, ColorBg);
164  mvaddnstr(y, x, s, Width ? Width : ScOsdWidth - x);
165 }
166 
167 void cCursesOsd::DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
168 {
169  SetColor(Color, Color);
170  int dx = x2 - x1;
171  int dy = y2 - y1;
172  if (dx >= dy) {
173  for (int y = y1; y <= y2; y++)
174  mvhline(y, x1, ' ', dx + 1);
175  }
176  else {
177  for (int x = x1; x <= x2; x++)
178  mvvline(y1, x, ' ', dy + 1);
179  }
180 }
181 
183 {
184  refresh();
185 }
186 
187 // --- cSkinCursesDisplayChannel ---------------------------------------------
188 
190 private:
193  bool message;
194 public:
195  cSkinCursesDisplayChannel(bool WithInfo);
196  virtual ~cSkinCursesDisplayChannel();
197  virtual void SetChannel(const cChannel *Channel, int Number);
198  virtual void SetEvents(const cEvent *Present, const cEvent *Following);
199  virtual void SetMessage(eMessageType Type, const char *Text);
200  virtual void Flush(void);
201  };
202 
204 {
205  int Lines = WithInfo ? 5 : 1;
206  message = false;
207  osd = new cCursesOsd(0, Setup.ChannelInfoPos ? 0 : ScOsdHeight - Lines);
208  timeWidth = strlen("00:00");
209  osd->DrawRectangle(0, 0, ScOsdWidth - 1, Lines - 1, clrBackground);
210 }
211 
213 {
214  delete osd;
215 }
216 
217 void cSkinCursesDisplayChannel::SetChannel(const cChannel *Channel, int Number)
218 {
219  osd->DrawRectangle(0, 0, ScOsdWidth - 1, 0, clrBackground);
220  osd->DrawText(0, 0, ChannelString(Channel, Number), clrWhite, clrBackground, &Font);
221 }
222 
223 void cSkinCursesDisplayChannel::SetEvents(const cEvent *Present, const cEvent *Following)
224 {
225  osd->DrawRectangle(0, 1, timeWidth - 1, 4, clrRed);
227  for (int i = 0; i < 2; i++) {
228  const cEvent *e = !i ? Present : Following;
229  if (e) {
230  osd->DrawText( 0, 2 * i + 1, e->GetTimeString(), clrWhite, clrRed, &Font);
231  osd->DrawText(timeWidth + 1, 2 * i + 1, e->Title(), clrCyan, clrBackground, &Font);
232  osd->DrawText(timeWidth + 1, 2 * i + 2, e->ShortText(), clrYellow, clrBackground, &Font);
233  }
234  }
235 }
236 
238 {
239  if (Text) {
240  osd->SaveRegion(0, 0, ScOsdWidth - 1, 0);
241  osd->DrawText(0, 0, Text, clrMessage[2 * Type], clrMessage[2 * Type + 1], &Font, ScOsdWidth, 0, taCenter);
242  message = true;
243  }
244  else {
245  osd->RestoreRegion();
246  message = false;
247  }
248 }
249 
251 {
252  if (!message) {
253  cString date = DayDateTime();
255  }
256  osd->Flush();
257 }
258 
259 // --- cSkinCursesDisplayMenu ------------------------------------------------
260 
262 private:
266  void DrawTitle(void);
267  void DrawScrollbar(int Total, int Offset, int Shown, int Top, int Height, bool CanScrollUp, bool CanScrollDown);
268  void SetTextScrollbar(void);
269 public:
271  virtual ~cSkinCursesDisplayMenu();
272  virtual void Scroll(bool Up, bool Page);
273  virtual int MaxItems(void);
274  virtual void Clear(void);
275  virtual void SetTitle(const char *Title);
276  virtual void SetButtons(const char *Red, const char *Green = NULL, const char *Yellow = NULL, const char *Blue = NULL);
277  virtual void SetMessage(eMessageType Type, const char *Text);
278  virtual void SetItem(const char *Text, int Index, bool Current, bool Selectable);
279  virtual void SetScrollbar(int Total, int Offset);
280  virtual void SetEvent(const cEvent *Event);
281  virtual void SetRecording(const cRecording *Recording);
282  virtual void SetText(const char *Text, bool FixedFont);
283  virtual const cFont *GetTextAreaFont(bool FixedFont) const { return &Font; }
284  virtual void Flush(void);
285  };
286 
288 {
289  osd = new cCursesOsd(0, 0);
290  lastDiskUsageState = -1;
292 }
293 
295 {
296  delete osd;
297 }
298 
299 void cSkinCursesDisplayMenu::DrawScrollbar(int Total, int Offset, int Shown, int Top, int Height, bool CanScrollUp, bool CanScrollDown)
300 {
301  if (Total > 0 && Total > Shown) {
302  int yt = Top;
303  int yb = yt + Height;
304  int st = yt;
305  int sb = yb;
306  int th = max(int((sb - st) * double(Shown) / Total + 0.5), 1);
307  int tt = min(int(st + (sb - st) * double(Offset) / Total + 0.5), sb - th);
308  int tb = min(tt + th, sb);
309  int xl = ScOsdWidth - 1;
310  osd->DrawRectangle(xl, st, xl, sb - 1, clrWhite);
311  osd->DrawRectangle(xl, tt, xl, tb - 1, clrCyan);
312  }
313 }
314 
316 {
317  if (textScroller.CanScroll())
319 }
320 
321 void cSkinCursesDisplayMenu::Scroll(bool Up, bool Page)
322 {
323  cSkinDisplayMenu::Scroll(Up, Page);
325 }
326 
328 {
329  return ScOsdHeight - 4;
330 }
331 
333 {
336 }
337 
339 {
340  bool WithDisk = MenuCategory() == mcMain || MenuCategory() == mcRecording;
341  osd->DrawText(0, 0, WithDisk ? cString::sprintf("%s - %s", *title, *cVideoDiskUsage::String()) : title, clrBlack, clrCyan, &Font, ScOsdWidth);
342 }
343 
344 void cSkinCursesDisplayMenu::SetTitle(const char *Title)
345 {
346  title = Title;
347  DrawTitle();
348 }
349 
350 void cSkinCursesDisplayMenu::SetButtons(const char *Red, const char *Green, const char *Yellow, const char *Blue)
351 {
352  int w = ScOsdWidth;
353  int t0 = 0;
354  int t1 = 0 + w / 4;
355  int t2 = 0 + w / 2;
356  int t3 = w - w / 4;
357  int t4 = w;
358  int y = ScOsdHeight - 1;
359  osd->DrawText(t0, y, Red, clrWhite, Red ? clrRed : clrBackground, &Font, t1 - t0, 0, taCenter);
360  osd->DrawText(t1, y, Green, clrBlack, Green ? clrGreen : clrBackground, &Font, t2 - t1, 0, taCenter);
361  osd->DrawText(t2, y, Yellow, clrBlack, Yellow ? clrYellow : clrBackground, &Font, t3 - t2, 0, taCenter);
362  osd->DrawText(t3, y, Blue, clrWhite, Blue ? clrBlue : clrBackground, &Font, t4 - t3, 0, taCenter);
363 }
364 
366 {
367  if (Text)
368  osd->DrawText(0, ScOsdHeight - 2, Text, clrMessage[2 * Type], clrMessage[2 * Type + 1], &Font, ScOsdWidth, 0, taCenter);
369  else
371 }
372 
373 void cSkinCursesDisplayMenu::SetItem(const char *Text, int Index, bool Current, bool Selectable)
374 {
375  int y = 2 + Index;
376  int ColorFg, ColorBg;
377  if (Current) {
378  ColorFg = clrBlack;
379  ColorBg = clrCyan;
380  }
381  else {
382  ColorFg = Selectable ? clrWhite : clrCyan;
383  ColorBg = clrBackground;
384  }
385  for (int i = 0; i < MaxTabs; i++) {
386  const char *s = GetTabbedText(Text, i);
387  if (s) {
388  int xt = Tab(i) / AvgCharWidth();// Tab() is in "pixel" - see also skins.c!!!
389  osd->DrawText(xt, y, s, ColorFg, ColorBg, &Font, ScOsdWidth - 2 - xt);
390  }
391  if (!Tab(i + 1))
392  break;
393  }
394  SetEditableWidth(ScOsdWidth - 2 - Tab(1) / AvgCharWidth()); // Tab() is in "pixel" - see also skins.c!!!
395 }
396 
397 void cSkinCursesDisplayMenu::SetScrollbar(int Total, int Offset)
398 {
399  DrawScrollbar(Total, Offset, MaxItems(), 2, MaxItems(), Offset > 0, Offset + MaxItems() < Total);
400 }
401 
403 {
404  if (!Event)
405  return;
406  int y = 2;
407  cTextScroller ts;
408  cString t = cString::sprintf("%s %s - %s", *Event->GetDateString(), *Event->GetTimeString(), *Event->GetEndTimeString());
409  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, t, &Font, clrYellow, clrBackground);
410  if (Event->Vps() && Event->Vps() != Event->StartTime()) {
411  cString buffer = cString::sprintf(" VPS: %s", *Event->GetVpsString());
412  osd->DrawText(ScOsdWidth - Utf8StrLen(buffer), y, buffer, clrBlack, clrYellow, &Font);
413  }
414  y += ts.Height();
415  if (Event->ParentalRating()) {
416  cString buffer = cString::sprintf(" %s ", *Event->GetParentalRatingString());
417  osd->DrawText(ScOsdWidth - Utf8StrLen(buffer), y, buffer, clrBlack, clrYellow, &Font);
418  }
419  y += 1;
420  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, Event->Title(), &Font, clrCyan, clrBackground);
421  y += ts.Height();
422  if (!isempty(Event->ShortText())) {
423  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, Event->ShortText(), &Font, clrYellow, clrBackground);
424  y += ts.Height();
425  }
426  for (int i = 0; Event->Contents(i); i++) {
427  const char *s = Event->ContentToString(Event->Contents(i));
428  if (!isempty(s)) {
429  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, s, &Font, clrYellow, clrBackground);
430  y += 1;
431  }
432  }
433  y += 1;
434  if (!isempty(Event->Description())) {
435  textScroller.Set(osd, 0, y, ScOsdWidth - 2, ScOsdHeight - y - 2, Event->Description(), &Font, clrCyan, clrBackground);
437  }
438 }
439 
441 {
442  if (!Recording)
443  return;
444  const cRecordingInfo *Info = Recording->Info();
445  int y = 2;
446  cTextScroller ts;
447  cString t = cString::sprintf("%s %s %s", *DateString(Recording->Start()), *TimeString(Recording->Start()), Info->ChannelName() ? Info->ChannelName() : "");
448  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, t, &Font, clrYellow, clrBackground);
449  y += ts.Height();
450  if (Info->GetEvent()->ParentalRating()) {
451  cString buffer = cString::sprintf(" %s ", *Info->GetEvent()->GetParentalRatingString());
452  osd->DrawText(ScOsdWidth - Utf8StrLen(buffer), y, buffer, clrBlack, clrYellow, &Font);
453  }
454  y += 1;
455  const char *Title = Info->Title();
456  if (isempty(Title))
457  Title = Recording->Name();
458  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, Title, &Font, clrCyan, clrBackground);
459  y += ts.Height();
460  if (!isempty(Info->ShortText())) {
461  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, Info->ShortText(), &Font, clrYellow, clrBackground);
462  y += ts.Height();
463  }
464  for (int i = 0; Info->GetEvent()->Contents(i); i++) {
465  const char *s = Info->GetEvent()->ContentToString(Info->GetEvent()->Contents(i));
466  if (!isempty(s)) {
467  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, s, &Font, clrYellow, clrBackground);
468  y += 1;
469  }
470  }
471  y += 1;
472  if (!isempty(Info->Description())) {
473  textScroller.Set(osd, 0, y, ScOsdWidth - 2, ScOsdHeight - y - 2, Info->Description(), &Font, clrCyan, clrBackground);
475  }
476 }
477 
478 void cSkinCursesDisplayMenu::SetText(const char *Text, bool FixedFont)
479 {
482 }
483 
485 {
487  DrawTitle();
488  cString date = DayDateTime();
489  osd->DrawText(ScOsdWidth - Utf8StrLen(date) - 2, 0, date, clrBlack, clrCyan, &Font);
490  osd->Flush();
491 }
492 
493 // --- cSkinCursesDisplayReplay ----------------------------------------------
494 
496 private:
498  bool message;
499 public:
500  cSkinCursesDisplayReplay(bool ModeOnly);
501  virtual ~cSkinCursesDisplayReplay();
502  virtual void SetTitle(const char *Title);
503  virtual void SetMode(bool Play, bool Forward, int Speed);
504  virtual void SetProgress(int Current, int Total);
505  virtual void SetCurrent(const char *Current);
506  virtual void SetTotal(const char *Total);
507  virtual void SetJump(const char *Jump);
508  virtual void SetMessage(eMessageType Type, const char *Text);
509  virtual void Flush(void);
510  };
511 
513 {
514  message = false;
515  osd = new cCursesOsd(0, ScOsdHeight - 3);
516  osd->DrawRectangle(0, 0, ScOsdWidth - 1, 2, ModeOnly ? clrTransparent : clrBackground);
517 }
518 
520 {
521  delete osd;
522 }
523 
524 void cSkinCursesDisplayReplay::SetTitle(const char *Title)
525 {
526  osd->DrawText(0, 0, Title, clrWhite, clrBackground, &Font, ScOsdWidth);
527 }
528 
529 void cSkinCursesDisplayReplay::SetMode(bool Play, bool Forward, int Speed)
530 {
531  if (Setup.ShowReplayMode) {
532  const char *Mode;
533  if (Speed == -1) Mode = Play ? " > " : " || ";
534  else if (Play) Mode = Forward ? " X>> " : " <<X ";
535  else Mode = Forward ? " X|> " : " <|X ";
536  char buf[16];
537  strn0cpy(buf, Mode, sizeof(buf));
538  char *p = strchr(buf, 'X');
539  if (p)
540  *p = Speed > 0 ? '1' + Speed - 1 : ' ';
541  SetJump(buf);
542  }
543 }
544 
545 void cSkinCursesDisplayReplay::SetProgress(int Current, int Total)
546 {
547  int p = Total > 0 ? ScOsdWidth * Current / Total : 0;
548  osd->DrawRectangle(0, 1, p, 1, clrGreen);
549  osd->DrawRectangle(p, 1, ScOsdWidth, 1, clrWhite);
550 }
551 
552 void cSkinCursesDisplayReplay::SetCurrent(const char *Current)
553 {
555 }
556 
557 void cSkinCursesDisplayReplay::SetTotal(const char *Total)
558 {
559  osd->DrawText(ScOsdWidth - Utf8StrLen(Total), 2, Total, clrWhite, clrBackground, &Font);
560 }
561 
562 void cSkinCursesDisplayReplay::SetJump(const char *Jump)
563 {
564  osd->DrawText(ScOsdWidth / 4, 2, Jump, clrWhite, clrBackground, &Font, ScOsdWidth / 2, 0, taCenter);
565 }
566 
568 {
569  if (Text) {
570  osd->SaveRegion(0, 2, ScOsdWidth - 1, 2);
571  osd->DrawText(0, 2, Text, clrMessage[2 * Type], clrMessage[2 * Type + 1], &Font, ScOsdWidth, 0, taCenter);
572  message = true;
573  }
574  else {
575  osd->RestoreRegion();
576  message = false;
577  }
578 }
579 
581 {
582  osd->Flush();
583 }
584 
585 // --- cSkinCursesDisplayVolume ----------------------------------------------
586 
588 private:
590 public:
592  virtual ~cSkinCursesDisplayVolume();
593  virtual void SetVolume(int Current, int Total, bool Mute);
594  virtual void Flush(void);
595  };
596 
598 {
599  osd = new cCursesOsd(0, ScOsdHeight - 1);
600 }
601 
603 {
604  delete osd;
605 }
606 
607 void cSkinCursesDisplayVolume::SetVolume(int Current, int Total, bool Mute)
608 {
609  if (Mute) {
610  osd->DrawRectangle(0, 0, ScOsdWidth - 1, 0, clrTransparent);
611  osd->DrawText(0, 0, tr("Key$Mute"), clrGreen, clrBackground, &Font);
612  }
613  else {
614  // TRANSLATORS: note the trailing blank!
615  const char *Prompt = tr("Volume ");
616  int l = Utf8StrLen(Prompt);
617  int p = (ScOsdWidth - l) * Current / Total;
618  osd->DrawText(0, 0, Prompt, clrGreen, clrBackground, &Font);
619  osd->DrawRectangle(l, 0, l + p - 1, 0, clrGreen);
620  osd->DrawRectangle(l + p, 0, ScOsdWidth - 1, 0, clrWhite);
621  }
622 }
623 
625 {
626  osd->Flush();
627 }
628 
629 // --- cSkinCursesDisplayTracks ----------------------------------------------
630 
632 private:
636  void SetItem(const char *Text, int Index, bool Current);
637 public:
638  cSkinCursesDisplayTracks(const char *Title, int NumTracks, const char * const *Tracks);
639  virtual ~cSkinCursesDisplayTracks();
640  virtual void SetTrack(int Index, const char * const *Tracks);
641  virtual void SetAudioChannel(int AudioChannel) {}
642  virtual void Flush(void);
643  };
644 
645 cSkinCursesDisplayTracks::cSkinCursesDisplayTracks(const char *Title, int NumTracks, const char * const *Tracks)
646 {
647  currentIndex = -1;
648  itemsWidth = Font.Width(Title);
649  for (int i = 0; i < NumTracks; i++)
650  itemsWidth = max(itemsWidth, Font.Width(Tracks[i]));
652  osd = new cCursesOsd(0, 0);
654  osd->DrawText(0, 0, Title, clrBlack, clrCyan, &Font, itemsWidth);
655  for (int i = 0; i < NumTracks; i++)
656  SetItem(Tracks[i], i, false);
657 }
658 
660 {
661  delete osd;
662 }
663 
664 void cSkinCursesDisplayTracks::SetItem(const char *Text, int Index, bool Current)
665 {
666  int y = 1 + Index;
667  int ColorFg, ColorBg;
668  if (Current) {
669  ColorFg = clrBlack;
670  ColorBg = clrCyan;
671  currentIndex = Index;
672  }
673  else {
674  ColorFg = clrWhite;
675  ColorBg = clrBackground;
676  }
677  osd->DrawText(0, y, Text, ColorFg, ColorBg, &Font, itemsWidth);
678 }
679 
680 void cSkinCursesDisplayTracks::SetTrack(int Index, const char * const *Tracks)
681 {
682  if (currentIndex >= 0)
683  SetItem(Tracks[currentIndex], currentIndex, false);
684  SetItem(Tracks[Index], Index, true);
685 }
686 
688 {
689  osd->Flush();
690 }
691 
692 // --- cSkinCursesDisplayMessage ---------------------------------------------
693 
695 private:
697 public:
699  virtual ~cSkinCursesDisplayMessage();
700  virtual void SetMessage(eMessageType Type, const char *Text);
701  virtual void Flush(void);
702  };
703 
705 {
706  osd = new cCursesOsd(0, ScOsdHeight - 1);
707 }
708 
710 {
711  delete osd;
712 }
713 
715 {
716  osd->DrawText(0, 0, Text, clrMessage[2 * Type], clrMessage[2 * Type + 1], &Font, ScOsdWidth, 0, taCenter);
717 }
718 
720 {
721  osd->Flush();
722 }
723 
724 // --- cSkinCurses -----------------------------------------------------------
725 
726 class cSkinCurses : public cSkin {
727 public:
728  cSkinCurses(void);
729  virtual const char *Description(void);
730  virtual cSkinDisplayChannel *DisplayChannel(bool WithInfo);
731  virtual cSkinDisplayMenu *DisplayMenu(void);
732  virtual cSkinDisplayReplay *DisplayReplay(bool ModeOnly);
733  virtual cSkinDisplayVolume *DisplayVolume(void);
734  virtual cSkinDisplayTracks *DisplayTracks(const char *Title, int NumTracks, const char * const *Tracks);
735  virtual cSkinDisplayMessage *DisplayMessage(void);
736  };
737 
739 :cSkin("curses")
740 {
741 }
742 
743 const char *cSkinCurses::Description(void)
744 {
745  return tr("Text mode");
746 }
747 
749 {
750  return new cSkinCursesDisplayChannel(WithInfo);
751 }
752 
754 {
755  return new cSkinCursesDisplayMenu;
756 }
757 
759 {
760  return new cSkinCursesDisplayReplay(ModeOnly);
761 }
762 
764 {
765  return new cSkinCursesDisplayVolume;
766 }
767 
768 cSkinDisplayTracks *cSkinCurses::DisplayTracks(const char *Title, int NumTracks, const char * const *Tracks)
769 {
770  return new cSkinCursesDisplayTracks(Title, NumTracks, Tracks);
771 }
772 
774 {
775  return new cSkinCursesDisplayMessage;
776 }
777 
778 // --- cPluginSkinCurses -----------------------------------------------------
779 
780 class cPluginSkinCurses : public cPlugin {
781 private:
782  // Add any member variables or functions you may need here.
783 public:
784  cPluginSkinCurses(void);
785  virtual ~cPluginSkinCurses();
786  virtual const char *Version(void) { return VERSION; }
787  virtual const char *Description(void) { return tr(DESCRIPTION); }
788  virtual const char *CommandLineHelp(void);
789  virtual bool ProcessArgs(int argc, char *argv[]);
790  virtual bool Initialize(void);
791  virtual bool Start(void);
792  virtual void Housekeeping(void);
793  virtual const char *MainMenuEntry(void) { return tr(MAINMENUENTRY); }
794  virtual cOsdObject *MainMenuAction(void);
795  virtual cMenuSetupPage *SetupMenu(void);
796  virtual bool SetupParse(const char *Name, const char *Value);
797  };
798 
800 {
801  // Initialize any member variables here.
802  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
803  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
804 }
805 
807 {
808  // Clean up after yourself!
809  endwin();
810 }
811 
813 {
814  // Return a string that describes all known command line options.
815  return NULL;
816 }
817 
818 bool cPluginSkinCurses::ProcessArgs(int argc, char *argv[])
819 {
820  // Implement command line argument processing here if applicable.
821  return true;
822 }
823 
825 {
826  // Initialize any background activities the plugin shall perform.
827  if (initscr())
828  return true;
829  return false;
830 }
831 
833 {
834  // Start any background activities the plugin shall perform.
835  cSkin *Skin = new cSkinCurses;
836  // This skin is normally used for debugging, so let's make it the current one:
837  Skins.SetCurrent(Skin->Name());
838  return true;
839 }
840 
842 {
843  // Perform any cleanup or other regular tasks.
844 }
845 
847 {
848  // Perform the action when selected from the main VDR menu.
849  return NULL;
850 }
851 
853 {
854  // Return a setup menu in case the plugin supports one.
855  return NULL;
856 }
857 
858 bool cPluginSkinCurses::SetupParse(const char *Name, const char *Value)
859 {
860  // Parse your own setup parameters and store their values.
861  return false;
862 }
863 
864 VDRPLUGINCREATOR(cPluginSkinCurses); // Don't touch this!
cString ChannelString(const cChannel *Channel, int Number)
Definition: channels.c:1166
Definition: osd.h:169
virtual int Width(uint c) const
Returns the width of the given character in pixel.
Definition: skincurses.c:24
virtual int Width(const char *s) const
Returns the width of the given string in pixel.
Definition: skincurses.c:25
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
virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
Draws the given text into the Bitmap at position (x, y) with the given colors.
Definition: skincurses.c:27
virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const
Definition: skincurses.c:28
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: skincurses.c:167
cVector< int > colorPairs
Definition: skincurses.c:63
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: skincurses.c:130
cCursesOsd(int Left, int Top)
Definition: skincurses.c:75
virtual void RestoreRegion(void)
Restores the region previously saved by a call to SaveRegion().
Definition: skincurses.c:121
WINDOW * savedRegion
Definition: skincurses.c:62
void SetColor(int colorFg, int colorBg=clrBackground)
Definition: skincurses.c:98
virtual void SaveRegion(int x1, int y1, int x2, int y2)
Saves the region defined by the given coordinates for later restoration through RestoreRegion().
Definition: skincurses.c:110
virtual void Flush(void)
Actually commits all data to the OSD hardware.
Definition: skincurses.c:182
virtual ~cCursesOsd()
Definition: skincurses.c:92
Definition: epg.h:71
time_t Vps(void) const
Definition: epg.h:112
static const char * ContentToString(uchar Content)
Definition: epg.c:279
cString GetDateString(void) const
Definition: epg.c:428
uchar Contents(int i=0) const
Definition: epg.h:107
int ParentalRating(void) const
Definition: epg.h:108
time_t StartTime(void) const
Definition: epg.h:109
cString GetTimeString(void) const
Definition: epg.c:433
const char * Title(void) const
Definition: epg.h:103
cString GetEndTimeString(void) const
Definition: epg.c:438
cString GetVpsString(void) const
Definition: epg.c:443
const char * ShortText(void) const
Definition: epg.h:104
cString GetParentalRatingString(void) const
Definition: epg.c:421
const char * Description(void) const
Definition: epg.h:105
Definition: font.h:37
The cOsd class is the interface to the "On Screen Display".
Definition: osd.h:729
int Width(void)
Definition: osd.h:826
virtual void SaveRegion(int x1, int y1, int x2, int y2)
Saves the region defined by the given coordinates for later restoration through RestoreRegion().
Definition: osd.c:2064
virtual void Flush(void)
Actually commits all data to the OSD hardware.
Definition: osd.c:2191
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:2161
int Left(void)
Definition: osd.h:824
int Top(void)
Definition: osd.h:825
virtual void RestoreRegion(void)
Restores the region previously saved by a call to SaveRegion().
Definition: osd.c:2080
int Height(void)
Definition: osd.h:827
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:2151
Definition: osd.h:454
virtual bool Start(void)
Definition: skincurses.c:832
virtual const char * MainMenuEntry(void)
Definition: skincurses.c:793
virtual ~cPluginSkinCurses()
Definition: skincurses.c:806
virtual bool Initialize(void)
Definition: skincurses.c:824
virtual cOsdObject * MainMenuAction(void)
Definition: skincurses.c:846
virtual void Housekeeping(void)
Definition: skincurses.c:841
cPluginSkinCurses(void)
Definition: skincurses.c:799
virtual const char * CommandLineHelp(void)
Definition: skincurses.c:812
virtual const char * Version(void)
Definition: skincurses.c:786
virtual bool ProcessArgs(int argc, char *argv[])
Definition: skincurses.c:818
virtual const char * Description(void)
Definition: skincurses.c:787
virtual cMenuSetupPage * SetupMenu(void)
Definition: skincurses.c:852
virtual bool SetupParse(const char *Name, const char *Value)
Definition: skincurses.c:858
Definition: plugin.h:22
const char * Name(void)
Definition: plugin.h:36
const cEvent * GetEvent(void) const
Definition: recording.h:87
const char * ChannelName(void) const
Definition: recording.h:86
const char * Title(void) const
Definition: recording.h:88
const char * Description(void) const
Definition: recording.h:90
const char * ShortText(void) const
Definition: recording.h:89
const char * Name(void) const
Returns the full name of the recording (without the video directory).
Definition: recording.h:151
time_t Start(void) const
Definition: recording.h:136
cRecordingInfo * Info(void) const
Definition: recording.h:158
int ShowReplayMode
Definition: config.h:344
int ChannelInfoPos
Definition: config.h:320
virtual void SetEvents(const cEvent *Present, const cEvent *Following)
Sets the Present and Following EPG events.
Definition: skincurses.c:223
virtual void SetChannel(const cChannel *Channel, int Number)
Sets the current channel to Channel.
Definition: skincurses.c:217
cSkinCursesDisplayChannel(bool WithInfo)
Definition: skincurses.c:203
virtual void Flush(void)
Actually draws the OSD display to the output device.
Definition: skincurses.c:250
virtual ~cSkinCursesDisplayChannel()
Definition: skincurses.c:212
virtual void SetMessage(eMessageType Type, const char *Text)
Sets a one line message Text, with the given Type.
Definition: skincurses.c:237
virtual void SetTitle(const char *Title)
Sets the title of this menu to Title.
Definition: skincurses.c:344
virtual void SetEvent(const cEvent *Event)
Sets the Event that shall be displayed, using the entire central area of the menu.
Definition: skincurses.c:402
virtual void Clear(void)
Clears the entire central area of the menu.
Definition: skincurses.c:332
virtual void SetRecording(const cRecording *Recording)
Sets the Recording that shall be displayed, using the entire central area of the menu.
Definition: skincurses.c:440
virtual const cFont * GetTextAreaFont(bool FixedFont) const
Returns a pointer to the font which is used to display text with SetText().
Definition: skincurses.c:283
virtual void SetButtons(const char *Red, const char *Green=NULL, const char *Yellow=NULL, const char *Blue=NULL)
Sets the color buttons to the given strings.
Definition: skincurses.c:350
void DrawScrollbar(int Total, int Offset, int Shown, int Top, int Height, bool CanScrollUp, bool CanScrollDown)
Definition: skincurses.c:299
virtual void SetText(const char *Text, bool FixedFont)
Sets the Text that shall be displayed, using the entire central area of the menu.
Definition: skincurses.c:478
virtual void SetItem(const char *Text, int Index, bool Current, bool Selectable)
Sets the item at the given Index to Text.
Definition: skincurses.c:373
virtual int MaxItems(void)
Returns the maximum number of items the menu can display.
Definition: skincurses.c:327
virtual void Scroll(bool Up, bool Page)
If this menu contains a text area that can be scrolled, this function will be called to actually scro...
Definition: skincurses.c:321
void SetTextScrollbar(void)
Definition: skincurses.c:315
virtual void Flush(void)
Actually draws the OSD display to the output device.
Definition: skincurses.c:484
virtual void SetMessage(eMessageType Type, const char *Text)
Sets a one line message Text, with the given Type.
Definition: skincurses.c:365
virtual ~cSkinCursesDisplayMenu()
Definition: skincurses.c:294
virtual void SetScrollbar(int Total, int Offset)
Sets the Total number of items in the currently displayed list, and the Offset of the first item that...
Definition: skincurses.c:397
virtual void SetMessage(eMessageType Type, const char *Text)
< This class implements a simple message display.
Definition: skincurses.c:714
virtual ~cSkinCursesDisplayMessage()
Definition: skincurses.c:709
virtual void Flush(void)
Actually draws the OSD display to the output device.
Definition: skincurses.c:719
cSkinCursesDisplayReplay(bool ModeOnly)
Definition: skincurses.c:512
virtual ~cSkinCursesDisplayReplay()
Definition: skincurses.c:519
virtual void SetMessage(eMessageType Type, const char *Text)
Sets a one line message Text, with the given Type.
Definition: skincurses.c:567
virtual void SetCurrent(const char *Current)
Sets the current position within the recording, as a user readable string if the form "h:mm:ss....
Definition: skincurses.c:552
virtual void SetProgress(int Current, int Total)
This function will be called whenever the position in or the total length of the recording has change...
Definition: skincurses.c:545
virtual void SetMode(bool Play, bool Forward, int Speed)
Sets the current replay mode, which can be used to display some indicator, showing the user whether w...
Definition: skincurses.c:529
virtual void SetJump(const char *Jump)
Sets the prompt that allows the user to enter a jump point.
Definition: skincurses.c:562
virtual void Flush(void)
Actually draws the OSD display to the output device.
Definition: skincurses.c:580
virtual void SetTotal(const char *Total)
Sets the total length of the recording, as a user readable string if the form "h:mm:ss".
Definition: skincurses.c:557
virtual void SetTitle(const char *Title)
Sets the title of the recording.
Definition: skincurses.c:524
cSkinCursesDisplayTracks(const char *Title, int NumTracks, const char *const *Tracks)
Definition: skincurses.c:645
void SetItem(const char *Text, int Index, bool Current)
Definition: skincurses.c:664
virtual void SetAudioChannel(int AudioChannel)
Sets the audio channel indicator.
Definition: skincurses.c:641
virtual void SetTrack(int Index, const char *const *Tracks)
< This class implements the track display.
Definition: skincurses.c:680
virtual void Flush(void)
Actually draws the OSD display to the output device.
Definition: skincurses.c:687
virtual ~cSkinCursesDisplayTracks()
Definition: skincurses.c:659
virtual ~cSkinCursesDisplayVolume()
Definition: skincurses.c:602
virtual void Flush(void)
Actually draws the OSD display to the output device.
Definition: skincurses.c:624
virtual void SetVolume(int Current, int Total, bool Mute)
< This class implements the volume/mute display.
Definition: skincurses.c:607
virtual cSkinDisplayMenu * DisplayMenu(void)
Creates and returns a new object for displaying a menu.
Definition: skincurses.c:753
virtual cSkinDisplayChannel * DisplayChannel(bool WithInfo)
Creates and returns a new object for displaying the current channel.
Definition: skincurses.c:748
virtual const char * Description(void)
Returns a user visible, single line description of this skin, which may consist of arbitrary text and...
Definition: skincurses.c:743
virtual cSkinDisplayTracks * DisplayTracks(const char *Title, int NumTracks, const char *const *Tracks)
Creates and returns a new object for displaying the available tracks.
Definition: skincurses.c:768
virtual cSkinDisplayReplay * DisplayReplay(bool ModeOnly)
Creates and returns a new object for displaying replay progress.
Definition: skincurses.c:758
cSkinCurses(void)
Definition: skincurses.c:738
virtual cSkinDisplayMessage * DisplayMessage(void)
Creates and returns a new object for displaying a message.
Definition: skincurses.c:773
virtual cSkinDisplayVolume * DisplayVolume(void)
Creates and returns a new object for displaying the current volume.
Definition: skincurses.c:763
virtual void Scroll(bool Up, bool Page)
If this menu contains a text area that can be scrolled, this function will be called to actually scro...
Definition: skins.c:107
cTextScroller textScroller
Definition: skins.h:173
int Tab(int n)
Returns the offset of the given tab from the left border of the item display area.
Definition: skins.h:174
eMenuCategory MenuCategory(void) const
Returns the menu category, set by a previous call to SetMenuCategory().
Definition: skins.h:183
const char * GetTabbedText(const char *s, int Tab)
Returns the part of the given string that follows the given Tab (where 0 indicates the beginning of t...
Definition: skins.c:112
static cSkinDisplay * Current(void)
Returns the currently active cSkinDisplay.
Definition: skins.h:61
void SetEditableWidth(int Width)
If an item is set through a call to cSkinDisplayMenu::SetItem(), this function shall be called to set...
Definition: skins.h:49
static int AvgCharWidth(void)
Returns the average width of a character in pixel (just a raw estimate).
Definition: skins.h:46
Definition: skins.h:402
const char * Name(void)
Definition: skins.h:421
bool SetCurrent(const char *Name=NULL)
Sets the current skin to the one indicated by name.
Definition: skins.c:231
Definition: tools.h:174
static cString sprintf(const char *fmt,...) __attribute__((format(printf
Definition: tools.c:1133
int Height(void)
Definition: osd.h:1057
bool CanScroll(void)
Definition: osd.h:1061
int Total(void)
Definition: osd.h:1058
int Top(void)
Definition: osd.h:1055
int Offset(void)
Definition: osd.h:1059
void Set(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg)
Definition: osd.c:2346
void Reset(void)
Definition: osd.c:2363
int Shown(void)
Definition: osd.h:1060
bool CanScrollDown(void)
Definition: osd.h:1063
bool CanScrollUp(void)
Definition: osd.h:1062
int Size(void) const
Definition: tools.h:721
int IndexOf(const T &Data)
Definition: tools.h:713
virtual void Append(T Data)
Definition: tools.h:741
static bool HasChanged(int &State)
Returns true if the usage of the video disk space has changed since the last call to this function wi...
Definition: videodir.c:205
static cString String(void)
Returns a localized string of the form "Disk nn% - hh:mm free".
Definition: videodir.c:229
cSetup Setup
Definition: config.c:372
uint32_t tColor
Definition: font.h:29
#define tr(s)
Definition: i18n.h:85
#define trNOOP(s)
Definition: i18n.h:88
@ taCenter
Definition: osd.h:158
@ taTop
Definition: osd.h:161
@ taBottom
Definition: osd.h:162
@ taRight
Definition: osd.h:160
@ taDefault
Definition: osd.h:164
@ taLeft
Definition: osd.h:159
static const char * VERSION
Definition: skincurses.c:15
static const char * DESCRIPTION
Definition: skincurses.c:16
static int ScOsdWidth
Definition: skincurses.c:57
#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
VDRPLUGINCREATOR(cPluginSkinCurses)
static int clrMessage[]
Definition: skincurses.c:46
static int ScOsdHeight
Definition: skincurses.c:58
#define clrRed
Definition: skincurses.c:38
#define clrYellow
Definition: skincurses.c:40
#define clrBackground
Definition: skincurses.c:35
#define clrCyan
Definition: skincurses.c:43
static const cCursesFont Font
Definition: skincurses.c:31
static const char * MAINMENUENTRY
Definition: skincurses.c:17
cSkins Skins
Definition: skins.c:219
@ mcMain
Definition: skins.h:107
@ mcRecording
Definition: skins.h:115
eMessageType
Definition: skins.h:37
cString TimeString(time_t t)
Converts the given time to a string of the form "hh:mm".
Definition: tools.c:1239
bool isempty(const char *s)
Definition: tools.c:333
int Utf8StrLen(const char *s)
Returns the number of UTF-8 symbols formed by the given string of character bytes.
Definition: tools.c:871
cString DateString(time_t t)
Converts the given time to a string of the form "www dd.mm.yyyy".
Definition: tools.c:1219
char * strn0cpy(char *dest, const char *src, size_t n)
Definition: tools.c:131
cString DayDateTime(time_t t)
Converts the given time to a string of the form "www dd.mm. hh:mm".
Definition: tools.c:1198
T min(T a, T b)
Definition: tools.h:58
T max(T a, T b)
Definition: tools.h:59