comparison ext/guichan-0.8.1/include/guichan/color.hpp @ 89:fa33cda75471

* Reverting back to 2543 as requested by sleek
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 19 Jul 2008 11:38:52 +0000
parents 4a0efb7baf70
children
comparison
equal deleted inserted replaced
88:1c2842ebe393 89:fa33cda75471
1 /* _______ __ __ __ ______ __ __ _______ __ __
2 * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
3 * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4 * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
5 * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
6 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8 *
9 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
10 *
11 *
12 * Per Larsson a.k.a finalman
13 * Olof Naessén a.k.a jansem/yakslem
14 *
15 * Visit: http://guichan.sourceforge.net
16 *
17 * License: (BSD)
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
26 * distribution.
27 * 3. Neither the name of Guichan nor the names of its contributors may
28 * be used to endorse or promote products derived from this software
29 * without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
37 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 #ifndef GCN_COLOR_HPP
45 #define GCN_COLOR_HPP
46
47 #include "guichan/platform.hpp"
48
49 #include <iostream>
50
51 namespace gcn
52 {
53 /**
54 * Represents a color with red, green, blue and alpha components.
55 */
56 class GCN_CORE_DECLSPEC Color
57 {
58 public:
59
60 /**
61 * Constructor. Initializes the color to black.
62 */
63 Color();
64
65 /**
66 * Constructor. Constructs a color from the bytes in an integer.
67 * Call it with a hexadecimal constant for HTML-style color representation.
68 * The alpha component is 255 by default.
69 *
70 * EXAMPLE: Color(0xff50a0) constructs a very nice pinkish color.
71 *
72 * NOTE: Because of this constructor, integers will be automatically
73 * casted to a color by your compiler.
74 *
75 * @param color The color to initialise the object with.
76 */
77 Color(int color);
78
79 /**
80 * Constructor. The default alpha value is 255.
81 *
82 * @param r Red color component (range 0-255).
83 * @param g Green color component (range 0-255).
84 * @param b Blue color component (range 0-255).
85 * @param a Alpha, used for transparency. A value of 0 means
86 * totaly transparent, 255 is totaly opaque.
87 */
88 Color(int r, int g, int b, int a = 255);
89
90 /**
91 * Adds the RGB values of two colors together. The values will be
92 * clamped if they go out of range.
93 *
94 * WARNING: This function will reset the alpha value of the
95 * returned color to 255.
96 *
97 * @param color A color to add to this color.
98 * @return The added colors with an alpha value set to 255.
99 */
100 Color operator+(const Color& color) const;
101
102 /**
103 * Subtracts the RGB values of one color from another.
104 * The values will be clamped if they go out of range.
105 *
106 * WARNING: This function will reset the alpha value of the
107 * returned color to 255.
108 *
109 * @param color A color to subtract from this color.
110 * @return The subtracted colors with an alpha value set to 255.
111 */
112 Color operator-(const Color& color) const;
113
114 /**
115 * Multiplies the RGB values of a color with a float value.
116 * The values will be clamped if they go out of range.
117 *
118 * @param value The value to multiply the color with.
119 * @return The multiplied colors. The alpha value will, unlike
120 * the add and subtract operations, be multiplied as
121 * well.
122 */
123 Color operator*(float value) const;
124
125 /**
126 * Compares two colors.
127 *
128 * @return True if the two colors have the same RGBA components
129 * false otherwise.
130 */
131 bool operator==(const Color& color) const;
132
133 /**
134 * Compares two colors.
135 *
136 * @return True if the two colors have different RGBA components,
137 * false otherwise.
138 */
139 bool operator!=(const Color& color) const;
140
141 /**
142 * Output operator for output.
143 *
144 * @param out The stream to output to.
145 * @param color The color to output.
146 */
147 friend std::ostream& operator<<(std::ostream& out,
148 const Color& Color);
149
150 /**
151 * Holds the red color component (range 0-255).
152 */
153 int r;
154
155 /**
156 * Holds the green color component (range 0-255).
157 */
158 int g;
159
160 /**
161 * Holds the blue color component (range 0-255).
162 */
163 int b;
164
165 /**
166 * Holds the alpha color component. A value of 0 means totally
167 * transparent while a value of 255 is considered opaque.
168 */
169 int a;
170 };
171 }
172
173 #endif // end GCN_COLOR_HPP