Cosmetics + started to add support for cairo drawing to eventually replace the X...
[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 #include <X11/XKBlib.h>
16
17 class SimpleEvent {
18 public:
19
20   enum {
21     NO_EVENT,
22     UNDEFINED,
23     MOUSE_CLICK_PRESS, MOUSE_CLICK_RELEASE,
24     MOUSE_MOTION,
25     KEY_PRESS, KEY_RELEASE
26   } type;
27
28   int x, y, button;
29   char key[32]; // This is the max length for the pressed key name ('a', 'Alt_L', etc.)
30   SimpleEvent();
31 };
32
33 class SimpleWindow {
34   Display *_display;
35   Window _window;
36   Pixmap _pixmap;
37   GC _gc;
38
39 protected:
40   int _red_mask, _green_mask, _blue_mask;
41   int _red_shift, _green_shift, _blue_shift;
42   int _width, _height;
43
44 public:
45   SimpleWindow(const char *name, int x, int y, int w, int h);
46   virtual ~SimpleWindow();
47
48   virtual int width();
49   virtual int height();
50
51   virtual void map();
52   virtual void unmap();
53   virtual void color(float red, float green, float blue);
54   virtual void draw_point(int x, int y);
55   virtual void draw_line(int x1, int y1, int x2, int y2);
56   virtual void draw_circle(int x, int y, int r);
57   virtual void draw_text(const char *s, int x, int y);
58   virtual void fill_rectangle(int x, int y, int w, int h);
59   virtual void fill_polygon(int nb, int *x, int *y);
60   virtual void show();
61   virtual void fill();
62
63   virtual int file_descriptor();
64   virtual SimpleEvent event();
65 };
66
67 #endif