diff options
Diffstat (limited to 'src/FbTk/Color.cc')
-rw-r--r-- | src/FbTk/Color.cc | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/src/FbTk/Color.cc b/src/FbTk/Color.cc index 6e13c65..44cd1bb 100644 --- a/src/FbTk/Color.cc +++ b/src/FbTk/Color.cc | |||
@@ -19,7 +19,7 @@ | |||
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.2 2002/11/28 19:22:40 fluxgen Exp $ | 22 | // $Id: Color.cc,v 1.3 2002/12/01 13:42:14 rathnor Exp $ |
23 | 23 | ||
24 | #include "Color.hh" | 24 | #include "Color.hh" |
25 | 25 | ||
@@ -30,10 +30,10 @@ using namespace std; | |||
30 | 30 | ||
31 | namespace { | 31 | namespace { |
32 | unsigned char maxValue(unsigned short colval) { | 32 | unsigned char maxValue(unsigned short colval) { |
33 | if (colval == 65535) | 33 | if (colval == 65535) |
34 | return 0xFF; | 34 | return 0xFF; |
35 | 35 | ||
36 | return static_cast<unsigned char>(colval/0xFF); | 36 | return static_cast<unsigned char>(colval/0xFF); |
37 | } | 37 | } |
38 | 38 | ||
39 | }; | 39 | }; |
@@ -41,130 +41,130 @@ unsigned char maxValue(unsigned short colval) { | |||
41 | namespace FbTk { | 41 | namespace FbTk { |
42 | 42 | ||
43 | Color::Color(): | 43 | Color::Color(): |
44 | m_allocated(false), | 44 | m_allocated(false), |
45 | m_screen(0) { | 45 | m_screen(0) { |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | Color::Color(const Color &col_copy) { | 49 | Color::Color(const Color &col_copy) { |
50 | copy(col_copy); | 50 | copy(col_copy); |
51 | } | 51 | } |
52 | 52 | ||
53 | Color::Color(unsigned char red, unsigned char green, unsigned char blue, int screen): | 53 | Color::Color(unsigned char red, unsigned char green, unsigned char blue, int screen): |
54 | m_red(red), m_green(green), m_blue(blue), | 54 | m_red(red), m_green(green), m_blue(blue), |
55 | m_pixel(0), m_allocated(false), | 55 | m_pixel(0), m_allocated(false), |
56 | m_screen(screen) { | 56 | m_screen(screen) { |
57 | allocate(red, green, blue, screen); | 57 | allocate(red, green, blue, screen); |
58 | } | 58 | } |
59 | 59 | ||
60 | Color::Color(const char *color_string, int screen): | 60 | Color::Color(const char *color_string, int screen): |
61 | m_allocated(false), | 61 | m_allocated(false), |
62 | m_screen(screen) { | 62 | m_screen(screen) { |
63 | setFromString(color_string, screen); | 63 | setFromString(color_string, screen); |
64 | } | 64 | } |
65 | 65 | ||
66 | Color::~Color() { | 66 | Color::~Color() { |
67 | free(); | 67 | free(); |
68 | } | 68 | } |
69 | 69 | ||
70 | bool Color::setFromString(const char *color_string, int screen) { | 70 | bool Color::setFromString(const char *color_string, int screen) { |
71 | 71 | ||
72 | if (color_string == 0) { | 72 | if (color_string == 0) { |
73 | free(); | 73 | free(); |
74 | return false; | 74 | return false; |
75 | } | 75 | } |
76 | 76 | ||
77 | Display *disp = App::instance()->display(); | 77 | Display *disp = App::instance()->display(); |
78 | Colormap colm = DefaultColormap(disp, screen); | 78 | Colormap colm = DefaultColormap(disp, screen); |
79 | 79 | ||
80 | XColor color; | 80 | XColor color; |
81 | 81 | ||
82 | if (! XParseColor(disp, colm, color_string, &color)) { | 82 | if (! XParseColor(disp, colm, color_string, &color)) { |
83 | cerr<<"FbTk::Color: Parse color error: \""<<color_string<<"\""<<endl; | 83 | cerr<<"FbTk::Color: Parse color error: \""<<color_string<<"\""<<endl; |
84 | return false; | 84 | return false; |
85 | } else if (! XAllocColor(disp, colm, &color)) { | 85 | } else if (! XAllocColor(disp, colm, &color)) { |
86 | cerr<<"FbTk::Color: Allocation error: \""<<color_string<<"\""<<endl; | 86 | cerr<<"FbTk::Color: Allocation error: \""<<color_string<<"\""<<endl; |
87 | return false; | 87 | return false; |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | 91 | ||
92 | setPixel(color.pixel); | 92 | setPixel(color.pixel); |
93 | setRGB(maxValue(color.red), | 93 | setRGB(maxValue(color.red), |
94 | maxValue(color.green), | 94 | maxValue(color.green), |
95 | maxValue(color.blue)); | 95 | maxValue(color.blue)); |
96 | setAllocated(true); | 96 | setAllocated(true); |
97 | m_screen = screen; | 97 | m_screen = screen; |
98 | 98 | ||
99 | return true; | 99 | return true; |
100 | } | 100 | } |
101 | 101 | ||
102 | /* | 102 | /* |
103 | Color &Color::Color::operator = (const Color &col_copy) { | 103 | Color &Color::Color::operator = (const Color &col_copy) { |
104 | // check for aliasing | 104 | // check for aliasing |
105 | if (this == &col_copy) | 105 | if (this == &col_copy) |
106 | return *this; | 106 | return *this; |
107 | 107 | ||
108 | copy(col_copy); | 108 | copy(col_copy); |
109 | return *this; | 109 | return *this; |
110 | } | 110 | } |
111 | */ | 111 | */ |
112 | 112 | ||
113 | void Color::free() { | 113 | void Color::free() { |
114 | if (isAllocated()) { | 114 | if (isAllocated()) { |
115 | unsigned long pixel = m_pixel; | 115 | unsigned long pixel = m_pixel; |
116 | Display *disp = App::instance()->display(); | 116 | Display *disp = App::instance()->display(); |
117 | XFreeColors(disp, DefaultColormap(disp, m_screen), &pixel, 1, 0); | 117 | XFreeColors(disp, DefaultColormap(disp, m_screen), &pixel, 1, 0); |
118 | setPixel(0); | 118 | setPixel(0); |
119 | setRGB(0, 0, 0); | 119 | setRGB(0, 0, 0); |
120 | setAllocated(false); | 120 | setAllocated(false); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | void Color::copy(const Color &col_copy) { | 124 | void Color::copy(const Color &col_copy) { |
125 | if (!col_copy.isAllocated()) { | 125 | if (!col_copy.isAllocated()) { |
126 | free(); | 126 | free(); |
127 | setRGB(col_copy.red(), col_copy.green(), col_copy.blue()); | 127 | setRGB(col_copy.red(), col_copy.green(), col_copy.blue()); |
128 | setPixel(col_copy.pixel()); | 128 | setPixel(col_copy.pixel()); |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | 131 | ||
132 | free(); | 132 | free(); |
133 | 133 | ||
134 | allocate(col_copy.red(), | 134 | allocate(col_copy.red(), |
135 | col_copy.green(), | 135 | col_copy.green(), |
136 | col_copy.blue(), | 136 | col_copy.blue(), |
137 | col_copy.m_screen); | 137 | col_copy.m_screen); |
138 | 138 | ||
139 | } | 139 | } |
140 | 140 | ||
141 | void Color::allocate(unsigned char red, unsigned char green, unsigned char blue, int screen) { | 141 | void Color::allocate(unsigned char red, unsigned char green, unsigned char blue, int screen) { |
142 | 142 | ||
143 | Display *disp = App::instance()->display(); | 143 | Display *disp = App::instance()->display(); |
144 | XColor color; | 144 | XColor color; |
145 | // fill xcolor structure | 145 | // fill xcolor structure |
146 | color.red = red; | 146 | color.red = red; |
147 | color.green = green; | 147 | color.green = green; |
148 | color.blue = blue; | 148 | color.blue = blue; |
149 | 149 | ||
150 | 150 | ||
151 | if (!XAllocColor(disp, DefaultColormap(disp, screen), &color)) { | 151 | if (!XAllocColor(disp, DefaultColormap(disp, screen), &color)) { |
152 | cerr<<"FbTk::Color: Allocation error."<<endl; | 152 | cerr<<"FbTk::Color: Allocation error."<<endl; |
153 | } else { | 153 | } else { |
154 | setRGB(maxValue(color.red), | 154 | setRGB(maxValue(color.red), |
155 | maxValue(color.green), | 155 | maxValue(color.green), |
156 | maxValue(color.blue)); | 156 | maxValue(color.blue)); |
157 | setPixel(color.pixel); | 157 | setPixel(color.pixel); |
158 | setAllocated(true); | 158 | setAllocated(true); |
159 | } | 159 | } |
160 | 160 | ||
161 | m_screen = screen; | 161 | m_screen = screen; |
162 | } | 162 | } |
163 | 163 | ||
164 | void Color::setRGB(unsigned char red, unsigned char green, unsigned char blue) { | 164 | void Color::setRGB(unsigned char red, unsigned char green, unsigned char blue) { |
165 | m_red = red; | 165 | m_red = red; |
166 | m_green = green; | 166 | m_green = green; |
167 | m_blue = blue; | 167 | m_blue = blue; |
168 | } | 168 | } |
169 | 169 | ||
170 | }; | 170 | }; |