mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-20 23:07:43 +00:00
Refactor xforms' colour handling code.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6107 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
5dc9643188
commit
26d5907fbc
@ -1,3 +1,17 @@
|
|||||||
|
2003-02-11 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* xforms_helpers.[Ch] (fl_getmcolor): new function; a wrapper for the
|
||||||
|
xforms routine that accepts unsigned ints.
|
||||||
|
|
||||||
|
* Color.[Ch] (getRGBColor): factorise code into one place.
|
||||||
|
|
||||||
|
* FormPreferences.[Ch] (X11hexname: not a class member. Move to
|
||||||
|
namespace anon.
|
||||||
|
|
||||||
|
* FormPreferences.C: use fl_getmcolor and getRGBColor.
|
||||||
|
* lyx_gui.C: use getRGBColor.
|
||||||
|
* xformsImage.C: use getRGBColor.
|
||||||
|
|
||||||
2003-02-11 Angus Leeming <leeming@lyx.org>
|
2003-02-11 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* bmtable.c: whitespace and indentation consistent with the other
|
* bmtable.c: whitespace and indentation consistent with the other
|
||||||
|
@ -32,6 +32,29 @@ int const nohue = -1;
|
|||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
|
bool getRGBColor(LColor::color col,
|
||||||
|
unsigned int & r, unsigned int & g, unsigned int & b)
|
||||||
|
{
|
||||||
|
string const name = lcolor.getX11Name(col);
|
||||||
|
Display * const display = fl_get_display();
|
||||||
|
Colormap const cmap = fl_state[fl_get_vclass()].colormap;
|
||||||
|
XColor xcol, ccol;
|
||||||
|
|
||||||
|
if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
|
||||||
|
r = 0;
|
||||||
|
g = 0;
|
||||||
|
b = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = xcol.red / 256;
|
||||||
|
g = xcol.green / 256;
|
||||||
|
b = xcol.blue / 256;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
RGBColor::RGBColor(HSVColor const & hsv)
|
RGBColor::RGBColor(HSVColor const & hsv)
|
||||||
{
|
{
|
||||||
double h = hsv.h;
|
double h = hsv.h;
|
||||||
|
@ -22,6 +22,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "LString.h"
|
#include "LString.h"
|
||||||
|
#include "LColor.h"
|
||||||
|
|
||||||
|
/** Given col, fills r, g, b in the range 0-255.
|
||||||
|
The function returns true if successful.
|
||||||
|
It returns false on failure and sets r, g, b to 0. */
|
||||||
|
bool getRGBColor(LColor::color col,
|
||||||
|
unsigned int & r, unsigned int & g, unsigned int & b);
|
||||||
|
|
||||||
struct RGBColor;
|
struct RGBColor;
|
||||||
|
|
||||||
@ -36,11 +43,11 @@ struct HSVColor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct RGBColor {
|
struct RGBColor {
|
||||||
int r;
|
unsigned int r;
|
||||||
int g;
|
unsigned int g;
|
||||||
int b;
|
unsigned int b;
|
||||||
RGBColor() : r(0), g(0), b(0) {}
|
RGBColor() : r(0), g(0), b(0) {}
|
||||||
RGBColor(int red, int green, 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 &);
|
||||||
};
|
};
|
||||||
|
@ -89,6 +89,18 @@ 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());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
@ -635,7 +647,7 @@ void FormPreferences::Colors::InputHSV()
|
|||||||
fl_redraw_object(dialog_->button_color);
|
fl_redraw_object(dialog_->button_color);
|
||||||
|
|
||||||
col = HSVColor(hue, 1.0, 1.0);
|
col = HSVColor(hue, 1.0, 1.0);
|
||||||
col.r = max(col.r, 0);
|
col.r = max(col.r, 0u);
|
||||||
fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
|
fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
|
||||||
fl_redraw_object(dialog_->dial_hue);
|
fl_redraw_object(dialog_->dial_hue);
|
||||||
|
|
||||||
@ -755,16 +767,13 @@ void FormPreferences::Colors::LoadBrowserLyX()
|
|||||||
|| lc == LColor::inherit
|
|| lc == LColor::inherit
|
||||||
|| lc == LColor::ignore) continue;
|
|| lc == LColor::ignore) continue;
|
||||||
|
|
||||||
string const name = lcolor.getX11Name(lc);
|
RGBColor col;
|
||||||
Display * display = fl_get_display();;
|
bool const success = getRGBColor(lc, col.r, col.g, col.b);
|
||||||
Colormap const colormap = fl_state[fl_get_vclass()].colormap;
|
if (!success) {
|
||||||
XColor xcol, ccol;
|
|
||||||
|
|
||||||
if (XLookupColor(display, colormap, name.c_str(), &xcol, &ccol)
|
|
||||||
== 0) {
|
|
||||||
lyxerr << "FormPreferences::Colors::LoadBrowserLyX:\n"
|
lyxerr << "FormPreferences::Colors::LoadBrowserLyX:\n"
|
||||||
<< "LColor " << lcolor.getLyXName(lc)
|
<< "LColor " << lcolor.getLyXName(lc)
|
||||||
<< ": X can't find color \"" << name
|
<< ": X can't find color \""
|
||||||
|
<< lcolor.getX11Name(lc)
|
||||||
<< "\". Set to \"black\"!" << endl;
|
<< "\". Set to \"black\"!" << endl;
|
||||||
|
|
||||||
string const arg = lcolor.getLyXName(lc) + " black";
|
string const arg = lcolor.getLyXName(lc) + " black";
|
||||||
@ -772,16 +781,6 @@ void FormPreferences::Colors::LoadBrowserLyX()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// X has found the color. Now find the "appropriate" X11 name
|
|
||||||
// for this color.
|
|
||||||
|
|
||||||
// Note that X stores the RGB values in the range 0 - 65535
|
|
||||||
// whilst we require them in the range 0 - 255.
|
|
||||||
RGBColor col;
|
|
||||||
col.r = xcol.red / 256;
|
|
||||||
col.g = xcol.green / 256;
|
|
||||||
col.b = xcol.blue / 256;
|
|
||||||
|
|
||||||
// Create a valid X11 name of the form "#rrggbb" and change the
|
// Create a valid X11 name of the form "#rrggbb" and change the
|
||||||
// LColor X11name to this. Don't want to trigger a redraw,
|
// LColor X11name to this. Don't want to trigger a redraw,
|
||||||
// as we're just changing the name not the RGB values.
|
// as we're just changing the name not the RGB values.
|
||||||
@ -878,7 +877,7 @@ void FormPreferences::Colors::SwitchColorSpace() const
|
|||||||
fl_set_slider_value(dialog_->slider_value, hsv.v);
|
fl_set_slider_value(dialog_->slider_value, hsv.v);
|
||||||
|
|
||||||
col = HSVColor(hsv.h, 1.0, 1.0);
|
col = HSVColor(hsv.h, 1.0, 1.0);
|
||||||
col.r = max(col.r, 0);
|
col.r = max(col.r, 0u);
|
||||||
fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
|
fl_mapcolor(GUI_COLOR_HUE_DIAL, col.r, col.g, col.b);
|
||||||
fl_redraw_object(dialog_->dial_hue);
|
fl_redraw_object(dialog_->dial_hue);
|
||||||
|
|
||||||
@ -916,18 +915,6 @@ void FormPreferences::Colors::SwitchColorSpace() const
|
|||||||
fl_unfreeze_form(dialog_->form);
|
fl_unfreeze_form(dialog_->form);
|
||||||
}
|
}
|
||||||
|
|
||||||
string const FormPreferences::Colors::X11hexname(RGBColor const & col) const
|
|
||||||
{
|
|
||||||
ostringstream ostr;
|
|
||||||
|
|
||||||
ostr << '#' << std::setbase(16) << setfill('0')
|
|
||||||
<< setw(2) << col.r
|
|
||||||
<< setw(2) << col.g
|
|
||||||
<< setw(2) << col.b;
|
|
||||||
|
|
||||||
return STRCONV(ostr.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FormPreferences::Converters::Converters(FormPreferences & p)
|
FormPreferences::Converters::Converters(FormPreferences & p)
|
||||||
: parent_(p)
|
: parent_(p)
|
||||||
|
@ -129,8 +129,6 @@ private:
|
|||||||
void Modify();
|
void Modify();
|
||||||
///
|
///
|
||||||
void SwitchColorSpace() const;
|
void SwitchColorSpace() const;
|
||||||
///
|
|
||||||
string const X11hexname(RGBColor const &) const;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
FormPreferences & parent_;
|
FormPreferences & parent_;
|
||||||
|
@ -325,26 +325,20 @@ FuncStatus lyx_gui::getStatus(FuncRequest const & /*ev*/)
|
|||||||
|
|
||||||
string const lyx_gui::hexname(LColor::color col)
|
string const lyx_gui::hexname(LColor::color col)
|
||||||
{
|
{
|
||||||
string const name = lcolor.getX11Name(col);
|
unsigned int r, g, b;
|
||||||
Display * const display = fl_get_display();
|
bool const success = getRGBColor(col, r, g, b);
|
||||||
Colormap const cmap = fl_state[fl_get_vclass()].colormap;
|
if (!success) {
|
||||||
XColor xcol, ccol;
|
lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
|
||||||
|
|
||||||
if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) {
|
|
||||||
lyxerr << "X can't find color \""
|
|
||||||
<< lcolor.getLyXName(col)
|
|
||||||
<< '"' << endl;
|
<< '"' << endl;
|
||||||
return string();
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
|
|
||||||
// Note that X stores the RGB values in the range 0 - 65535
|
|
||||||
// whilst we require them in the range 0 - 255.
|
|
||||||
os << setbase(16) << setfill('0')
|
os << setbase(16) << setfill('0')
|
||||||
<< setw(2) << (xcol.red / 256)
|
<< setw(2) << r
|
||||||
<< setw(2) << (xcol.green / 256)
|
<< setw(2) << g
|
||||||
<< setw(2) << (xcol.blue / 256);
|
<< setw(2) << b;
|
||||||
|
|
||||||
return STRCONV(os.str());
|
return STRCONV(os.str());
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "xformsImage.h"
|
#include "xformsImage.h"
|
||||||
#include "graphics/GraphicsParams.h"
|
#include "graphics/GraphicsParams.h"
|
||||||
#include "LColor.h"
|
#include "Color.h"
|
||||||
#include "converter.h" // formats
|
#include "converter.h" // formats
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "support/LAssert.h"
|
#include "support/LAssert.h"
|
||||||
@ -454,24 +454,14 @@ void init_graphics()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int packedcolor(LColor::color c)
|
unsigned int packedcolor(LColor::color col)
|
||||||
{
|
{
|
||||||
string const x11color = lcolor.getX11Name(c);
|
unsigned int r, g, b;
|
||||||
|
bool const success = getRGBColor(col, r, g, b);
|
||||||
Display * display = fl_get_display();
|
if (!success)
|
||||||
Colormap cmap = fl_state[fl_get_vclass()].colormap;
|
// Set to black on failure
|
||||||
XColor xcol;
|
|
||||||
XColor ccol;
|
|
||||||
if (XLookupColor(display, cmap, x11color.c_str(), &xcol, &ccol) == 0)
|
|
||||||
// Unable to parse x11color.
|
|
||||||
return FL_PACK(255,255,255);
|
return FL_PACK(255,255,255);
|
||||||
|
|
||||||
// Note that X stores the RGB values in the range 0 - 65535
|
|
||||||
// whilst we require them in the range 0 - 255.
|
|
||||||
unsigned int const r = xcol.red / 256;
|
|
||||||
unsigned int const g = xcol.green / 256;
|
|
||||||
unsigned int const b = xcol.blue / 256;
|
|
||||||
|
|
||||||
return FL_PACK(r, g, b);
|
return FL_PACK(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,19 @@ bool isActive(FL_OBJECT * ob)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// A wrapper for the xforms routine, but this one accepts uint args
|
||||||
|
unsigned long fl_getmcolor(int i,
|
||||||
|
unsigned int * r, unsigned int * g, unsigned int * b)
|
||||||
|
{
|
||||||
|
int r2, g2, b2;
|
||||||
|
unsigned long ret_val = ::fl_getmcolor(i, &r2, &g2, &b2);
|
||||||
|
*r = r2;
|
||||||
|
*g = g2;
|
||||||
|
*b = b2;
|
||||||
|
return ret_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set an FL_OBJECT to activated or deactivated
|
// Set an FL_OBJECT to activated or deactivated
|
||||||
void setEnabled(FL_OBJECT * ob, bool enable)
|
void setEnabled(FL_OBJECT * ob, bool enable)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
|
|
||||||
class LyXLength;
|
class LyXLength;
|
||||||
|
|
||||||
|
// A wrapper for the xforms routine, but this one accepts uint args
|
||||||
|
unsigned long fl_getmcolor(int i, unsigned int * r, unsigned int * g,
|
||||||
|
unsigned int * b);
|
||||||
|
|
||||||
// what we always need for lengths
|
// what we always need for lengths
|
||||||
string const choice_Length_All =
|
string const choice_Length_All =
|
||||||
"cm|mm|in|text%%|col%%|page%%|line%%|ex|em|pt|sp|bp|dd|pc|cc|mu";
|
"cm|mm|in|text%%|col%%|page%%|line%%|ex|em|pt|sp|bp|dd|pc|cc|mu";
|
||||||
|
Loading…
Reference in New Issue
Block a user