17 #ifndef COLOURLINESPEC_H_ 18 #define COLOURLINESPEC_H_ 26 #include <cairo/cairo.h> 40 static const char *shortColoursPrivate[];
41 static const char *X11ColoursPrivate[];
49 template <
int dummy>
const char *
StandardColours<dummy>::X11ColoursPrivate[]= {(
char *)
"blue", (
char *)
"green", (
char *)
"red", (
char *)
"cyan", (
char *)
"magenta", (
char *)
"yellow", (
char *)
"white", (
char *)
"black", (
char *)
"orange", (
char *)
"gray"};
66 #if GTK_MAJOR_VERSION==3 82 setColourAndLinesOrPoints(
"b1");
91 if (strlen(clsChar)==0)
92 setColourAndLinesOrPoints(
"b1");
94 setColourAndLinesOrPoints(clsChar);
106 return !sizeNotSpecified;
118 return !colourNotSpecified;
125 sizeNotSpecified=
false;
132 sizeNotSpecified=
false;
146 #if GTK_MAJOR_VERSION>2 147 void setColour(GdkRGBA c){
151 colourNotSpecified=
false;
159 colourNotSpecified=
false;
160 #if GTK_MAJOR_VERSION>2 161 gdk_rgba_parse(&colour, c);
163 gdk_color_parse(c,&colour);
170 #if GTK_MAJOR_VERSION>2 171 GdkRGBA getColour(
void)
const {
182 #if GTK_MAJOR_VERSION>2 183 return gdk_rgba_to_string(&colour);
185 return gdk_color_to_string(&colour);
195 sizeNotSpecified=
true;
196 colourNotSpecified=
true;
199 string clsStr(clsChar);
200 #if GTK_MAJOR_VERSION>2 201 gdk_rgba_parse(&colour,
"blue");
203 gdk_color_parse(
"blue",&colour);
206 if (shortColours.size()==X11Colours.size() && X11Colours.size()!=0){
207 for (
unsigned int i=0; i<X11Colours.size(); i++)
208 if (clsStr.find(shortColours[i].c_str())!=string::npos) {
209 #if GTK_MAJOR_VERSION>2 210 gdk_rgba_parse(&colour, X11Colours[i].c_str());
212 gdk_color_parse(X11Colours[i].c_str(),&colour);
214 colourNotSpecified=
false;
218 for (
int i=0; i<colourCntPrivate; i++)
219 if (clsStr.find(shortColoursPrivate[i])!=string::npos) {
220 #if GTK_MAJOR_VERSION>2 221 gdk_rgba_parse(&colour, X11ColoursPrivate[i]);
223 gdk_color_parse(X11ColoursPrivate[i],&colour);
225 colourNotSpecified=
false;
231 if (clsStr.find(
':')!=string::npos) {
237 unsigned int minC=clsStr.find_first_of(
"0123456789");
239 if ((minC!=string::npos) & (minC<=clsStr.size())) {
240 int maxC=clsStr.find_last_of(
"0123456789");
241 size=atof(clsStr.substr(minC,maxC-minC+1).c_str());
242 sizeNotSpecified=
false;
249 setColourAndLinesOrPoints(
"b1");
251 setColourAndLinesOrPoints(c.c_str());
257 setColourAndLinesOrPoints(
"b1");
259 setColourAndLinesOrPoints(c);
267 return shortColoursPrivate;
275 return shortColoursPrivate[i%colourCntPrivate];
285 float maxVal = (float)(1<<8*
sizeof(colour.red));
286 cairo_set_source_rgb(cr, colour.red/maxVal, colour.green/maxVal, colour.blue/maxVal);
287 cairo_set_line_width(cr, size);
298 float maxVal = (float)(1<<8*
sizeof(colour.red));
299 cairo_set_source_rgba(cr, colour.red/maxVal, colour.green/maxVal, colour.blue/maxVal, alpha);
300 cairo_set_line_width(cr, size);
306 #endif // COLOURLINESPEC_H_ bool wasColourSpecified(void)
gchar * getColourString(void)
void setColourAndLinesOrPoints(const char *clsChar)
interprets the octave style line/colour spec. By default implements lines specify points using the ':...
ColourLineSpec(const char *clsChar)
use a octave like string to define the line/points or colour Speciy whether to use points or lines an...
float getSize(void) const
ColourLineSpec(void)
default constructor with blue colour Initiates the defaul blue line type of size 1 ...
static const char ** getColourLabels(void)
bool wasSizeSpecified(void)
void setColour(const char *c)
void setColour(GdkColor c)
ColourLineSpec & operator>>(cairo_t *cr)
ColourLineSpec setRGBA(cairo_t *cr, double alpha)
vector< string > shortColours
User specified colours in character notation :
ColourLineSpec & operator=(const char *c)
bool colourNotSpecified
Set to true if the colour was not specified ... i.e. "12" for size 12 with no colour.
static const char * getColour(uint i)
float size
The size of the line or point.
GdkColor colour
The colour holder.
static int colourCntPrivate
The number of colours defined in the following char ** variables.
ColourLineSpec & operator=(string &c)
bool sizeNotSpecified
Set to true if the size was not specified ... i.e. "r" for red with no size.
vector< string > X11Colours
User specified colour strings :
bool linePlot
The indication for lines or points plotting.
encapsulates a method to specify colour and line or point plotting This class tries to encapsulate oc...