|
SASC
DVBSoftCAM
|
00001 /* 00002 * osd.h: Abstract On Screen Display layer 00003 * 00004 * See the main source file 'vdr.c' for copyright information and 00005 * how to reach the author. 00006 * 00007 * $Id: osd.h 1.55 2007/06/17 13:59:22 kls Exp $ 00008 */ 00009 00010 #ifndef __OSD_H 00011 #define __OSD_H 00012 00013 #include <limits.h> 00014 #include <stdio.h> 00015 #include <stdint.h> 00016 #include "config.h" 00017 #include "font.h" 00018 00019 #define MAXNUMCOLORS 256 00020 00021 enum { 00022 //AARRGGBB 00023 clrTransparent = 0x00000000, 00024 clrGray50 = 0x7F000000, // 50% gray 00025 clrBlack = 0xFF000000, 00026 clrRed = 0xFFFC1414, 00027 clrGreen = 0xFF24FC24, 00028 clrYellow = 0xFFFCC024, 00029 clrMagenta = 0xFFB000FC, 00030 clrBlue = 0xFF0000FC, 00031 clrCyan = 0xFF00FCFC, 00032 clrWhite = 0xFFFCFCFC, 00033 }; 00034 00035 enum eOsdError { oeOk, 00036 oeTooManyAreas, 00037 oeTooManyColors, 00038 oeBppNotSupported, 00039 oeAreasOverlap, 00040 oeWrongAlignment, 00041 oeOutOfMemory, 00042 oeWrongAreaSize, 00043 oeUnknown, 00044 }; 00045 00046 typedef uint32_t tColor; // see also font.h 00047 typedef uint8_t tIndex; 00048 00049 class cPalette { 00050 private: 00051 tColor color[MAXNUMCOLORS]; 00052 int bpp; 00053 int maxColors, numColors; 00054 bool modified; 00055 double antiAliasGranularity; 00056 protected: 00057 typedef tIndex tIndexes[MAXNUMCOLORS]; 00058 public: 00059 cPalette(int Bpp = 8); 00061 void SetAntiAliasGranularity(uint FixedColors, uint BlendColors); 00071 int Bpp(void) { return bpp; } 00072 void Reset(void); 00074 int Index(tColor Color); 00079 tColor Color(int Index) { return Index < maxColors ? color[Index] : 0; } 00082 void SetBpp(int Bpp); 00085 void SetColor(int Index, tColor Color); 00089 const tColor *Colors(int &NumColors); 00094 void Take(const cPalette &Palette, tIndexes *Indexes = NULL, tColor ColorFg = 0, tColor ColorBg = 0); 00101 void Replace(const cPalette &Palette); 00104 tColor Blend(tColor ColorFg, tColor ColorBg, uint8_t Level); 00110 int ClosestColor(tColor Color, int MaxDiff = INT_MAX); 00116 }; 00117 00118 enum eTextAlignment { taCenter = 0x00, 00119 taLeft = 0x01, 00120 taRight = 0x02, 00121 taTop = 0x04, 00122 taBottom = 0x08, 00123 taDefault = taTop | taLeft 00124 }; 00125 00126 class cFont; 00127 00128 class cBitmap : public cPalette { 00129 private: 00130 tIndex *bitmap; 00131 int x0, y0; 00132 int width, height; 00133 int dirtyX1, dirtyY1, dirtyX2, dirtyY2; 00134 public: 00135 cBitmap(int Width, int Height, int Bpp, int X0 = 0, int Y0 = 0); 00140 cBitmap(const char *FileName); 00142 cBitmap(const char *const Xpm[]); 00144 virtual ~cBitmap(); 00145 int X0(void) const { return x0; } 00146 int Y0(void) const { return y0; } 00147 int Width(void) const { return width; } 00148 int Height(void) const { return height; } 00149 void SetSize(int Width, int Height); 00154 bool Contains(int x, int y) const; 00156 bool Covers(int x1, int y1, int x2, int y2) const; 00159 bool Intersects(int x1, int y1, int x2, int y2) const; 00162 bool Dirty(int &x1, int &y1, int &x2, int &y2); 00165 void Clean(void); 00167 bool LoadXpm(const char *FileName); 00170 bool SetXpm(const char *const Xpm[], bool IgnoreNone = false); 00180 void SetIndex(int x, int y, tIndex Index); 00183 void DrawPixel(int x, int y, tColor Color); 00187 void DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0, bool ReplacePalette = false, bool Overlay = false); 00197 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); 00203 void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color); 00208 void DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants = 0); 00218 void DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type); 00230 const tIndex *Data(int x, int y); 00232 tColor GetColor(int x, int y) { return Color(*Data(x, y)); } 00234 }; 00235 00236 struct tArea { 00237 int x1, y1, x2, y2; 00238 int bpp; 00239 int Width(void) const { return x2 - x1 + 1; } 00240 int Height(void) const { return y2 - y1 + 1; } 00241 bool Intersects(const tArea &Area) const { return !(x2 < Area.x1 || x1 > Area.x2 || y2 < Area.y1 || y1 > Area.y2); } 00242 }; 00243 00244 #define MAXOSDAREAS 16 00245 00246 class cOsd { 00247 friend class cOsdProvider; 00248 private: 00249 static int osdLeft, osdTop, osdWidth, osdHeight; 00250 static int isOpen; 00251 cBitmap *savedRegion; 00252 cBitmap *bitmaps[MAXOSDAREAS]; 00253 int numBitmaps; 00254 int left, top, width, height; 00255 protected: 00256 cOsd(int Left, int Top); 00272 public: 00273 virtual ~cOsd(); 00275 static int OsdLeft(void) { return osdLeft ? osdLeft : Setup.OSDLeft; } 00276 static int OsdTop(void) { return osdTop ? osdTop : Setup.OSDTop; } 00277 static int OsdWidth(void) { return osdWidth ? osdWidth : Setup.OSDWidth; } 00278 static int OsdHeight(void) { return osdHeight ? osdHeight : Setup.OSDHeight; } 00279 static void SetOsdPostion(int Left, int Top, int Width, int Height); 00284 static int IsOpen(void) { return isOpen; } 00285 int Left(void) { return left; } 00286 int Top(void) { return top; } 00287 int Width(void) { return width; } 00288 int Height(void) { return height; } 00289 void SetAntiAliasGranularity(uint FixedColors, uint BlendColors); 00299 cBitmap *GetBitmap(int Area); 00302 virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas); 00310 virtual eOsdError SetAreas(const tArea *Areas, int NumAreas); 00318 virtual void SaveRegion(int x1, int y1, int x2, int y2); 00322 virtual void RestoreRegion(void); 00325 virtual eOsdError SetPalette(const cPalette &Palette, int Area); 00327 virtual void DrawPixel(int x, int y, tColor Color); 00333 virtual void DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0, bool ReplacePalette = false, bool Overlay = false); 00343 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); 00349 virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color); 00352 virtual void DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants = 0); 00362 virtual void DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type); 00374 virtual void Flush(void); 00376 }; 00377 00378 class cOsdProvider { 00379 private: 00380 static cOsdProvider *osdProvider; 00381 protected: 00382 virtual cOsd *CreateOsd(int Left, int Top) = 0; 00385 public: 00386 cOsdProvider(void); 00387 //XXX maybe parameter to make this one "sticky"??? (frame-buffer etc.) 00388 virtual ~cOsdProvider(); 00389 static cOsd *NewOsd(int Left, int Top); 00395 static void Shutdown(void); 00397 }; 00398 00399 class cTextScroller { 00400 private: 00401 cOsd *osd; 00402 int left, top, width, height; 00403 const cFont *font; 00404 tColor colorFg, colorBg; 00405 int offset, shown; 00406 cTextWrapper textWrapper; 00407 void DrawText(void); 00408 public: 00409 cTextScroller(void); 00410 cTextScroller(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg); 00411 void Set(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg); 00412 void Reset(void); 00413 int Left(void) { return left; } 00414 int Top(void) { return top; } 00415 int Width(void) { return width; } 00416 int Height(void) { return height; } 00417 int Total(void) { return textWrapper.Lines(); } 00418 int Offset(void) { return offset; } 00419 int Shown(void) { return shown; } 00420 bool CanScroll(void) { return CanScrollUp() || CanScrollDown(); } 00421 bool CanScrollUp(void) { return offset > 0; } 00422 bool CanScrollDown(void) { return offset + shown < Total(); } 00423 void Scroll(bool Up, bool Page); 00424 }; 00425 00426 #endif //__OSD_H