RGB-to-string and back methods into Color.[Ch].

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7513 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Martin Vermeer 2003-08-06 18:42:58 +00:00
parent 6820291d13
commit f8568ce1db
4 changed files with 48 additions and 11 deletions

View File

@ -1,3 +1,9 @@
2003-08-06 Martin Vermeer <martin.vermeer@hut.di>
* Color.[Ch]:
* FormPreferences.C: moved the RGB to hex string method
from FormPreferences to Color and added a hex string to RGB
method.
2003-08-04 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* Makefile.am (BUILT_SOURCES): add lyx_forms.h and lyx_xpm.h

View File

@ -14,7 +14,12 @@
#include "Color.h"
#include <algorithm> // max
#include <cmath> // floor
#include <iomanip>
#include "lyx_forms.h"
#include "Lsstream.h"
#include "support/LAssert.h"
namespace support = lyx::support;
#ifndef CXX_GLOBAL_CSTD
using std::floor;
@ -23,13 +28,23 @@ using std::floor;
using std::max;
using std::min;
namespace {
int const nohue = -1;
int hexstrToInt(string const & str)
{
int val = 0;
istringstream is(str);
is >> std::setbase(16) >> val;
return val;
}
} // namespace anon
bool getRGBColor(LColor::color col,
unsigned int & r, unsigned int & g, unsigned int & b)
{
@ -52,6 +67,29 @@ bool getRGBColor(LColor::color col,
}
string const X11hexname(RGBColor const & col)
{
ostringstream ostr;
ostr << '#' << std::setbase(16) << std::setfill('0')
<< setw(2) << col.r
<< setw(2) << col.g
<< setw(2) << col.b;
return STRCONV(ostr.str());
}
RGBColor::RGBColor(string const & x11hexname)
: r(0), g(0), b(0)
{
support::Assert(x11hexname.size() == 7 && x11hexname[0] == '#');
r = hexstrToInt(x11hexname.substr(1,2));
g = hexstrToInt(x11hexname.substr(3,2));
b = hexstrToInt(x11hexname.substr(5,2));
}
RGBColor::RGBColor(HSVColor const & hsv)
{
double h = hsv.h;

View File

@ -27,6 +27,8 @@ bool getRGBColor(LColor::color col,
unsigned int & r, unsigned int & g, unsigned int & b);
struct RGBColor;
/// returns a string of form #rrggbb, given an RGBColor struct
string const X11hexname(RGBColor const & col);
struct HSVColor {
double h;
@ -46,6 +48,8 @@ struct RGBColor {
RGBColor(unsigned int red, unsigned int green, unsigned int blue)
: r(red), g(green), b(blue) {}
RGBColor(HSVColor const &);
/// \param x11hexname is of the form "#ffa071"
RGBColor(string const & x11hexname);
};
struct NamedColor : public RGBColor {

View File

@ -91,17 +91,6 @@ pair<string,string> parseFontName(string const & name)
}
string const X11hexname(RGBColor const & col)
{
ostringstream ostr;
ostr << '#' << std::setbase(16) << setfill('0')
<< setw(2) << col.r
<< setw(2) << col.g
<< setw(2) << col.b;
return STRCONV(ostr.str());
}
#if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
bool const scalableTabfolders = false;