37218ebef0795bc5c839022a267211746a25e902
[universe.git] / simple_window.h
1
2 // Written and (C) by Francois Fleuret
3 // Contact <francois.fleuret@idiap.ch> for comments & bug reports
4
5 #ifndef SIMPLE_WINDOW_H
6 #define SIMPLE_WINDOW_H
7
8 #include <iostream>
9 #include <fstream>
10
11 using namespace std;
12
13 #include <X11/Xlib.h>
14 #include <X11/Xutil.h>
15
16 class SimpleEvent {
17 public:
18
19   enum {
20     NO_EVENT,
21     UNDEFINED,
22     MOUSE_CLICK_PRESS, MOUSE_CLICK_RELEASE,
23     MOUSE_MOTION,
24     KEY_PRESS, KEY_RELEASE
25   } type;
26
27   int x, y, button;
28   char key[32]; // This is the max length for the pressed key name ('a', 'Alt_L', etc.)
29   SimpleEvent();
30 };
31
32 class SimpleWindow {
33   Display *_display;
34   Window _window;
35   Pixmap _pixmap;
36   GC _gc;
37
38 protected:
39   int _red_mask, _green_mask, _blue_mask;
40   int _red_shift, _green_shift, _blue_shift;
41   int _width, _height;
42
43 public:
44   SimpleWindow(const char *name, int x, int y, int w, int h);
45   virtual ~SimpleWindow();
46
47   virtual int width();
48   virtual int height();
49
50   virtual void map();
51   virtual void unmap();
52   virtual void color(float red, float green, float blue);
53   virtual void draw_point(int x, int y);
54   virtual void draw_line(int x1, int y1, int x2, int y2);
55   virtual void draw_circle(int x, int y, int r);
56   virtual void draw_text(const char *s, int x, int y);
57   virtual void fill_rectangle(int x, int y, int w, int h);
58   virtual void fill_polygon(int nb, int *x, int *y);
59   virtual void show();
60   virtual void fill();
61
62   virtual int file_descriptor();
63   virtual SimpleEvent event();
64 };
65
66 #endif