]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: palette.h | |
e54c96f1 | 3 | // Purpose: interface of wxPalette |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
8 | /** | |
9 | @class wxPalette | |
7c913512 | 10 | |
23324ae1 FM |
11 | A palette is a table that maps pixel values to RGB colours. It allows the |
12 | colours of a low-depth bitmap, for example, to be mapped to the available | |
13 | colours in a display. The notion of palettes is becoming more and more | |
14 | obsolete nowadays and only the MSW port is still using a native palette. | |
15 | All other ports use generic code which is basically just an array of | |
7c913512 FM |
16 | colours. |
17 | ||
23324ae1 FM |
18 | It is likely that in the future the only use for palettes within wxWidgets |
19 | will be for representing colour indeces from images (such as GIF or PNG). | |
20 | The image handlers for these formats have been modified to create a palette | |
21 | if there is such information in the original image file (usually 256 or less | |
22 | colour images). See wxImage for more information. | |
7c913512 | 23 | |
23324ae1 FM |
24 | @library{wxcore} |
25 | @category{gdi} | |
7c913512 | 26 | |
23324ae1 | 27 | @stdobjects |
74bf4e64 | 28 | ::wxNullPalette |
7c913512 | 29 | |
74bf4e64 | 30 | @see wxDC::SetPalette(), wxBitmap |
23324ae1 FM |
31 | */ |
32 | class wxPalette : public wxGDIObject | |
33 | { | |
34 | public: | |
74bf4e64 FM |
35 | |
36 | /** | |
37 | Default constructor. | |
38 | */ | |
39 | wxPalette(); | |
65874118 | 40 | |
74bf4e64 FM |
41 | /** |
42 | Copy constructor, uses @ref overview_refcount. | |
dd72e767 FM |
43 | |
44 | @param palette | |
45 | A reference to the palette to copy. | |
74bf4e64 FM |
46 | */ |
47 | wxPalette(const wxPalette& palette); | |
65874118 | 48 | |
23324ae1 | 49 | /** |
65874118 | 50 | Creates a palette from arrays of size @a n, one for each red, blue or |
74bf4e64 | 51 | green component. |
3c4f71cc | 52 | |
7c913512 | 53 | @param n |
4cc4bfaf | 54 | The number of indices in the palette. |
7c913512 | 55 | @param red |
4cc4bfaf | 56 | An array of red values. |
7c913512 | 57 | @param green |
4cc4bfaf | 58 | An array of green values. |
7c913512 | 59 | @param blue |
4cc4bfaf | 60 | An array of blue values. |
3c4f71cc | 61 | |
1058f652 MB |
62 | @beginWxPerlOnly |
63 | In wxPerl this method takes as parameters | |
64 | 3 array references (they must be of the same length). | |
65 | @endWxPerlOnly | |
66 | ||
4cc4bfaf | 67 | @see Create() |
23324ae1 | 68 | */ |
7c913512 FM |
69 | wxPalette(int n, const unsigned char* red, |
70 | const unsigned char* green, | |
71 | const unsigned char* blue); | |
23324ae1 FM |
72 | |
73 | /** | |
74 | Destructor. | |
74bf4e64 FM |
75 | |
76 | @see @ref overview_refcount_destruct "reference-counted object destruction" | |
23324ae1 | 77 | */ |
adaaa686 | 78 | virtual ~wxPalette(); |
23324ae1 FM |
79 | |
80 | /** | |
65874118 | 81 | Creates a palette from arrays of size @a n, one for each red, blue or |
74bf4e64 | 82 | green component. |
3c4f71cc | 83 | |
7c913512 | 84 | @param n |
4cc4bfaf | 85 | The number of indices in the palette. |
7c913512 | 86 | @param red |
4cc4bfaf | 87 | An array of red values. |
7c913512 | 88 | @param green |
4cc4bfaf | 89 | An array of green values. |
7c913512 | 90 | @param blue |
4cc4bfaf | 91 | An array of blue values. |
3c4f71cc | 92 | |
d29a9a8a | 93 | @return @true if the creation was successful, @false otherwise. |
3c4f71cc | 94 | |
4cc4bfaf | 95 | @see wxPalette() |
23324ae1 FM |
96 | */ |
97 | bool Create(int n, const unsigned char* red, | |
98 | const unsigned char* green, | |
99 | const unsigned char* blue); | |
100 | ||
101 | /** | |
102 | Returns number of entries in palette. | |
103 | */ | |
adaaa686 | 104 | virtual int GetColoursCount() const; |
23324ae1 FM |
105 | |
106 | /** | |
107 | Returns a pixel value (index into the palette) for the given RGB values. | |
3c4f71cc | 108 | |
7c913512 | 109 | @param red |
4cc4bfaf | 110 | Red value. |
7c913512 | 111 | @param green |
4cc4bfaf | 112 | Green value. |
7c913512 | 113 | @param blue |
4cc4bfaf | 114 | Blue value. |
3c4f71cc | 115 | |
d29a9a8a | 116 | @return The nearest palette index or @c wxNOT_FOUND for unexpected errors. |
3c4f71cc | 117 | |
4cc4bfaf | 118 | @see GetRGB() |
23324ae1 FM |
119 | */ |
120 | int GetPixel(unsigned char red, unsigned char green, | |
328f5751 | 121 | unsigned char blue) const; |
23324ae1 FM |
122 | |
123 | /** | |
124 | Returns RGB values for a given palette index. | |
3c4f71cc | 125 | |
7c913512 | 126 | @param pixel |
4cc4bfaf | 127 | The palette index. |
7c913512 | 128 | @param red |
4cc4bfaf | 129 | Receives the red value. |
7c913512 | 130 | @param green |
4cc4bfaf | 131 | Receives the green value. |
7c913512 | 132 | @param blue |
4cc4bfaf | 133 | Receives the blue value. |
3c4f71cc | 134 | |
d29a9a8a | 135 | @return @true if the operation was successful. |
3c4f71cc | 136 | |
1058f652 MB |
137 | @beginWxPerlOnly |
138 | In wxPerl this method takes only the @a pixel parameter and | |
139 | returns a 3-element list (or the empty list upon failure). | |
140 | @endWxPerlOnly | |
141 | ||
4cc4bfaf | 142 | @see GetPixel() |
23324ae1 | 143 | */ |
43c48e1e FM |
144 | bool GetRGB(int pixel, unsigned char* red, unsigned char* green, |
145 | unsigned char* blue) const; | |
23324ae1 FM |
146 | |
147 | /** | |
148 | Returns @true if palette data is present. | |
149 | */ | |
0004982c | 150 | virtual bool IsOk() const; |
23324ae1 FM |
151 | |
152 | /** | |
74bf4e64 | 153 | Assignment operator, using @ref overview_refcount. |
23324ae1 | 154 | */ |
74bf4e64 | 155 | wxPalette& operator =(const wxPalette& palette); |
23324ae1 | 156 | }; |
e54c96f1 FM |
157 | |
158 | ||
e54c96f1 | 159 | /** |
65874118 | 160 | An empty palette. |
e54c96f1 FM |
161 | */ |
162 | wxPalette wxNullPalette; | |
163 | ||
164 |