1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Completely moved OSD handling out of the cDvbApi class, into the new cOsd

This commit is contained in:
Klaus Schmidinger 2002-05-18 14:03:22 +02:00
parent 3e5b31af5e
commit bdccbbe93e
13 changed files with 332 additions and 303 deletions

View File

@ -1309,3 +1309,4 @@ Video Disk Recorder Revision History
- Added an error message if the directory specified in the '-L' option can't be - Added an error message if the directory specified in the '-L' option can't be
accessed (suggested by Stefan Huelswitt). accessed (suggested by Stefan Huelswitt).
- Rearranged OSD class names to make 'cOsd' available for the main OSD interface. - Rearranged OSD class names to make 'cOsd' available for the main OSD interface.
- Completely moved OSD handling out of the cDvbApi class, into the new cOsd.

221
dvbapi.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbapi.c 1.176 2002/05/18 09:21:39 kls Exp $ * $Id: dvbapi.c 1.177 2002/05/18 14:03:17 kls Exp $
*/ */
#include "dvbapi.h" #include "dvbapi.h"
@ -1759,24 +1759,7 @@ cDvbApi::cDvbApi(int n)
} }
else else
esyslog("ERROR: can't open video device %d", n); esyslog("ERROR: can't open video device %d", n);
cols = rows = 0;
#if defined(DEBUG_OSD) || defined(REMOTE_KBD)
initscr();
keypad(stdscr, true);
nonl();
cbreak();
noecho();
timeout(10);
#endif
#if defined(DEBUG_OSD)
memset(&colorPairs, 0, sizeof(colorPairs));
start_color();
leaveok(stdscr, true);
window = NULL;
#else
osd = NULL;
#endif
currentChannel = 1; currentChannel = 1;
mute = false; mute = false;
volume = Setup.CurrentVolume; volume = Setup.CurrentVolume;
@ -1785,15 +1768,11 @@ cDvbApi::cDvbApi(int n)
cDvbApi::~cDvbApi() cDvbApi::~cDvbApi()
{ {
delete siProcessor; delete siProcessor;
Close();
StopReplay(); StopReplay();
StopRecord(); StopRecord();
StopTransfer(); StopTransfer();
// We're not explicitly closing any device files here, since this sometimes // We're not explicitly closing any device files here, since this sometimes
// caused segfaults. Besides, the program is about to terminate anyway... // caused segfaults. Besides, the program is about to terminate anyway...
#if defined(DEBUG_OSD) || defined(REMOTE_KBD)
endwin();
#endif
} }
void cDvbApi::SetUseDvbApi(int n) void cDvbApi::SetUseDvbApi(int n)
@ -1923,7 +1902,7 @@ bool cDvbApi::Probe(const char *FileName)
return false; return false;
} }
bool cDvbApi::Init(void) bool cDvbApi::Initialize(void)
{ {
NumDvbApis = 0; NumDvbApis = 0;
for (int i = 0; i < MAXDVBAPI; i++) { for (int i = 0; i < MAXDVBAPI; i++) {
@ -1943,7 +1922,7 @@ bool cDvbApi::Init(void)
return NumDvbApis > 0; return NumDvbApis > 0;
} }
void cDvbApi::Cleanup(void) void cDvbApi::Shutdown(void)
{ {
for (int i = 0; i < NumDvbApis; i++) { for (int i = 0; i < NumDvbApis; i++) {
delete dvbApi[i]; delete dvbApi[i];
@ -2045,200 +2024,6 @@ bool cDvbApi::GrabImage(const char *FileName, bool Jpeg, int Quality, int SizeX,
return false; return false;
} }
#ifdef DEBUG_OSD
void cDvbApi::SetColor(eDvbColor colorFg, eDvbColor colorBg)
{
int color = (colorBg << 16) | colorFg | 0x80000000;
for (int i = 0; i < MaxColorPairs; i++) {
if (!colorPairs[i]) {
colorPairs[i] = color;
init_pair(i + 1, colorFg, colorBg);
wattrset(window, COLOR_PAIR(i + 1));
break;
}
else if (color == colorPairs[i]) {
wattrset(window, COLOR_PAIR(i + 1));
break;
}
}
}
#endif
void cDvbApi::Open(int w, int h)
{
int d = (h < 0) ? Setup.OSDheight + h : 0;
h = abs(h);
cols = w;
rows = h;
#ifdef DEBUG_OSD
window = subwin(stdscr, h, w, d, (Setup.OSDwidth - w) / 2);
syncok(window, true);
#define B2C(b) (((b) * 1000) / 255)
#define SETCOLOR(n, r, g, b, o) init_color(n, B2C(r), B2C(g), B2C(b))
//XXX
SETCOLOR(clrBackground, 0x00, 0x00, 0x00, 127); // background 50% gray
SETCOLOR(clrBlack, 0x00, 0x00, 0x00, 255);
SETCOLOR(clrRed, 0xFC, 0x14, 0x14, 255);
SETCOLOR(clrGreen, 0x24, 0xFC, 0x24, 255);
SETCOLOR(clrYellow, 0xFC, 0xC0, 0x24, 255);
SETCOLOR(clrBlue, 0x00, 0x00, 0xFC, 255);
SETCOLOR(clrCyan, 0x00, 0xFC, 0xFC, 255);
SETCOLOR(clrMagenta, 0xB0, 0x00, 0xFC, 255);
SETCOLOR(clrWhite, 0xFC, 0xFC, 0xFC, 255);
#else
w *= charWidth;
h *= lineHeight;
d *= lineHeight;
int x = (720 - w + charWidth) / 2; //TODO PAL vs. NTSC???
int y = (576 - Setup.OSDheight * lineHeight) / 2 + d;
//XXX
osd = new cDvbOsd(fd_osd, x, y);
//XXX TODO this should be transferred to the places where the individual windows are requested (there's too much detailed knowledge here!)
if (h / lineHeight == 5) { //XXX channel display
osd->Create(0, 0, w, h, 4);
}
else if (h / lineHeight == 1) { //XXX info display
osd->Create(0, 0, w, h, 4);
}
else if (d == 0) { //XXX full menu
osd->Create(0, 0, w, lineHeight, 2);
osd->Create(0, lineHeight, w, (Setup.OSDheight - 3) * lineHeight, 2);
osd->AddColor(clrBackground);
osd->AddColor(clrCyan);
osd->AddColor(clrWhite);
osd->AddColor(clrBlack);
osd->Create(0, (Setup.OSDheight - 2) * lineHeight, w, 2 * lineHeight, 4);
}
else { //XXX progress display
/*XXX
osd->Create(0, 0, w, lineHeight, 1);
osd->Create(0, lineHeight, w, lineHeight, 2, false);
osd->Create(0, 2 * lineHeight, w, lineHeight, 1);
XXX*///XXX some pixels are not drawn correctly with lower bpp values
osd->Create(0, 0, w, 3*lineHeight, 4);
}
#endif
}
void cDvbApi::Close(void)
{
#ifdef DEBUG_OSD
if (window) {
delwin(window);
window = 0;
}
#else
delete osd;
osd = NULL;
#endif
}
void cDvbApi::Clear(void)
{
#ifdef DEBUG_OSD
SetColor(clrBackground, clrBackground);
Fill(0, 0, cols, rows, clrBackground);
#else
osd->Clear();
#endif
}
void cDvbApi::Fill(int x, int y, int w, int h, eDvbColor color)
{
if (x < 0) x = cols + x;
if (y < 0) y = rows + y;
#ifdef DEBUG_OSD
SetColor(color, color);
for (int r = 0; r < h; r++) {
wmove(window, y + r, x); // ncurses wants 'y' before 'x'!
whline(window, ' ', w);
}
wsyncup(window); // shouldn't be necessary because of 'syncok()', but w/o it doesn't work
#else
osd->Fill(x * charWidth, y * lineHeight, (x + w) * charWidth - 1, (y + h) * lineHeight - 1, color);
#endif
}
void cDvbApi::SetBitmap(int x, int y, const cBitmap &Bitmap)
{
#ifndef DEBUG_OSD
osd->SetBitmap(x, y, Bitmap);
#endif
}
void cDvbApi::ClrEol(int x, int y, eDvbColor color)
{
Fill(x, y, cols - x, 1, color);
}
int cDvbApi::CellWidth(void)
{
#ifdef DEBUG_OSD
return 1;
#else
return charWidth;
#endif
}
int cDvbApi::LineHeight(void)
{
#ifdef DEBUG_OSD
return 1;
#else
return lineHeight;
#endif
}
int cDvbApi::Width(unsigned char c)
{
#ifdef DEBUG_OSD
return 1;
#else
return osd->Width(c);
#endif
}
int cDvbApi::WidthInCells(const char *s)
{
#ifdef DEBUG_OSD
return strlen(s);
#else
return (osd->Width(s) + charWidth - 1) / charWidth;
#endif
}
eDvbFont cDvbApi::SetFont(eDvbFont Font)
{
#ifdef DEBUG_OSD
return Font;
#else
return osd->SetFont(Font);
#endif
}
void cDvbApi::Text(int x, int y, const char *s, eDvbColor colorFg, eDvbColor colorBg)
{
if (x < 0) x = cols + x;
if (y < 0) y = rows + y;
#ifdef DEBUG_OSD
SetColor(colorFg, colorBg);
wmove(window, y, x); // ncurses wants 'y' before 'x'!
waddnstr(window, s, cols - x);
#else
osd->Text(x * charWidth, y * lineHeight, s, colorFg, colorBg);
#endif
}
void cDvbApi::Flush(void)
{
#ifdef DEBUG_OSD
refresh();
#else
if (osd)
osd->Flush();
#endif
}
int cDvbApi::Priority(void) int cDvbApi::Priority(void)
{ {
return (this == PrimaryDvbApi && !Recording()) ? Setup.PrimaryLimit - 1 : priority; return (this == PrimaryDvbApi && !Recording()) ? Setup.PrimaryLimit - 1 : priority;

View File

@ -4,16 +4,12 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbapi.h 1.69 2002/04/21 09:49:22 kls Exp $ * $Id: dvbapi.h 1.70 2002/05/18 14:03:12 kls Exp $
*/ */
#ifndef __DVBAPI_H #ifndef __DVBAPI_H
#define __DVBAPI_H #define __DVBAPI_H
#if defined(DEBUG_OSD) || defined(REMOTE_KBD)
#include <ncurses.h>
#undef ERR //XXX ncurses defines this - but this clashes with newer system header files
#endif
#include <stdlib.h> // FIXME: this is apparently necessary for the ost/... header files #include <stdlib.h> // FIXME: this is apparently necessary for the ost/... header files
// FIXME: shouldn't every header file include ALL the other header // FIXME: shouldn't every header file include ALL the other header
// FIXME: files it depends on? The sequence in which header files // FIXME: files it depends on? The sequence in which header files
@ -25,10 +21,7 @@
#include <ost/frontend.h> #include <ost/frontend.h>
#include <ost/video.h> #include <ost/video.h>
#include <ost/audio.h> #include <ost/audio.h>
#include <ost/osd.h>
#include <stdio.h> #include <stdio.h>
#include "dvbosd.h"
#include "eit.h" #include "eit.h"
#include "thread.h" #include "thread.h"
@ -76,6 +69,7 @@ public:
}; };
class cDvbApi { class cDvbApi {
friend class cOsd;
friend class cRecordBuffer; friend class cRecordBuffer;
friend class cReplayBuffer; friend class cReplayBuffer;
friend class cTransferBuffer; friend class cTransferBuffer;
@ -83,6 +77,7 @@ private:
FrontendType frontendType; FrontendType frontendType;
int fd_osd, fd_frontend, fd_sec, fd_dvr, fd_audio, fd_video, fd_demuxa1, fd_demuxa2, fd_demuxd1, fd_demuxd2, fd_demuxv, fd_demuxt; int fd_osd, fd_frontend, fd_sec, fd_dvr, fd_audio, fd_video, fd_demuxa1, fd_demuxa2, fd_demuxd1, fd_demuxd2, fd_demuxv, fd_demuxt;
int vPid, aPid1, aPid2, dPid1, dPid2; int vPid, aPid1, aPid2, dPid1, dPid2;
int OsdDeviceHandle(void) { return fd_osd; }
bool SetPid(int fd, dmxPesType_t PesType, int Pid, dmxOutput_t Output); bool SetPid(int fd, dmxPesType_t PesType, int Pid, dmxOutput_t Output);
bool SetVpid(int Vpid, dmxOutput_t Output) { return SetPid(fd_demuxv, DMX_PES_VIDEO, Vpid, Output); } bool SetVpid(int Vpid, dmxOutput_t Output) { return SetPid(fd_demuxv, DMX_PES_VIDEO, Vpid, Output); }
bool SetApid1(int Apid, dmxOutput_t Output) { return SetPid(fd_demuxa1, DMX_PES_AUDIO, Apid, Output); } bool SetApid1(int Apid, dmxOutput_t Output) { return SetPid(fd_demuxa1, DMX_PES_AUDIO, Apid, Output); }
@ -109,7 +104,7 @@ public:
static cDvbApi *PrimaryDvbApi; static cDvbApi *PrimaryDvbApi;
static void SetUseDvbApi(int n); static void SetUseDvbApi(int n);
// Sets the 'useDvbApi' flag of the given DVB device. // Sets the 'useDvbApi' flag of the given DVB device.
// If this function is not called before Init(), all DVB devices // If this function is not called before Initialize(), all DVB devices
// will be used. // will be used.
static bool SetPrimaryDvbApi(int n); static bool SetPrimaryDvbApi(int n);
// Sets the primary DVB device to 'n' (which must be in the range // Sets the primary DVB device to 'n' (which must be in the range
@ -137,10 +132,10 @@ public:
// in caCaps is returned. // in caCaps is returned.
static bool Probe(const char *FileName); static bool Probe(const char *FileName);
// Probes for existing DVB devices. // Probes for existing DVB devices.
static bool Init(void); static bool Initialize(void);
// Initializes the DVB API. // Initializes the DVB API.
// Must be called before accessing any DVB functions. // Must be called before accessing any DVB functions.
static void Cleanup(void); static void Shutdown(void);
// Closes down all DVB devices. // Closes down all DVB devices.
// Must be called at the end of the program. // Must be called at the end of the program.
@ -153,36 +148,6 @@ public:
bool GrabImage(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1); bool GrabImage(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
// On Screen Display facilities
private:
enum { charWidth = 12, // average character width
lineHeight = 27 // smallest text height
};
#ifdef DEBUG_OSD
WINDOW *window;
enum { MaxColorPairs = 16 };
int colorPairs[MaxColorPairs];
void SetColor(eDvbColor colorFg, eDvbColor colorBg = clrBackground);
#else
cDvbOsd *osd;
#endif
int cols, rows;
public:
void Open(int w, int h);
void Close(void);
void Clear(void);
void Fill(int x, int y, int w, int h, eDvbColor color = clrBackground);
void SetBitmap(int x, int y, const cBitmap &Bitmap);
void ClrEol(int x, int y, eDvbColor color = clrBackground);
int CellWidth(void);
int LineHeight(void);
int Width(unsigned char c);
int WidthInCells(const char *s);
eDvbFont SetFont(eDvbFont Font);
void Text(int x, int y, const char *s, eDvbColor colorFg = clrWhite, eDvbColor colorBg = clrBackground);
void Flush(void);
// Video format facilities: // Video format facilities:
void SetVideoFormat(videoFormat_t Format); void SetVideoFormat(videoFormat_t Format);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbosd.c 1.16 2002/05/18 12:39:39 kls Exp $ * $Id: dvbosd.c 1.17 2002/05/18 13:39:02 kls Exp $
*/ */
#include "dvbosd.h" #include "dvbosd.h"
@ -13,12 +13,12 @@
#include <sys/unistd.h> #include <sys/unistd.h>
#include "tools.h" #include "tools.h"
cDvbOsd::cDvbOsd(int VideoDev, int x, int y) cDvbOsd::cDvbOsd(int OsdDev, int x, int y)
:cOsdBase(x, y) :cOsdBase(x, y)
{ {
videoDev = VideoDev; osdDev = OsdDev;
if (videoDev < 0) if (osdDev < 0)
esyslog("ERROR: illegal video device handle (%d)!", videoDev); esyslog("ERROR: illegal OSD device handle (%d)!", osdDev);
} }
cDvbOsd::~cDvbOsd() cDvbOsd::~cDvbOsd()
@ -44,7 +44,7 @@ bool cDvbOsd::SetWindow(cWindow *Window)
void cDvbOsd::Cmd(OSD_Command cmd, int color, int x0, int y0, int x1, int y1, const void *data) void cDvbOsd::Cmd(OSD_Command cmd, int color, int x0, int y0, int x1, int y1, const void *data)
{ {
if (videoDev >= 0) { if (osdDev >= 0) {
osd_cmd_t dc; osd_cmd_t dc;
dc.cmd = cmd; dc.cmd = cmd;
dc.color = color; dc.color = color;
@ -58,7 +58,7 @@ void cDvbOsd::Cmd(OSD_Command cmd, int color, int x0, int y0, int x1, int y1, co
sigfillset(&set); sigfillset(&set);
sigdelset(&set, SIGALRM); sigdelset(&set, SIGALRM);
sigprocmask(SIG_BLOCK, &set, &oldset); sigprocmask(SIG_BLOCK, &set, &oldset);
ioctl(videoDev, OSD_SEND_CMD, &dc); ioctl(osdDev, OSD_SEND_CMD, &dc);
if (cmd == OSD_SetBlock) // XXX this is the only command that takes longer if (cmd == OSD_SetBlock) // XXX this is the only command that takes longer
usleep(5000); // XXX Workaround for a driver bug (cInterface::DisplayChannel() displayed texts at wrong places usleep(5000); // XXX Workaround for a driver bug (cInterface::DisplayChannel() displayed texts at wrong places
// XXX and sometimes the OSD was no longer displayed). // XXX and sometimes the OSD was no longer displayed).

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbosd.h 1.12 2002/05/18 12:39:31 kls Exp $ * $Id: dvbosd.h 1.13 2002/05/18 13:38:09 kls Exp $
*/ */
#ifndef __DVBOSD_H #ifndef __DVBOSD_H
@ -15,7 +15,7 @@
class cDvbOsd : public cOsdBase { class cDvbOsd : public cOsdBase {
private: private:
int videoDev; int osdDev;
bool SetWindow(cWindow *Window); bool SetWindow(cWindow *Window);
void Cmd(OSD_Command cmd, int color = 0, int x0 = 0, int y0 = 0, int x1 = 0, int y1 = 0, const void *data = NULL); void Cmd(OSD_Command cmd, int color = 0, int x0 = 0, int y0 = 0, int x1 = 0, int y1 = 0, const void *data = NULL);
protected: protected:
@ -26,7 +26,7 @@ protected:
virtual void MoveWindow(cWindow *Window, int x, int y); virtual void MoveWindow(cWindow *Window, int x, int y);
virtual void CloseWindow(cWindow *Window); virtual void CloseWindow(cWindow *Window);
public: public:
cDvbOsd(int VideoDev, int x, int y); cDvbOsd(int OsdDev, int x, int y);
virtual ~cDvbOsd(); virtual ~cDvbOsd();
}; };

View File

@ -4,13 +4,14 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: interface.c 1.48 2002/05/13 16:30:22 kls Exp $ * $Id: interface.c 1.49 2002/05/18 13:08:20 kls Exp $
*/ */
#include "interface.h" #include "interface.h"
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include "i18n.h" #include "i18n.h"
#include "osd.h"
cInterface *Interface = NULL; cInterface *Interface = NULL;
@ -50,7 +51,7 @@ void cInterface::Open(int NumCols, int NumLines)
NumCols = Setup.OSDwidth; NumCols = Setup.OSDwidth;
if (NumLines == 0) if (NumLines == 0)
NumLines = Setup.OSDheight; NumLines = Setup.OSDheight;
cDvbApi::PrimaryDvbApi->Open(width = NumCols, height = NumLines); cOsd::Open(width = NumCols, height = NumLines);
} }
} }
@ -59,7 +60,7 @@ void cInterface::Close(void)
if (open == 1) if (open == 1)
Clear(); Clear();
if (!--open) { if (!--open) {
cDvbApi::PrimaryDvbApi->Close(); cOsd::Close();
width = height = 0; width = height = 0;
} }
} }
@ -125,31 +126,31 @@ eKeys cInterface::Wait(int Seconds, bool KeepChar)
void cInterface::Clear(void) void cInterface::Clear(void)
{ {
if (open) if (open)
cDvbApi::PrimaryDvbApi->Clear(); cOsd::Clear();
} }
void cInterface::ClearEol(int x, int y, eDvbColor Color) void cInterface::ClearEol(int x, int y, eDvbColor Color)
{ {
if (open) if (open)
cDvbApi::PrimaryDvbApi->ClrEol(x, y, Color); cOsd::ClrEol(x, y, Color);
} }
void cInterface::Fill(int x, int y, int w, int h, eDvbColor Color) void cInterface::Fill(int x, int y, int w, int h, eDvbColor Color)
{ {
if (open) if (open)
cDvbApi::PrimaryDvbApi->Fill(x, y, w, h, Color); cOsd::Fill(x, y, w, h, Color);
} }
void cInterface::SetBitmap(int x, int y, const cBitmap &Bitmap) void cInterface::SetBitmap(int x, int y, const cBitmap &Bitmap)
{ {
if (open) if (open)
cDvbApi::PrimaryDvbApi->SetBitmap(x, y, Bitmap); cOsd::SetBitmap(x, y, Bitmap);
} }
void cInterface::Flush(void) void cInterface::Flush(void)
{ {
if (open) if (open)
cDvbApi::PrimaryDvbApi->Flush(); cOsd::Flush();
} }
void cInterface::SetCols(int *c) void cInterface::SetCols(int *c)
@ -163,7 +164,7 @@ void cInterface::SetCols(int *c)
eDvbFont cInterface::SetFont(eDvbFont Font) eDvbFont cInterface::SetFont(eDvbFont Font)
{ {
return cDvbApi::PrimaryDvbApi->SetFont(Font); return cOsd::SetFont(Font);
} }
char *cInterface::WrapText(const char *Text, int Width, int *Height) char *cInterface::WrapText(const char *Text, int Width, int *Height)
@ -183,7 +184,7 @@ char *cInterface::WrapText(const char *Text, int Width, int *Height)
char *Delim = NULL; char *Delim = NULL;
int w = 0; int w = 0;
Width *= cDvbApi::PrimaryDvbApi->CellWidth(); Width *= cOsd::CellWidth();
while (*t && t[strlen(t) - 1] == '\n') while (*t && t[strlen(t) - 1] == '\n')
t[strlen(t) - 1] = 0; // skips trailing newlines t[strlen(t) - 1] = 0; // skips trailing newlines
@ -198,7 +199,7 @@ char *cInterface::WrapText(const char *Text, int Width, int *Height)
} }
else if (isspace(*p)) else if (isspace(*p))
Blank = p; Blank = p;
int cw = cDvbApi::PrimaryDvbApi->Width(*p); int cw = cOsd::Width(*p);
if (w + cw > Width) { if (w + cw > Width) {
if (Blank) { if (Blank) {
*Blank = '\n'; *Blank = '\n';
@ -237,7 +238,7 @@ char *cInterface::WrapText(const char *Text, int Width, int *Height)
void cInterface::Write(int x, int y, const char *s, eDvbColor FgColor, eDvbColor BgColor) void cInterface::Write(int x, int y, const char *s, eDvbColor FgColor, eDvbColor BgColor)
{ {
if (open) if (open)
cDvbApi::PrimaryDvbApi->Text(x, y, s, FgColor, BgColor); cOsd::Text(x, y, s, FgColor, BgColor);
} }
void cInterface::WriteText(int x, int y, const char *s, eDvbColor FgColor, eDvbColor BgColor) void cInterface::WriteText(int x, int y, const char *s, eDvbColor FgColor, eDvbColor BgColor)
@ -278,7 +279,7 @@ void cInterface::Title(const char *s)
strn0cpy(buffer, s, n + 1); strn0cpy(buffer, s, n + 1);
Write(1, 0, buffer, clrBlack, clrCyan); Write(1, 0, buffer, clrBlack, clrCyan);
t++; t++;
Write(-(cDvbApi::PrimaryDvbApi->WidthInCells(t) + 1), 0, t, clrBlack, clrCyan); Write(-(cOsd::WidthInCells(t) + 1), 0, t, clrBlack, clrCyan);
} }
else { else {
int x = (Width() - strlen(s)) / 2; int x = (Width() - strlen(s)) / 2;
@ -337,12 +338,12 @@ void cInterface::HelpButton(int Index, const char *Text, eDvbColor FgColor, eDvb
{ {
if (open) { if (open) {
const int w = Width() / 4; const int w = Width() / 4;
cDvbApi::PrimaryDvbApi->Fill(Index * w, -1, w, 1, Text ? BgColor : clrBackground); cOsd::Fill(Index * w, -1, w, 1, Text ? BgColor : clrBackground);
if (Text) { if (Text) {
int l = (w - int(strlen(Text))) / 2; int l = (w - int(strlen(Text))) / 2;
if (l < 0) if (l < 0)
l = 0; l = 0;
cDvbApi::PrimaryDvbApi->Text(Index * w + l, -1, Text, FgColor, BgColor); cOsd::Text(Index * w + l, -1, Text, FgColor, BgColor);
} }
} }
} }

View File

@ -4,14 +4,14 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: interface.h 1.25 2002/04/19 13:17:15 kls Exp $ * $Id: interface.h 1.26 2002/05/18 13:43:20 kls Exp $
*/ */
#ifndef __INTERFACE_H #ifndef __INTERFACE_H
#define __INTERFACE_H #define __INTERFACE_H
#include "config.h" #include "config.h"
#include "dvbapi.h" #include "osdbase.h"
#include "remote.h" #include "remote.h"
#include "svdrp.h" #include "svdrp.h"

10
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menu.c 1.193 2002/05/18 12:35:21 kls Exp $ * $Id: menu.c 1.194 2002/05/18 13:08:42 kls Exp $
*/ */
#include "menu.h" #include "menu.h"
@ -2354,7 +2354,7 @@ void cDisplayVolume::Show(void)
Interface->Fill(l, 0, p, 1, clrGreen); Interface->Fill(l, 0, p, 1, clrGreen);
Interface->Fill(l + p, 0, Width() - l - p, 1, clrWhite); Interface->Fill(l + p, 0, Width() - l - p, 1, clrWhite);
#else #else
cVolumeBar VolumeBar(Width() * dvbApi->CellWidth(), dvbApi->LineHeight(), Current, Total, Prompt); cVolumeBar VolumeBar(Width() * cOsd::CellWidth(), cOsd::LineHeight(), Current, Total, Prompt);
Interface->SetBitmap(0, 0, VolumeBar); Interface->SetBitmap(0, 0, VolumeBar);
#endif #endif
} }
@ -2719,7 +2719,7 @@ void cReplayControl::Hide(void)
void cReplayControl::DisplayAtBottom(const char *s) void cReplayControl::DisplayAtBottom(const char *s)
{ {
if (s) { if (s) {
int w = dvbApi->WidthInCells(s); int w = cOsd::WidthInCells(s);
int d = max(Width() - w, 0) / 2; int d = max(Width() - w, 0) / 2;
if (modeOnly) //XXX remove when displaying replay mode differently if (modeOnly) //XXX remove when displaying replay mode differently
Interface->Fill(0, -1, Interface->Width(), 1, clrTransparent); //XXX remove when displaying replay mode differently Interface->Fill(0, -1, Interface->Width(), 1, clrTransparent); //XXX remove when displaying replay mode differently
@ -2795,8 +2795,8 @@ bool cReplayControl::ShowProgress(bool Initial)
Interface->Fill(0, 1, p, 1, clrGreen); Interface->Fill(0, 1, p, 1, clrGreen);
Interface->Fill(p, 1, Width() - p, 1, clrWhite); Interface->Fill(p, 1, Width() - p, 1, clrWhite);
#else #else
cProgressBar ProgressBar(Width() * dvbApi->CellWidth(), dvbApi->LineHeight(), Current, Total, marks); cProgressBar ProgressBar(Width() * cOsd::CellWidth(), cOsd::LineHeight(), Current, Total, marks);
Interface->SetBitmap(0, dvbApi->LineHeight(), ProgressBar); Interface->SetBitmap(0, cOsd::LineHeight(), ProgressBar);
if (!Initial) if (!Initial)
Interface->Flush(); Interface->Flush();
#endif #endif

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menuitems.c 1.3 2002/05/18 08:53:59 kls Exp $ * $Id: menuitems.c 1.4 2002/05/18 13:09:04 kls Exp $
*/ */
#include "menuitems.h" #include "menuitems.h"
@ -186,18 +186,18 @@ void cMenuEditStrItem::Set(void)
strncpy(buf, value, pos); strncpy(buf, value, pos);
snprintf(buf + pos, sizeof(buf) - pos - 2, fmt, *(value + pos), value + pos + 1); snprintf(buf + pos, sizeof(buf) - pos - 2, fmt, *(value + pos), value + pos + 1);
int width = Interface->Width() - Interface->GetCols()[0]; int width = Interface->Width() - Interface->GetCols()[0];
if (cDvbApi::PrimaryDvbApi->WidthInCells(buf) <= width) { if (cOsd::WidthInCells(buf) <= width) {
// the whole buffer fits on the screen // the whole buffer fits on the screen
SetValue(buf); SetValue(buf);
return; return;
} }
width *= cDvbApi::PrimaryDvbApi->CellWidth(); width *= cOsd::CellWidth();
width -= cDvbApi::PrimaryDvbApi->Width('>'); // assuming '<' and '>' have the same with width -= cOsd::Width('>'); // assuming '<' and '>' have the same with
int w = 0; int w = 0;
int i = 0; int i = 0;
int l = strlen(buf); int l = strlen(buf);
while (i < l && w <= width) while (i < l && w <= width)
w += cDvbApi::PrimaryDvbApi->Width(buf[i++]); w += cOsd::Width(buf[i++]);
if (i >= pos + 4) { if (i >= pos + 4) {
// the cursor fits on the screen // the cursor fits on the screen
buf[i - 1] = '>'; buf[i - 1] = '>';
@ -214,7 +214,7 @@ void cMenuEditStrItem::Set(void)
else else
i--; i--;
while (i >= 0 && w <= width) while (i >= 0 && w <= width)
w += cDvbApi::PrimaryDvbApi->Width(buf[i--]); w += cOsd::Width(buf[i--]);
buf[++i] = '<'; buf[++i] = '<';
SetValue(buf + i); SetValue(buf + i);
} }

232
osd.c
View File

@ -4,13 +4,243 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: osd.c 1.25 2002/05/12 11:38:39 kls Exp $ * $Id: osd.c 1.26 2002/05/18 14:00:21 kls Exp $
*/ */
#include "osd.h" #include "osd.h"
#include <string.h> #include <string.h>
#include "dvbapi.h"
#include "i18n.h" #include "i18n.h"
// --- cOsd ------------------------------------------------------------------
#ifdef DEBUG_OSD
WINDOW *cOsd::window = NULL;
int cOsd::colorPairs[MaxColorPairs] = { 0 };
#else
cDvbOsd *cOsd::osd = NULL;
#endif
int cOsd::cols = 0;
int cOsd::rows = 0;
void cOsd::Initialize(void)
{
#if defined(DEBUG_OSD) || defined(REMOTE_KBD)
initscr();
keypad(stdscr, true);
nonl();
cbreak();
noecho();
timeout(10);
#endif
#if defined(DEBUG_OSD)
start_color();
leaveok(stdscr, true);
#endif
}
void cOsd::Shutdown(void)
{
Close();
#if defined(DEBUG_OSD) || defined(REMOTE_KBD)
endwin();
#endif
}
#ifdef DEBUG_OSD
void cOsd::SetColor(eDvbColor colorFg, eDvbColor colorBg)
{
int color = (colorBg << 16) | colorFg | 0x80000000;
for (int i = 0; i < MaxColorPairs; i++) {
if (!colorPairs[i]) {
colorPairs[i] = color;
init_pair(i + 1, colorFg, colorBg);
wattrset(window, COLOR_PAIR(i + 1));
break;
}
else if (color == colorPairs[i]) {
wattrset(window, COLOR_PAIR(i + 1));
break;
}
}
}
#endif
void cOsd::Open(int w, int h)
{
int d = (h < 0) ? Setup.OSDheight + h : 0;
h = abs(h);
cols = w;
rows = h;
#ifdef DEBUG_OSD
window = subwin(stdscr, h, w, d, (Setup.OSDwidth - w) / 2);
syncok(window, true);
#define B2C(b) (((b) * 1000) / 255)
#define SETCOLOR(n, r, g, b, o) init_color(n, B2C(r), B2C(g), B2C(b))
//XXX
SETCOLOR(clrBackground, 0x00, 0x00, 0x00, 127); // background 50% gray
SETCOLOR(clrBlack, 0x00, 0x00, 0x00, 255);
SETCOLOR(clrRed, 0xFC, 0x14, 0x14, 255);
SETCOLOR(clrGreen, 0x24, 0xFC, 0x24, 255);
SETCOLOR(clrYellow, 0xFC, 0xC0, 0x24, 255);
SETCOLOR(clrBlue, 0x00, 0x00, 0xFC, 255);
SETCOLOR(clrCyan, 0x00, 0xFC, 0xFC, 255);
SETCOLOR(clrMagenta, 0xB0, 0x00, 0xFC, 255);
SETCOLOR(clrWhite, 0xFC, 0xFC, 0xFC, 255);
#else
w *= charWidth;
h *= lineHeight;
d *= lineHeight;
int x = (720 - w + charWidth) / 2; //TODO PAL vs. NTSC???
int y = (576 - Setup.OSDheight * lineHeight) / 2 + d;
//XXX
osd = new cDvbOsd(cDvbApi::PrimaryDvbApi->OsdDeviceHandle(), x, y);
//XXX TODO this should be transferred to the places where the individual windows are requested (there's too much detailed knowledge here!)
if (h / lineHeight == 5) { //XXX channel display
osd->Create(0, 0, w, h, 4);
}
else if (h / lineHeight == 1) { //XXX info display
osd->Create(0, 0, w, h, 4);
}
else if (d == 0) { //XXX full menu
osd->Create(0, 0, w, lineHeight, 2);
osd->Create(0, lineHeight, w, (Setup.OSDheight - 3) * lineHeight, 2);
osd->AddColor(clrBackground);
osd->AddColor(clrCyan);
osd->AddColor(clrWhite);
osd->AddColor(clrBlack);
osd->Create(0, (Setup.OSDheight - 2) * lineHeight, w, 2 * lineHeight, 4);
}
else { //XXX progress display
/*XXX
osd->Create(0, 0, w, lineHeight, 1);
osd->Create(0, lineHeight, w, lineHeight, 2, false);
osd->Create(0, 2 * lineHeight, w, lineHeight, 1);
XXX*///XXX some pixels are not drawn correctly with lower bpp values
osd->Create(0, 0, w, 3*lineHeight, 4);
}
#endif
}
void cOsd::Close(void)
{
#ifdef DEBUG_OSD
if (window) {
delwin(window);
window = 0;
}
#else
delete osd;
osd = NULL;
#endif
}
void cOsd::Clear(void)
{
#ifdef DEBUG_OSD
SetColor(clrBackground, clrBackground);
Fill(0, 0, cols, rows, clrBackground);
#else
osd->Clear();
#endif
}
void cOsd::Fill(int x, int y, int w, int h, eDvbColor color)
{
if (x < 0) x = cols + x;
if (y < 0) y = rows + y;
#ifdef DEBUG_OSD
SetColor(color, color);
for (int r = 0; r < h; r++) {
wmove(window, y + r, x); // ncurses wants 'y' before 'x'!
whline(window, ' ', w);
}
wsyncup(window); // shouldn't be necessary because of 'syncok()', but w/o it doesn't work
#else
osd->Fill(x * charWidth, y * lineHeight, (x + w) * charWidth - 1, (y + h) * lineHeight - 1, color);
#endif
}
void cOsd::SetBitmap(int x, int y, const cBitmap &Bitmap)
{
#ifndef DEBUG_OSD
osd->SetBitmap(x, y, Bitmap);
#endif
}
void cOsd::ClrEol(int x, int y, eDvbColor color)
{
Fill(x, y, cols - x, 1, color);
}
int cOsd::CellWidth(void)
{
#ifdef DEBUG_OSD
return 1;
#else
return charWidth;
#endif
}
int cOsd::LineHeight(void)
{
#ifdef DEBUG_OSD
return 1;
#else
return lineHeight;
#endif
}
int cOsd::Width(unsigned char c)
{
#ifdef DEBUG_OSD
return 1;
#else
return osd->Width(c);
#endif
}
int cOsd::WidthInCells(const char *s)
{
#ifdef DEBUG_OSD
return strlen(s);
#else
return (osd->Width(s) + charWidth - 1) / charWidth;
#endif
}
eDvbFont cOsd::SetFont(eDvbFont Font)
{
#ifdef DEBUG_OSD
return Font;
#else
return osd->SetFont(Font);
#endif
}
void cOsd::Text(int x, int y, const char *s, eDvbColor colorFg, eDvbColor colorBg)
{
if (x < 0) x = cols + x;
if (y < 0) y = rows + y;
#ifdef DEBUG_OSD
SetColor(colorFg, colorBg);
wmove(window, y, x); // ncurses wants 'y' before 'x'!
waddnstr(window, s, cols - x);
#else
osd->Text(x * charWidth, y * lineHeight, s, colorFg, colorBg);
#endif
}
void cOsd::Flush(void)
{
#ifdef DEBUG_OSD
refresh();
#else
if (osd)
osd->Flush();
#endif
}
// --- cOsdItem -------------------------------------------------------------- // --- cOsdItem --------------------------------------------------------------
cOsdItem::cOsdItem(eOSState State) cOsdItem::cOsdItem(eOSState State)

39
osd.h
View File

@ -4,14 +4,19 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: osd.h 1.30 2002/05/18 12:36:30 kls Exp $ * $Id: osd.h 1.31 2002/05/18 14:00:15 kls Exp $
*/ */
#ifndef __OSD_H #ifndef __OSD_H
#define __OSD_H #define __OSD_H
#if defined(DEBUG_OSD) || defined(REMOTE_KBD)
#include <ncurses.h>
#endif
#include "config.h" #include "config.h"
#include "dvbosd.h"
#include "interface.h" #include "interface.h"
#include "osdbase.h"
#include "tools.h" #include "tools.h"
#define MAXOSDITEMS (Setup.OSDheight - 4) #define MAXOSDITEMS (Setup.OSDheight - 4)
@ -47,6 +52,38 @@ enum eOSState { osUnknown,
osUser10, osUser10,
}; };
class cOsd {
private:
enum { charWidth = 12, // average character width
lineHeight = 27 // smallest text height
};
#ifdef DEBUG_OSD
static WINDOW *window;
enum { MaxColorPairs = 16 };
static int colorPairs[MaxColorPairs];
static void SetColor(eDvbColor colorFg, eDvbColor colorBg = clrBackground);
#else
static cDvbOsd *osd;
#endif
static int cols, rows;
public:
static void Initialize(void);
static void Shutdown(void);
static void Open(int w, int h);
static void Close(void);
static void Clear(void);
static void Fill(int x, int y, int w, int h, eDvbColor color = clrBackground);
static void SetBitmap(int x, int y, const cBitmap &Bitmap);
static void ClrEol(int x, int y, eDvbColor color = clrBackground);
static int CellWidth(void);
static int LineHeight(void);
static int Width(unsigned char c);
static int WidthInCells(const char *s);
static eDvbFont SetFont(eDvbFont Font);
static void Text(int x, int y, const char *s, eDvbColor colorFg = clrWhite, eDvbColor colorBg = clrBackground);
static void Flush(void);
};
class cOsdItem : public cListObject { class cOsdItem : public cListObject {
private: private:
const char *text; const char *text;

View File

@ -6,7 +6,7 @@
* *
* Ported to LIRC by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16. * Ported to LIRC by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16.
* *
* $Id: remote.c 1.26 2002/05/13 16:31:27 kls Exp $ * $Id: remote.c 1.27 2002/05/18 12:55:39 kls Exp $
*/ */
#include "remote.h" #include "remote.h"
@ -24,6 +24,10 @@
#include <sys/un.h> #include <sys/un.h>
#endif #endif
#if defined REMOTE_KBD
#include <ncurses.h>
#endif
#include "config.h" #include "config.h"
#include "tools.h" #include "tools.h"

12
vdr.c
View File

@ -22,7 +22,7 @@
* *
* The project's page is at http://www.cadsoft.de/people/kls/vdr * The project's page is at http://www.cadsoft.de/people/kls/vdr
* *
* $Id: vdr.c 1.111 2002/05/18 12:35:34 kls Exp $ * $Id: vdr.c 1.112 2002/05/18 14:03:22 kls Exp $
*/ */
#include <getopt.h> #include <getopt.h>
@ -36,6 +36,7 @@
#include "i18n.h" #include "i18n.h"
#include "interface.h" #include "interface.h"
#include "menu.h" #include "menu.h"
#include "osd.h"
#include "plugin.h" #include "plugin.h"
#include "recording.h" #include "recording.h"
#include "tools.h" #include "tools.h"
@ -322,7 +323,7 @@ int main(int argc, char *argv[])
// DVB interfaces: // DVB interfaces:
if (!cDvbApi::Init()) if (!cDvbApi::Initialize())
return 2; return 2;
cDvbApi::SetPrimaryDvbApi(Setup.PrimaryDVB); cDvbApi::SetPrimaryDvbApi(Setup.PrimaryDVB);
@ -334,6 +335,10 @@ int main(int argc, char *argv[])
if (!PluginManager.StartPlugins()) if (!PluginManager.StartPlugins())
return 2; return 2;
// OSD:
cOsd::Initialize();
// Channel: // Channel:
Channels.SwitchTo(Setup.CurrentChannel); Channels.SwitchTo(Setup.CurrentChannel);
@ -592,11 +597,12 @@ int main(int argc, char *argv[])
delete Menu; delete Menu;
delete ReplayControl; delete ReplayControl;
delete Interface; delete Interface;
cOsd::Shutdown();
PluginManager.Shutdown(true); PluginManager.Shutdown(true);
Setup.CurrentChannel = cDvbApi::CurrentChannel(); Setup.CurrentChannel = cDvbApi::CurrentChannel();
Setup.CurrentVolume = cDvbApi::CurrentVolume(); Setup.CurrentVolume = cDvbApi::CurrentVolume();
Setup.Save(); Setup.Save();
cDvbApi::Cleanup(); cDvbApi::Shutdown();
if (WatchdogTimeout > 0) if (WatchdogTimeout > 0)
dsyslog("max. latency time %d seconds", MaxLatencyTime); dsyslog("max. latency time %d seconds", MaxLatencyTime);
isyslog("exiting"); isyslog("exiting");