mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-14 06:57:01 +00:00
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:
parent
6820291d13
commit
f8568ce1db
@ -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>
|
2003-08-04 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||||
|
|
||||||
* Makefile.am (BUILT_SOURCES): add lyx_forms.h and lyx_xpm.h
|
* Makefile.am (BUILT_SOURCES): add lyx_forms.h and lyx_xpm.h
|
||||||
|
@ -14,7 +14,12 @@
|
|||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
#include <algorithm> // max
|
#include <algorithm> // max
|
||||||
#include <cmath> // floor
|
#include <cmath> // floor
|
||||||
|
#include <iomanip>
|
||||||
#include "lyx_forms.h"
|
#include "lyx_forms.h"
|
||||||
|
#include "Lsstream.h"
|
||||||
|
#include "support/LAssert.h"
|
||||||
|
|
||||||
|
namespace support = lyx::support;
|
||||||
|
|
||||||
#ifndef CXX_GLOBAL_CSTD
|
#ifndef CXX_GLOBAL_CSTD
|
||||||
using std::floor;
|
using std::floor;
|
||||||
@ -23,13 +28,23 @@ using std::floor;
|
|||||||
using std::max;
|
using std::max;
|
||||||
using std::min;
|
using std::min;
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
int const nohue = -1;
|
int const nohue = -1;
|
||||||
|
|
||||||
|
int hexstrToInt(string const & str)
|
||||||
|
{
|
||||||
|
int val = 0;
|
||||||
|
istringstream is(str);
|
||||||
|
is >> std::setbase(16) >> val;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool getRGBColor(LColor::color col,
|
bool getRGBColor(LColor::color col,
|
||||||
unsigned int & r, unsigned int & g, unsigned int & b)
|
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)
|
RGBColor::RGBColor(HSVColor const & hsv)
|
||||||
{
|
{
|
||||||
double h = hsv.h;
|
double h = hsv.h;
|
||||||
|
@ -27,6 +27,8 @@ bool getRGBColor(LColor::color col,
|
|||||||
unsigned int & r, unsigned int & g, unsigned int & b);
|
unsigned int & r, unsigned int & g, unsigned int & b);
|
||||||
|
|
||||||
struct RGBColor;
|
struct RGBColor;
|
||||||
|
/// returns a string of form #rrggbb, given an RGBColor struct
|
||||||
|
string const X11hexname(RGBColor const & col);
|
||||||
|
|
||||||
struct HSVColor {
|
struct HSVColor {
|
||||||
double h;
|
double h;
|
||||||
@ -46,6 +48,8 @@ struct RGBColor {
|
|||||||
RGBColor(unsigned int red, unsigned int green, unsigned int blue)
|
RGBColor(unsigned int red, unsigned int green, unsigned int blue)
|
||||||
: r(red), g(green), b(blue) {}
|
: r(red), g(green), b(blue) {}
|
||||||
RGBColor(HSVColor const &);
|
RGBColor(HSVColor const &);
|
||||||
|
/// \param x11hexname is of the form "#ffa071"
|
||||||
|
RGBColor(string const & x11hexname);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NamedColor : public RGBColor {
|
struct NamedColor : public RGBColor {
|
||||||
|
@ -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)
|
#if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL < 2)
|
||||||
bool const scalableTabfolders = false;
|
bool const scalableTabfolders = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user