Prepared the OSD functions for multiple overlapping windows

This commit is contained in:
Klaus Schmidinger 2002-01-13 15:55:08 +01:00
parent b2202e7998
commit 441c35e8e8
4 changed files with 215 additions and 51 deletions

View File

@ -887,3 +887,4 @@ Video Disk Recorder Revision History
- Fixed channel data for "DW TV" (thanks to Axel Gruber).
- Added DPID to "PREMIERE MOVIE 1" in channels.conf.cable (thanks to Stephan
Schreiber).
- Prepared the OSD functions for multiple overlapping windows.

View File

@ -7,7 +7,7 @@
* DVD support initially written by Andreas Schultz <aschultz@warp10.net>
* based on dvdplayer-0.5 by Matjaz Thaler <matjaz.thaler@guest.arnes.si>
*
* $Id: dvbapi.c 1.141 2001/11/25 16:38:09 kls Exp $
* $Id: dvbapi.c 1.142 2002/01/13 15:48:37 kls Exp $
*/
//#define DVDDEBUG 1
@ -2842,7 +2842,11 @@ void cDvbApi::Open(int w, int h)
}
else if (d == 0) { //XXX full menu
osd->Create(0, 0, w, lineHeight, 2);
osd->Create(0, lineHeight, w, (Setup.OSDheight - 3) * lineHeight, 2, true, clrBackground, clrCyan, clrWhite, clrBlack);
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
@ -3197,7 +3201,7 @@ eSetChannelResult cDvbApi::SetChannel(int ChannelNumber, int Frequency, char Pol
}
}
else
esyslog(LOG_ERR, "ERROR %d in frontend get event", res);
esyslog(LOG_ERR, "ERROR %d in frontend get event (channel %d, card %d)", res, ChannelNumber, CardIndex() + 1);
}
else
esyslog(LOG_ERR, "ERROR: timeout while tuning");

184
dvbosd.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: dvbosd.c 1.10 2001/07/24 16:25:34 kls Exp $
* $Id: dvbosd.c 1.11 2002/01/13 15:49:28 kls Exp $
*/
#include "dvbosd.h"
@ -257,25 +257,35 @@ const char *cBitmap::Data(int x, int y)
class cWindow : public cBitmap {
private:
int handle; // the index within the OSD's window array (0...MAXNUMWINDOWS - 1)
int x0, y0;
int bpp;
bool tiled;
bool shown;
public:
cWindow(int x, int y, int w, int h, int Bpp, bool ClearWithBackground = true);
cWindow(int Handle, int x, int y, int w, int h, int Bpp, bool ClearWithBackground, bool Tiled);
int X0(void) { return x0; }
int Y0(void) { return y0; }
int Bpp(void) { return bpp; }
bool Tiled(void) { return tiled; }
bool Shown(void) { bool s = shown; shown = true; return s; }
int Handle(void) { return handle; }
bool Contains(int x, int y);
void Relocate(int x, int y);
void Fill(int x1, int y1, int x2, int y2, eDvbColor Color);
void SetBitmap(int x, int y, const cBitmap &Bitmap);
void Text(int x, int y, const char *s, eDvbColor ColorFg = clrWhite, eDvbColor ColorBg = clrBackground);
const char *Data(int x, int y);
};
cWindow::cWindow(int x, int y, int w, int h, int Bpp, bool ClearWithBackground)
cWindow::cWindow(int Handle, int x, int y, int w, int h, int Bpp, bool ClearWithBackground, bool Tiled)
:cBitmap(w, h, Bpp, ClearWithBackground)
{
handle = Handle;
x0 = x;
y0 = y;
bpp = Bpp;
tiled = Tiled;
shown = false;
}
@ -286,19 +296,39 @@ bool cWindow::Contains(int x, int y)
return x >= 0 && y >= 0 && x < width && y < height;
}
void cWindow::Relocate(int x, int y)
{
x0 = x;
y0 = y;
}
void cWindow::Fill(int x1, int y1, int x2, int y2, eDvbColor Color)
{
cBitmap::Fill(x1 - x0, y1 - y0, x2 - x0, y2 - y0, Color);
if (tiled) {
x1 -= x0;
y1 -= y0;
x2 -= x0;
y2 -= y0;
}
cBitmap::Fill(x1, y1, x2, y2, Color);
}
void cWindow::SetBitmap(int x, int y, const cBitmap &Bitmap)
{
cBitmap::SetBitmap(x - x0, y - y0, Bitmap);
if (tiled) {
x -= x0;
y -= y0;
}
cBitmap::SetBitmap(x, y, Bitmap);
}
void cWindow::Text(int x, int y, const char *s, eDvbColor ColorFg, eDvbColor ColorBg)
{
cBitmap::Text(x - x0, y - y0, s, ColorFg, ColorBg);
if (tiled) {
x -= x0;
y -= y0;
}
cBitmap::Text(x, y, s, ColorFg, ColorBg);
}
const char *cWindow::Data(int x, int y)
@ -325,14 +355,28 @@ cDvbOsd::cDvbOsd(int VideoDev, int x, int y, int w, int h, int Bpp)
cDvbOsd::~cDvbOsd()
{
if (videoDev >= 0) {
while (numWindows > 0) {
Cmd(OSD_SetWindow, 0, numWindows--);
Cmd(OSD_Close);
delete window[numWindows];
}
for (int i = 0; i < numWindows; i++) {
SetWindow(window[i]);
Cmd(OSD_Close);
delete window[i];
}
numWindows = 0;
}
}
bool cDvbOsd::SetWindow(cWindow *Window)
{
// Window handles are counted 0...(MAXNUMWINDOWS - 1), but the actual window
// numbers in the driver are used from 1...MAXNUMWINDOWS.
int Handle = Window->Handle();
if (0 <= Handle && Handle < MAXNUMWINDOWS) {
Cmd(OSD_SetWindow, 0, Handle + 1);
return true;
}
esyslog(LOG_ERR, "ERROR: illegal window handle: %d", Handle);
return -1;
}
void cDvbOsd::Cmd(OSD_Command cmd, int color, int x0, int y0, int x1, int y1, const void *data)
{
if (videoDev >= 0) {
@ -349,60 +393,74 @@ void cDvbOsd::Cmd(OSD_Command cmd, int color, int x0, int y0, int x1, int y1, co
sigfillset(&set);
sigprocmask(SIG_BLOCK, &set, &oldset);
ioctl(videoDev, OSD_SEND_CMD, &dc);
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 Increase the value if the problem still persists on your particular system.
// TODO Check if this is still necessary with driver versions after 0.7.
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
// XXX and sometimes the OSD was no longer displayed).
// XXX Increase the value if the problem still persists on your particular system.
// TODO Check if this is still necessary with driver versions after 0.7.
sigprocmask(SIG_SETMASK, &oldset, NULL);
}
}
bool cDvbOsd::Create(int x, int y, int w, int h, int Bpp, bool ClearWithBackground, eDvbColor Color0, eDvbColor Color1, eDvbColor Color2, eDvbColor Color3)
tWindowHandle cDvbOsd::Create(int x, int y, int w, int h, int Bpp, bool ClearWithBackground, bool Tiled)
{
/* TODO XXX
- check that no two windows overlap
*/
if (numWindows < MAXNUMWINDOWS) {
if (x >= 0 && y >= 0 && w > 0 && h > 0 && (Bpp == 1 || Bpp == 2 || Bpp == 4 || Bpp == 8)) {
if ((w & 0x03) != 0) {
w += 4 - (w & 0x03);
esyslog(LOG_ERR, "ERROR: OSD window width must be a multiple of 4 - increasing to %d", w);
}
cWindow *win = new cWindow(x, y, w, h, Bpp, ClearWithBackground);
if (Color0 != clrTransparent) {
win->Index(Color0);
win->Index(Color1);
win->Index(Color2);
win->Index(Color3);
win->Reset();
cWindow *win = new cWindow(numWindows, x, y, w, h, Bpp, ClearWithBackground, Tiled);
if (SetWindow(win)) {
window[win->Handle()] = win;
Cmd(OSD_Open, Bpp, x0 + x, y0 + y, x0 + x + w - 1, y0 + y + h - 1, (void *)1); // initially hidden!
numWindows++;
return win->Handle();
}
window[numWindows++] = win;
Cmd(OSD_SetWindow, 0, numWindows);
Cmd(OSD_Open, Bpp, x0 + x, y0 + y, x0 + x + w - 1, y0 + y + h - 1, (void *)1); // initially hidden!
else
delete win;
}
else
esyslog(LOG_ERR, "ERROR: illegal OSD parameters");
}
else
esyslog(LOG_ERR, "ERROR: too many OSD windows");
return false;
return -1;
}
void cDvbOsd::AddColor(eDvbColor Color, tWindowHandle Window)
{
cWindow *w = GetWindow(Window);
if (w) {
w->Index(Color);
w->Reset();
}
}
cWindow *cDvbOsd::GetWindow(int x, int y)
{
for (int i = 0; i < numWindows; i++) {
if (window[i]->Contains(x, y))
if (window[i]->Tiled() && window[i]->Contains(x, y))
return window[i];
}
return NULL;
}
cWindow *cDvbOsd::GetWindow(tWindowHandle Window)
{
if (0 <= Window && Window < numWindows)
return window[Window];
if (Window == LAST_CREATED_WINDOW && numWindows > 0)
return window[numWindows - 1];
return NULL;
}
void cDvbOsd::Flush(void)
{
for (int i = 0; i < numWindows; i++) {
int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
if (window[i]->Dirty(x1, y1, x2, y2)) {
Cmd(OSD_SetWindow, 0, i + 1);
SetWindow(window[i]);
int FirstColor = 0, LastColor = 0;
const eDvbColor *pal;
while ((pal = window[i]->Colors(FirstColor, LastColor)) != NULL)
@ -414,28 +472,36 @@ void cDvbOsd::Flush(void)
// Showing the windows in a separate loop to avoid seeing them come up one after another
for (int i = 0; i < numWindows; i++) {
if (!window[i]->Shown()) {
Cmd(OSD_SetWindow, 0, i + 1);
SetWindow(window[i]);
Cmd(OSD_MoveWindow, 0, x0 + window[i]->X0(), y0 + window[i]->Y0());
}
}
}
void cDvbOsd::Clear(void)
void cDvbOsd::Clear(tWindowHandle Window)
{
for (int i = 0; i < numWindows; i++)
window[i]->Clear();
if (Window == ALL_TILED_WINDOWS || Window == ALL_WINDOWS) {
for (int i = 0; i < numWindows; i++)
if (Window == ALL_WINDOWS || window[i]->Tiled())
window[i]->Clear();
}
else {
cWindow *w = GetWindow(Window);
if (w)
w->Clear();
}
}
void cDvbOsd::Fill(int x1, int y1, int x2, int y2, eDvbColor Color)
void cDvbOsd::Fill(int x1, int y1, int x2, int y2, eDvbColor Color, tWindowHandle Window)
{
cWindow *w = GetWindow(x1, y1);
cWindow *w = (Window == ALL_TILED_WINDOWS) ? GetWindow(x1, y1) : GetWindow(Window);
if (w)
w->Fill(x1, y1, x2, y2, Color);
}
void cDvbOsd::SetBitmap(int x, int y, const cBitmap &Bitmap)
void cDvbOsd::SetBitmap(int x, int y, const cBitmap &Bitmap, tWindowHandle Window)
{
cWindow *w = GetWindow(x, y);
cWindow *w = (Window == ALL_TILED_WINDOWS) ? GetWindow(x, y) : GetWindow(Window);
if (w)
w->SetBitmap(x, y, Bitmap);
}
@ -458,10 +524,44 @@ eDvbFont cDvbOsd::SetFont(eDvbFont Font)
return oldFont;
}
void cDvbOsd::Text(int x, int y, const char *s, eDvbColor ColorFg = clrWhite, eDvbColor ColorBg = clrBackground)
void cDvbOsd::Text(int x, int y, const char *s, eDvbColor ColorFg = clrWhite, eDvbColor ColorBg = clrBackground, tWindowHandle Window)
{
cWindow *w = GetWindow(x, y);
cWindow *w = (Window == ALL_TILED_WINDOWS) ? GetWindow(x, y) : GetWindow(Window);
if (w)
w->Text(x, y, s, ColorFg, ColorBg);
}
void cDvbOsd::Relocate(tWindowHandle Window, int x, int y, int NewWidth, int NewHeight)
{
cWindow *w = GetWindow(Window);
if (w) {
SetWindow(w);
if (NewWidth > 0 && NewHeight > 0) {
if ((NewWidth & 0x03) != 0) {
NewWidth += 4 - (NewWidth & 0x03);
esyslog(LOG_ERR, "ERROR: OSD window width must be a multiple of 4 - increasing to %d", NewWidth);
}
Cmd(OSD_Close);
window[w->Handle()] = new cWindow(w->Handle(), x, y, NewWidth, NewHeight, w->Bpp(), w->ClearWithBackground(), w->Tiled());
delete w;
Cmd(OSD_Open, 2, x0 + x, y0 + y, x0 + x + NewWidth - 1, y0 + y + NewHeight - 1, (void *)1); // initially hidden!
}
else {
w->Relocate(x, y);
Cmd(OSD_MoveWindow, 0, x0 + x, y0 + y);
}
}
}
void cDvbOsd::Hide(tWindowHandle Window)
{
if (SetWindow(GetWindow(Window)))
Cmd(OSD_Hide, 0);
}
void cDvbOsd::Show(tWindowHandle Window)
{
if (SetWindow(GetWindow(Window)))
Cmd(OSD_Show, 0);
}

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: dvbosd.h 1.8 2001/07/28 16:22:32 kls Exp $
* $Id: dvbosd.h 1.9 2002/01/13 15:48:00 kls Exp $
*/
#ifndef __DVBOSD_H
@ -75,6 +75,7 @@ protected:
public:
cBitmap(int Width, int Height, int Bpp, bool ClearWithBackground = true);
virtual ~cBitmap();
bool ClearWithBackground(void) { return clearWithBackground; }
eDvbFont SetFont(eDvbFont Font);
bool Dirty(int &x1, int &y1, int &x2, int &y2);
void SetPixel(int x, int y, eDvbColor Color);
@ -93,26 +94,84 @@ public:
class cWindow;
typedef int tWindowHandle;
// '-1' is used as an error return value!
#define ALL_WINDOWS (-2)
#define ALL_TILED_WINDOWS (-3)
#define LAST_CREATED_WINDOW (-4)
class cDvbOsd {
private:
int videoDev;
int numWindows;
int x0, y0;
cWindow *window[MAXNUMWINDOWS];
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);
cWindow *GetWindow(int x, int y);
cWindow *GetWindow(tWindowHandle Window);
public:
cDvbOsd(int VideoDev, int x, int y, int w = -1, int h = -1, int Bpp = -1);
// Initializes the OSD on the given VideoDev, starting at screen coordinates
// (x, y). If w, h and Bpp are given, one window with that width, height and
// color depth will be created - otherwise the actual windows will have to
// be created by separate calls to Create().
~cDvbOsd();
bool Create(int x, int y, int w, int h, int Bpp, bool ClearWithBackground = true, eDvbColor Color0 = clrTransparent, eDvbColor Color1 = clrTransparent, eDvbColor Color2 = clrTransparent, eDvbColor Color3 = clrTransparent);
// Destroys all windows and shuts down the OSD.
tWindowHandle Create(int x, int y, int w, int h, int Bpp, bool ClearWithBackground = true, bool Tiled = true);
// Creates a window at coordinates (x, y), which are relative to the OSD's
// origin given in the constructor, with the given width, height and color
// depth. ClearWithBackground controls whether the window will be filled with
// clrBackground when it is cleared. Setting this to 'false' may be useful
// for windows that don't need clrBackground but want to save this color
// palette entry for a different color. Tiled controls whether this will
// be part of a multi section OSD (with several windows that all have
// different color depths and palettes and form one large OSD area), or
// whether this is a "standalone" window that will be drawn "in front"
// of any windows defined *after* this one (this can be used for highlighting
// certain parts of the OSD, as would be done in a 'cursor').
// Returns a handle that can be used to identify this window.
void AddColor(eDvbColor Color, tWindowHandle Window = LAST_CREATED_WINDOW);
// Adds the Color to the color palette of the given window if it is not
// already contained in the palette (and if the palette still has free
// slots for new colors). The default value LAST_CREATED_WINDOW will
// access the most recently created window, without the need of explicitly
// using a window handle.
void Flush(void);
void Clear(void);
void Fill(int x1, int y1, int x2, int y2, eDvbColor Color);
void SetBitmap(int x, int y, const cBitmap &Bitmap);
// Actually commits all data of all windows to the OSD.
void Clear(tWindowHandle Window = ALL_TILED_WINDOWS);
// Clears the given window. If ALL_TILED_WINDOWS is given, only the tiled
// windows will be cleared, leaving the standalone windows untouched. If
// ALL_WINDOWS is given, the standalone windows will also be cleared.
void Fill(int x1, int y1, int x2, int y2, eDvbColor Color, tWindowHandle Window = ALL_TILED_WINDOWS);
// Fills the rectangle defined by the upper left (x1, y2) and lower right
// (x2, y2) corners with the given Color. If a specific window is given,
// the coordinates are relative to that window's upper left corner.
// Otherwise they are relative to the upper left corner of the entire OSD.
// If all tiled windows are selected, only that window which contains the
// point (x1, y1) will actually be filled.
void SetBitmap(int x, int y, const cBitmap &Bitmap, tWindowHandle Window = ALL_TILED_WINDOWS);
// Sets the pixels within the given window with the data from the given
// Bitmap. See Fill() for details about the coordinates.
int Width(unsigned char c);
// Returns the width (in pixels) of the given character in the current font.
int Width(const char *s);
// Returns the width (in pixels) of the given string in the current font.
eDvbFont SetFont(eDvbFont Font);
void Text(int x, int y, const char *s, eDvbColor ColorFg = clrWhite, eDvbColor ColorBg = clrBackground);
// Sets the current font for subsequent Width() and Text() operations.
void Text(int x, int y, const char *s, eDvbColor ColorFg = clrWhite, eDvbColor ColorBg = clrBackground, tWindowHandle Window = ALL_TILED_WINDOWS);
// Writes the given string at coordinates (x, y) with the given foreground
// and background color into the given window (see Fill() for details
// about the coordinates).
void Relocate(tWindowHandle Window, int x, int y, int NewWidth = -1, int NewHeight = -1);
// Moves the given window to the new location at (x, y). If NewWidth and
// NewHeight are also given, the window will also be resized to the new
// width and height.
void Hide(tWindowHandle Window);
// Hides the given window.
void Show(tWindowHandle Window);
// Shows the given window.
};
#endif //__DVBOSD_H