diff options
author | fluxgen <fluxgen> | 2002-11-26 15:57:11 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-11-26 15:57:11 (GMT) |
commit | b5acf3a78f51e9fb1503f82e2235d98694328a67 (patch) | |
tree | a003883b85909bc1e1d20d30e1e2d98f8df6e470 /src/Color.cc | |
parent | fe2e6b32e7fd285a32d5210220e18da9abb7732f (diff) | |
download | fluxbox_pavel-b5acf3a78f51e9fb1503f82e2235d98694328a67.zip fluxbox_pavel-b5acf3a78f51e9fb1503f82e2235d98694328a67.tar.bz2 |
moved to FbTk
Diffstat (limited to 'src/Color.cc')
-rw-r--r-- | src/Color.cc | 166 |
1 files changed, 0 insertions, 166 deletions
diff --git a/src/Color.cc b/src/Color.cc deleted file mode 100644 index e848def..0000000 --- a/src/Color.cc +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | // Color.cc for Fluxbox window manager | ||
2 | // Copyright (c) 2002 Henrik Kinnunen (fluxgen@users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: Color.cc,v 1.3 2002/09/20 13:02:39 fluxgen Exp $ | ||
23 | |||
24 | #include "Color.hh" | ||
25 | |||
26 | #include "BaseDisplay.hh" | ||
27 | |||
28 | #include <iostream> | ||
29 | using namespace std; | ||
30 | |||
31 | namespace { | ||
32 | unsigned char maxValue(unsigned short colval) { | ||
33 | if (colval == 65535) | ||
34 | return 0xFF; | ||
35 | |||
36 | return static_cast<unsigned char>(colval/0xFF); | ||
37 | } | ||
38 | |||
39 | }; | ||
40 | |||
41 | namespace FbTk { | ||
42 | Color::Color(): | ||
43 | m_allocated(false), | ||
44 | m_screen(0) { | ||
45 | |||
46 | } | ||
47 | |||
48 | Color::Color(const Color &col_copy) { | ||
49 | copy(col_copy); | ||
50 | } | ||
51 | |||
52 | Color::Color(unsigned char red, unsigned char green, unsigned char blue, int screen): | ||
53 | m_red(red), m_green(green), m_blue(blue), | ||
54 | m_pixel(0), m_allocated(false), | ||
55 | m_screen(screen) { | ||
56 | allocate(red, green, blue, screen); | ||
57 | } | ||
58 | |||
59 | Color::Color(const char *color_string, int screen): | ||
60 | m_allocated(false), | ||
61 | m_screen(screen) { | ||
62 | setFromString(color_string, screen); | ||
63 | } | ||
64 | |||
65 | Color::~Color() { | ||
66 | free(); | ||
67 | } | ||
68 | |||
69 | bool Color::setFromString(const char *color_string, int screen) { | ||
70 | |||
71 | if (color_string == 0) { | ||
72 | free(); | ||
73 | return false; | ||
74 | } | ||
75 | |||
76 | Display *disp = BaseDisplay::instance()->getXDisplay(); | ||
77 | Colormap colm = DefaultColormap(disp, screen); | ||
78 | |||
79 | XColor color; | ||
80 | |||
81 | if (! XParseColor(disp, colm, color_string, &color)) | ||
82 | cerr<<"FbTk::Color: Parse color error: \""<<color_string<<"\""<<endl; | ||
83 | else if (! XAllocColor(disp, colm, &color)) | ||
84 | cerr<<"FbTk::Color: Allocation error: \""<<color_string<<"\""<<endl; | ||
85 | |||
86 | |||
87 | |||
88 | setPixel(color.pixel); | ||
89 | setRGB(maxValue(color.red), | ||
90 | maxValue(color.green), | ||
91 | maxValue(color.blue)); | ||
92 | setAllocated(true); | ||
93 | m_screen = screen; | ||
94 | |||
95 | return true; | ||
96 | } | ||
97 | |||
98 | /* | ||
99 | Color &Color::Color::operator = (const Color &col_copy) { | ||
100 | // check for aliasing | ||
101 | if (this == &col_copy) | ||
102 | return *this; | ||
103 | |||
104 | copy(col_copy); | ||
105 | return *this; | ||
106 | } | ||
107 | */ | ||
108 | |||
109 | void Color::free() { | ||
110 | if (isAllocated()) { | ||
111 | unsigned long pixel = m_pixel; | ||
112 | Display *disp = BaseDisplay::getXDisplay(); | ||
113 | XFreeColors(disp, DefaultColormap(disp, m_screen), &pixel, 1, 0); | ||
114 | setPixel(0); | ||
115 | setRGB(0, 0, 0); | ||
116 | setAllocated(false); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | void Color::copy(const Color &col_copy) { | ||
121 | if (!col_copy.isAllocated()) { | ||
122 | free(); | ||
123 | setRGB(col_copy.red(), col_copy.green(), col_copy.blue()); | ||
124 | setPixel(col_copy.pixel()); | ||
125 | return; | ||
126 | } | ||
127 | |||
128 | free(); | ||
129 | |||
130 | allocate(col_copy.red(), | ||
131 | col_copy.green(), | ||
132 | col_copy.blue(), | ||
133 | col_copy.m_screen); | ||
134 | |||
135 | } | ||
136 | |||
137 | void Color::allocate(unsigned char red, unsigned char green, unsigned char blue, int screen) { | ||
138 | |||
139 | Display *disp = BaseDisplay::getXDisplay(); | ||
140 | XColor color; | ||
141 | // fill xcolor structure | ||
142 | color.red = red; | ||
143 | color.green = green; | ||
144 | color.blue = blue; | ||
145 | |||
146 | |||
147 | if (!XAllocColor(disp, DefaultColormap(disp, screen), &color)) { | ||
148 | cerr<<"FbTk::Color: Allocation error."<<endl; | ||
149 | } else { | ||
150 | setRGB(maxValue(color.red), | ||
151 | maxValue(color.green), | ||
152 | maxValue(color.blue)); | ||
153 | setPixel(color.pixel); | ||
154 | setAllocated(true); | ||
155 | } | ||
156 | |||
157 | m_screen = screen; | ||
158 | } | ||
159 | |||
160 | void Color::setRGB(unsigned char red, unsigned char green, unsigned char blue) { | ||
161 | m_red = red; | ||
162 | m_green = green; | ||
163 | m_blue = blue; | ||
164 | } | ||
165 | |||
166 | }; | ||