00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef HEADER_X11_DISPLAY_HXX
00021 #define HEADER_X11_DISPLAY_HXX
00022
00023 #include <X11/Xlib.h>
00024 #include <X11/Xutil.h>
00025
00026 #ifdef HAVE_LIBXXF86VM
00027 # include <X11/extensions/xf86vmode.h>
00028 #endif
00029
00030 #include "math.hxx"
00031 #include "graphic_context.hxx"
00032 #include "input_context.hxx"
00033
00034 #define X11_FULLSCREEN_MODE true
00035 #define X11_WINDOW_MODE false
00036
00037 struct FlipRect
00038 {
00039 int x1;
00040 int y1;
00041 int x2;
00042 int y2;
00043 };
00044
00046 class X11Display : public GraphicContext,
00047 public InputContext
00048 {
00049 private:
00050 bool doublebuffer;
00051 #ifdef HAVE_LIBXXF86VM
00052 XF86VidModeModeLine orig_modeline;
00053 #endif
00054 int orig_viewport_x;
00055 int orig_viewport_y;
00056 int orig_dotclock;
00057
00058 int width;
00059 int height;
00060 Display* display;
00061 Window window;
00062 Colormap colormap;
00063 Drawable drawable;
00064 GC gc;
00065
00066 bool shift_pressed;
00067 int mouse_x;
00068 int mouse_y;
00069
00071 bool fullscreen;
00072
00073 std::vector<FlipRect> flip_rects;
00074 std::vector<FlipRect> last_flip_rects;
00075 public:
00076 X11Display (int w, int h, bool fullscreen_);
00077 virtual ~X11Display ();
00078
00079
00080 void draw_lines (std::vector<Line>& lines, Color color, int wide = 0);
00081 void draw_line(float x1, float y1, float x2, float y2, Color color, int wide = 0);
00082 void draw_rect(float x1, float y1, float x2, float y2, Color color);
00083 void draw_fill_rect(float x1, float y1, float x2, float y2, Color color);
00084 void draw_circle(float x, float y, float r, Color color);
00085 void draw_circles(std::vector<Circle>& circles, Color color);
00086
00087 void draw_fill_circle(float x, float y, float r, Color color);
00088 void draw_string(float x, float y, const std::string& str, Color color);
00089 void draw_string_centered(float x, float y, const std::string& str, Color color);
00090
00091 int get_width () { return width; }
00092 int get_height () { return height; }
00093
00094 void set_fullscreen (bool fullscreen);
00095 void restore_mode ();
00096
00097 void clear ();
00098
00100 void flip ();
00101
00103 void real_flip ();
00104
00105 void flip (int x1, int y1, int x2, int y2);
00106
00107
00108 int get_mouse_x ();
00109 int get_mouse_y ();
00110
00111 bool get_key (int key);
00112
00114 void wait_for_events_blocking ();
00115
00116 void wait_for_events ();
00117
00118 void run();
00119
00120 void set_clip_rect (int x1_, int y1_, int x2_, int y2_);
00121
00122 unsigned int get_color_value(Color& color);
00123 private:
00124 bool read_event ();
00125 void send_button_press (int i);
00126 void send_button_release (int i);
00127 void send_load_or_save(int n);
00128
00129 X11Display (const X11Display&);
00130 X11Display& operator= (const X11Display&);
00131 };
00132
00133 #endif
00134
00135