Remove cf::color_t

This wrapper is no longer used.
This commit is contained in:
Allan Odgaard
2013-02-20 12:54:52 +01:00
parent 4bae908d49
commit a7c33be67e
3 changed files with 0 additions and 81 deletions

View File

@@ -1,7 +1,6 @@
#ifndef CF_H_HHFWBJSW
#define CF_H_HHFWBJSW
#include "color.h"
#include "image.h"
#include <oak/oak.h>

View File

@@ -1,41 +0,0 @@
#include "color.h"
#include <oak/debug.h>
#include <text/format.h>
namespace cf
{
color_t::color_t (std::string const& str)
{
unsigned int r = 0, g = 0, b = 0, a = 0xFF;
if(str == NULL_STR || sscanf(str.c_str(), "#%02x%02x%02x%02x", &r, &g, &b, &a) < 3)
*this = color_t(0, 0, 0, 1);
*this = color_t(r/255.0, g/255.0, b/255.0, a/255.0);
}
color_t::operator CGColorRef () const
{
if(!cachedValue)
{
CGFloat components[4] = { _red, _green, _blue, _alpha };
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
cachedValue.reset(CGColorCreate(colorspace, components), CGColorRelease);
CGColorSpaceRelease(colorspace);
}
return cachedValue.get();
}
bool color_t::operator== (color_t const& rhs) const { return _red == rhs._red && _blue == rhs._blue && _green == rhs._green && _alpha == rhs._alpha; }
bool color_t::operator!= (color_t const& rhs) const { return _red != rhs._red || _blue != rhs._blue || _green != rhs._green || _alpha != rhs._alpha; }
std::string to_s (color_t const& c)
{
return text::format("#%02lX%02lX%02lX%02lX", lround(c._red*0xFF), lround(c._green*0xFF), lround(c._blue*0xFF), lround(c._alpha*0xFF));
}
bool color_is_dark (color_t const& color)
{
return 0.30*color._red + 0.59*color._green + 0.11*color._blue < 0.5;
}
} /* cf */

View File

@@ -1,39 +0,0 @@
#ifndef CF_COLOR_H_2BFCUP1C
#define CF_COLOR_H_2BFCUP1C
#include <oak/misc.h>
namespace cf
{
struct PUBLIC color_t
{
color_t () : _empty(true) { }
color_t (std::string const& str);
color_t (CGFloat r, CGFloat g, CGFloat b, CGFloat a) : _red(r), _green(g), _blue(b), _alpha(a) { }
bool operator== (color_t const& rhs) const;
bool operator!= (color_t const& rhs) const;
operator CGColorRef () const;
explicit operator bool () const { return !_empty; }
CGFloat red () const { return _red; }
CGFloat green () const { return _green; }
CGFloat blue () const { return _blue; }
CGFloat alpha () const { return _alpha; }
private:
CGFloat _red, _green, _blue, _alpha;
mutable std::shared_ptr<struct CGColor> cachedValue;
bool _empty = false;
friend std::string to_s (color_t const& c);
friend bool color_is_dark (color_t const& color);
};
PUBLIC std::string to_s (color_t const& c);
PUBLIC bool color_is_dark (color_t const& color);
} /* cf */
#endif /* end of include guard: CF_COLOR_H_2BFCUP1C */