GTK+ IOStream  Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ColourLineSpec.H
Go to the documentation of this file.
1 #ifndef COLOURLINESPEC_H_
2 #define COLOURLINESPEC_H_
3 
4 //#include <gtk/gtk.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <string>
8 #include <gtk/gtk.h>
9 
10 using namespace std;
11 
28  static int colourCnt;
29  static const char *shortColours[];
30  static const char *X11Colours[];
33  int size;
34  GdkColor colour;
35 public:
36  bool linePlot;
37 
42  setColourAndLinesOrPoints("b1");
43  }
44 
50  ColourLineSpec(const char* clsChar) {
51  if (strlen(clsChar)==0)
52  setColourAndLinesOrPoints("b1");
53  else
54  setColourAndLinesOrPoints(clsChar);
55  }
56 
65  bool wasSizeSpecified(void){
66  return !sizeNotSpecified;
67  }
68 
77  bool wasColourSpecified(void){
78  return !colourNotSpecified;
79  }
80 
84  void setSize(int s){
85  sizeNotSpecified=false;
86  size=s;
87  }
88 
92  int getSize(void){
93  return size;
94  }
95 
99  void setColour(GdkColor c){
100  colourNotSpecified=false;
101  colour=c;
102  }
103 
107  void setColour(const char* c){
108  colourNotSpecified=false;
109  gdk_color_parse(c,&colour);
110  }
111 
115  GdkColor getColour(void){
116  return colour;
117  }
118 
122  gchar *getColourString(void){
123  return gdk_color_to_string(&colour);
124  }
125 
131  void setColourAndLinesOrPoints(const char* clsChar) {
132  //colourCnt=sizeof(shortColours)/sizeof(char*);
133  //cout<<"colourCnt = "<<colourCnt<<endl;
134  sizeNotSpecified=true;
135  colourNotSpecified=true;
136 
137  linePlot=1;
138  string clsStr(clsChar);
139  gdk_color_parse("blue",&colour);
140  //cout<<"ColourLineSpec::setColourAndLinesOrPoints colour = "<<"blue"<<endl;
141  for (int i=0; i<colourCnt; i++)
142  if (clsStr.find(shortColours[i])!=string::npos) {
143  gdk_color_parse(X11Colours[i],&colour);
144  colourNotSpecified=false; // indicate that the colour was specified
145  // cout<<"ColourLineSpec::setColourAndLinesOrPoints colour = "<<X11Colours[i]<<endl;
146  break;
147  }
148 
149  if (clsStr.find(':')!=string::npos) { // check for the points plotting style
150  linePlot=false;
151  //cout<<"ColourLineSpec::setColourAndLinesOrPoints linePlot = "<<linePlot<<endl;
152  } //else cout<<"ColourLineSpec::setColourAndLinesOrPoints linePlot = "<<linePlot<<endl;
153 
154  size=1;
155  unsigned int minC=clsStr.find_first_of("0123456789");
156  //cout<<"clsStr : "<<clsStr<<endl;
157  if ((minC!=string::npos) & (minC<=clsStr.size())) {
158  int maxC=clsStr.find_last_of("0123456789");
159  size=atoi(clsStr.substr(minC,maxC-minC+1).c_str());
160  sizeNotSpecified=false; // indicate that the size was specified
161  }
162  //cout<<"ColourLineSpec::setColourAndLinesOrPoints size = "<<size<<endl;
163  }
164 
166  if (c.size()==0)
167  setColourAndLinesOrPoints("b1");
168  else
169  setColourAndLinesOrPoints(c.c_str());
170  return *this;
171  }
172 
174  if (strlen(c)==0)
175  setColourAndLinesOrPoints("b1");
176  else
177  setColourAndLinesOrPoints(c);
178  return *this;
179  }
180 
181 
182  static const char ** getColourLabels(void){
183  return shortColours;
184  }
185 };
186 
187 #endif // COLOURLINESPEC_H_