libcvd
videodisplay.h
1 //-*- c++ -*-
3 // //
4 // VideoDisplay - Cheap and cheeful way of creating a GL X //
5 // display //
6 // //
7 // Tom Drummong & Paul Smith 2002 //
8 // //
10 
11 #ifndef __VIDEODISPLAY_H
12 #define __VIDEODISPLAY_H
13 
14 #include <assert.h>
15 #include <math.h>
16 #include <string>
17 
18 #include <GL/gl.h> // OpenGL proper
19 #include <GL/glx.h> // OpenGL (X extensions)
20 #include <X11/Xlib.h> //X11
21 
22 #include <cvd/exceptions.h>
23 #include <cvd/image_ref.h>
24 
25 namespace CVD
26 {
27 
28 namespace Exceptions
29 {
32  namespace VideoDisplay
33  {
36  struct All : public CVD::Exceptions::All
37  {
38  using CVD::Exceptions::All::All;
39  };
40 
43  struct InitialisationError : public All
44  {
45  InitialisationError(std::string w);
46  };
47 
50  struct RuntimeError : public All
51  {
52  RuntimeError(std::string w);
53  };
54  }
55 }
56 
59 extern int defAttr[];
60 
71 {
72  struct DoNotMapStruct
73  {
74  DoNotMapStruct() { }
75  };
76 
77  public:
78  static const DoNotMapStruct DoNotMap;
79 
88  VideoDisplay(double left, double top, double right, double bottom, double scale = 1, int* visualAttr = defAttr, bool map = true);
89 
94  VideoDisplay(ImageRef size, const DoNotMapStruct&, int* visualAttr = defAttr);
95 
100  VideoDisplay(ImageRef size, double scale = 1, int* visualAttr = defAttr);
101 
103  ~VideoDisplay();
104 
107  void set_title(const std::string& s);
108 
110  int get_fd() { return ConnectionNumber(my_display); }
113  void select_events(long event_mask);
117  void get_event(XEvent* event);
121  void locate_display_pointer(int& x, int& y);
125  void locate_video_pointer(double& x, double& y);
127  void flush();
129  int pending();
130 
137  void set_zoom(double left, double top, double right, double bottom, double scale);
142  void zoom_in(double cx, double cy, double factor = 2);
147  void zoom_out(double cx, double cy, double factor = 2)
148  {
149  assert(factor != 0.0);
150  zoom_in(cx, cy, 1 / factor);
151  }
153  void zoom_reset()
154  {
155  set_zoom(my_orig_left, my_orig_top, my_orig_right, my_orig_bottom, my_orig_scale);
156  }
157 
159  double video_width() const { return fabs(my_right - my_left); }
161  double video_height() const { return fabs(my_bottom - my_top); }
162 
168  void display_to_video(int dx, int dy, double& vx, double& vy);
174  void video_to_display(double dx, double dy, int& vx, int& vy);
175 
179  void make_current();
180 
183  void swap_buffers();
185  Display* display() { return my_display; }
187  Window window() { return my_window; }
188 
189  private:
190  double my_left;
191  double my_top;
192  double my_right;
193  double my_bottom;
194  bool my_positive_right;
195  bool my_positive_down;
196  double my_scale;
197  double my_orig_left;
198  double my_orig_top;
199  double my_orig_right;
200  double my_orig_bottom;
201  double my_orig_scale;
202  Display* my_display;
203  XVisualInfo* my_visual;
204  GLXContext my_glx_context;
205  Colormap my_cmap;
206  Window my_window;
207 
208  VideoDisplay(VideoDisplay& copyof);
209  int operator=(VideoDisplay& copyof);
210 
211  void init(double, double, double, double, double, int* visualAttr, bool);
212 };
213 
214 } // CVD
215 
216 #endif
All classes and functions are within the CVD namespace.
Definition: argb.h:6
void zoom_reset()
Reset the image mapping to that when the VideoDisplay was created.
Definition: videodisplay.h:153
double video_width() const
What is the width of the local GL co-ordinates displayed?
Definition: videodisplay.h:159
An exception occurred during initialisation.
Definition: videodisplay.h:43
A cheap and cheerful GL display window using X and the GLX library.
Definition: videodisplay.h:70
void zoom_out(double cx, double cy, double factor=2)
Change the image mapping to zoom out around the specified point.
Definition: videodisplay.h:147
Display * display()
What is my display?
Definition: videodisplay.h:185
Base class for all CVD exceptions.
Definition: exceptions.h:15
Base class for all CVD::VideoDisplay exceptions.
Definition: videodisplay.h:36
Window window()
Which is my window?
Definition: videodisplay.h:187
An exception occurred during run-time.
Definition: videodisplay.h:50
int get_fd()
Returns the connection number for this display.
Definition: videodisplay.h:110
Definition: image_ref.h:29
double video_height() const
What is the height of the local GL co-ordinates displayed?
Definition: videodisplay.h:161