f42e931c8d9f4da583e5a6417c062b89d999a427
[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 // $Id: simple_window.h,v 1.2 2007-04-24 21:22:52 fleuret Exp $
17
18 #ifndef SIMPLE_WINDOW_H
19 #define SIMPLE_WINDOW_H
20
21 #include <iostream>
22 #include <fstream>
23
24 using namespace std;
25
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28
29 class SimpleEvent {
30 public:
31
32   enum {
33     NO_EVENT,
34     UNDEFINED,
35     MOUSE_CLICK_PRESS, MOUSE_CLICK_RELEASE,
36     MOUSE_MOTION,
37     KEY_PRESS, KEY_RELEASE
38   } type;
39
40   int x, y, button;
41   char key[32]; // This is the max length for the pressed key name ('a', 'Alt_L', etc.)
42   SimpleEvent();
43 };
44
45 class SimpleWindow {
46   Display *_display;
47   Window _window;
48   Pixmap _pixmap;
49   GC _gc;
50
51 protected:
52   int _red_mask, _green_mask, _blue_mask;
53   int _red_shift, _green_shift, _blue_shift;
54   int _width, _height;
55
56 public:
57   SimpleWindow(char *name, int x, int y, int w, int h);
58   virtual ~SimpleWindow();
59
60   virtual int width();
61   virtual int height();
62
63   virtual void map();
64   virtual void unmap();
65   virtual void color(float red, float green, float blue);
66   virtual void draw_point(int x, int y);
67   virtual void draw_line(int x1, int y1, int x2, int y2);
68   virtual void draw_circle(int x, int y, int r);
69   virtual void draw_text(char *s, int x, int y);
70   virtual void fill_rectangle(int x, int y, int w, int h);
71   virtual void fill_polygon(int nb, int *x, int *y);
72   virtual void show();
73   virtual void fill();
74
75   virtual int file_descriptor();
76   virtual SimpleEvent event();
77 };
78
79 #endif