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