Support customized subtitles.
[vuplus_dvbapp] / lib / gdi / gpixmap.h
index 396d92b..202cd01 100644 (file)
@@ -4,23 +4,11 @@
 #include <pthread.h>
 #include <string>
 #include <lib/base/object.h>
+#include <lib/base/smartptr.h>
 #include <lib/base/elock.h>
 #include <lib/gdi/erect.h>
 #include <lib/gdi/fb.h>
 
-struct gColor
-{
-       int color;
-       gColor(int color): color(color)
-       {
-       }
-       gColor(): color(0)
-       {
-       }
-       operator int() const { return color; }
-       bool operator==(const gColor &o) const { return o.color==color; }
-};
-
 struct gRGB
 {
        unsigned char b, g, r, a;
@@ -30,9 +18,32 @@ struct gRGB
        gRGB(unsigned long val): b(val&0xFF), g((val>>8)&0xFF), r((val>>16)&0xFF), a((val>>24)&0xFF)            // ARGB
        {
        }
+       gRGB(const char *colorstring)
+       {
+               unsigned long val = 0;
+               if (colorstring)
+               {
+                       for (int i = 0; i < 8; i++)
+                       {
+                               if (i) val <<= 4;
+                               if (!colorstring[i]) break;
+                               val |= (colorstring[i]) & 0x0f;
+                       }
+               }
+               b = val&0xFF;
+               g = (val>>8)&0xFF;
+               r = (val>>16)&0xFF;
+               a = (val>>24)&0xFF;
+       }
        gRGB(): b(0), g(0), r(0), a(0)
        {
        }
+
+       unsigned long argb() const
+       {
+               return (a<<24)|(r<<16)|(g<<8)|b;
+       }
+
        void operator=(unsigned long val)
        {
                b = val&0xFF;
@@ -62,6 +73,36 @@ struct gRGB
        {
                return (b == c.b) && (g == c.g) && (r == c.r) && (a == c.a);
        }
+       bool operator != (const gRGB &c) const
+       {
+               return (b != c.b) || (g != c.g) || (r != c.r) || (a != c.a);
+       }
+       operator const std::string () const
+       {
+               unsigned long val = (a<<24)|(r<<16)|(g<<8)|b;
+               std::string escapecolor = "\\c";
+               escapecolor.resize(10);
+               for (int i = 9; i >= 2; i--)
+               {
+                       escapecolor[i] = 0x40 | (val & 0xf);
+                       val >>= 4;
+               }
+               return escapecolor;
+       }
+};
+
+#ifndef SWIG
+struct gColor
+{
+       int color;
+       gColor(int color): color(color)
+       {
+       }
+       gColor(): color(0)
+       {
+       }
+       operator int() const { return color; }
+       bool operator==(const gColor &o) const { return o.color==color; }
 };
 
 struct gPalette
@@ -81,40 +122,6 @@ struct gLookup
        void build(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
 };
 
-/**
- * \brief A softreference to a font.
- *
- * The font is specified by a name and a size.
- * \c gFont is part of the \ref gdi.
- */
-class gFont: public iObject
-{
-DECLARE_REF(gFont);
-public:
-
-       std::string family;
-       int pointSize;
-       
-       /**
-        * \brief Constructs a font with the given name and size.
-        * \param family The name of the font, for example "NimbusSansL-Regular Sans L Regular".
-        * \param pointSize the size of the font in PIXELS.
-        */
-       gFont(const std::string &family, int pointSize):
-                       family(family), pointSize(pointSize)
-       {
-       }
-       
-       virtual ~gFont()
-       {
-       }
-       
-       gFont()
-               :pointSize(0)
-       {
-       }
-};
-
 struct gSurface
 {
        int type;
@@ -122,31 +129,33 @@ struct gSurface
        gPalette clut;
        
        void *data;
-       virtual ~gSurface();
-};
+       int data_phys;
+       int offset; // only for backbuffers
 
-struct gSurfaceSystem: gSurface
-{
-       gSurfaceSystem(eSize size, int bpp);
-       ~gSurfaceSystem();
+       gSurface();
+       gSurface(eSize size, int bpp, int accel);
+       ~gSurface();
 };
+#endif
 
-struct gPixmap: public iObject
+class gRegion;
+
+SWIG_IGNORE(gPixmap);
+class gPixmap: public iObject
 {
-DECLARE_REF(gPixmap);
-private:
-       friend class gDC;
-       void fill(const gRegion &clip, const gColor &color);
-       
+       DECLARE_REF(gPixmap);
+public:
+#ifndef SWIG
        enum
        {
-               blitAlphaTest=1
+               blitAlphaTest=1,
+               blitAlphaBlend=2,
+               blitScale=4
        };
-       void blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flags=0);
-       
-       void mergePalette(const gPixmap &target);
-       void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
-public:
+
+       gPixmap(gSurface *surface);
+       gPixmap(eSize, int bpp, int accel = 0);
+
        gSurface *surface;
        
        eLock contentlock;
@@ -154,12 +163,24 @@ public:
        
        gPixmap *lock();
        void unlock();
+       inline bool needClut() const { return surface && surface->bpp <= 8; }
+#endif
+       virtual ~gPixmap();
+       eSize size() const { return eSize(surface->x, surface->y); }
+private:
+       bool must_delete_surface;
+       friend class gDC;
+       void fill(const gRegion &clip, const gColor &color);
+       void fill(const gRegion &clip, const gRGB &color);
        
-       eSize getSize() const { return eSize(surface->x, surface->y); }
+       void blit(const gPixmap &src, const eRect &pos, const gRegion &clip, int flags=0);
        
-       gPixmap(gSurface *surface);
-       gPixmap(eSize, int bpp);
-       virtual ~gPixmap();
+       void mergePalette(const gPixmap &target);
+       void line(const gRegion &clip, ePoint start, ePoint end, gColor color);
+#ifdef SWIG
+       gPixmap();
+#endif
 };
+SWIG_TEMPLATE_TYPEDEF(ePtr<gPixmap>, gPixmapPtr);
 
 #endif