00001
00002
00003
00004 #ifndef _XVWINDOWX_H_
00005 #define _XVWINDOWX_H_
00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 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;
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;
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
00237
00238
00239
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