1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
// Generated by gtkmmproc -- DO NOT MODIFY!
#include <gdkmm/color.h>
#include <gdkmm/private/color_p.h>
// -*- c++ -*-
/* $Id: color.ccg,v 1.4 2005/11/29 16:38:10 murrayc Exp $ */
/*
*
* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gdkmm/colormap.h>
#include <gdk/gdk.h>
namespace Gdk
{
Color::Color()
{
GdkColor tmp = { 0, 0, 0, 0, };
gobject_ = gdk_color_copy(&tmp);
}
Color::Color(const Glib::ustring& value)
{
GdkColor tmp = { 0, 0, 0, 0, };
gobject_ = gdk_color_copy(&tmp);
set(value);
}
void Color::set_grey(gushort value)
{
gobject_->red = gobject_->green = gobject_->blue = value;
}
void Color::set_grey_p(double g)
{
gobject_->red = gobject_->green = gobject_->blue = (gushort)(g * 65535.0);
}
void Color::set_rgb(gushort red_, gushort green_, gushort blue_)
{
gobject_->red = red_;
gobject_->green = green_;
gobject_->blue = blue_;
}
void Color::set_rgb_p(double red_, double green_, double blue_)
{
gobject_->red = (gushort)(red_ * 65535.0);
gobject_->green = (gushort)(green_ * 65535.0);
gobject_->blue = (gushort)(blue_ * 65535.0);
}
void Color::set_hsv(double h, double s, double v)
{
//TODO: Comments/Documentation. I have no idea what this code does. murrayc.
h /= 60.0;
int i = (int)h;
double p = v * (1 - s);
double q = v * (1 - s * (h - i));
double t = v * (1 - s * (1 - h + i));
switch(i)
{
case 0:
set_rgb_p(v, t, p);
break;
case 1:
set_rgb_p(q, v, p);
break;
case 2:
set_rgb_p(p, v, t);
break;
case 3:
set_rgb_p(p, q, v);
break;
case 4:
set_rgb_p(t, p, v);
break;
default:
set_rgb_p(v, p, q);
}
}
void Color::set_hsl(double h, double s, double l)
{
//TODO: Comments/Documentation. I have no idea what this code does. murrayc.
if(s == 0.0)
set_grey_p(l);
else
{
double t2 = (l < 0.5) ? l * (1.0 + s) : l + s - l * s;
double t1 = 2*l-t2;
h /= 360.0;
double tr = h + 1.0/3.0;
double tg = h;
double tb = h - 1.0/3.0;
if (tb < 0) tb += 1.0;
double r = 0.0, g = 0.0, b = 0.0;
if (tr < 1.0/6.0)
r = t1 +(t2-t1) * 6 * tr;
else if (tr < 1.0/2.0)
r = t2;
else if (tr < 2.0/3.0)
r = t1+(t2-t1)*(2.0/3.0 - tr) * 6.0;
if (tg < 1.0/6.0)
g = t1 + (t2 - t1) * 6 * tg;
else if (tg < 1.0/2.0)
g = t2;
else if (tg < 2.0/3.0)
g = t1+(t2-t1)*(2.0/3.0 - tg) * 6.0;
if (tb < 1.0/6.0)
b = t1 +(t2-t1) * 6 * tb;
else if (tb < 1.0/2.0)
b = t2;
else if (tb < 2.0/3.0)
b = t1+(t2-t1)*(2.0/3.0 - tb) * 6.0;
set_rgb_p(r, g, b);
}
}
bool Color::set(const Glib::ustring& value)
{
return gdk_color_parse(value.c_str(), gobj());
}
#ifndef GDKMM_DISABLE_DEPRECATED
bool Color::parse(const Glib::ustring& spec)
{
return set(spec);
}
#endif // GDKMM_DISABLE_DEPRECATED
gushort Color::get_red() const
{
return gobject_->red;
}
gushort Color::get_green() const
{
return gobject_->green;
}
gushort Color::get_blue() const
{
return gobject_->blue;
}
void Color::set_red(gushort value)
{
gobject_->red = value;
}
void Color::set_green(gushort value)
{
gobject_->green = value;
}
void Color::set_blue(gushort value)
{
gobject_->blue = value;
}
#ifndef GDKMM_DISABLE_DEPRECATED
void Color::rgb_find_color(const Glib::RefPtr<Gdk::Colormap>& map)
{
gdk_rgb_find_color(Glib::unwrap(map), gobj());
}
#endif // GDKMM_DISABLE_DEPRECATED
guint Color::get_pixel() const
{
return gobject_->pixel;
}
double Color::get_red_p() const
{
return gobject_->red / 65535.0;
}
double Color::get_green_p() const
{
return gobject_->green / 65535.0;
}
double Color::get_blue_p() const
{
return gobject_->blue / 65535.0;
}
Glib::ustring Color::to_string() const
{
return Glib::convert_return_gchar_ptr_to_ustring( gdk_color_to_string(gobject_) );
}
ColorTraits::CType ColorTraits::to_c_type(const CppType& obj)
{
return *obj.gobj();
}
ColorTraits::CType ColorTraits::to_c_type(const CType& obj)
{
return obj;
}
ColorTraits::CppType ColorTraits::to_cpp_type(const CType& obj)
{
return CppType(const_cast<CType*>(&obj), true);
}
void ColorTraits::release_c_type(const CType&)
{}
} //namespace Gdk
namespace
{
} // anonymous namespace
namespace Glib
{
Gdk::Color wrap(GdkColor* object, bool take_copy)
{
return Gdk::Color(object, take_copy);
}
} // namespace Glib
namespace Gdk
{
// static
GType Color::get_type()
{
return gdk_color_get_type();
}
Color::Color(const Color& other)
:
gobject_ ((other.gobject_) ? gdk_color_copy(other.gobject_) : 0)
{}
Color::Color(GdkColor* gobject, bool make_a_copy)
:
// For BoxedType wrappers, make_a_copy is true by default. The static
// BoxedType wrappers must always take a copy, thus make_a_copy = true
// ensures identical behaviour if the default argument is used.
gobject_ ((make_a_copy && gobject) ? gdk_color_copy(gobject) : gobject)
{}
Color& Color::operator=(const Color& other)
{
Color temp (other);
swap(temp);
return *this;
}
Color::~Color()
{
if(gobject_)
gdk_color_free(gobject_);
}
void Color::swap(Color& other)
{
GdkColor *const temp = gobject_;
gobject_ = other.gobject_;
other.gobject_ = temp;
}
GdkColor* Color::gobj_copy() const
{
return gdk_color_copy(gobject_);
}
bool operator==(const Color& lhs, const Color& rhs)
{
return (gdk_color_equal(lhs.gobj(), rhs.gobj()) != 0);
}
bool operator!=(const Color& lhs, const Color& rhs)
{
return (gdk_color_equal(lhs.gobj(), rhs.gobj()) == 0);
}
} // namespace Gdk
|