Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Consoles/XVWindowX.h

00001 // *** BEGIN_XVISION2_COPYRIGHT_NOTICE ***
00002 // *** END_XVISION2_COPYRIGHT_NOTICE ***
00003 
00004 #ifndef _XVWINDOWX_H_
00005 #define _XVWINDOWX_H_
00006 /*
00007  * $Author: xvis $
00008  * $Log: XVWindowX.h,v $
00009  * Revision 1.11  2001/03/12 05:43:59  xvis
00010  * XClearWindow function added to clear the window content
00011  *
00012  * Darius
00013  *
00014  * Revision 1.10  2001/03/08 18:56:28  xvis
00015  * Restored the original version of getXDrawable now - fixing the
00016  * flickering problem.
00017  *
00018  * Revision 1.9  2001/03/08 17:58:42  xvis
00019  * The bugs I was chasing yesterday were due to opening 2 separate
00020  * connections to the X server and then trying to manipulate the same
00021  * objects through two separate connections.  One of the consequences of
00022  * trying to use 2 separate X-related libraries.  The fix was to add this
00023  * method to XVWindowX<...> and modify the graphics library.
00024  *
00025  *   Display* getXDisplay(void)
00026  *
00027  * Revision 1.8  2001/03/07 19:30:58  xvis
00028  * Added a method to support the Haskell Hackers (lets you see the XWindow (or backing buffer) inside the XVWindow
00029  *
00030  * Revision 1.7  2001/03/05 11:08:54  xvis
00031  * SLANG::3.5.1.  Added setCOPY and setXOR functions to XVDrawable.
00032  *
00033  * Revision 1.6  2001/03/01 10:10:12  xvis
00034  * SLANG::3.1.1.  removed templates from XVInteractive and XVDrawable.
00035  *
00036  * Revision 1.5  2001/03/01 09:57:34  xvis
00037  * SLANG::3.1.1.  Added an include for XVimageRGB
00038  *
00039  * Revision 1.4  2001/02/21 15:02:55  xvis
00040  * SLANG::2.21.01.  Added a currentImage member to XVWindow
00041  *
00042  * Revision 1.3  2001/02/21 12:32:28  xvis
00043  * SLANG::2.21.01.  Added virtuals to functions in XVWindowX
00044  *
00045  * Revision 1.2  2001/02/21 12:19:39  xvis
00046  * SLANG::2.21.01.  added using statements to XVDrawWindowX and XVInteractWindowX.
00047  *
00048  * Revision 1.1  2001/02/21 12:07:50  xvis
00049  * SLANG::2.21.01.  Changed structure of Consoles stuff.  XVWindow is now an abstract window for all windows.
00050  *
00051  * Revision 1.16  2001/02/05 07:15:30  xvis
00052  * SLANG::2.5.01.  Added functionality for displaying and interactive selection.
00053  *
00054  * Revision 1.15  2001/02/02 04:45:39  xvis
00055  * SLANG::2.1.01.  Fixed double buffering problem, but now double buffering may
00056  * not work on RedHat 6.1.  (but at least it works on both 6.2 & 7!)  Replaced
00057  * the HAVE_LIBXDPMS with HAVE_LIBXEXT.  the Xdpms library apparently is wrapped
00058  * in the Xext library now.
00059  *
00060  * Revision 1.14  2000/10/31 20:18:54  xvis
00061  * Depth problem in XVWindow solved ???
00062  *
00063  * Revision 1.13  2000/10/24 22:27:01  xvis
00064  * *** empty log message ***
00065  *
00066  * Revision 1.12  2000/10/24 22:22:13  xvis
00067  * *** empty log message ***
00068  *
00069  * Revision 1.11  2000/09/13 15:04:16  xvis
00070  * slang.  Darius (and me) added checks in CopyImage & CopySubImage that wait for the XServer to say its ready to receive stuff to display in the window.  Used XNextEvent and Expose...9.13.00.
00071  *
00072  * Revision 1.10  2000/09/11 15:37:56  xvis
00073  * slang.  added millisecond sleep in map so that image is displayed. 9.11.00.
00074  *
00075  * Revision 1.9  2000/08/31 18:25:50  xvis
00076  * increased maximum possible size of a window. SVM
00077  *
00078  * Revision 1.8  2000/07/27 22:01:18  xvis
00079  * *** empty log message ***
00080  *
00081  * Revision 1.7  2000/07/27 18:26:15  xvis
00082  * fixed for multiple definitions of XVPixmap. SVM
00083  *
00084  * Revision 1.6  2000/07/27 15:22:01  xvis
00085  * shared_memory only active on local display, but remote displays
00086  * possible now
00087  * clean-up in double-buffering
00088  *
00089  * Revision 1.5  2000/07/12 13:54:57  hager
00090  * Fixed a number of bugs in Images etc. etc. etc
00091  *
00092  * Revision 1.4  2000/06/26 19:40:37  hager
00093  * Broke images into several ssubclasses and did various modifications to
00094  * make that work.
00095  *
00096  * Revision 1.3  2000/06/22 16:03:34  xvis
00097  * iterators added.
00098  *
00099  * Revision 1.9  2000/05/22 16:39:59  cips
00100  * clean-up in buffer locking. Pointer-handle still not included.
00101  * Warnings in XVWindow removed.
00102  *
00103  * Darius
00104  *
00105  * Revision 1.8  2000/04/06 15:18:50  cips
00106  * my version of the locking
00107  *
00108  * Revision 1.7  2000/03/14 03:50:46  cips
00109  * Greg's bugfixes in image conversion (uups, these were not only a few)
00110  *
00111  * Revision 1.6  2000/03/10 00:16:38  cips
00112  * Pixmap structure added. TODO: GC managment for operations.
00113  *
00114  * Revision 1.5  2000/02/29 02:41:47  cips
00115  * *** empty log message ***
00116  *
00117  * Revision 1.4  2000/02/15 23:45:35  cips
00118  * *** empty log message ***
00119  *
00120  * Revision 1.3  2000/02/11 19:41:33  cips
00121  * Real game as pong2
00122  *
00123  * Revision 1.2  2000/02/05 00:20:26  cips
00124  * Sun compatible now
00125  *
00126  * Revision 1.1.1.1  2000/02/04 18:27:50  cips
00127  *
00128  *
00129  */
00130 
00131 #include <X11/Xlib.h>
00132 #include <X11/Xatom.h>
00133 #include <X11/Xutil.h>
00134 #ifdef HAVE_LIBXEXT
00135 #include <X11/extensions/Xdbe.h>
00136 #endif
00137 #include <X11/Intrinsic.h>
00138 #include <X11/StringDefs.h>
00139 #ifdef HAVE_LIBXEXT
00140 #include <X11/extensions/XShm.h>
00141 #include <sys/shm.h>
00142 #endif
00143 #include <config.h>
00144 #include <sys/time.h>
00145 #include <unistd.h>
00146 #include <iostream.h>
00147 
00148 #include <XVImageRGB.h>
00149 #include <XVWindow.h>
00150 
00151 #define  RESIZED        (1<<3)
00152 #define  BUTTON_PRESSED (1<<2)
00153 #define  RIGHT_BUTTON   (1<<1)
00154 #define  LEFT_BUTTON     (1<<0)
00155 
00156 #define B_LEFT           1
00157 #define B_RIGHT               3
00158 
00159 #define  DRAW_COLORS     16
00160 #define  BW_MAP          0
00161 #define  DRAW_MAP   1
00162 #define REMAP
00163 
00164 #define  MAX_FONT_NUM    5
00165 
00166 
00167 template <class T>
00168 class XVWindowX: public virtual XVWindow<T>
00169 {
00170  protected:
00171    Display          *dpy;
00172    Window      window;
00173    const T               **shared_fields;
00174    XImage         **shm_images;
00175    XImage      *def_image;
00176 #ifdef HAVE_LIBXEXT
00177    XShmSegmentInfo      *def_shminfo;
00178 #endif
00179    int                 buffer_count;
00180    int              bitmap_pad;    // screen depth
00181    u_short          flip;
00182 
00183    XGCValues        xgcv;
00184    unsigned long    bw_color[256];
00185    unsigned long    draw_color[DRAW_COLORS+2];
00186    GC               gc_window[DRAW_COLORS];
00187    GC               gc_clear;
00188    void             get_colors(void);
00189    u_short          back_flag;     // double buffering avail?
00190    u_short          shared_memory;
00191    int              num_fonts;
00192    Font             *font;
00193 #ifdef HAVE_LIBXEXT
00194    XdbeBackBuffer       back_buffer;
00195    XdbeSwapInfo          swap_info;
00196 #else
00197    int              back_buffer;
00198 #endif
00199    
00200    bool                 exposeEvent;
00201    
00202   public:
00203    virtual void          map(void){if(window)
00204                      {XMapWindow(dpy,window);XFlush(dpy);}};
00205    virtual void          unmap(void){if(window)
00206                               {XUnmapWindow(dpy,window);XFlush(dpy);}};
00207    virtual void          resize(XVImageBase<T> *image);
00208    int              check_events(int *ret_field);
00209 
00210    int              get_font(char *name);
00211    int              print_string(char *string,int x, int y,
00212                                        int col_index=0,
00213                            int font_index=0);
00214    virtual void          swap_buffers(void)
00215 #ifdef HAVE_LIBXEXT 
00216                     {if(back_flag)
00217                         XdbeSwapBuffers(dpy,&swap_info,1);};
00218 #else     
00219                     {};
00220 #endif
00221    virtual void          setImages(XVImageBase<T> *frames,int count);
00222    virtual void     ClearWindow(void) {XClearWindow(dpy,window);};
00223    virtual void             CopyImage(int which,u_short flip=0);
00224    virtual void          CopySubImage(XVImageBase<T> *image);
00225 
00226    virtual void         flush(void){XSync(dpy,0);};
00227    void                 expose(void) { exposeEvent = true; };
00228    const T          **get_shared_fields(void) const {
00229                        return (const T**)shared_fields;};
00230                XVWindowX(XVImageBase<T> *image,int posx=0,int
00231                     posy=0, char * title = NULL, int event_mask=0,
00232                     char *display=NULL,int num_buf=2,
00233                     int double_buf=0);
00234                ~XVWindowX(void);
00235    XVImageBase<T> * getDisplayedImage() { return currentImage; };               
00236    // This is a hook for use by the Haskell people to let them use
00237    // their existing graphics library on this window.
00238    // The idea is that they copy an image over, do some graphics
00239    // on this drawable and then swap buffers.
00240    Display*         getXDisplay(void) { return dpy; };
00241    Drawable         getXDrawable(void) { 
00242 #ifdef HAVE_LIBXEXT
00243      return back_flag ? back_buffer : window; 
00244 #else
00245      return window;
00246 #endif
00247    };
00248 
00249 };
00250 
00251 
00252 static char *color_names[]=
00253 {
00254   "yellow","tourquise1","green","pink","brown","orange",
00255   "violet","red","dark green","aquamarine",
00256   "purple","pink","yellow","blue","peru","burlywood"
00257 };
00258 
00259 #include <XVDrawable.h>
00260 #include <XVInteractive.h>
00261 
00262 #include <pthread.h>
00263 #include <map>
00264 #include <string>
00265 #include <X11/cursorfont.h>
00266 
00267 class CannotAllocColorException : public XVException { 
00268  public:
00269   CannotAllocColorException() : XVException("CannotAllocColorException: Could Not Allocate the specified color") {}
00270   CannotAllocColorException(char * err) : XVException(err){}
00271 };
00272 
00273 template <class PIXEL>
00274 class XVDrawWindowX : public XVDrawable, public XVWindowX<PIXEL> {
00275   
00276   typedef map<DrawColor, GC>::iterator MI;
00277   
00278  protected:
00279   
00280   map<DrawColor, GC> GCmap;
00281   int function;
00282 
00283   void setFunction(int);
00284   
00285  public:
00286   
00287   XVDrawWindowX(XVImageRGB<PIXEL > * im, int px = 0, int py = 0,
00288           char * title = NULL,
00289           int event_mask = 0, char * disp = NULL, 
00290           int num_buf = 2, int double_buf = 1, int function = GXcopy);
00291   
00292   void setXOR(){ function = GXxor; setFunction(function); }
00293   void setCOPY(){ function = GXcopy; setFunction(function); }
00294   
00295   inline virtual DrawColor addColor(DrawColor);
00296   
00297   inline virtual bool drawPoint(int x, int y, DrawColor c = DEFAULT_COLOR);
00298   inline virtual bool drawLine(int x1, int y1, int x2, int y2, DrawColor c = DEFAULT_COLOR);
00299   inline virtual bool drawRectangle(int x, int y, int w, int h, DrawColor c = DEFAULT_COLOR);
00300   inline virtual bool drawEllipse(int x, int y, int w, int h, DrawColor c = DEFAULT_COLOR);
00301   inline virtual bool fillRectangle(int x, int y, int w, int h, DrawColor c = DEFAULT_COLOR);
00302   inline virtual bool fillEllipse(int x, int y, int w, int h, DrawColor c = DEFAULT_COLOR);
00303   inline virtual bool drawString(int x, int y, char * str, int length, DrawColor c = DEFAULT_COLOR);
00304 
00305   using XVWindowX<PIXEL>::map;
00306   using XVWindowX<PIXEL>::unmap;
00307   using XVWindowX<PIXEL>::resize;
00308   using XVWindowX<PIXEL>::setImages;
00309   using XVWindowX<PIXEL>::CopyImage;
00310   using XVWindowX<PIXEL>::CopySubImage;
00311   using XVWindowX<PIXEL>::swap_buffers;
00312   using XVWindowX<PIXEL>::flush;
00313 };
00314 
00315 template <class PIXEL>
00316 class XVInteractWindowX : public XVInteractive, public XVDrawWindowX<PIXEL> {
00317 
00318  protected:
00319 
00320   Cursor crossHair, arrow;
00321 
00322   inline void grabPointer();
00323   inline void unGrabPointer();
00324 
00325  public:
00326 
00327   XVInteractWindowX(XVImageRGB<PIXEL > * im, int px = 0, int py = 0, 
00328               char * title = NULL,
00329              int event_mask = 0, char * disp = NULL,
00330              int num_buf = 2, int double_buf = 1, int function = GXxor);
00331 
00332   inline virtual XVPosition selectPoint(DrawColor c = DEFAULT_COLOR);
00333   inline virtual void selectLine(XVPosition &, XVPosition &, DrawColor c = DEFAULT_COLOR);
00334   inline virtual XVImageGeneric selectRectangle(DrawColor c = DEFAULT_COLOR);
00335   inline virtual XVImageGeneric selectEllipse(DrawColor c = DEFAULT_COLOR);
00336 
00337   using XVWindowX<PIXEL>::map;
00338   using XVWindowX<PIXEL>::unmap;
00339   using XVWindowX<PIXEL>::resize;
00340   using XVWindowX<PIXEL>::setImages;
00341   using XVWindowX<PIXEL>::CopyImage;
00342   using XVWindowX<PIXEL>::CopySubImage;
00343   using XVWindowX<PIXEL>::swap_buffers;
00344   using XVWindowX<PIXEL>::flush;
00345 };
00346 
00347 #endif

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000