Rebuild autotool system
[construo.git] / x11_display.hxx
blob4270f4b8c9347234364900ab4c0a2a9280bada33
1 // $Id: x11_display.hxx,v 1.25 2003/07/28 21:03:22 grumbel Exp $
2 //
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef HEADER_X11_DISPLAY_HXX
21 #define HEADER_X11_DISPLAY_HXX
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
26 #ifdef HAVE_LIBXXF86VM
27 # include <X11/extensions/xf86vmode.h>
28 #endif
30 #include "cursors.hxx"
31 #include "math.hxx"
32 #include "root_graphic_context.hxx"
33 #include "input_context.hxx"
35 #define X11_FULLSCREEN_MODE true
36 #define X11_WINDOW_MODE false
38 struct FlipRect
40 int x1;
41 int y1;
42 int x2;
43 int y2;
46 /** X11Display driver */
47 class X11Display : public RootGraphicContext,
48 public InputContext
50 private:
51 Cursor cursor_scroll;
52 Pixmap cursor_scroll_pix;
53 Pixmap cursor_scroll_mask;
55 Cursor cursor_zoom;
56 Pixmap cursor_zoom_pix;
57 Pixmap cursor_zoom_mask;
59 Cursor cursor_insert;
60 Pixmap cursor_insert_pix;
61 Pixmap cursor_insert_mask;
63 Cursor cursor_select;
64 Pixmap cursor_select_pix;
65 Pixmap cursor_select_mask;
67 Cursor cursor_collider;
68 Pixmap cursor_collider_pix;
69 Pixmap cursor_collider_mask;
71 bool doublebuffer;
72 #ifdef HAVE_LIBXXF86VM
73 XF86VidModeModeLine orig_modeline;
74 #endif
75 int orig_viewport_x;
76 int orig_viewport_y;
77 int orig_dotclock;
79 int width;
80 int height;
81 Display* display;
82 Window window;
83 Colormap colormap;
84 Drawable drawable;
85 GC gc;
87 bool shift_pressed;
88 int mouse_x;
89 int mouse_y;
91 /** Color Depth of the Display */
92 int depth;
94 /** true if display is in fullscreen mode, false for window mode */
95 bool fullscreen;
97 std::vector<FlipRect> flip_rects;
98 std::vector<FlipRect> last_flip_rects;
100 /** Save the current visual mode for later restoration after leaving
101 fullscreen */
102 void save_mode();
103 public:
104 X11Display (int w, int h, bool fullscreen_);
105 virtual ~X11Display ();
107 // Graphic Context stuff
108 void draw_lines (std::vector<Line>& lines, Color color, int wide = 0);
109 void draw_line(float x1, float y1, float x2, float y2, Color color, int wide = 0);
110 void draw_rect(float x1, float y1, float x2, float y2, Color color);
111 void draw_fill_rect(float x1, float y1, float x2, float y2, Color color);
112 void draw_circle(float x, float y, float r, Color color);
113 void draw_circles(std::vector<Circle>& circles, Color color);
115 void draw_fill_circle(float x, float y, float r, Color color);
116 void draw_string(float x, float y, const std::string& str, Color color);
117 void draw_string_centered(float x, float y, const std::string& str, Color color);
119 int get_width () { return width; }
120 int get_height () { return height; }
122 void toggle_fullscreen();
124 void clear ();
126 /** Flip the double buffered display */
127 void flip ();
129 void enter_fullscreen();
130 void leave_fullscreen();
132 /** perform the real flip, only flip marked reagions */
133 void real_flip ();
135 void flip (int x1, int y1, int x2, int y2);
137 // Input Context stuff
138 int get_mouse_x ();
139 int get_mouse_y ();
141 bool get_key (int key);
143 /** Waits for events to come in, blocks until new events are available */
144 void wait_for_events_blocking ();
146 void wait_for_events ();
148 void run();
150 void set_clip_rect (int x1_, int y1_, int x2_, int y2_);
152 unsigned int get_color_value(const Color& color);
153 XColor get_xcolor(const Color& color);
155 void set_cursor_real(CursorType cursor);
156 private:
157 bool read_event ();
158 void send_button_press (int i);
159 void send_button_release (int i);
160 void send_load_or_save(int n);
162 X11Display (const X11Display&);
163 X11Display& operator= (const X11Display&);
166 #endif
168 /* EOF */