f68a57480f896efedcdc1ef8a51733c0b98b40df
[vuplus_dvbapp] / lib / gdi / gpixmap.h
1 #ifndef __gpixmap_h
2 #define __gpixmap_h
3
4 #include <pthread.h>
5 #include <lib/base/estring.h>
6 #include <lib/gdi/erect.h>
7 #include <lib/gdi/fb.h>
8 #include <lib/base/elock.h>
9
10 #include <lib/base/object.h>
11
12 struct gColor
13 {
14         int color;
15         gColor(int color): color(color)
16         {
17         }
18         gColor(): color(0)
19         {
20         }
21         operator int() const { return color; }
22         bool operator==(const gColor &o) const { return o.color==color; }
23 };
24
25 struct gRGB
26 {
27         int b, g, r, a;
28         gRGB(int r, int g, int b, int a=0): b(b), g(g), r(r), a(a)
29         {
30         }
31         gRGB(unsigned long val): b(val&0xFF), g((val>>8)&0xFF), r((val>>16)&0xFF), a((val>>24)&0xFF)            // ARGB
32         {
33         }
34         gRGB()
35         {
36         }
37         bool operator < (const gRGB &c) const
38         {
39                 if (b < c.b)
40                         return 1;
41                 if (b == c.b)
42                 {
43                         if (g < c.g)
44                                 return 1;
45                         if (g == c.g)
46                         {
47                                 if (r < c.r)
48                                         return 1;
49                                 if (r == c.r)
50                                         return a < c.a;
51                         }
52                 }
53                 return 0;
54         }
55         bool operator==(const gRGB &c) const
56         {
57                 return (b == c.b) && (g == c.g) && (r == c.r) && (a == c.a);
58         }
59 };
60
61 struct gPalette
62 {
63         int start, colors;
64         gRGB *data;
65         gColor findColor(const gRGB &rgb) const;
66 };
67
68 struct gLookup
69 {
70         int size;
71         gColor *lookup;
72         gLookup(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
73         gLookup();
74         void build(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
75 };
76
77 /**
78  * \brief A softreference to a font.
79  *
80  * The font is specified by a name and a size.
81  * \c gFont is part of the \ref gdi.
82  */
83 struct gFont
84 {
85         eString family;
86         int pointSize;
87         
88         /**
89          * \brief Constructs a font with the given name and size.
90          * \param family The name of the font, for example "NimbusSansL-Regular Sans L Regular".
91          * \param pointSize the size of the font in PIXELS.
92          */
93         gFont(const eString &family, int pointSize):
94                         family(family), pointSize(pointSize)
95         {
96         }
97         
98         enum
99         {
100                 tRegular, tFixed
101         };
102         
103         gFont(int type, int pointSize);
104         
105         gFont()
106                 :pointSize(0)
107         {
108         }
109 };
110
111 struct gPixmap: public iObject
112 {
113 DECLARE_REF;
114 public:
115         int x, y, bpp, bypp, stride;
116         void *data;
117         
118         gPalette clut;
119         
120         eSize getSize() const { return eSize(x, y); }
121         
122         void fill(const eRect &area, const gColor &color);
123         
124         enum
125         {
126                 blitAlphaTest=1
127         };
128         void blit(const gPixmap &src, ePoint pos, const eRect &clip=eRect(), int flags=0);
129         
130         void mergePalette(const gPixmap &target);
131         void line(ePoint start, ePoint end, gColor color);
132         gPixmap();
133         virtual ~gPixmap();
134 };
135
136 struct gImage: gPixmap
137 {
138         gImage(eSize size, int bpp);
139         ~gImage();
140 };
141
142 #endif