2009-12-07 Rolf Bjarne Kvinge <RKvinge@novell.com>
[moon.git] / src / color.h
blob9715aaadc9fbd772e768ed1db2597a53fee579a1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * color.h
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #ifndef __MOON_COLOR_H__
12 #define __MOON_COLOR_H__
14 #include <glib.h>
15 #include <math.h>
17 /* @IncludeInKinds */
18 /* @Namespace=System.Windows.Media */
19 struct Color {
20 double r, g, b, a;
22 Color () : r(0.0), g(0.0), b(0.0), a(0.0) {}
24 Color (guint32 argb)
26 a = (argb >> 24) / 255.0f;
27 r = ((argb >> 16) & 0xFF) / 255.0f;
28 g = ((argb >> 8) & 0xFF) / 255.0f;
29 b = (argb & 0xFF) / 255.0f;
32 Color (double r, double g, double b, double a)
34 this->r = r;
35 this->g = g;
36 this->b = b;
37 this->a = a;
40 Color operator+ (const Color &color)
42 return Color (r + color.r,
43 g + color.g,
44 b + color.b,
45 a + color.a);
48 Color operator- (const Color &color)
50 return Color (r - color.r,
51 g - color.g,
52 b - color.b,
53 a - color.a);
56 Color operator* (double v)
58 return Color (r * v,
59 g * v,
60 b * v,
61 a * v);
64 bool operator!= (const Color &v) const
66 return !(*this == v);
69 bool operator== (const Color &v) const
71 return (fabs (r-v.r) < DBL_EPSILON && fabs (g-v.g) < DBL_EPSILON && fabs (b-v.b) < DBL_EPSILON && fabs (a-v.a) < DBL_EPSILON);
75 G_BEGIN_DECLS
77 const char *color_to_string (Color *color);
79 Color *color_from_str (const char *name);
81 G_END_DECLS
83 #endif /* __MOON_COLOR_H__ */