Back to index

plt-scheme  4.2.1
WindowDC.h
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: device context to draw drawables
00004  *          (windows and pixmaps, even if pixmaps are covered by wxMemoryDC)
00005  *
00006  * Authors: Markus Holzem and Julian Smart
00007  *
00008  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00009  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00010  * Copyright: (C) 1995, GNU (Markus)
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00025  * 02110-1301 USA.
00026  */
00027 
00028 #ifndef WindowDC_h
00029 #define WindowDC_h
00030 
00031 // wxWindowDC is applyable to ALL from wxWindow derived classes!
00032 // wxCanvasDC and wxPanelDC are aliases for compatibility
00033 #define wxCanvasDC wxWindowDC
00034 #define wxPanelDC  wxWindowDC
00035 
00036 #ifdef __GNUG__
00037 #pragma interface
00038 #endif
00039 
00040 class wxBitmap;
00041 class wxBrush;
00042 class wxColour;
00043 class wxColourMap;
00044 class wxFont;
00045 class wxIcon;
00046 class wxList;
00047 class wxPen;
00048 
00049 #ifdef USE_GL
00050 class wxGL;
00051 class wxGLConfig;
00052 #endif
00053 
00054 #ifdef Have_X_Types
00055 class wxWindowDC_Xinit : public gc {
00056 public:
00057     Display* dpy;           // display of drawable
00058     Screen* scn;            // screen of drawable
00059     Drawable drawable;             // init to 0 if drawable is not created
00060     wxWindow *owner;
00061 };
00062 class wxWindowDC_Xintern : public gc { // X GDI data
00063 public:
00064     GC           pen_gc, brush_gc, text_gc, bg_gc;
00065     Region       user_reg, expose_reg, current_reg;
00066     Display      *dpy;
00067     Screen       *scn;
00068     Drawable     drawable;
00069 #ifdef WX_USE_XRENDER
00070     long picture; /* If WX_USE_XFT, picture is actually an XftDraw* */
00071 #endif
00072 #ifdef WX_USE_CAIRO
00073     long cairo_dev;
00074     char reset_cairo_clip;
00075 #endif
00076     Window       draw_window;
00077     unsigned int width, height, depth;
00078     wxWindow     *owner;
00079 
00080 #ifdef USE_GL
00081     wxGL *wx_gl;
00082     wxGLConfig *gl_cfg;
00083 #endif
00084 
00085     /* Implement GetPixel */
00086     XImage *get_pixel_image_cache;
00087     int get_pixel_cache_pos;
00088     XColor *get_pixel_color_cache;
00089     short get_pixel_cache_full, set_a_pixel;
00090     Bool         is_window;
00091     int cache_dx, cache_dy;
00092 };
00093 // easier access to private data
00094 #define PEN_GC              (X->pen_gc)
00095 #define BRUSH_GC     (X->brush_gc)
00096 #define TEXT_GC             (X->text_gc)
00097 #define BG_GC        (X->bg_gc)
00098 #define USER_REG     (X->user_reg)
00099 #define EXPOSE_REG   (X->expose_reg)
00100 #define CURRENT_REG  (X->current_reg)
00101 #define DPY          (X->dpy)
00102 #define SCN          (X->scn)
00103 #define DRAWABLE     (X->drawable)
00104 #define DRAW_WINDOW  (X->draw_window)
00105 #define WIDTH        (X->width)
00106 #define HEIGHT              (X->height)
00107 #define DEPTH        (X->depth)
00108 #define CMAP            GETCOLORMAP(current_cmap)
00109 # ifdef WX_USE_XFT
00110 #  define XFTDRAW         ((XftDraw *)X->picture)
00111 #  define TO_PICTURE(x)   XftDrawPicture((XftDraw *)x)
00112 #  define PICTURE         TO_PICTURE(XFTDRAW)
00113 # else
00114 #  define TO_PICTURE(x)   ((Picture)x)
00115 #  define PICTURE         ((Picture)X->picture)
00116 # endif
00117 #define CAIRO_DEV       ((cairo_t *)X->cairo_dev)
00118 #else // not implementation but use!
00119 class wxWindowDC_Xinit;
00120 class wxWindowDC_Xintern;
00121 #endif
00122 
00123 class wxWindowDC : public wxDC {
00124 public:
00125   wxWindowDC(void);
00126   ~wxWindowDC(void);
00127 
00128   // virtual methods, declared in wxDC
00129   Bool  Blit(double xdest, double ydest, double w, double h, wxBitmap *bm,
00130             double xsrc, double ysrc, int rop=wxSOLID, wxColour *c=NULL, wxBitmap *mask=NULL);
00131   Bool  GCBlit(double xdest, double ydest, double w, double h, wxBitmap *bm,
00132               double xsrc, double ysrc, wxBitmap *mask=NULL);
00133   Bool  CanGetTextExtent(void) { return TRUE; }
00134   Bool  CanDrawBitmap(void) { return TRUE; }
00135   void  Clear(void);
00136   void  DrawArc(double x1, double y1, double x2, double y2, double xc, double yc);
00137   void  DrawEllipse(double x, double y, double w, double h);
00138   void  DrawLine(double x1, double y1, double x2, double y2);
00139   void  DrawLines(int n, wxPoint pts[], double xoff=0, double yoff=0);
00140   void  DrawPoint(double x, double y);
00141   void  DrawPolygon(int n, wxPoint pts[], double xoff=0, double yoff=0, int fill=wxODDEVEN_RULE);
00142   void  DrawRectangle(double x, double y, double w, double h);
00143   void  DrawRoundedRectangle(double x, double y, double w, double h, double radius=20);
00144   void  DrawPath(wxPath *p, double dx, double dy, int fill=wxODDEVEN_RULE);
00145 
00146   void  DrawText(char *text, double x, double y, Bool combine = FALSE, Bool use16 = FALSE, int dt = 0, double angle = 0.0);
00147   double GetCharHeight(void);
00148   double GetCharWidth(void);
00149   void  GetTextExtent(const char *s, double *w, double *h, double *descent = 0,
00150                     double *ext_leading = 0,     wxFont *font=NULL,
00151                     Bool combine=FALSE, Bool use16bit=FALSE, int dt=0,
00152                       int len=-1);
00153   void  SetBackground(wxColour *c);
00154   void  SetBrush(wxBrush *brush);
00155   void  ResetBrush(wxBrush *brush);
00156   void  SetClippingRect(double x, double y, double w, double h);
00157   void  SetClippingRegion(wxRegion*);
00158   wxRegion* GetClippingRegion();
00159   void  SetColourMap(wxColourMap *cmap);
00160   void  SetFont(wxFont *font);
00161   void  SetPen(wxPen *pen);
00162   void  ResetPen(wxPen *pen);
00163   void  SetTextBackground(wxColour *col);
00164   void  SetTextForeground(wxColour *col);
00165 
00166   // methods unique to wxWindowDC
00167   void  SetCanvasClipping(void);
00168 
00169   virtual void GetSize(double *w, double *h);
00170 
00171   void TryColour(wxColour *src, wxColour *dest);
00172 
00173   Bool GetPixel(double x, double y, wxColour *col);
00174 
00175   void BeginSetPixel(int mini, int near_i, int near_j);
00176   void EndSetPixel();
00177   void SetPixel(double x, double y, wxColour *col);
00178   
00179   Bool BeginSetPixelFast(int x, int y, int w, int h);
00180   void EndSetPixelFast();
00181   void SetPixelFast(int x, int y, int r, int g, int b);
00182 
00183   Bool BeginGetPixelFast(int x, int y, int w, int h);
00184   void EndGetPixelFast();
00185   void GetPixelFast(int x, int y, int *r, int *g, int *b);
00186 
00187   void FillPrivateColor(wxColour *c);
00188 
00189   virtual Bool GlyphAvailable(int c, wxFont *f = NULL);
00190 
00191   virtual Bool Ok(void);
00192 
00193   virtual int CacheFontMetricsKey();
00194 
00195 #ifdef WX_USE_XRENDER
00196   virtual void InitPicture();
00197   void InitPictureClip();
00198 #endif
00199 
00200 #ifdef USE_GL
00201   virtual wxGL *GetGL();
00202   void SetGLConfig(wxGLConfig *cfg);
00203 #endif
00204 
00205   void SetAntiAlias(int v);
00206 
00207 #ifdef WX_USE_CAIRO
00208   void InitCairoDev();
00209   void ReleaseCairoDev();
00210   Bool SetCairoPen();
00211   Bool SetCairoBrush();
00212 
00213   void SetAlpha(double d);
00214 
00215   Bool AlignSmoothing();
00216   double GetPenSmoothingOffset();
00217   double SmoothingXFormX(double x);
00218   double SmoothingXFormY(double y);
00219   double SmoothingXFormW(double w, double x);
00220   double SmoothingXFormH(double h, double y);
00221   double SmoothingXFormXB(double x);
00222   double SmoothingXFormYB(double y);
00223   double SmoothingXFormWL(double w, double x);
00224   double SmoothingXFormHL(double h, double y);
00225 #endif
00226 
00227 protected:
00228   friend class wxWindow;
00229   friend class wxPostScriptDC;
00230 
00231   char need_x_set_font;
00232 
00233   void  Initialize(wxWindowDC_Xinit* init);
00234   void  Destroy(void);
00235 
00236   virtual void FreeGetPixelCache(void);
00237 
00238   wxWindowDC_Xintern* X;
00239 };
00240 
00241 #ifdef WX_USE_XRENDER
00242 # ifdef Have_X_Types
00243 extern int wxXRenderHere(void);
00244 extern long wxMakePicture(Drawable d, int color); // returns Picture or XftDraw*
00245 extern void wxFreePicture(long);
00246 # endif
00247 #endif
00248 
00249 
00250 #ifdef USE_GL
00251 class wxGL : public wxObject {
00252 public:
00253   wxGL();
00254   virtual ~wxGL();
00255 
00256   int Ok();
00257 
00258   void Reset(wxGLConfig *_cfg, long d, Bool offscreen);
00259 
00260   long draw_to; /* really a Drawable */
00261   long GLctx; /* really a GLXContext */
00262   long glx_pm; /* really a GLXPixmap */
00263 
00264   void SwapBuffers(void);
00265   void ThisContextCurrent(void);
00266 };
00267 #endif
00268 
00269 #ifdef Have_X_Types
00270 void wxGetTextExtent(Display *dpy, double scale_x, double scale_y,
00271                    const char *orig_s, double *_w, double *_h, double *_descent,
00272                    double *_topspace, wxFont *font_to_use,
00273                    Bool combine, Bool isUnicode, int dt, int len);
00274 #endif
00275 
00276 #endif // WindowDC_hh