First checkin, AXE release 0.2
[AXE.git] / src / Xclass.h
1 /*
2  *  C++ X Windows class library
3  */
4
5 #include <X11/Xlib.h>
6
7 class drawable;
8 class window;
9
10 class point
11 {
12    short  _x, _y;
13
14 public:
15
16    point()   { _x = 0; _y = 0; }
17
18    point(int x, int y)   { _x = x; _y = y; }
19
20    short x()   { return _x; }
21
22    short y()   { return _y; }
23
24 };
25
26
27 class line
28 {
29    int   npoints;
30    int   mode;
31    point *points;
32
33    friend drawable;
34
35    void drawline(drawable &d);
36
37 public:
38
39    line()
40    {
41       npoints = 0;
42       mode = CoordModeOrigin;
43    }
44
45    line(short x1, short y1, short x2, short y2)
46    {
47       npoints = 2;
48       mode = CoordModeOrigin;
49       points = new point[2];
50       points[0] = point(x1, y1);
51       points[1] = point(x2, y2);
52    }
53
54    line(point p1, point p2)
55    {
56       npoints = 2;
57       mode = CoordModeOrigin;
58       points = new point[2];
59       points[0] = p1;
60       points[1] = p2;
61    }
62
63    ~line()
64    {
65       if (npoints != 0)
66          delete [] points;
67    }
68
69    point &operator[] (int index);
70
71 };
72
73 class rectangle
74 {
75    short          x, y;
76    unsigned short width, height;
77
78    friend drawable;
79
80 public:
81
82    rectangle()
83    {
84       x      = 0;
85       y      = 0;
86       width  = 0;
87       height = 0;
88    }
89
90    rectangle(int _x, int _y, unsigned int _w, unsigned int _h)
91    {
92       x      = _x;
93       y      = _y;
94       width  = _w;
95       height = _h;
96    }
97
98    //  Define a rectangle by its diagonal
99
100    rectangle(point p1, point p2);
101
102 //   friend window &operator<< (window &d, rectangle &r);
103 //   friend pixmap &operator<< (pixmap &d, rectangle &r);
104 };
105
106 class box
107 {
108    short          x, y;
109    unsigned short width, height;
110
111 public:
112
113    box()
114    {
115       x      = 0;
116       y      = 0;
117       width  = 0;
118       height = 0;
119    }
120
121    box(int _x, int _y, unsigned int _w, unsigned int _h)
122    {
123       x      = _x;
124       y      = _y;
125       width  = _w;
126       height = _h;
127    }
128
129    //  Define a box by its diagonal
130
131    box(point p1, point p2);
132
133 //   friend window &operator<< (window &d, box &b);
134 //   friend pixmap &operator<< (pixmap &d, box &b);
135 };
136
137 class text
138 {
139    short x, y;
140    String txt;
141
142    friend drawable;
143
144 public:
145
146    text()
147    {
148       x = 0;
149       y = 0;
150    }
151
152    text(int _x, int _y, String str)
153    {
154       x = _x;
155       y = _y;
156       txt = str;
157    }
158
159    text(point p, String s)
160    {
161       x = p.x();
162       y = p.y();
163       txt = s;
164    }
165
166 //   friend window &operator<< (window &d, text &t);
167 //   friend pixmap &operator<< (pixmap &d, text &t);
168 };
169
170 class drawable
171 {
172    friend window;
173
174    XID   id;   // The window or pixmap id in the server.
175    GC    gc;   // The graphics context.
176
177 public:
178
179    XID  Id()
180    {
181       return id;
182    }
183
184    GC  Gc()
185    {
186       return gc;
187    }
188
189    void foreground(unsigned long color)
190    {
191       XSetForeground(stddpy.Dpy(), gc, color);
192    }
193
194    void background(unsigned long color)
195    {
196       XSetBackground(stddpy.Dpy(), gc, color);
197    }
198
199    drawable &operator<< (point &p);
200    drawable &operator<< (line &l);
201
202    drawable &operator<< (rectangle &r);
203    drawable &operator<< (text &t);
204 };
205
206 class window : public drawable
207 {
208 public:
209    window(int x=0, int y=0, unsigned int w=100, unsigned int h=100);
210    window(window &, int x=0, int y=0, unsigned int w=100, unsigned int h=100);
211    ~window();
212
213    //   Mapping and unmapping
214
215    void operator++()
216    {
217       XMapWindow(stddpy.Dpy(), id);
218    }
219    
220    void operator--()
221    {
222       XUnmapWindow(stddpy.Dpy(), id);
223    }
224    
225 };
226
227 class pixmap : public drawable
228 {
229 };
230