Back to index

plt-scheme  4.2.1
DC.h
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: basic device context
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifndef DC_h
00028 #define DC_h
00029 
00030 #ifndef MZ_PRECISE_GC
00031 # ifdef __GNUG__
00032 # pragma interface
00033 # endif
00034 #endif
00035 
00036 /* for floor(): */
00037 #include <math.h>
00038 
00039 #ifdef USE_GL
00040 class wxGL;
00041 class wxGLConfig;
00042 #endif
00043 
00044 // wxPoint
00045 class wxPoint : public wxObject {
00046 public:
00047   inline wxPoint(void);
00048   inline wxPoint(double a, double b);
00049   double x, y;
00050 };
00051 
00052 inline wxPoint::wxPoint(void) 
00053 : wxObject(WXGC_NO_CLEANUP)
00054 { 
00055   x = y = 0.0;
00056 }
00057 
00058 inline wxPoint::wxPoint(double a, double b) 
00059 : wxObject(WXGC_NO_CLEANUP)
00060 {
00061   x = a;
00062   y = b;
00063 }
00064 
00065 class wxBitmap;
00066 class wxBrush;
00067 class wxCanvas;
00068 class wxColour;
00069 class wxColourMap;
00070 class wxFont;
00071 class wxList;
00072 class wxPen;
00073 class wxRegion;
00074 class wxPath;
00075 
00076 class wxDC : public wxObject {
00077 public:
00078     wxDC(void);
00079 
00080     // pure virtual methods, must be implemented for all DCs
00081     virtual Bool  Blit(double xdest, double ydest, double w, double h, wxBitmap *src,
00082                      double xsrc, double ysrc, int rop=wxSOLID, wxColour *c=NULL, wxBitmap *mask=NULL) = 0;
00083     virtual Bool  CanGetTextExtent(void) = 0;
00084     virtual Bool  CanDrawBitmap(void) = 0;
00085     virtual void  Clear(void) = 0;
00086     virtual void  DrawArc(double x, double y, double w, double h, double start, double end) = 0;
00087     virtual void  DrawEllipse(double x, double y, double w, double h) = 0;
00088     virtual void  DrawLine(double x1, double y1, double x2, double y2) = 0;
00089     virtual void  DrawLines(int n, wxPoint pts[],
00090                          double xoff=0, double yoff=0) = 0;
00091     virtual void  DrawLines(wxList *pts, double xoff=0, double yoff=0);
00092     virtual void  DrawPoint(double x, double y) = 0;
00093             void  DrawPoint(wxPoint *pt)  { DrawPoint(pt->x, pt->y); }
00094     virtual void  DrawPolygon(int n, wxPoint pts[], double xoff=0, double yoff=0,
00095                            int fill=wxODDEVEN_RULE) = 0;
00096     virtual void  DrawPolygon(wxList *pts, double xoff=0, double yoff=0,
00097                            int fill=wxODDEVEN_RULE);
00098     virtual void  DrawRectangle(double x, double y, double w, double h) = 0;
00099     virtual void  DrawRoundedRectangle(double x, double y, double w, double h,
00100                                    double radius=20) = 0;
00101     virtual void  DrawPath(wxPath *p, double dx, double dy, int fill=wxODDEVEN_RULE) = 0;
00102 
00103     virtual void  DrawText(char *text, double x, double y, Bool combine=FALSE,
00104                         Bool use16 = FALSE, int dt = 0, double angle = 0.0) = 0;
00105     virtual double GetCharHeight(void) = 0;
00106     virtual double GetCharWidth(void) = 0;
00107     virtual void  GetTextExtent(const char *s, double *w, double *h,
00108                             double *descent = 0, double *ext_leading = 0,
00109                             wxFont *font=NULL, 
00110                             Bool combine=FALSE, Bool use16bit=FALSE, int dt=0,
00111                                 int len = -1) = 0;
00112     virtual void  SetBackground(wxColour *c) = 0;
00113     virtual void  SetBrush(wxBrush *brush) = 0;
00114     virtual void  SetClippingRect(double x, double y, double w, double h) = 0;
00115     virtual void  SetClippingRegion(wxRegion *r) = 0;
00116     virtual wxRegion *GetClippingRegion() = 0;
00117     virtual void  SetColourMap(wxColourMap *cmap) = 0;
00118     virtual void  SetFont(wxFont *font) = 0;
00119     virtual void  SetPen(wxPen *pen) = 0;
00120     virtual void  SetTextBackground(wxColour *col) = 0;
00121     virtual void  SetTextForeground(wxColour *col) = 0;
00122 
00123     virtual void TryColour(wxColour *src, wxColour *dest) = 0;
00124 
00125     // only necessary for printing
00126     virtual Bool  StartDoc(char *WXUNUSED(message)) { return TRUE; }
00127     virtual void  EndDoc(void) {}
00128     virtual void  StartPage(void) {}
00129     virtual void  EndPage(void) {}
00130 
00131     // non virtual methods, same in all subclasses
00132     void AutoSetTools(Bool set_auto)
00133        { auto_setting = set_auto; }
00134     void BeginDrawing(void)
00135        {}
00136     virtual double DeviceToLogicalX(int x)
00137        { return XDEV2LOG(x); }
00138     virtual double DeviceToLogicalXRel(int x)
00139        { return XDEV2LOGREL(x); }
00140     virtual double UnscrolledDeviceToLogicalX(int x)
00141        { return XDEV2LOG(x); }
00142     virtual double DeviceToLogicalY(int y)
00143        { return YDEV2LOG(y); }
00144     virtual double DeviceToLogicalYRel(int y)
00145        { return YDEV2LOGREL(y); }
00146     virtual double UnscrolledDeviceToLogicalY(int y)
00147        { return YDEV2LOG(y); }
00148     void  DrawSpline(int n, wxPoint pts[]);
00149     void  DrawSpline(wxList *pts);
00150     virtual void DrawSpline(double x1,double y1, double x2,double y2, double x3,double y3);
00151     void  EndDrawing(void)
00152        {}
00153     wxColour *GetBackground(void);
00154     wxBrush *GetBrush(void)
00155        { return current_brush; }
00156     wxFont *GetFont(void)
00157        { return current_font; }
00158     int GetMapMode(void)
00159        { return current_map_mode; }
00160     Bool GetOptimization(void)
00161        { return optimize; }
00162     wxPen *GetPen(void)
00163        { return current_pen; }
00164     Bool GetPixel(double WXUNUSED(x), double WXUNUSED(y),
00165                 wxColour *WXUNUSED(col))
00166        { return FALSE; }
00167     virtual void GetSize(double *w, double *h)
00168        { *w = (double)10; *h = (double)10; }
00169     void GetSizeMM(double *w, double *h)
00170        { GetSize(w, h); *w/=(scale_x*mm_to_pix_x); *h/=(scale_y*mm_to_pix_y); }
00171     int GetTextAlignment(void)
00172        { return current_text_alignment; }
00173     wxColour* GetTextBackground(void)
00174        { return current_text_bg; }
00175     wxColour* GetTextForeground(void)
00176        { return current_text_fg; }
00177     virtual int LogicalToDeviceX(double x)
00178        { return XLOG2DEV(x); }
00179     virtual int LogicalToDeviceXRel(double x)
00180        { return XLOG2DEVREL(x); }
00181     virtual int LogicalToUnscrolledDeviceX(double x)
00182        { return XLOG2DEV(x); }
00183     virtual int LogicalToDeviceY(double y)
00184        { return YLOG2DEV(y); }
00185     virtual int LogicalToDeviceYRel(double y)
00186        { return YLOG2DEVREL(y); }
00187     virtual int LogicalToUnscrolledDeviceY(double y)
00188        { return YLOG2DEV(y); }
00189     virtual double FLogicalToDeviceX(double x)
00190        { return XLOG2DEV(x); }
00191     virtual double FLogicalToDeviceXRel(double x)
00192        { return XLOG2DEVREL(x); }
00193     virtual double FLogicalToUnscrolledDeviceX(double x)
00194        { return XLOG2DEV(x); }
00195     virtual double FLogicalToDeviceY(double y)
00196        { return YLOG2DEV(y); }
00197     virtual double FLogicalToDeviceYRel(double y)
00198        { return YLOG2DEVREL(y); }
00199     virtual double FLogicalToUnscrolledDeviceY(double y)
00200        { return YLOG2DEV(y); }
00201     virtual Bool Ok(void)
00202        { return ok; }
00203     void SetBackgroundMode(int mode)
00204        { current_text_bgmode = mode; }
00205     int GetBackgroundMode()
00206        { return current_text_bgmode; }
00207     void SetOptimization(Bool opt)
00208        { optimize = opt; }
00209     void SetTextAlignment(int new_alignment)
00210        { current_text_alignment = new_alignment; }
00211     // scale and origin methods
00212     void  SetDeviceOrigin(double x, double y);
00213     void  SetLogicalScale(double xs, double ys);
00214     void  SetMapMode(int mode);
00215     virtual void  SetUserScale(double xs, double ys);
00216 
00217     void GetUserScale(double *xs, double *ys)
00218       { *xs = user_scale_x; *ys = user_scale_y; }
00219     void GetDeviceOrigin(double *x, double *y) 
00220       { *x = device_origin_x; *y = device_origin_y; }
00221 
00222     virtual Bool GlyphAvailable(int c, wxFont *f = NULL) = 0;
00223 
00224 #ifdef USE_GL
00225     virtual wxGL *GetGL();
00226 #endif
00227 
00228     int GetAntiAlias();
00229     virtual void SetAntiAlias(int v);  
00230 
00231     virtual void SetAlpha(double d);
00232     double GetAlpha();
00233 
00234     virtual int CacheFontMetricsKey();
00235 
00236     // public data members
00237     Bool  Colour;
00238     int   device;
00239     double current_alpha;
00240 protected:
00241     Bool  auto_setting, optimize, ok;
00242     // everything needed for sizing
00243     double mm_to_pix_x, mm_to_pix_y;
00244     double scale_x, scale_y;
00245     double device_origin_x, device_origin_y;
00246     double logical_scale_x, logical_scale_y, user_scale_x, user_scale_y;
00247     // Tools for drawing
00248     wxColour*    current_background_color;
00249     wxBrush*     current_brush;
00250     wxColourMap* current_cmap;
00251     wxFont*      current_font;
00252     int          current_map_mode;
00253     wxPen*       current_pen;
00254     int               current_text_alignment;
00255     wxColour*    current_text_bg;
00256     int               current_text_bgmode;
00257     wxColour*    current_text_fg;
00258     wxRegion     *clipping;
00259     int          anti_alias;
00260     // utilities for internal use
00261     void  CalcBoundingBox(double x, double y);
00262     void  ComputeScaleAndOrigin(void);
00263     // abbreviations
00264     double XDEV2LOG(int x)
00265       { return (double(x) / scale_x) - device_origin_x; }
00266     double XDEV2LOGREL(int x)
00267       { return double(double(x) / scale_x); }
00268     double YDEV2LOG(int y)
00269       { return (double(y) / scale_y) - device_origin_y; }
00270     double YDEV2LOGREL(int y)
00271       { return double(double(y) / scale_y); }
00272     int XLOG2DEV(double x)
00273       { double a = (x * scale_x) + device_origin_x;
00274        return (int)floor(a); }
00275     int XLOG2DEVREL(double x)
00276       { double a = x * scale_x;
00277        return (int)floor(a); }
00278     int YLOG2DEV(double y)
00279       { double a = (y * scale_y) + device_origin_y;
00280        return (int)floor(a); }
00281     int YLOG2DEVREL(double y)
00282       { double a = y * scale_y;
00283        return (int)floor(a); }
00284     // virtual function for spline drawing
00285     virtual void DrawOpenSpline(wxList *pts);
00286 };
00287 
00288 #endif // DC_h