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