/* ** ClanLib SDK ** Copyright (c) 1997-2005 The ClanLib Team ** ** This software is provided 'as-is', without any express or implied ** warranty. In no event will the authors be held liable for any damages ** arising from the use of this software. ** ** Permission is granted to anyone to use this software for any purpose, ** including commercial applications, and to alter it and redistribute it ** freely, subject to the following restrictions: ** ** 1. The origin of this software must not be misrepresented; you must not ** claim that you wrote the original software. If you use this software ** in a product, an acknowledgment in the product documentation would be ** appreciated but is not required. ** 2. Altered source versions must be plainly marked as such, and must not be ** misrepresented as being the original software. ** 3. This notice may not be removed or altered from any source distribution. ** ** Note: Some of the libraries ClanLib may link to may have additional ** requirements or restrictions. ** ** File Author(s): ** ** Magnus Norddahl ** (if your name is missing here, please add it) */ //! clanDisplay="Display 2D" //! header=display.h #ifndef header_color #define header_color #ifdef CL_API_DLL #ifdef CL_DISPLAY_EXPORT #define CL_API_DISPLAY __declspec(dllexport) #else #define CL_API_DISPLAY __declspec(dllimport) #endif #else #define CL_API_DISPLAY #endif #if _MSC_VER > 1000 #pragma once #endif #include #include class CL_PixelFormat; class CL_Colorf; //: Color description class. //- !group=Display/Display 2D! //- !header=display.h! class CL_API_DISPLAY CL_Color { //! Construction: public: //: Constructs a color. //-

Color components are specified in the range 0 to 255.

//-

An alpha value of 0 means complete transparency, while 255 means completely opaque (solid).

//param red: Red color component. //param green: Green color component. //param blue: Blue color component. //param alpha: Alpha (transparency) color component. CL_Color() : color(0) { return; } explicit CL_Color(const CL_Colorf&); CL_Color(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha = 255) : color((alpha<<24) | (red<<16) | (green<<8) | blue) { return; } //! Attributes: public: //: Returns the alpha color component, in the range 0-255. unsigned int get_alpha() const { return (color >> 24) & 0xff; } //: Returns the red color component, in the range 0-255. unsigned int get_red() const { return (color >> 16) & 0xff; } //: Returns the green color component, in the range 0-255. unsigned int get_green() const { return (color >> 8) & 0xff; } //: Returns the blue color component, in the range 0-255. unsigned int get_blue() const { return color & 0xff; } //: Color in ARGB8888 format. unsigned int color; // Operations: public: //: Color == Color operator (deep compare) bool operator==(const CL_Color &c) const { return (color == c.color); } //: Color != Color operator (deep compare) bool operator!=(const CL_Color &c) const { return (color != c.color); } //! Statics: public: //: rgb(240, 248, 255). static CL_Color aliceblue; //: rgb(250, 235, 215). static CL_Color antiquewhite; //: rgb( 0, 255, 255). static CL_Color aqua; //: rgb(127, 255, 212). static CL_Color aquamarine; //: rgb(240, 255, 255). static CL_Color azure; //: rgb(245, 245, 220). static CL_Color beige; //: rgb(255, 228, 196). static CL_Color bisque; //: rgb( 0, 0, 0). static CL_Color black; //: rgb(255, 235, 205). static CL_Color blanchedalmond; //: rgb( 0, 0, 255). static CL_Color blue; //: rgb(138, 43, 226). static CL_Color blueviolet; //: rgb(165, 42, 42). static CL_Color brown; //: rgb(222, 184, 135). static CL_Color burlywood; //: rgb( 95, 158, 160). static CL_Color cadetblue; //: rgb(127, 255, 0). static CL_Color chartreuse; //: rgb(210, 105, 30). static CL_Color chocolate; //: rgb(255, 127, 80). static CL_Color coral; //: rgb(100, 149, 237). static CL_Color cornflowerblue; //: rgb(255, 248, 220). static CL_Color cornsilk; //: rgb(220, 20, 60). static CL_Color crimson; //: rgb( 0, 255, 255). static CL_Color cyan; //: rgb( 0, 0, 139). static CL_Color darkblue; //: rgb( 0, 139, 139). static CL_Color darkcyan; //: rgb(184, 134, 11). static CL_Color darkgoldenrod; //: rgb(169, 169, 169). static CL_Color darkgray; //: rgb( 0, 100, 0). static CL_Color darkgreen; //: rgb(169, 169, 169). static CL_Color darkgrey; //: rgb(189, 183, 107). static CL_Color darkkhaki; //: rgb(139, 0, 139). static CL_Color darkmagenta; //: rgb( 85, 107, 47). static CL_Color darkolivegreen; //: rgb(255, 140, 0). static CL_Color darkorange; //: rgb(153, 50, 204). static CL_Color darkorchid; //: rgb(139, 0, 0). static CL_Color darkred; //: rgb(233, 150, 122). static CL_Color darksalmon; //: rgb(143, 188, 143). static CL_Color darkseagreen; //: rgb( 72, 61, 139). static CL_Color darkslateblue; //: rgb( 47, 79, 79). static CL_Color darkslategray; //: rgb( 47, 79, 79). static CL_Color darkslategrey; //: rgb( 0, 206, 209). static CL_Color darkturquoise; //: rgb(148, 0, 211). static CL_Color darkviolet; //: rgb(255, 20, 147). static CL_Color deeppink; //: rgb( 0, 191, 255). static CL_Color deepskyblue; //: rgb(105, 105, 105). static CL_Color dimgray; //: rgb(105, 105, 105). static CL_Color dimgrey; //: rgb( 30, 144, 255). static CL_Color dodgerblue; //: rgb(178, 34, 34). static CL_Color firebrick; //: rgb(255, 250, 240). static CL_Color floralwhite; //: rgb( 34, 139, 34). static CL_Color forestgreen; //: rgb(255, 0, 255). static CL_Color fuchsia; //: rgb(220, 220, 220). static CL_Color gainsboro; //: rgb(248, 248, 255). static CL_Color ghostwhite; //: rgb(255, 215, 0). static CL_Color gold; //: rgb(218, 165, 32). static CL_Color goldenrod; //: rgb(128, 128, 128). static CL_Color gray; //: rgb(128, 128, 128). static CL_Color grey; //: rgb( 0, 128, 0). static CL_Color green; //: rgb(173, 255, 47). static CL_Color greenyellow; //: rgb(240, 255, 240). static CL_Color honeydew; //: rgb(255, 105, 180). static CL_Color hotpink; //: rgb(205, 92, 92). static CL_Color indianred; //: rgb( 75, 0, 130). static CL_Color indigo; //: rgb(255, 255, 240). static CL_Color ivory; //: rgb(240, 230, 140). static CL_Color khaki; //: rgb(230, 230, 250). static CL_Color lavender; //: rgb(255, 240, 245). static CL_Color lavenderblush; //: rgb(124, 252, 0). static CL_Color lawngreen; //: rgb(255, 250, 205). static CL_Color lemonchiffon; //: rgb(173, 216, 230). static CL_Color lightblue; //: rgb(240, 128, 128). static CL_Color lightcoral; //: rgb(224, 255, 255). static CL_Color lightcyan; //: rgb(250, 250, 210). static CL_Color lightgoldenrodyellow; //: rgb(211, 211, 211). static CL_Color lightgray; //: rgb(144, 238, 144). static CL_Color lightgreen; //: rgb(211, 211, 211). static CL_Color lightgrey; //: rgb(255, 182, 193). static CL_Color lightpink; //: rgb(255, 160, 122). static CL_Color lightsalmon; //: rgb( 32, 178, 170). static CL_Color lightseagreen; //: rgb(135, 206, 250). static CL_Color lightskyblue; //: rgb(119, 136, 153). static CL_Color lightslategray; //: rgb(119, 136, 153). static CL_Color lightslategrey; //: rgb(176, 196, 222). static CL_Color lightsteelblue; //: rgb(255, 255, 224). static CL_Color lightyellow; //: rgb( 0, 255, 0). static CL_Color lime; //: rgb( 50, 205, 50). static CL_Color limegreen; //: rgb(250, 240, 230). static CL_Color linen; //: rgb(255, 0, 255). static CL_Color magenta; //: rgb(128, 0, 0). static CL_Color maroon; //: rgb(102, 205, 170). static CL_Color mediumaquamarine; //: rgb( 0, 0, 205). static CL_Color mediumblue; //: rgb(186, 85, 211). static CL_Color mediumorchid; //: rgb(147, 112, 219). static CL_Color mediumpurple; //: rgb( 60, 179, 113). static CL_Color mediumseagreen; //: rgb(123, 104, 238). static CL_Color mediumslateblue; //: rgb( 0, 250, 154). static CL_Color mediumspringgreen; //: rgb( 72, 209, 204). static CL_Color mediumturquoise; //: rgb(199, 21, 133). static CL_Color mediumvioletred; //: rgb( 25, 25, 112). static CL_Color midnightblue; //: rgb(245, 255, 250). static CL_Color mintcream; //: rgb(255, 228, 225). static CL_Color mistyrose; //: rgb(255, 228, 181). static CL_Color moccasin; //: rgb(255, 222, 173). static CL_Color navajowhite; //: rgb( 0, 0, 128). static CL_Color navy; //: rgb(253, 245, 230). static CL_Color oldlace; //: rgb(128, 128, 0). static CL_Color olive; //: rgb(107, 142, 35). static CL_Color olivedrab; //: rgb(255, 165, 0). static CL_Color orange; //: rgb(255, 69, 0). static CL_Color orangered; //: rgb(218, 112, 214). static CL_Color orchid; //: rgb(238, 232, 170). static CL_Color palegoldenrod; //: rgb(152, 251, 152). static CL_Color palegreen; //: rgb(175, 238, 238). static CL_Color paleturquoise; //: rgb(219, 112, 147). static CL_Color palevioletred; //: rgb(255, 239, 213). static CL_Color papayawhip; //: rgb(255, 218, 185). static CL_Color peachpuff; //: rgb(205, 133, 63). static CL_Color peru; //: rgb(255, 192, 203). static CL_Color pink; //: rgb(221, 160, 221). static CL_Color plum; //: rgb(176, 224, 230). static CL_Color powderblue; //: rgb(128, 0, 128). static CL_Color purple; //: rgb(255, 0, 0). static CL_Color red; //: rgb(188, 143, 143). static CL_Color rosybrown; //: rgb( 65, 105, 225). static CL_Color royalblue; //: rgb(139, 69, 19). static CL_Color saddlebrown; //: rgb(250, 128, 114). static CL_Color salmon; //: rgb(244, 164, 96). static CL_Color sandybrown; //: rgb( 46, 139, 87). static CL_Color seagreen; //: rgb(255, 245, 238). static CL_Color seashell; //: rgb(160, 82, 45). static CL_Color sienna; //: rgb(192, 192, 192). static CL_Color silver; //: rgb(135, 206, 235). static CL_Color skyblue; //: rgb(106, 90, 205). static CL_Color slateblue; //: rgb(112, 128, 144). static CL_Color slategray; //: rgb(112, 128, 144). static CL_Color slategrey; //: rgb(255, 250, 250). static CL_Color snow; //: rgb( 0, 255, 127). static CL_Color springgreen; //: rgb( 70, 130, 180). static CL_Color steelblue; //: rgb(210, 180, 140). static CL_Color tan; //: rgb( 0, 128, 128). static CL_Color teal; //: rgb(216, 191, 216). static CL_Color thistle; //: rgb(255, 99, 71). static CL_Color tomato; //: rgb( 64, 224, 208). static CL_Color turquoise; //: rgb(238, 130, 238). static CL_Color violet; //: rgb(245, 222, 179). static CL_Color wheat; //: rgb(255, 255, 255). static CL_Color white; //: rgb(245, 245, 245). static CL_Color whitesmoke; //: rgb(255, 255, 0). static CL_Color yellow; //: rgb(154, 205, 50). static CL_Color yellowgreen; //: Find and returns the static color matching a string. //param name: Name of color to match, eg. "blue". //return: Reference to matching static color, or rgba(0,0,0,0) if there was no match. static CL_Color &find_color(const std::string &name); //: Returns the names of static colors defined. static std::vector &get_names(); //! Operations: public: //: Set alpha color component, in the range 0-255. void set_alpha(unsigned int value) { color = (color & 0x00ffffff) | (value << 24); } //: Set red color component, in the range 0-255. void set_red(unsigned int value) { color = (color & 0xff00ffff) | (value << 16); } //: Set green color component, in the range 0-255. void set_green(unsigned int value) { color = (color & 0xffff00ff) | (value << 8); } //: Set blue color component, in the range 0-255. void set_blue(unsigned int value) { color = (color & 0xffffff00) | value; } //: Set color based on rgba color components in the range 0-255. void set_color(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha = 255) { color = (alpha<<24) | (red<<16) | (green<<8) | blue; } //: Converts the color to a given pixel format. unsigned int to_pixelformat(const CL_PixelFormat &pf) const; //: Converts a raw pixel in a given pixel format to a color. static CL_Color from_pixelformat(unsigned int raw_color, const CL_PixelFormat &pf); }; //: float pointing based Color description class. //- !group=Display/Display 2D! //- !header=display.h! class CL_Colorf { //! Attributes: public: float red; float green; float blue; float alpha; //! Operations: public: //: Constructs a black and fully transparent color. CL_Colorf() : red(0.0f), green(0.0f), blue(0.0f), alpha(0.0f) {} //: Construct a CL_Colorf out of a given byte based CL_Color CL_Colorf(const CL_Color& color) : red(color.get_red()/255.0f), green(color.get_green()/255.0f), blue(color.get_blue()/255.0f), alpha(color.get_alpha()/255.0f) {} //: Constructs a color. //-

Color components are specified in the range 0.0f to 1.0f.

//-

An alpha value of 0.0f means complete transparency, while 1.0f means completely opaque (solid).

//param red: Red color component. //param green: Green color component. //param blue: Blue color component. //param alpha: Alpha (transparency) color component. CL_Colorf(float r, float g, float b, float a = 1.0f) : red(r), green(g), blue(b), alpha(a) {} //: Normalize the color by ensuring that all color values lie inbetween (0.0, 1.0) void normalize() { red = (red < 0.0f) ? 0.0f : ((red > 1.0f) ? 1.0f : red); green = (green < 0.0f) ? 0.0f : ((green > 1.0f) ? 1.0f : green); blue = (blue < 0.0f) ? 0.0f : ((blue > 1.0f) ? 1.0f : blue); alpha = (alpha < 0.0f) ? 0.0f : ((alpha > 1.0f) ? 1.0f : alpha); } // Operations: public: //: Color == Color operator (deep compare) bool operator==(const CL_Colorf &c) const { return (red == c.red) && (green == c.green) && (blue == c.blue) && (alpha == c.alpha); } //: Color != Color operator (deep compare) bool operator!=(const CL_Colorf &c) const { return (red != c.red) || (green != c.green) || (blue != c.blue) || (alpha != c.alpha); } }; #endif