From f8568ce1dbcd222ec4ec6a35a32fcc4a80142c89 Mon Sep 17 00:00:00 2001 From: Martin Vermeer Date: Wed, 6 Aug 2003 18:42:58 +0000 Subject: [PATCH] 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 --- src/frontends/xforms/ChangeLog | 6 ++++ src/frontends/xforms/Color.C | 38 ++++++++++++++++++++++++++ src/frontends/xforms/Color.h | 4 +++ src/frontends/xforms/FormPreferences.C | 11 -------- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index d13919d84e..2314f9c0e7 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,9 @@ +2003-08-06 Martin Vermeer + * 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 * Makefile.am (BUILT_SOURCES): add lyx_forms.h and lyx_xpm.h diff --git a/src/frontends/xforms/Color.C b/src/frontends/xforms/Color.C index 30ee8e00a9..a34806b360 100644 --- a/src/frontends/xforms/Color.C +++ b/src/frontends/xforms/Color.C @@ -14,7 +14,12 @@ #include "Color.h" #include // max #include // floor +#include #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; diff --git a/src/frontends/xforms/Color.h b/src/frontends/xforms/Color.h index 95186eabe7..d92dfe0ac3 100644 --- a/src/frontends/xforms/Color.h +++ b/src/frontends/xforms/Color.h @@ -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 { diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 1859eadc7d..016498431a 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -91,17 +91,6 @@ pair 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; -- 2.39.2