aboutsummaryrefslogtreecommitdiff
path: root/lib/gdi/gpixmap.h
blob: f68a57480f896efedcdc1ef8a51733c0b98b40df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef __gpixmap_h
#define __gpixmap_h

#include <pthread.h>
#include <lib/base/estring.h>
#include <lib/gdi/erect.h>
#include <lib/gdi/fb.h>
#include <lib/base/elock.h>

#include <lib/base/object.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
{
	int b, g, r, a;
	gRGB(int r, int g, int b, int a=0): b(b), g(g), r(r), a(a)
	{
	}
	gRGB(unsigned long val): b(val&0xFF), g((val>>8)&0xFF), r((val>>16)&0xFF), a((val>>24)&0xFF)		// ARGB
	{
	}
	gRGB()
	{
	}
	bool operator < (const gRGB &c) const
	{
		if (b < c.b)
			return 1;
		if (b == c.b)
		{
			if (g < c.g)
				return 1;
			if (g == c.g)
			{
				if (r < c.r)
					return 1;
				if (r == c.r)
					return a < c.a;
			}
		}
		return 0;
	}
	bool operator==(const gRGB &c) const
	{
		return (b == c.b) && (g == c.g) && (r == c.r) && (a == c.a);
	}
};

struct gPalette
{
	int start, colors;
	gRGB *data;
	gColor findColor(const gRGB &rgb) const;
};

struct gLookup
{
	int size;
	gColor *lookup;
	gLookup(int size, const gPalette &pal, const gRGB &start, const gRGB &end);
	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.
 */
struct gFont
{
	eString 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 eString &family, int pointSize):
			family(family), pointSize(pointSize)
	{
	}
	
	enum
	{
		tRegular, tFixed
	};
	
	gFont(int type, int pointSize);
	
	gFont()
		:pointSize(0)
	{
	}
};

struct gPixmap: public iObject
{
DECLARE_REF;
public:
	int x, y, bpp, bypp, stride;
	void *data;
	
	gPalette clut;
	
	eSize getSize() const { return eSize(x, y); }
	
	void fill(const eRect &area, const gColor &color);
	
	enum
	{
		blitAlphaTest=1
	};
	void blit(const gPixmap &src, ePoint pos, const eRect &clip=eRect(), int flags=0);
	
	void mergePalette(const gPixmap &target);
	void line(ePoint start, ePoint end, gColor color);
	gPixmap();
	virtual ~gPixmap();
};

struct gImage: gPixmap
{
	gImage(eSize size, int bpp);
	~gImage();
};

#endif