add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gdk / gdkmm / color.h
1 // -*- c++ -*-
2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GDKMM_COLOR_H
4 #define _GDKMM_COLOR_H
5
6 #include <gdkmmconfig.h>
7
8
9 #include <glibmm.h>
10
11 /* $Id$ */
12
13 /* Copyright (C) 1998-2002 The gtkmm Development Team
14  *
15  * This library is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU Library General Public
17  * License as published by the Free Software Foundation; either
18  * version 2 of the License, or (at your option) any later version.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23  * Library General Public License for more details.
24  *
25  * You should have received a copy of the GNU Library General Public
26  * License along with this library; if not, write to the Free
27  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28  */
29
30 // This is for including the config header before any code (such as
31 // the #ifndef GDKMM_DISABLE_DEPRECATED in deprecated classes) is generated:
32
33
34 #include <gdk/gdkcolor.h>
35
36
37 #ifndef DOXYGEN_SHOULD_SKIP_THIS
38 extern "C" { typedef struct _GdkColor GdkColor; }
39 #endif
40
41 namespace Gdk
42 {
43
44 class Colormap;
45
46 /** Gdk::Color is used to describe an allocated or unallocated color.
47  * It contains the following data:
48  *   pixel: For allocated colors, the value used to draw this color on the screen.
49  *   red: The red component of the color. This is a value between 0 and 65535, with 65535 indicating full intensitiy.
50  *   green: The green component of the color.
51  *   blue: The blue component of the color.
52  */
53 class Color
54 {
55   public:
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57   typedef Color CppObjectType;
58   typedef GdkColor BaseObjectType;
59
60   static GType get_type() G_GNUC_CONST;
61 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
62
63
64   explicit Color(GdkColor* gobject, bool make_a_copy = true);
65
66   Color(const Color& other);
67   Color& operator=(const Color& other);
68
69   ~Color();
70
71   void swap(Color& other);
72
73   ///Provides access to the underlying C instance.
74   GdkColor*       gobj()       { return gobject_; }
75
76   ///Provides access to the underlying C instance.
77   const GdkColor* gobj() const { return gobject_; }
78
79   ///Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.
80   GdkColor* gobj_copy() const;
81
82 protected:
83   GdkColor* gobject_;
84
85 private:
86
87 public:
88
89   
90   /** Instantiate a new Gdk::Color.
91    * You should then use the set methods and call Gdk::Colormap::alloc_color().
92    */
93   Color();
94
95   /** Instantiate a new Gdk::Color.
96    * The color is not allocated - you must call Gdk::Colormap::alloc_color() yourself.
97    * The text string can be in any of the forms accepted by XParseColor; these include names for a color from rgb.txt,
98    * such as DarkSlateGray, or a hex specification such as 305050.
99    * @param value the string specifying the color..
100    */
101   explicit Color(const Glib::ustring& value);
102
103   /** Set a grey color, by using the same value for all color components.
104    * @param value The value to be used for the red, green, and blue components.
105    */
106   void set_grey(gushort value);
107   void set_grey_p(double g);
108
109   /** Set the color, by specifying red, green, and blue color component values.
110    * @param red_ The red component of the color.
111    * @param green_ The green component of the color.
112    * @param blue_ The blue component of the color.
113    */
114   void set_rgb(gushort red_, gushort green_, gushort blue_);
115
116   /** Set the color, by specifying red, green, and blue color component values, as percentages.
117    * @param red_ The red component of the color, as a percentage.
118    * @param green_ The green component of the color, as a percentage.
119    * @param blue_ The blue component of the color, as a percentage.
120    */
121   void set_rgb_p(double red_, double green_, double blue_);
122
123   void set_hsv(double h, double s, double v);
124   void set_hsl(double h, double s, double l);
125
126   /** Parses a textual specification of a color and fills in the red, green, and blue values.
127   * The color is not allocated - you must call Gdk::Colormap::alloc_color() yourself.
128   * The text string can be in any of the forms accepted by XParseColor; these include names for a color from rgb.txt,
129   * such as DarkSlateGray, or a hex specification such as 305050.
130   *
131   * @param value the string specifying the color.
132   * @result true if the parsing succeeded.
133   */
134   bool set(const Glib::ustring& value);
135
136   #ifndef GDKMM_DISABLE_DEPRECATED
137
138   /** 
139    * @deprecated See set().
140    */
141   bool parse(const Glib::ustring& spec);
142   #endif // GDKMM_DISABLE_DEPRECATED
143
144
145   /** Get the red component of the color.
146    * @result The red component of the color.
147    */
148   gushort get_red() const;
149
150   /** Get the green component of the color.
151    * @result The green component of the color.
152    */
153   gushort get_green() const;
154
155   /** Get the blue component of the color.
156    * @result The blue component of the color.
157    */
158   gushort get_blue() const;
159
160   /** Set the red component of the color.
161    * @param value The red component of the color.
162    */
163   void set_red(gushort value);
164
165   /** Set the green component of the color.
166    * @param value The green component of the color.
167    */
168   void set_green(gushort value);
169
170   /** Set the blue component of the color.
171    * @param value The blue component of the color.
172    */
173   void set_blue(gushort value);
174
175   /** This will fill in the pixel field with the best matching pixel from a color cube.
176    * The color is then ready to be used for drawing, e.g. you can call Gdk::GC::set_foreground() which expects pixel to be initialized.
177    * Call this after setting the red, green, and blue fields.
178    *
179    * In many cases, you can avoid this whole issue by calling Gdk::GC::set_rgb_fg_color() or Gdk::GC::set_rgb_bg_color(),
180    * which do not expect pixels to be initialized in advance. If you use those methods, there's no need for this method().
181    *
182    * @param map The colormap for the graphics context and drawable you're using to draw. If you're drawing to a Gtk::Widget, call Gtk::Widget::get_colormap().
183    */
184   void rgb_find_color(const Glib::RefPtr<Gdk::Colormap>& map);
185
186   /** Get the pixel value, for allocated colors.
187    * @result For allocated colors, the value used to draw this color on the screen.
188    */
189   guint get_pixel() const;
190
191   /** Get the red component of the color, as a percentage.
192    * @result The red component of the color, as a percentage.
193    */
194   double get_red_p() const;
195
196   /** Get the green component of the color, as a percentage.
197    * @result The green component of the color, as a percentage.
198    */
199   double get_green_p() const;
200
201   /** Get the blue component of the color, as a percentage.
202    * @result The blue component of the color, as a percentage.
203    */
204   double get_blue_p() const;
205
206
207 };
208
209
210 #ifndef DOXYGEN_SHOULD_SKIP_THIS
211 /* These traits are for arrays of GdkColor structs -- not pointer arrays.
212  */
213 struct ColorTraits
214 {
215   typedef Gdk::Color  CppType;
216   typedef GdkColor    CType;
217   typedef GdkColor    CTypeNonConst;
218
219   static CType   to_c_type      (const CppType& obj) { return *obj.gobj(); }
220   static CType   to_c_type      (const CType&   obj) { return obj; }
221   static CppType to_cpp_type    (const CType&   obj) { return CppType(const_cast<CType*>(&obj), true); }
222   static void    release_c_type (const CType&)       {}
223 };
224 #endif //DOXYGEN_SHOULD_SKIP_THIS
225
226 typedef Glib::ArrayHandle<Color,ColorTraits> ArrayHandle_Color;
227
228 } // namespace Gdk
229
230
231 namespace Gdk
232 {
233
234 /** @relates Gdk::Color
235  * @param lhs The left-hand side
236  * @param rhs The right-hand side
237  * @result The result
238  */
239 bool operator==(const Color& lhs, const Color& rhs);
240
241 /** @relates Gdk::Color
242  * @param lhs The left-hand side
243  * @param rhs The right-hand side
244  * @result The result
245  */
246 bool operator!=(const Color& lhs, const Color& rhs);
247
248
249 } // namespace Gdk
250
251
252 namespace Gdk
253 {
254
255 /** @relates Gdk::Color
256  * @param lhs The left-hand side
257  * @param rhs The right-hand side
258  */
259 inline void swap(Color& lhs, Color& rhs)
260   { lhs.swap(rhs); }
261
262 } // namespace Gdk
263
264 namespace Glib
265 {
266
267 /** A Glib::wrap() method for this object.
268  * 
269  * @param object The C instance.
270  * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
271  * @result A C++ instance that wraps this C instance.
272  *
273  * @relates Gdk::Color
274  */
275 Gdk::Color wrap(GdkColor* object, bool take_copy = false);
276
277 #ifndef DOXYGEN_SHOULD_SKIP_THIS
278 template <>
279 class Value<Gdk::Color> : public Glib::Value_Boxed<Gdk::Color>
280 {};
281 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
282
283 } // namespace Glib
284
285
286 #endif /* _GDKMM_COLOR_H */
287