vdr-1.4.7/osd.h

Go to the documentation of this file.
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.53 2006/02/26 14:45:05 kls Exp $
00008  */
00009 
00010 #ifndef __OSD_H
00011 #define __OSD_H
00012 
00013 #include <stdio.h>
00014 #include <stdint.h>
00015 #include "font.h"
00016 
00017 #define MAXNUMCOLORS 256
00018 
00019 enum {
00020                    //AARRGGBB
00021   clrTransparent = 0x00000000,
00022   clrGray50      = 0x7F000000, // 50% gray
00023   clrBlack       = 0xFF000000,
00024   clrRed         = 0xFFFC1414,
00025   clrGreen       = 0xFF24FC24,
00026   clrYellow      = 0xFFFCC024,
00027   clrMagenta     = 0xFFB000FC,
00028   clrBlue        = 0xFF0000FC,
00029   clrCyan        = 0xFF00FCFC,
00030   clrWhite       = 0xFFFCFCFC,
00031   };
00032 
00033 enum eOsdError { oeOk,
00034                  oeTooManyAreas,
00035                  oeTooManyColors,
00036                  oeBppNotSupported,
00037                  oeAreasOverlap,
00038                  oeWrongAlignment,
00039                  oeOutOfMemory,
00040                  oeWrongAreaSize,
00041                  oeUnknown,
00042                };
00043 
00044 typedef uint32_t tColor;
00045 typedef uint8_t tIndex;
00046 
00047 class cPalette {
00048 private:
00049   tColor color[MAXNUMCOLORS];
00050   int bpp;
00051   int maxColors, numColors;
00052   bool modified;
00053 protected:
00054   typedef tIndex tIndexes[MAXNUMCOLORS];
00055 public:
00056   cPalette(int Bpp = 8);
00058   int Bpp(void) { return bpp; }
00059   void Reset(void);
00061   int Index(tColor Color);
00066   tColor Color(int Index) { return Index < maxColors ? color[Index] : 0; }
00069   void SetBpp(int Bpp);
00072   void SetColor(int Index, tColor Color);
00076   const tColor *Colors(int &NumColors);
00081   void Take(const cPalette &Palette, tIndexes *Indexes = NULL, tColor ColorFg = 0, tColor ColorBg = 0);
00088   void Replace(const cPalette &Palette);
00091   };
00092 
00093 enum eTextAlignment { taCenter  = 0x00,
00094                       taLeft    = 0x01,
00095                       taRight   = 0x02,
00096                       taTop     = 0x04,
00097                       taBottom  = 0x08,
00098                       taDefault = taTop | taLeft
00099                     };
00100 
00101 class cBitmap : public cPalette {
00102 private:
00103   tIndex *bitmap;
00104   int x0, y0;
00105   int width, height;
00106   int dirtyX1, dirtyY1, dirtyX2, dirtyY2;
00107 public:
00108   cBitmap(int Width, int Height, int Bpp, int X0 = 0, int Y0 = 0);
00113   cBitmap(const char *FileName);
00115   cBitmap(const char *const Xpm[]);
00117   virtual ~cBitmap();
00118   int X0(void) const { return x0; }
00119   int Y0(void) const { return y0; }
00120   int Width(void) const { return width; }
00121   int Height(void) const { return height; }
00122   void SetSize(int Width, int Height);
00127   bool Contains(int x, int y) const;
00129   bool Covers(int x1, int y1, int x2, int y2) const;
00132   bool Intersects(int x1, int y1, int x2, int y2) const;
00135   bool Dirty(int &x1, int &y1, int &x2, int &y2);
00138   void Clean(void);
00140   bool LoadXpm(const char *FileName);
00143   bool SetXpm(const char *const Xpm[], bool IgnoreNone = false);
00153   void SetIndex(int x, int y, tIndex Index);
00156   void DrawPixel(int x, int y, tColor Color);
00160   void DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0, bool ReplacePalette = false, bool Overlay = false);
00170   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);
00176   void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color);
00181   void DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants = 0);
00191   void DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type);
00203   const tIndex *Data(int x, int y);
00205   };
00206 
00207 struct tArea {
00208   int x1, y1, x2, y2;
00209   int bpp;
00210   int Width(void) const { return x2 - x1 + 1; }
00211   int Height(void) const { return y2 - y1 + 1; }
00212   bool Intersects(const tArea &Area) const { return !(x2 < Area.x1 || x1 > Area.x2 || y2 < Area.y1 || y1 > Area.y2); }
00213   };
00214 
00215 #define MAXOSDAREAS 16
00216 
00217 class cOsd {
00218   friend class cOsdProvider;
00219 private:
00220   static int isOpen;
00221   cBitmap *savedRegion;
00222   cBitmap *bitmaps[MAXOSDAREAS];
00223   int numBitmaps;
00224   int left, top, width, height;
00225 protected:
00226   cOsd(int Left, int Top);
00242 public:
00243   virtual ~cOsd();
00245   static int IsOpen(void) { return isOpen; }
00246   int Left(void) { return left; }
00247   int Top(void) { return top; }
00248   int Width(void) { return width; }
00249   int Height(void) { return height; }
00250   cBitmap *GetBitmap(int Area);
00253   virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas);
00261   virtual eOsdError SetAreas(const tArea *Areas, int NumAreas);
00269   virtual void SaveRegion(int x1, int y1, int x2, int y2);
00273   virtual void RestoreRegion(void);
00276   virtual eOsdError SetPalette(const cPalette &Palette, int Area);
00278   virtual void DrawPixel(int x, int y, tColor Color);
00284   virtual void DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0, bool ReplacePalette = false, bool Overlay = false);
00294   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);
00300   virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color);
00303   virtual void DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants = 0);
00313   virtual void DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type);
00325   virtual void Flush(void);
00327   };
00328 
00329 class cOsdProvider {
00330 private:
00331   static cOsdProvider *osdProvider;
00332 protected:
00333   virtual cOsd *CreateOsd(int Left, int Top) = 0;
00336 public:
00337   cOsdProvider(void);
00338       //XXX maybe parameter to make this one "sticky"??? (frame-buffer etc.)
00339   virtual ~cOsdProvider();
00340   static cOsd *NewOsd(int Left, int Top);
00346   static void Shutdown(void);
00348   };
00349 
00350 class cTextScroller {
00351 private:
00352   cOsd *osd;
00353   int left, top, width, height;
00354   const cFont *font;
00355   tColor colorFg, colorBg;
00356   int offset, shown;
00357   cTextWrapper textWrapper;
00358   void DrawText(void);
00359 public:
00360   cTextScroller(void);
00361   cTextScroller(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg);
00362   void Set(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg);
00363   void Reset(void);
00364   int Left(void) { return left; }
00365   int Top(void) { return top; }
00366   int Width(void) { return width; }
00367   int Height(void) { return height; }
00368   int Total(void) { return textWrapper.Lines(); }
00369   int Offset(void) { return offset; }
00370   int Shown(void) { return shown; }
00371   bool CanScroll(void) { return CanScrollUp() || CanScrollDown(); }
00372   bool CanScrollUp(void) { return offset > 0; }
00373   bool CanScrollDown(void) { return offset + shown < Total(); }
00374   void Scroll(bool Up, bool Page);
00375   };
00376 
00377 #endif //__OSD_H

Generated on Tue Nov 6 19:57:54 2007 for VDR by  doxygen 1.5.3-20071008