Back to index

plt-scheme  4.2.1
Region.h
Go to the documentation of this file.
00001 
00002 #ifndef wb_rgnh
00003 #define wb_rgnh
00004 
00005 #include "wx_dc.h"
00006 
00007 /************************************************************/
00008 
00009 /* We start with wxPSStream, because we need it to output region
00010    paths. */
00011 
00012 class wxPSStream : public wxObject {
00013  public:
00014   void *f, *f_in;
00015   int int_width;
00016   wxPSStream(char *file);
00017   ~wxPSStream(void);
00018 
00019   int good(void);
00020   void Out(char s);
00021   void Out(const char *s);
00022   void Out(double n);
00023   void Out(long l);
00024   void Out(int i);
00025 
00026   void flush();
00027 
00028   long tellp(void);
00029   void seekp(long pos);
00030 
00031   void width(int w);
00032 
00033   long read_at(long pos, char *buf, long amt);
00034 };
00035 
00036 class wxPostScriptDC;
00037 
00038 /************************************************************/
00039 
00040 #ifdef UseXtRegions
00041 typedef Region XtRegion;
00042 #else
00043 typedef void *XtRegion;
00044 #endif
00045 
00046 class wxPathRgn;
00047 class wxPath;
00048 #ifdef wx_msw
00049 class LazyRgn;
00050 #endif
00051 
00052 class wxRegion : public wxObject 
00053 {
00054  public:
00055 #ifdef wx_msw
00056   LazyRgn *lazy_rgn;
00057   HRGN real_rgn;
00058   HRGN GetRgn();
00059 #endif
00060 #ifdef wx_x
00061   XtRegion rgn;
00062 #endif
00063 #ifdef wx_mac
00064   RgnHandle rgn;
00065 #endif
00066   wxPathRgn *prgn;
00067   wxDC *dc;
00068   char is_ps, no_prgn;
00069   int locked;
00070 
00071   wxRegion(wxDC *dc, wxRegion *r = NULL, Bool no_prgn = FALSE);
00072   ~wxRegion();
00073 
00074   inline wxDC *GetDC() { return dc; }
00075 
00076   void Lock(int v);
00077   
00078   void SetRectangle(double x, double y, double width, double height);
00079   void SetRoundedRectangle(double x, double y, double width, double height, double radius = 20.0);
00080   void SetEllipse(double x, double y, double width, double height);
00081   void SetPolygon(int n, wxPoint points[], double xoffset = 0, double yoffset = 0, 
00082                 int fillStyle=wxODDEVEN_RULE, int delta = 0);
00083   void SetPath(wxPath *p, double xoffset = 0, double yoffset = 0, 
00084               int fillStyle=wxODDEVEN_RULE);
00085   void SetArc(double x, double y, double w, double h, double start, double end);
00086 
00087   void Union(wxRegion *);
00088   void Intersect(wxRegion *);
00089   void Subtract(wxRegion *);
00090   void Xor(wxRegion *r);
00091 
00092   void BoundingBox(double *x, double *y, double *w, double *h);
00093 
00094   Bool Empty();
00095   Bool ReallyEmpty();
00096 
00097   Bool IsInRegion(double x, double y);
00098   
00099   void Cleanup();
00100 
00101   void Install(long target, Bool align);
00102   void InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00103 };
00104 
00105 /************************************************************/
00106 
00107 class wxPathRgn : public wxObject
00108 {
00109  public:
00110   double ox, oy, sx, sy;
00111   int is_rect;
00112 
00113   wxPathRgn(wxDC *dc_for_scale);
00114   ~wxPathRgn();
00115   virtual Bool Install(long target, Bool reverse, Bool align) = 0;
00116 
00117   void PrepareScale(long target, Bool oe, Bool align, void *m);
00118   void RestoreScale(long target, Bool align, void *m);
00119 
00120   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s) = 0;
00121 
00122   double XFormX(double x, Bool align);
00123   double XFormY(double x, Bool align);
00124   double XFormXB(double x, Bool align);
00125   double XFormYB(double x, Bool align);
00126   double XFormW(double w, double x, Bool align);
00127   double XFormH(double h, double y, Bool align);
00128 };
00129 
00130 class wxRectanglePathRgn : public wxPathRgn
00131 {
00132  public:
00133   double x;
00134   double y;
00135   double width;
00136   double height;
00137   wxRectanglePathRgn(wxDC *dc_for_scale, double x, double y, double width, double height);
00138   virtual Bool Install(long target, Bool reverse, Bool align);
00139   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00140 };
00141 
00142 class wxRoundedRectanglePathRgn : public wxPathRgn
00143 {
00144  public:
00145   double x;
00146   double y;
00147   double width;
00148   double height;
00149   double radius;
00150   wxRoundedRectanglePathRgn(wxDC *dc_for_scale, double x, double y, double width, double height, double radius);
00151   virtual Bool Install(long target, Bool reverse, Bool align);
00152   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00153 };
00154 
00155 class wxPolygonPathRgn : public wxPathRgn
00156 {
00157  public:
00158   int n;
00159   wxPoint *points;
00160   double xoffset;
00161   double yoffset;
00162   int fillStyle;
00163   wxPolygonPathRgn(wxDC *dc_for_scale, int n, wxPoint points[], double xoffset, double yoffset, int fillStyle);
00164   virtual Bool Install(long target, Bool reverse, Bool align);
00165   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00166 };
00167 
00168 class wxArcPathRgn : public wxPathRgn
00169 {
00170  public:
00171   double x;
00172   double y;
00173   double w;
00174   double h;
00175   double start;
00176   double end;
00177   wxArcPathRgn(wxDC *dc_for_scale, double x, double y, double w, double h, double start, double end);
00178   virtual Bool Install(long target, Bool reverse, Bool align);
00179   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00180 };
00181 
00182 class wxPathPathRgn : public wxPathRgn
00183 {
00184  public:
00185   wxPath *p;
00186   int fillStyle;
00187   wxPathPathRgn(wxDC *dc_for_scale, wxPath *p, double xoffset, double yoffset, int fillStyle);
00188   virtual Bool Install(long target, Bool reverse, Bool align);
00189   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00190 };
00191 
00192 class wxUnionPathRgn : public wxPathRgn
00193 {
00194  public:
00195   wxPathRgn *a, *b;
00196   wxUnionPathRgn(wxPathRgn *f, wxPathRgn *s);
00197   virtual Bool Install(long target, Bool reverse, Bool align);
00198   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00199 };
00200 
00201 class wxIntersectPathRgn : public wxPathRgn
00202 {
00203  public:
00204   wxPathRgn *a, *b;
00205   wxIntersectPathRgn(wxPathRgn *f, wxPathRgn *s);
00206   virtual Bool Install(long target, Bool reverse, Bool align);
00207   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00208 };
00209 
00210 class wxDiffPathRgn : public wxPathRgn
00211 {
00212  public:
00213   wxPathRgn *a, *b;
00214   wxDiffPathRgn(wxPathRgn *f, wxPathRgn *s);
00215   virtual Bool Install(long target, Bool reverse, Bool align);
00216   virtual Bool InstallPS(wxPostScriptDC *dc, wxPSStream *s);
00217 };
00218 
00219 /************************************************************/
00220 
00221 class wxPath : public wxObject
00222 {
00223  public:
00224   long cmd_size, alloc_cmd_size, last_cmd;
00225   double *cmds;
00226 
00227   int num_polys;
00228   double **poly_pts;
00229 
00230   wxPath();
00231   ~wxPath();
00232 
00233   void Reset();
00234 
00235   Bool IsOpen();
00236 
00237   void Close();
00238   void MoveTo(double x, double y);
00239   void LineTo(double x, double y);
00240   void Arc(double x, double y, double w, double h, double start, double end, Bool ccw);
00241   void CurveTo(double x1, double y1, double x2, double y2, double x3, double y3);
00242 
00243   void Rectangle(double x, double y, double width, double height);
00244   void RoundedRectangle(double x, double y, double width, double height, double radius = 20.0);
00245   void Ellipse(double x, double y, double width, double height);
00246   void Lines(int n, wxPoint points[], double xoffset = 0, double yoffset = 0);
00247 
00248   void Translate(double x, double y);
00249   void Scale(double x, double y);
00250   void Rotate(double a);
00251 
00252   void Reverse(int start_cmd = 0, Bool start_with_line = 0);
00253 
00254   void AddPath(wxPath *p);
00255   
00256   void Install(long target, double dx, double dy,
00257               double ox, double oy, double sx, double sy, 
00258               Bool align, double pox, double poy);
00259   void InstallPS(wxPostScriptDC *dc, wxPSStream *s, double dx, double dy);
00260   int ToPolygons(int **_lens, double ***_pts, double sx, double sy);
00261 
00262   void BoundingBox(double *x1, double *y1, double *x2, double *y2);
00263 
00264  private:
00265   void MakeRoom(int n);
00266   void ClearCache();
00267 };
00268 
00269 #endif