diff options
author | fluxgen <fluxgen> | 2002-09-14 13:49:51 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-09-14 13:49:51 (GMT) |
commit | 62086e6f6806cf3d910c32607842c2c8d990d1bd (patch) | |
tree | c4f408e59c27c60d22ab45d9d942bfa163d8e572 | |
parent | 60bc660aa5200e6b5952b75a56299247efe0f14d (diff) | |
download | fluxbox_lack-62086e6f6806cf3d910c32607842c2c8d990d1bd.zip fluxbox_lack-62086e6f6806cf3d910c32607842c2c8d990d1bd.tar.bz2 |
fixed copy
-rw-r--r-- | src/Color.cc | 90 |
1 files changed, 68 insertions, 22 deletions
diff --git a/src/Color.cc b/src/Color.cc index b234150..d8b75b2 100644 --- a/src/Color.cc +++ b/src/Color.cc | |||
@@ -19,10 +19,15 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: Color.cc,v 1.1 2002/09/14 12:47:50 fluxgen Exp $ | 22 | // $Id: Color.cc,v 1.2 2002/09/14 13:49:51 fluxgen Exp $ |
23 | 23 | ||
24 | #include "Color.hh" | 24 | #include "Color.hh" |
25 | 25 | ||
26 | #include "BaseDisplay.hh" | ||
27 | |||
28 | #include <iostream> | ||
29 | using namespace std; | ||
30 | |||
26 | namespace { | 31 | namespace { |
27 | unsigned char maxValue(unsigned short colval) { | 32 | unsigned char maxValue(unsigned short colval) { |
28 | if (colval == 65535) | 33 | if (colval == 65535) |
@@ -35,30 +40,20 @@ unsigned char maxValue(unsigned short colval) { | |||
35 | 40 | ||
36 | namespace FbTk { | 41 | namespace FbTk { |
37 | Color::Color(): | 42 | Color::Color(): |
38 | m_allocated(false) { | 43 | m_allocated(false), |
44 | m_screen(0) { | ||
39 | 45 | ||
40 | } | 46 | } |
41 | 47 | ||
48 | Color::Color(const Color &col_copy) { | ||
49 | copy(col_copy); | ||
50 | } | ||
51 | |||
42 | Color::Color(unsigned char red, unsigned char green, unsigned char blue, int screen): | 52 | Color::Color(unsigned char red, unsigned char green, unsigned char blue, int screen): |
43 | m_red(red), m_green(green), m_blue(blue), | 53 | m_red(red), m_green(green), m_blue(blue), |
44 | m_pixel(0), m_allocated(false) { | 54 | m_pixel(0), m_allocated(false), |
45 | 55 | m_screen(screen) { | |
46 | Display *disp = BaseDisplay::getXDisplay(); | 56 | allocate(red, green, blue, screen); |
47 | XColor color; | ||
48 | // fill xcolor structure | ||
49 | color.red = red; | ||
50 | color.blue = blue; | ||
51 | color.green = green; | ||
52 | |||
53 | if (!XAllocColor(disp, DefaultColormap(disp, screen), &color)) { | ||
54 | cerr<<"FbTk::Color: Allocation error."<<endl; | ||
55 | } else { | ||
56 | setRGB(maxValue(color.red), | ||
57 | maxValue(color.green), | ||
58 | maxValue(color.blue)); | ||
59 | setPixel(color.pixel); | ||
60 | setAllocated(true); | ||
61 | } | ||
62 | } | 57 | } |
63 | 58 | ||
64 | Color::Color(const char *color_string, int screen): | 59 | Color::Color(const char *color_string, int screen): |
@@ -66,6 +61,10 @@ m_allocated(false) { | |||
66 | setFromString(color_string, screen); | 61 | setFromString(color_string, screen); |
67 | } | 62 | } |
68 | 63 | ||
64 | Color::~Color() { | ||
65 | free(); | ||
66 | } | ||
67 | |||
69 | bool Color::setFromString(const char *color_string, int screen) { | 68 | bool Color::setFromString(const char *color_string, int screen) { |
70 | 69 | ||
71 | if (color_string == 0) { | 70 | if (color_string == 0) { |
@@ -90,18 +89,65 @@ bool Color::setFromString(const char *color_string, int screen) { | |||
90 | maxValue(color.green), | 89 | maxValue(color.green), |
91 | maxValue(color.blue)); | 90 | maxValue(color.blue)); |
92 | setAllocated(true); | 91 | setAllocated(true); |
92 | m_screen = screen; | ||
93 | 93 | ||
94 | return true; | 94 | return true; |
95 | } | 95 | } |
96 | 96 | ||
97 | Color &Color::Color::operator = (const Color &col_copy) { | ||
98 | copy(col_copy); | ||
99 | return *this; | ||
100 | } | ||
101 | |||
97 | void Color::free() { | 102 | void Color::free() { |
98 | if (isAllocated()) { | 103 | if (isAllocated()) { |
99 | unsigned long pixel = col.pixel(); | 104 | unsigned long pixel = m_pixel; |
100 | XFreeColors(disp, colm, &pixel, 1, 0); | 105 | Display *disp = BaseDisplay::getXDisplay(); |
106 | XFreeColors(disp, DefaultColormap(disp, m_screen), &pixel, 1, 0); | ||
101 | setPixel(0); | 107 | setPixel(0); |
102 | setRGB(0, 0, 0); | 108 | setRGB(0, 0, 0); |
103 | setAllocated(false); | 109 | setAllocated(false); |
104 | } | 110 | } |
105 | } | 111 | } |
106 | 112 | ||
113 | void Color::copy(const Color &col_copy) { | ||
114 | if (!col_copy.isAllocated()) { | ||
115 | free(); | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | free(); | ||
120 | |||
121 | allocate(col_copy.red(), | ||
122 | col_copy.green(), | ||
123 | col_copy.blue(), | ||
124 | col_copy.m_screen); | ||
125 | |||
126 | } | ||
127 | |||
128 | void Color::allocate(unsigned char red, unsigned char green, unsigned char blue, int screen) { | ||
129 | |||
130 | Display *disp = BaseDisplay::getXDisplay(); | ||
131 | XColor color; | ||
132 | // fill xcolor structure | ||
133 | color.red = red; | ||
134 | color.blue = blue; | ||
135 | color.green = green; | ||
136 | |||
137 | if (!XAllocColor(disp, DefaultColormap(disp, screen), &color)) { | ||
138 | cerr<<"FbTk::Color: Allocation error."<<endl; | ||
139 | } else { | ||
140 | setRGB(maxValue(color.red), | ||
141 | maxValue(color.green), | ||
142 | maxValue(color.blue)); | ||
143 | setPixel(color.pixel); | ||
144 | setAllocated(true); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | void Color::setRGB(unsigned char red, unsigned char green, unsigned char blue) { | ||
149 | m_red = red; | ||
150 | m_green = green; | ||
151 | m_blue = blue; | ||
152 | } | ||
107 | }; | 153 | }; |