summaryrefslogtreecommitdiff
path: root/displayreplay.c
blob: 9c9e8a81a23668b130bdd3b316467671159b66f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 * skinlcars.c: A VDR skin with Star Trek's "LCARS" layout
 *
 * See the main source file 'vdr.c' for copyright information and
 * how to reach the author.
 *
 * $Id: skinlcars.c 4.1 2015/09/01 10:07:07 kls Exp $
 */

// "Star Trek: The Next Generation"(R) is a registered trademark of Paramount Pictures,
// registered in the United States Patent and Trademark Office, all rights reserved.
// The LCARS system is based upon the designs of Michael Okuda and his Okudagrams.
//
// "LCARS" is short for "Library Computer Access and Retrieval System".
// Some resources used for writing this skin can be found at
// http://www.lcars.org.uk
// http://www.lcarsdeveloper.com
// http://www.lcarscom.net
// http://lds-jedi.deviantart.com/art/LCARS-Swept-Tutorial-213936938
// http://lds-jedi.deviantart.com/art/LCARS-Button-Tutorial-210783437
// http://zelldenver.deviantart.com/art/LCARS-Color-Standard-179565780
// http://www.lcars47.com
// http://www.bracercom.com/tutorial/content/CoherentLCARSInterface/LCARSCoherentInterface.html
// http://www.bracercom.com/tutorial/content/lcars_manifesto/the_lcars_manifesto.html

#include "lcarsng.h"
#include "displayreplay.h"
#include "config.h"
#include <vdr/font.h>
#include <vdr/menu.h>
#include <vdr/osd.h>
#if APIVERSNUM > 20101
#include <vdr/positioner.h>
#endif
#include <vdr/themes.h>
#include <vdr/thread.h>
#include <vdr/tools.h>
#include <vdr/videodir.h>
#include <sys/statvfs.h>
#include <string>

cBitmap cLCARSNGDisplayReplay::bmTeletext(teletext_xpm);
cBitmap cLCARSNGDisplayReplay::bmRadio(radio_xpm);
cBitmap cLCARSNGDisplayReplay::bmAudio(audio_xpm);
cBitmap cLCARSNGDisplayReplay::bmDolbyDigital(dolbydigital_xpm);
cBitmap cLCARSNGDisplayReplay::bmEncrypted(encrypted_xpm);
cBitmap cLCARSNGDisplayReplay::bmRecording(recording_xpm);

// --- cLCARSNGDisplayReplay -----------------------------------------------

cLCARSNGDisplayReplay::cLCARSNGDisplayReplay(bool ModeOnly):cThread("LCARS DisplRepl")
{
  font = cFont::GetFont(fontOsd);
  modeOnly = ModeOnly;
  lineHeight = font->Height();
  iconHeight = bmRecording.Height();
  frameColorBg = Theme.Color(clrReplayFrameBg);
  frameColorFg = Theme.Color(clrReplayFrameFg);
  frameColorMg = Theme.Color(clrReplayFrameMg);
  Margin = Config.Margin;
  lastCurrentWidth = 0;
  lastTotalWidth = 0;
  memset(&lastTrackId, 0, sizeof(lastTrackId));
  initial = true;
  lastOn = false;
  On = false;
  message = false;
  isRecording = false;
  timshiftMode = false;
  fps = DEFAULTFRAMESPERSECOND;
  framesTotal = 0;
  pbinit = true;
  int d = 5 * lineHeight;
  xp00 = 0;
  xp01 = xp00 + d / 2;
  xp02 = xp00 + d;
  xp03 = xp02 + lineHeight;
  xp04 = xp02 + d / 4;
  xp05 = xp02 + d;
  xp06 = xp05 + Gap;
  xp15 = cOsd::OsdWidth();
  xp14 = xp15 - lineHeight;
  xp13 = xp14 - Gap;
  xp07 = (xp15 + xp00) / 2;
  xp08 = xp07 + Gap;
  xp09 = xp08 + lineHeight;
  xp10 = xp09 + Gap;
  xp11 = (xp10 + xp13 + Gap) / 2;
  xp12 = xp11 + Gap;

  yp00 = lineHeight;
  yp01 = yp00 + 2 * lineHeight + 2 * Margin;
  yp02 = yp01 + Gap;
  yp03 = yp02 + 2 * lineHeight + 2 * Margin;
  yp04 = yp03 + Gap;
  yp09 = yp04 + 3 * lineHeight + Gap / 2 + 2 * Margin;
  yp08 = yp09 - max(lineHeight, iconHeight) - 2 * Margin;
  yp07 = yp08 - lineHeight;
  yp06 = yp08 - d / 4;
  yp05 = yp09 - d / 2;

  osd = CreateOsd(cOsd::OsdLeft(), cOsd::OsdTop() + cOsd::OsdHeight() - yp09, xp00, yp00 - lineHeight, xp15 - 1, yp09 - 1);
  osd->DrawRectangle(xp00, yp00, xp15 - 1, yp09 - 1, modeOnly ? clrTransparent : Theme.Color(clrBackground));
  // Rectangles:
  if (!modeOnly) {
     DrawRectangleOutline(osd, xp00, yp00, xp02 - 1, yp01 - 1, frameColorMg, frameColorBg, 15);
     }
  DrawRectangleOutline(osd, xp00, yp02, xp02 - 1, yp03 - 1, frameColorMg, frameColorBg, 15);
  if (!modeOnly) {
     // Elbow:
     DrawRectangleOutline(osd, xp00, yp04, xp02 - 1, yp08 - 1, frameColorMg, frameColorBg, 7);
     DrawRectangleOutline(osd, xp00, yp08, xp02 - 1, yp09 - 1, frameColorMg, frameColorBg, 8);
     DrawRectangleOutline(osd, xp02, yp08, xp05 - 1, yp09 - 1, frameColorMg, frameColorBg, 14);
     osd->DrawRectangle(xp00, yp05, xp01 - 1, yp09 - 1, clrTransparent);
     osd->DrawEllipse  (xp00, yp05, xp01 - 1, yp09 - 1, frameColorMg, 3);
     osd->DrawEllipse  (xp00 + Margin, yp05, xp01 - 1, yp09 - 1 - Margin, frameColorBg, 3);
     osd->DrawEllipse  (xp02 - 1, yp06, xp04 - 1, yp08, frameColorMg, -3);
     osd->DrawEllipse  (xp02 - 1 - Margin, yp06, xp04 - 1, yp08 + Margin, frameColorBg, -3);
     // Status area:
     DrawRectangleOutline(osd, xp06, yp08, xp07 - 1, yp09 - 1, frameColorMg, frameColorBg, 15);
     DrawRectangleOutline(osd, xp08, yp08, xp09 - 1, yp09 - 1, frameColorMg, frameColorBg, 15);
     DrawRectangleOutline(osd, xp10, yp08, xp11 - 1, yp09 - 1, frameColorMg, frameColorBg, 15);
     DrawRectangleOutline(osd, xp12, yp08, xp13 - 1, yp09 - 1, frameColorMg, frameColorBg, 15);
     DrawRectangleOutline(osd, xp14, yp08, xp14 + lineHeight / 2 - 1, yp09 - 1, frameColorMg, frameColorBg, 11);
     osd->DrawRectangle(xp14 + lineHeight / 2, yp08 + lineHeight / 2, xp15 - 1, yp09 - 1, clrTransparent);
     osd->DrawEllipse  (xp14 + lineHeight / 2, yp08, xp15 - 1, yp09 - 1, frameColorMg, 5);
     osd->DrawEllipse  (xp14 + lineHeight / 2, yp08 + Margin, xp15 - 1 - Margin, yp09 - 1 - Margin, frameColorBg, 5);
     // Upper Right:
     osd->DrawRectangle(xp13, yp00 - lineHeight, xp15 - 1, yp00 - 1, Theme.Color(clrBackground));
     DrawRectangleOutline(osd, xp14, yp00 - lineHeight, xp14 + lineHeight / 2 - 1, yp00 - 1, frameColorMg, frameColorBg, 11);
     osd->DrawRectangle(xp14 + lineHeight / 2, yp00 - lineHeight, xp15 - 1, yp00 - lineHeight / 2 - 1, clrTransparent);
     osd->DrawEllipse  (xp14 + lineHeight / 2, yp00  - lineHeight, xp15 - 1, yp00 - 1, frameColorMg, 5);
     osd->DrawEllipse  (xp14 + lineHeight / 2, yp00  - lineHeight + Margin, xp15 - 1 - Margin, yp00 - 1 - Margin, frameColorBg, 5);
     // Progressbar
     DrawRectangleOutline(osd, xp03, yp03 - lineHeight, xp13 - 1, yp03 - 1, frameColorMg, frameColorBg, 15);
     }
}

cLCARSNGDisplayReplay::~cLCARSNGDisplayReplay()
{
  Cancel(3);
  delete osd;
}

void cLCARSNGDisplayReplay::DrawDate(void)
{
  cString s = DayDateTime();
  if (!*lastDate || strcmp(s, lastDate)) {
     osd->DrawText(xp12, yp00 - lineHeight, s, Theme.Color(clrDateFg), Theme.Color(clrDateBg), font, xp13 - xp12 - 1, lineHeight, taRight | taBorder);
     lastDate = s;
     }
}

void cLCARSNGDisplayReplay::DrawTrack(void)
{
  cDevice *Device = cDevice::PrimaryDevice();
  const tTrackId *Track = Device->GetTrack(Device->GetCurrentAudioTrack());
  if (Track ? strcmp(lastTrackId.description, Track->description) : *lastTrackId.description) {
     osd->DrawText(xp10 + Margin, yp08 + Margin, Track ? Track->description : "", Theme.Color(clrTrackName), clrTransparent, font, xp11 - xp10 - 2 * Margin, yp09 - yp08 - 2 * Margin, taRight | taBorder);
     strn0cpy(lastTrackId.description, Track ? Track->description : "", sizeof(lastTrackId.description));
     }
}

void cLCARSNGDisplayReplay::DrawBlinkingRec(void)
{ 
  if (message)
     return;

  bool rec = cRecordControls::Active();

  if (rec) {
     if (!Running()) {
        Start();
        On = true;
        }
     }
  else {
     if (Running())
        Cancel(3);
     On = false;
     }
  if (initial || On != lastOn) { 
     int x = xp13;
     x -= bmRecording.Width() + SymbolSpacing;
     osd->DrawBitmap(x - Margin, yp08 + (yp09 - yp08 - bmRecording.Height()) / 2, bmRecording, Theme.Color(rec ? On ? clrChannelSymbolRecFg : clrChannelSymbolOff : clrChannelSymbolOff), rec ? On ? Theme.Color(clrChannelSymbolRecBg) : frameColorMg : frameColorMg);
     lastOn = On;
     }
}

void cLCARSNGDisplayReplay::SetRecording(const cRecording *Recording)
{
  const cRecordingInfo *RecordingInfo = Recording->Info();
  if (!RecordingInfo)
     return;
 
  SetTitle(RecordingInfo->Title());
  const cFont *fontsml = cFont::GetFont(fontSml);
  int w = fontsml->Width(RecordingInfo->ShortText());
  osd->DrawText(xp03, yp01 - lineHeight - Margin, RecordingInfo->ShortText(), Theme.Color(clrEventShortText), frameColorBg, fontsml, min(xp13, (xp03 + w)) - xp03, lineHeight, taCenter);
  osd->DrawText(xp00 + Margin, yp00 + Margin, ShortDateString(Recording->Start()), frameColorFg, frameColorBg, font, xp02 - xp00 - 2 * Margin, lineHeight, taTop | taRight | taBorder);
  osd->DrawText(xp00 + Margin, yp01 - lineHeight - Margin, TimeString(Recording->Start()), frameColorFg, frameColorBg, font, xp02 - xp00 - 2 * Margin, lineHeight, taBottom | taRight | taBorder);

  //check for instant recording
  const char *recName = Recording->Name();
  int usage = Recording->IsInUse();
  if (usage & ruTimer)
     isRecording = true;
  if ((recName && *recName == '@') && (isRecording)) {
     timshiftMode = true;
     return;
  }
  if (!isRecording)
     return;
  const cEvent *Event = RecordingInfo->GetEvent();
  if (!Event)
     return;
  fps = Recording->FramesPerSecond();
  time_t liveEventStop = Event->EndTime();
  time_t recordingStart = time(0) - Recording->LengthInSeconds();
  framesTotal = (liveEventStop - recordingStart) * fps;
  endTime = cString::sprintf("%s: %s", tr("length"), *IndexToHMSF(framesTotal, false, fps));
}

void cLCARSNGDisplayReplay::SetTitle(const char *Title)
{
  int w = font->Width(Title);
  osd->DrawText(xp03, yp00 + Margin, Title, Theme.Color(clrEventTitle), frameColorBg, font, min(xp13, (xp03 + w)) - xp03, lineHeight);
}

static const char *const *ReplaySymbols[2][2][5] = {
  { { pause_xpm, srew_xpm, srew1_xpm, srew2_xpm, srew3_xpm },
    { pause_xpm, sfwd_xpm, sfwd1_xpm, sfwd2_xpm, sfwd3_xpm }, },
  { { play_xpm,  frew_xpm, frew1_xpm, frew2_xpm, frew3_xpm },
    { play_xpm,  ffwd_xpm, ffwd1_xpm, ffwd2_xpm, ffwd3_xpm } }
  };

void cLCARSNGDisplayReplay::SetMode(bool Play, bool Forward, int Speed)
{
  Speed = constrain(Speed, -1, 3);
  cBitmap bm(ReplaySymbols[Play][Forward][Speed + 1]);
  osd->DrawBitmap(xp01 - bm.Width() / 2, (yp02 + yp03 - bm.Height()) / 2, bm, frameColorFg, frameColorBg);
}

void cLCARSNGDisplayReplay::SetProgress(int Current, int Total)
{
  int x = 0;
  int lH = lineHeight / 4;
  if (timshiftMode) {
     cString tM = "TimeshiftMode";
     int w = font->Width(tM);
     osd->DrawText(xp13 - w, yp01, tM, Theme.Color(clrReplayPosition), frameColorBg, font, w, 0, taRight);
  }
  if (isRecording) {
     int w = font->Width(endTime);
     if (Total > framesTotal) {
        osd->DrawRectangle(xp13 - w, yp01, xp13 - 1, yp03 - lineHeight - 1, Theme.Color(clrBackground)); // Clear endTime
        isRecording = false;
        x = 0;
     }
     else {
        double rest = ((double)framesTotal - (double)Total) / (double)framesTotal;
        x = (int)((xp13 - xp03) * rest);
        osd->DrawText(xp13 - w, yp01, *endTime, Theme.Color(clrReplayPosition), frameColorBg, font, w, 0, taRight);
     }
     if (pbinit) {
        osd->DrawRectangle(xp03 + Margin, yp03 - lineHeight + 4 + lH, xp13 - Margin, yp03 - 4 - lH, frameColorMg); // small rectangle
        pbinit = false;
     }
  }
  if ((xp13 - xp03 - x - 5) > 0) {
     cProgressBar pb(xp13 - xp03 - x - 2 * Margin, lineHeight - 2 * Margin, Current, Total, marks, Theme.Color(clrReplayProgressSeen), Theme.Color(clrReplayProgressRest), Theme.Color(clrReplayProgressSelected), Theme.Color(clrReplayProgressMark), Theme.Color(clrReplayProgressCurrent));
     osd->DrawBitmap(xp03 + Margin, yp03 - lineHeight + Margin, pb); // Progressbar
  }
}

void cLCARSNGDisplayReplay::SetCurrent(const char *Current)
{
  int w = font->Width(Current);
  osd->DrawText(xp03, yp04, Current, Theme.Color(clrReplayPosition), frameColorBg, font, max(lastCurrentWidth, w), 0, taTop | taLeft);
  if (lastCurrentWidth > w)
     osd->DrawRectangle(xp03 + lastCurrentWidth - (lastCurrentWidth - w), yp04, xp03 + lastCurrentWidth, yp04 + lineHeight, Theme.Color(clrBackground));
  lastCurrentWidth = w;
}

void cLCARSNGDisplayReplay::SetTotal(const char *Total)
{
  int w = font->Width(Total);
  osd->DrawText(xp13 - w, yp04, Total, Theme.Color(clrReplayPosition), frameColorBg, font, max(lastTotalWidth, w), 0, taTop | taRight);
  lastTotalWidth = w;
}

void cLCARSNGDisplayReplay::SetJump(const char *Jump)
{
  if (!Jump)
     osd->DrawRectangle(xp06 + Margin, yp08 + Margin, xp07 - 1 - Margin, yp09 - 1 - Margin, frameColorBg);
  osd->DrawText(xp06 + Margin, yp08 + Margin, Jump, Theme.Color(clrReplayJumpFg), Jump ? Theme.Color(clrReplayJumpBg) : frameColorBg, font, xp07 - xp06 - 1 - 2 * Margin, yp09 - yp08 - 1 - 2 * Margin, taCenter);
}

void cLCARSNGDisplayReplay::SetMessage(eMessageType Type, const char *Text)
{
  if (Text) {
     tColor ColorFg = Theme.Color(clrMessageStatusFg + 2 * Type);
     tColor ColorBg = Theme.Color(clrMessageStatusBg + 2 * Type);
     int x0, x1, y0, y1, lx, ly;
     x0 = xp06;
     x1 = xp13 - 1;
     y0 = yp08;
     y1 = yp09 - 1;
     lx = x1 - x0 - 2 * Margin;
     ly = y1 - y0 - 2 * Margin;
     message = true;
     osd->SaveRegion(x0, y0, x1, y1);
     DrawRectangleOutline(osd, x0, y0, x1, y1, ColorFg, ColorBg, 15);
     osd->DrawText(x0 + Margin, y0 + Margin, Text, ColorFg, ColorBg, cFont::GetFont(fontSml), lx, ly, taCenter);
     }
  else {
     osd->RestoreRegion();
     message = false;
     }
}

void cLCARSNGDisplayReplay::Action(void)
{
  int i = 0;

  while (Running()) {
     i++;
     if (message || i > 9) {
        i = 0;
        On = !On;
        DrawBlinkingRec();
        if (osd) osd->Flush();
        }
     cCondWait::SleepMs(100);
  }
}

void cLCARSNGDisplayReplay::Flush(void)
{
  if (!modeOnly) {
     DrawDate();
     DrawTrack();
     if (initial)
        DrawBlinkingRec();
     }
  osd->Flush();
  initial = false;
}