vdr  2.7.6
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 5.3 2025/04/12 20:40:48 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.3";
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 override { return 1; }
24  virtual int Width(uint c) const override { return 1; }
25  virtual int Width(const char *s) const override { return s ? Utf8StrLen(s) : 0; }
26  virtual int Height(void) const override { return 1; }
27  virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const override {}
28  virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const override {}
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() override;
68  virtual void SaveRegion(int x1, int y1, int x2, int y2) override;
69  virtual void RestoreRegion(void) override;
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) override;
71  virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color) override;
72  virtual void Flush(void) override;
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() override;
197  virtual void SetChannel(const cChannel *Channel, int Number) override;
198  virtual void SetEvents(const cEvent *Present, const cEvent *Following) override;
199  virtual void SetMessage(eMessageType Type, const char *Text) override;
200  virtual void Flush(void) override;
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() override;
272  virtual void Scroll(bool Up, bool Page) override;
273  virtual int MaxItems(void) override;
274  virtual void Clear(void) override;
275  virtual void SetTitle(const char *Title) override;
276  virtual void SetButtons(const char *Red, const char *Green = NULL, const char *Yellow = NULL, const char *Blue = NULL) override;
277  virtual void SetMessage(eMessageType Type, const char *Text) override;
278  virtual void SetItem(const char *Text, int Index, bool Current, bool Selectable) override;
279  virtual void SetScrollbar(int Total, int Offset) override;
280  virtual void SetEvent(const cEvent *Event) override;
281  virtual void SetRecording(const cRecording *Recording) override;
282  virtual void SetText(const char *Text, bool FixedFont) override;
283  virtual const cFont *GetTextAreaFont(bool FixedFont) const override { return &Font; }
284  virtual void Flush(void) override;
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  int xt = ScOsdWidth;
451  if (Info->GetEvent()->ParentalRating()) {
452  cString buffer = cString::sprintf(" %s ", *Info->GetEvent()->GetParentalRatingString());
453  int w = Utf8StrLen(buffer);
454  osd->DrawText(xt - w, y, buffer, clrBlack, clrYellow, &Font);
455  xt -= w + 1;
456  }
457  if (Info->Errors() > 0) {
458  cString buffer = cString::sprintf(" %d %s ", Info->Errors(), tr("errors"));
459  int w = Utf8StrLen(buffer);
460  osd->DrawText(xt - w, y, buffer, clrBlack, clrYellow, &Font);
461  xt -= w + 1;
462  }
463  y += 1;
464  const char *Title = Info->Title();
465  if (isempty(Title))
466  Title = Recording->Name();
467  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, Title, &Font, clrCyan, clrBackground);
468  y += ts.Height();
469  if (!isempty(Info->ShortText())) {
470  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, Info->ShortText(), &Font, clrYellow, clrBackground);
471  y += ts.Height();
472  }
473  for (int i = 0; Info->GetEvent()->Contents(i); i++) {
474  const char *s = Info->GetEvent()->ContentToString(Info->GetEvent()->Contents(i));
475  if (!isempty(s)) {
476  ts.Set(osd, 0, y, ScOsdWidth, ScOsdHeight - y - 2, s, &Font, clrYellow, clrBackground);
477  y += 1;
478  }
479  }
480  y += 1;
481  if (!isempty(Info->Description())) {
482  textScroller.Set(osd, 0, y, ScOsdWidth - 2, ScOsdHeight - y - 2, Info->Description(), &Font, clrCyan, clrBackground);
484  }
485 }
486 
487 void cSkinCursesDisplayMenu::SetText(const char *Text, bool FixedFont)
488 {
491 }
492 
494 {
496  DrawTitle();
497  cString date = DayDateTime();
498  osd->DrawText(ScOsdWidth - Utf8StrLen(date) - 2, 0, date, clrBlack, clrCyan, &Font);
499  osd->Flush();
500 }
501 
502 // --- cSkinCursesDisplayReplay ----------------------------------------------
503 
505 private:
507  bool message;
508 public:
509  cSkinCursesDisplayReplay(bool ModeOnly);
510  virtual ~cSkinCursesDisplayReplay() override;
511  virtual void SetTitle(const char *Title) override;
512  virtual void SetMode(bool Play, bool Forward, int Speed) override;
513  virtual void SetProgress(int Current, int Total) override;
514  virtual void SetCurrent(const char *Current) override;
515  virtual void SetTotal(const char *Total) override;
516  virtual void SetJump(const char *Jump) override;
517  virtual void SetMessage(eMessageType Type, const char *Text) override;
518  virtual void Flush(void) override;
519  };
520 
522 {
523  message = false;
524  osd = new cCursesOsd(0, ScOsdHeight - 3);
525  osd->DrawRectangle(0, 0, ScOsdWidth - 1, 2, ModeOnly ? clrTransparent : clrBackground);
526 }
527 
529 {
530  delete osd;
531 }
532 
533 void cSkinCursesDisplayReplay::SetTitle(const char *Title)
534 {
535  osd->DrawText(0, 0, Title, clrWhite, clrBackground, &Font, ScOsdWidth);
536 }
537 
538 void cSkinCursesDisplayReplay::SetMode(bool Play, bool Forward, int Speed)
539 {
540  if (Setup.ShowReplayMode) {
541  const char *Mode;
542  if (Speed == -1) Mode = Play ? " > " : " || ";
543  else if (Play) Mode = Forward ? " X>> " : " <<X ";
544  else Mode = Forward ? " X|> " : " <|X ";
545  char buf[16];
546  strn0cpy(buf, Mode, sizeof(buf));
547  char *p = strchr(buf, 'X');
548  if (p)
549  *p = Speed > 0 ? '1' + Speed - 1 : ' ';
550  SetJump(buf);
551  }
552 }
553 
554 void cSkinCursesDisplayReplay::SetProgress(int Current, int Total)
555 {
556  int p = Total > 0 ? ScOsdWidth * Current / Total : 0;
557  osd->DrawRectangle(0, 1, p, 1, clrGreen);
558  osd->DrawRectangle(p, 1, ScOsdWidth, 1, clrWhite);
559 }
560 
561 void cSkinCursesDisplayReplay::SetCurrent(const char *Current)
562 {
564 }
565 
566 void cSkinCursesDisplayReplay::SetTotal(const char *Total)
567 {
568  osd->DrawText(ScOsdWidth - Utf8StrLen(Total), 2, Total, clrWhite, clrBackground, &Font);
569 }
570 
571 void cSkinCursesDisplayReplay::SetJump(const char *Jump)
572 {
573  osd->DrawText(ScOsdWidth / 4, 2, Jump, clrWhite, clrBackground, &Font, ScOsdWidth / 2, 0, taCenter);
574 }
575 
577 {
578  if (Text) {
579  osd->SaveRegion(0, 2, ScOsdWidth - 1, 2);
580  osd->DrawText(0, 2, Text, clrMessage[2 * Type], clrMessage[2 * Type + 1], &Font, ScOsdWidth, 0, taCenter);
581  message = true;
582  }
583  else {
584  osd->RestoreRegion();
585  message = false;
586  }
587 }
588 
590 {
591  osd->Flush();
592 }
593 
594 // --- cSkinCursesDisplayVolume ----------------------------------------------
595 
597 private:
599 public:
601  virtual ~cSkinCursesDisplayVolume() override;
602  virtual void SetVolume(int Current, int Total, bool Mute) override;
603  virtual void Flush(void) override;
604  };
605 
607 {
608  osd = new cCursesOsd(0, ScOsdHeight - 1);
609 }
610 
612 {
613  delete osd;
614 }
615 
616 void cSkinCursesDisplayVolume::SetVolume(int Current, int Total, bool Mute)
617 {
618  if (Mute) {
619  osd->DrawRectangle(0, 0, ScOsdWidth - 1, 0, clrTransparent);
620  osd->DrawText(0, 0, tr("Key$Mute"), clrGreen, clrBackground, &Font);
621  }
622  else {
623  // TRANSLATORS: note the trailing blank!
624  const char *Prompt = tr("Volume ");
625  int l = Utf8StrLen(Prompt);
626  int p = (ScOsdWidth - l) * Current / Total;
627  osd->DrawText(0, 0, Prompt, clrGreen, clrBackground, &Font);
628  osd->DrawRectangle(l, 0, l + p - 1, 0, clrGreen);
629  osd->DrawRectangle(l + p, 0, ScOsdWidth - 1, 0, clrWhite);
630  }
631 }
632 
634 {
635  osd->Flush();
636 }
637 
638 // --- cSkinCursesDisplayTracks ----------------------------------------------
639 
641 private:
645  void SetItem(const char *Text, int Index, bool Current);
646 public:
647  cSkinCursesDisplayTracks(const char *Title, int NumTracks, const char * const *Tracks);
648  virtual ~cSkinCursesDisplayTracks() override;
649  virtual void SetTrack(int Index, const char * const *Tracks) override;
650  virtual void SetAudioChannel(int AudioChannel) override {}
651  virtual void Flush(void) override;
652  };
653 
654 cSkinCursesDisplayTracks::cSkinCursesDisplayTracks(const char *Title, int NumTracks, const char * const *Tracks)
655 {
656  currentIndex = -1;
657  itemsWidth = Font.Width(Title);
658  for (int i = 0; i < NumTracks; i++)
659  itemsWidth = max(itemsWidth, Font.Width(Tracks[i]));
661  osd = new cCursesOsd(0, 0);
663  osd->DrawText(0, 0, Title, clrBlack, clrCyan, &Font, itemsWidth);
664  for (int i = 0; i < NumTracks; i++)
665  SetItem(Tracks[i], i, false);
666 }
667 
669 {
670  delete osd;
671 }
672 
673 void cSkinCursesDisplayTracks::SetItem(const char *Text, int Index, bool Current)
674 {
675  int y = 1 + Index;
676  int ColorFg, ColorBg;
677  if (Current) {
678  ColorFg = clrBlack;
679  ColorBg = clrCyan;
680  currentIndex = Index;
681  }
682  else {
683  ColorFg = clrWhite;
684  ColorBg = clrBackground;
685  }
686  osd->DrawText(0, y, Text, ColorFg, ColorBg, &Font, itemsWidth);
687 }
688 
689 void cSkinCursesDisplayTracks::SetTrack(int Index, const char * const *Tracks)
690 {
691  if (currentIndex >= 0)
692  SetItem(Tracks[currentIndex], currentIndex, false);
693  SetItem(Tracks[Index], Index, true);
694 }
695 
697 {
698  osd->Flush();
699 }
700 
701 // --- cSkinCursesDisplayMessage ---------------------------------------------
702 
704 private:
706 public:
708  virtual ~cSkinCursesDisplayMessage() override;
709  virtual void SetMessage(eMessageType Type, const char *Text) override;
710  virtual void Flush(void) override;
711  };
712 
714 {
715  osd = new cCursesOsd(0, ScOsdHeight - 1);
716 }
717 
719 {
720  delete osd;
721 }
722 
724 {
725  osd->DrawText(0, 0, Text, clrMessage[2 * Type], clrMessage[2 * Type + 1], &Font, ScOsdWidth, 0, taCenter);
726 }
727 
729 {
730  osd->Flush();
731 }
732 
733 // --- cSkinCurses -----------------------------------------------------------
734 
735 class cSkinCurses : public cSkin {
736 public:
737  cSkinCurses(void);
738  virtual const char *Description(void) override;
739  virtual cSkinDisplayChannel *DisplayChannel(bool WithInfo) override;
740  virtual cSkinDisplayMenu *DisplayMenu(void) override;
741  virtual cSkinDisplayReplay *DisplayReplay(bool ModeOnly) override;
742  virtual cSkinDisplayVolume *DisplayVolume(void) override;
743  virtual cSkinDisplayTracks *DisplayTracks(const char *Title, int NumTracks, const char * const *Tracks) override;
744  virtual cSkinDisplayMessage *DisplayMessage(void) override;
745  };
746 
748 :cSkin("curses")
749 {
750 }
751 
752 const char *cSkinCurses::Description(void)
753 {
754  return tr("Text mode");
755 }
756 
758 {
759  return new cSkinCursesDisplayChannel(WithInfo);
760 }
761 
763 {
764  return new cSkinCursesDisplayMenu;
765 }
766 
768 {
769  return new cSkinCursesDisplayReplay(ModeOnly);
770 }
771 
773 {
774  return new cSkinCursesDisplayVolume;
775 }
776 
777 cSkinDisplayTracks *cSkinCurses::DisplayTracks(const char *Title, int NumTracks, const char * const *Tracks)
778 {
779  return new cSkinCursesDisplayTracks(Title, NumTracks, Tracks);
780 }
781 
783 {
784  return new cSkinCursesDisplayMessage;
785 }
786 
787 // --- cPluginSkinCurses -----------------------------------------------------
788 
789 class cPluginSkinCurses : public cPlugin {
790 private:
791  // Add any member variables or functions you may need here.
792 public:
793  cPluginSkinCurses(void);
794  virtual ~cPluginSkinCurses() override;
795  virtual const char *Version(void) override { return VERSION; }
796  virtual const char *Description(void) override { return tr(DESCRIPTION); }
797  virtual const char *CommandLineHelp(void) override;
798  virtual bool ProcessArgs(int argc, char *argv[]) override;
799  virtual bool Initialize(void) override;
800  virtual bool Start(void) override;
801  virtual void Housekeeping(void) override;
802  virtual const char *MainMenuEntry(void) override { return tr(MAINMENUENTRY); }
803  virtual cOsdObject *MainMenuAction(void) override;
804  virtual cMenuSetupPage *SetupMenu(void) override;
805  virtual bool SetupParse(const char *Name, const char *Value) override;
806  };
807 
809 {
810  // Initialize any member variables here.
811  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
812  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
813 }
814 
816 {
817  // Clean up after yourself!
818  endwin();
819 }
820 
822 {
823  // Return a string that describes all known command line options.
824  return NULL;
825 }
826 
827 bool cPluginSkinCurses::ProcessArgs(int argc, char *argv[])
828 {
829  // Implement command line argument processing here if applicable.
830  return true;
831 }
832 
834 {
835  // Initialize any background activities the plugin shall perform.
836  if (initscr())
837  return true;
838  return false;
839 }
840 
842 {
843  // Start any background activities the plugin shall perform.
844  cSkin *Skin = new cSkinCurses;
845  // This skin is normally used for debugging, so let's make it the current one:
846  Skins.SetCurrent(Skin->Name());
847  return true;
848 }
849 
851 {
852  // Perform any cleanup or other regular tasks.
853 }
854 
856 {
857  // Perform the action when selected from the main VDR menu.
858  return NULL;
859 }
860 
862 {
863  // Return a setup menu in case the plugin supports one.
864  return NULL;
865 }
866 
867 bool cPluginSkinCurses::SetupParse(const char *Name, const char *Value)
868 {
869  // Parse your own setup parameters and store their values.
870  return false;
871 }
872 
873 VDRPLUGINCREATOR(cPluginSkinCurses); // Don't touch this!
cString ChannelString(const cChannel *Channel, int Number)
Definition: channels.c:1173
Definition: osd.h:169
virtual int Width(void) const override
Returns the original character width as requested when the font was created, or 0 if the default widt...
Definition: skincurses.c:23
virtual int Width(const char *s) const override
Returns the width of the given string in pixel.
Definition: skincurses.c:25
virtual int Height(void) const override
Returns the height of this font in pixel (all characters have the same height).
Definition: skincurses.c:26
virtual int Width(uint c) const override
Returns the width of the given character in pixel.
Definition: skincurses.c:24
virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const override
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 override
Definition: skincurses.c:28
cVector< int > colorPairs
Definition: skincurses.c:63
virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color) override
Draws a filled rectangle defined by the upper left (x1, y1) and lower right (x2, y2) corners with the...
Definition: skincurses.c:167
virtual void SaveRegion(int x1, int y1, int x2, int y2) override
Saves the region defined by the given coordinates for later restoration through RestoreRegion().
Definition: skincurses.c:110
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) override
Draws the given string at coordinates (x, y) with the given foreground and background color and font.
Definition: skincurses.c:130
virtual ~cCursesOsd() override
Definition: skincurses.c:92
cCursesOsd(int Left, int Top)
Definition: skincurses.c:75
WINDOW * savedRegion
Definition: skincurses.c:62
void SetColor(int colorFg, int colorBg=clrBackground)
Definition: skincurses.c:98
virtual void Flush(void) override
Actually commits all data to the OSD hardware.
Definition: skincurses.c:182
virtual void RestoreRegion(void) override
Restores the region previously saved by a call to SaveRegion().
Definition: skincurses.c:121
Definition: epg.h:73
time_t Vps(void) const
Definition: epg.h:114
static const char * ContentToString(uchar Content)
Definition: epg.c:282
cString GetDateString(void) const
Definition: epg.c:431
uchar Contents(int i=0) const
Definition: epg.h:109
int ParentalRating(void) const
Definition: epg.h:110
time_t StartTime(void) const
Definition: epg.h:111
cString GetTimeString(void) const
Definition: epg.c:436
const char * Title(void) const
Definition: epg.h:105
cString GetEndTimeString(void) const
Definition: epg.c:441
cString GetVpsString(void) const
Definition: epg.c:446
const char * ShortText(void) const
Definition: epg.h:106
cString GetParentalRatingString(void) const
Definition: epg.c:424
const char * Description(void) const
Definition: epg.h:107
Definition: font.h:37
The cOsd class is the interface to the "On Screen Display".
Definition: osd.h:753
int Width(void)
Definition: osd.h:844
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:2127
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
int Left(void)
Definition: osd.h:842
int Top(void)
Definition: osd.h:843
virtual void RestoreRegion(void)
Restores the region previously saved by a call to SaveRegion().
Definition: osd.c:2143
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
virtual const char * Description(void) override
Definition: skincurses.c:796
virtual ~cPluginSkinCurses() override
Definition: skincurses.c:815
virtual cMenuSetupPage * SetupMenu(void) override
Definition: skincurses.c:861
virtual void Housekeeping(void) override
Definition: skincurses.c:850
virtual const char * MainMenuEntry(void) override
Definition: skincurses.c:802
virtual bool SetupParse(const char *Name, const char *Value) override
Definition: skincurses.c:867
virtual const char * Version(void) override
Definition: skincurses.c:795
cPluginSkinCurses(void)
Definition: skincurses.c:808
virtual bool Start(void) override
Definition: skincurses.c:841
virtual bool Initialize(void) override
Definition: skincurses.c:833
virtual cOsdObject * MainMenuAction(void) override
Definition: skincurses.c:855
virtual const char * CommandLineHelp(void) override
Definition: skincurses.c:821
virtual bool ProcessArgs(int argc, char *argv[]) override
Definition: skincurses.c:827
Definition: plugin.h:22
const char * Name(void)
Definition: plugin.h:36
int Errors(void) const
Definition: recording.h:110
const cEvent * GetEvent(void) const
Definition: recording.h:89
const char * ChannelName(void) const
Definition: recording.h:88
const char * Title(void) const
Definition: recording.h:90
const char * Description(void) const
Definition: recording.h:92
const char * ShortText(void) const
Definition: recording.h:91
const char * Name(void) const
Returns the full name of the recording (without the video directory).
Definition: recording.h:164
time_t Start(void) const
Definition: recording.h:149
cRecordingInfo * Info(void) const
Definition: recording.h:171
int ShowReplayMode
Definition: config.h:360
int ChannelInfoPos
Definition: config.h:337
virtual void SetChannel(const cChannel *Channel, int Number) override
Sets the current channel to Channel.
Definition: skincurses.c:217
virtual void SetEvents(const cEvent *Present, const cEvent *Following) override
Sets the Present and Following EPG events.
Definition: skincurses.c:223
virtual void Flush(void) override
Actually draws the OSD display to the output device.
Definition: skincurses.c:250
cSkinCursesDisplayChannel(bool WithInfo)
Definition: skincurses.c:203
virtual void SetMessage(eMessageType Type, const char *Text) override
Sets a one line message Text, with the given Type.
Definition: skincurses.c:237
virtual ~cSkinCursesDisplayChannel() override
Definition: skincurses.c:212
virtual void Clear(void) override
Clears the entire central area of the menu.
Definition: skincurses.c:332
virtual void SetText(const char *Text, bool FixedFont) override
Sets the Text that shall be displayed, using the entire central area of the menu.
Definition: skincurses.c:487
virtual const cFont * GetTextAreaFont(bool FixedFont) const override
Returns a pointer to the font which is used to display text with SetText().
Definition: skincurses.c:283
virtual void SetItem(const char *Text, int Index, bool Current, bool Selectable) override
Sets the item at the given Index to Text.
Definition: skincurses.c:373
virtual void Flush(void) override
Actually draws the OSD display to the output device.
Definition: skincurses.c:493
virtual ~cSkinCursesDisplayMenu() override
Definition: skincurses.c:294
virtual void SetRecording(const cRecording *Recording) override
Sets the Recording that shall be displayed, using the entire central area of the menu.
Definition: skincurses.c:440
virtual void SetButtons(const char *Red, const char *Green=NULL, const char *Yellow=NULL, const char *Blue=NULL) override
Sets the color buttons to the given strings.
Definition: skincurses.c:350
virtual void SetEvent(const cEvent *Event) override
Sets the Event that shall be displayed, using the entire central area of the menu.
Definition: skincurses.c:402
virtual void Scroll(bool Up, bool Page) override
If this menu contains a text area that can be scrolled, this function will be called to actually scro...
Definition: skincurses.c:321
void DrawScrollbar(int Total, int Offset, int Shown, int Top, int Height, bool CanScrollUp, bool CanScrollDown)
Definition: skincurses.c:299
virtual void SetTitle(const char *Title) override
Sets the title of this menu to Title.
Definition: skincurses.c:344
virtual void SetMessage(eMessageType Type, const char *Text) override
Sets a one line message Text, with the given Type.
Definition: skincurses.c:365
void SetTextScrollbar(void)
Definition: skincurses.c:315
virtual void SetScrollbar(int Total, int Offset) override
Sets the Total number of items in the currently displayed list, and the Offset of the first item that...
Definition: skincurses.c:397
virtual int MaxItems(void) override
Returns the maximum number of items the menu can display.
Definition: skincurses.c:327
virtual void Flush(void) override
Actually draws the OSD display to the output device.
Definition: skincurses.c:728
virtual ~cSkinCursesDisplayMessage() override
Definition: skincurses.c:718
virtual void SetMessage(eMessageType Type, const char *Text) override
< This class implements a simple message display.
Definition: skincurses.c:723
cSkinCursesDisplayReplay(bool ModeOnly)
Definition: skincurses.c:521
virtual void SetJump(const char *Jump) override
Sets the prompt that allows the user to enter a jump point.
Definition: skincurses.c:571
virtual void SetTotal(const char *Total) override
Sets the total length of the recording, as a user readable string in the form "h:mm:ss".
Definition: skincurses.c:566
virtual void Flush(void) override
Actually draws the OSD display to the output device.
Definition: skincurses.c:589
virtual void SetMode(bool Play, bool Forward, int Speed) override
Sets the current replay mode, which can be used to display some indicator, showing the user whether w...
Definition: skincurses.c:538
virtual void SetMessage(eMessageType Type, const char *Text) override
Sets a one line message Text, with the given Type.
Definition: skincurses.c:576
virtual void SetTitle(const char *Title) override
Sets the title of the recording.
Definition: skincurses.c:533
virtual void SetProgress(int Current, int Total) override
This function will be called whenever the position in or the total length of the recording has change...
Definition: skincurses.c:554
virtual ~cSkinCursesDisplayReplay() override
Definition: skincurses.c:528
virtual void SetCurrent(const char *Current) override
Sets the current position within the recording, as a user readable string in the form "h:mm:ss....
Definition: skincurses.c:561
cSkinCursesDisplayTracks(const char *Title, int NumTracks, const char *const *Tracks)
Definition: skincurses.c:654
virtual ~cSkinCursesDisplayTracks() override
Definition: skincurses.c:668
void SetItem(const char *Text, int Index, bool Current)
Definition: skincurses.c:673
virtual void SetAudioChannel(int AudioChannel) override
Sets the audio channel indicator.
Definition: skincurses.c:650
virtual void Flush(void) override
Actually draws the OSD display to the output device.
Definition: skincurses.c:696
virtual void SetTrack(int Index, const char *const *Tracks) override
< This class implements the track display.
Definition: skincurses.c:689
virtual void SetVolume(int Current, int Total, bool Mute) override
< This class implements the volume/mute display.
Definition: skincurses.c:616
virtual void Flush(void) override
Actually draws the OSD display to the output device.
Definition: skincurses.c:633
virtual ~cSkinCursesDisplayVolume() override
Definition: skincurses.c:611
virtual const char * Description(void) override
Returns a user visible, single line description of this skin, which may consist of arbitrary text and...
Definition: skincurses.c:752
virtual cSkinDisplayMenu * DisplayMenu(void) override
Creates and returns a new object for displaying a menu.
Definition: skincurses.c:762
virtual cSkinDisplayTracks * DisplayTracks(const char *Title, int NumTracks, const char *const *Tracks) override
Creates and returns a new object for displaying the available tracks.
Definition: skincurses.c:777
cSkinCurses(void)
Definition: skincurses.c:747
virtual cSkinDisplayMessage * DisplayMessage(void) override
Creates and returns a new object for displaying a message.
Definition: skincurses.c:782
virtual cSkinDisplayReplay * DisplayReplay(bool ModeOnly) override
Creates and returns a new object for displaying replay progress.
Definition: skincurses.c:767
virtual cSkinDisplayVolume * DisplayVolume(void) override
Creates and returns a new object for displaying the current volume.
Definition: skincurses.c:772
virtual cSkinDisplayChannel * DisplayChannel(bool WithInfo) override
Creates and returns a new object for displaying the current channel.
Definition: skincurses.c:757
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:265
Definition: tools.h:178
static cString sprintf(const char *fmt,...) __attribute__((format(printf
Definition: tools.c:1195
int Height(void)
Definition: osd.h:1088
bool CanScroll(void)
Definition: osd.h:1092
int Total(void)
Definition: osd.h:1089
int Top(void)
Definition: osd.h:1086
int Offset(void)
Definition: osd.h:1090
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:2421
void Reset(void)
Definition: osd.c:2438
int Shown(void)
Definition: osd.h:1091
bool CanScrollDown(void)
Definition: osd.h:1094
bool CanScrollUp(void)
Definition: osd.h:1093
int Size(void) const
Definition: tools.h:754
int IndexOf(const T &Data)
Definition: tools.h:746
virtual void Append(T Data)
Definition: tools.h:774
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:210
static cString String(void)
Returns a localized string of the form "Disk nn% - hh:mm free".
Definition: videodir.c:234
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:253
@ 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:1301
bool isempty(const char *s)
Definition: tools.c:357
int Utf8StrLen(const char *s)
Returns the number of UTF-8 symbols formed by the given string of character bytes.
Definition: tools.c:903
cString DateString(time_t t)
Converts the given time to a string of the form "www dd.mm.yyyy".
Definition: tools.c:1281
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:1260
T min(T a, T b)
Definition: tools.h:63
T max(T a, T b)
Definition: tools.h:64