aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-09-14 13:49:51 (GMT)
committerfluxgen <fluxgen>2002-09-14 13:49:51 (GMT)
commit62086e6f6806cf3d910c32607842c2c8d990d1bd (patch)
treec4f408e59c27c60d22ab45d9d942bfa163d8e572 /src
parent60bc660aa5200e6b5952b75a56299247efe0f14d (diff)
downloadfluxbox-62086e6f6806cf3d910c32607842c2c8d990d1bd.zip
fluxbox-62086e6f6806cf3d910c32607842c2c8d990d1bd.tar.bz2
fixed copy
Diffstat (limited to 'src')
-rw-r--r--src/Color.cc90
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>
29using namespace std;
30
26namespace { 31namespace {
27unsigned char maxValue(unsigned short colval) { 32unsigned 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
36namespace FbTk { 41namespace FbTk {
37Color::Color(): 42Color::Color():
38m_allocated(false) { 43m_allocated(false),
44m_screen(0) {
39 45
40} 46}
41 47
48Color::Color(const Color &col_copy) {
49 copy(col_copy);
50}
51
42Color::Color(unsigned char red, unsigned char green, unsigned char blue, int screen): 52Color::Color(unsigned char red, unsigned char green, unsigned char blue, int screen):
43m_red(red), m_green(green), m_blue(blue), 53m_red(red), m_green(green), m_blue(blue),
44m_pixel(0), m_allocated(false) { 54m_pixel(0), m_allocated(false),
45 55m_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
64Color::Color(const char *color_string, int screen): 59Color::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
64Color::~Color() {
65 free();
66}
67
69bool Color::setFromString(const char *color_string, int screen) { 68bool 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
97Color &Color::Color::operator = (const Color &col_copy) {
98 copy(col_copy);
99 return *this;
100}
101
97void Color::free() { 102void 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
113void 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
128void 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
148void 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};