3761fcd4b5cd7ec73833b138741470470f4a4742
[universe.git] / simple_window.h
1
2 ////////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or              //
4 // modify it under the terms of the GNU General Public License                //
5 // version 2 as published by the Free Software Foundation.                    //
6 //                                                                            //
7 // This program is distributed in the hope that it will be useful, but        //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of                 //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          //
10 // General Public License for more details.                                   //
11 //                                                                            //
12 // Written and (C) by François Fleuret                                        //
13 // Contact <francois.fleuret@epfl.ch> for comments & bug reports              //
14 ////////////////////////////////////////////////////////////////////////////////
15
16 #ifndef SIMPLE_WINDOW_H
17 #define SIMPLE_WINDOW_H
18
19 #include <iostream>
20 #include <fstream>
21
22 using namespace std;
23
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26
27 class SimpleEvent {
28 public:
29
30   enum {
31     NO_EVENT,
32     UNDEFINED,
33     MOUSE_CLICK_PRESS, MOUSE_CLICK_RELEASE,
34     MOUSE_MOTION,
35     KEY_PRESS, KEY_RELEASE
36   } type;
37
38   int x, y, button;
39   char key[32]; // This is the max length for the pressed key name ('a', 'Alt_L', etc.)
40   SimpleEvent();
41 };
42
43 class SimpleWindow {
44   Display *_display;
45   Window _window;
46   Pixmap _pixmap;
47   GC _gc;
48
49 protected:
50   int _red_mask, _green_mask, _blue_mask;
51   int _red_shift, _green_shift, _blue_shift;
52   int _width, _height;
53
54 public:
55   SimpleWindow(char *name, int x, int y, int w, int h);
56   virtual ~SimpleWindow();
57
58   virtual int width();
59   virtual int height();
60
61   virtual void map();
62   virtual void unmap();
63   virtual void color(float red, float green, float blue);
64   virtual void draw_point(int x, int y);
65   virtual void draw_line(int x1, int y1, int x2, int y2);
66   virtual void draw_circle(int x, int y, int r);
67   virtual void draw_text(char *s, int x, int y);
68   virtual void fill_rectangle(int x, int y, int w, int h);
69   virtual void fill_polygon(int nb, int *x, int *y);
70   virtual void show();
71   virtual void fill();
72
73   virtual int file_descriptor();
74   virtual SimpleEvent event();
75 };
76
77 #endif