mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Remove cf::color_t
This wrapper is no longer used.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#ifndef CF_H_HHFWBJSW
|
||||
#define CF_H_HHFWBJSW
|
||||
|
||||
#include "color.h"
|
||||
#include "image.h"
|
||||
#include <oak/oak.h>
|
||||
|
||||
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
Reference in New Issue
Block a user