mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
Completely moved OSD handling out of the cDvbApi class, into the new cOsd
This commit is contained in:
232
osd.c
232
osd.c
@@ -4,13 +4,243 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* 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 <string.h>
|
||||
#include "dvbapi.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(eOSState State)
|
||||
|
Reference in New Issue
Block a user