CVD 0.8
cvd/videodisplay.h
00001 /*                       
00002     This file is part of the CVD Library.
00003 
00004     Copyright (C) 2005 The Authors
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library; if not, write to the Free Software
00018     Foundation, Inc., 
00019     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 */
00021 //-*- c++ -*-
00023 //                                                                  //
00024 //   VideoDisplay - Cheap and cheeful way of creating a GL X        //
00025 //                  display                                         //
00026 //                                                                  //
00027 //   Tom Drummong & Paul Smith   2002                               //
00028 //                                                                  //
00030 
00031 #ifndef __VIDEODISPLAY_H
00032 #define __VIDEODISPLAY_H
00033 
00034 #include <string>
00035 #include <assert.h>
00036 #include <math.h>
00037 
00038 #include <X11/Xlib.h>   //X11
00039 #include <GL/glx.h>  // OpenGL (X extensions)
00040 #include <GL/gl.h>   // OpenGL proper
00041 
00042 #include <cvd/exceptions.h>
00043 #include <cvd/image_ref.h>
00044 
00045 namespace CVD {
00046 
00047     namespace Exceptions
00048     {
00051         namespace VideoDisplay
00052         {
00055             struct All: public CVD::Exceptions::All{};
00056 
00059             struct InitialisationError: public All
00060             {
00061                 InitialisationError(std::string w); 
00062             };
00063 
00066             struct RuntimeError: public All
00067             {
00068                 RuntimeError(std::string w); 
00069             };
00070         }
00071     }
00072 
00073 
00076     extern int defAttr[];
00077 
00087     class VideoDisplay
00088     {
00089         public:
00097             VideoDisplay(double left, double top, double right, double bottom, double scale=1, int* visualAttr = defAttr);
00098 
00099 
00100 
00105             VideoDisplay(ImageRef size, double scale=1, int* visualAttr = defAttr);
00106             
00108             ~VideoDisplay();
00109 
00112             void set_title(const std::string& s);
00113             
00115             int get_fd() {return ConnectionNumber(my_display);}
00118             void select_events(long event_mask);
00122             void get_event(XEvent* event);
00126             void locate_display_pointer(int& x, int& y);
00130             void locate_video_pointer(double& x, double& y);
00132             void flush();
00134             int pending();
00135 
00142             void set_zoom(double left, double top, double right, double bottom, double scale);
00147             void zoom_in(double cx, double cy, double factor = 2);
00152             void zoom_out(double cx, double cy, double factor = 2)
00153             {assert(factor != 0.0); zoom_in(cx, cy, 1/factor);}
00155             void zoom_reset()
00156             {set_zoom(my_orig_left, my_orig_top, my_orig_right, my_orig_bottom, my_orig_scale);}
00157 
00159             double video_width() const {return fabs(my_right - my_left);}
00161             double video_height() const {return fabs(my_bottom - my_top);}
00162 
00168             void display_to_video(int dx, int dy, double& vx, double& vy);
00174             void video_to_display(double dx, double dy, int& vx, int & vy);
00175 
00179             void make_current();
00180 
00183       void swap_buffers();
00185       Display* display() {return my_display;}
00187             Window window() {return my_window;}
00188 
00189         private:
00190             double my_left;
00191             double my_top;
00192             double my_right;
00193             double my_bottom;
00194             bool my_positive_right;
00195             bool my_positive_down;
00196             double my_scale;
00197             double my_orig_left;
00198             double my_orig_top;
00199             double my_orig_right;
00200             double my_orig_bottom;
00201             double my_orig_scale;
00202             Display *my_display;
00203             XVisualInfo* my_visual;
00204             GLXContext my_glx_context;
00205             Colormap my_cmap;
00206             Window my_window;
00207 
00208             VideoDisplay( VideoDisplay& copyof );
00209             int operator = ( VideoDisplay& copyof );
00210 
00211 
00212             void init(double, double, double, double, double, int* visualAttr);
00213     };
00214    
00215 } // CVD
00216 
00217 #endif