-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalette.hh
44 lines (39 loc) · 1009 Bytes
/
Palette.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef PALETTE_H
#define PALETTE_H
#include <X11/Xlib.h>
#include <vector>
#include <cstdio>
#define NAMEDCOLOR(A) XAllocNamedColor(display, scr_cmap,#A, &A, &A);
class Palette
{
public:
XColor red,green,blue,yellow,dark_slate_gray;
std::vector<XColor> grays;
// cat /usr/share/X11/rgb.txt
Palette( Display* display, int screen_number) {
Colormap scr_cmap = DefaultColormap(display,screen_number);
NAMEDCOLOR(blue);
NAMEDCOLOR(red);
NAMEDCOLOR(green);
NAMEDCOLOR(yellow);
XAllocNamedColor(display, scr_cmap, "dark slate gray", &dark_slate_gray, &dark_slate_gray);
for(int i=0;i<=100;i++)
{
XColor g;
char tmp[10];
sprintf(tmp,"gray%d",i);
XAllocNamedColor(display, scr_cmap,tmp,&g,&g);
grays.push_back(g);
}
}
XColor& gray(int i) {
if(i<0) i=0;
if(i>(int)this->grays.size()) i=(int)this->grays.size()-1;
return this->grays[i];
}
XColor& gray(double f) {
return this->gray((int)(f*this->grays.size()));
}
};
#undef NAMEDCOLOR
#endif