ugeom.hpp

00001 /* ==================================================== ======== ======= *
00002 *
00003 *  ugeom.hpp
00004 *  Ubit Project
00005 *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006 *  (C) 1999-2006 / Eric Lecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007 *
00008 * ***********************************************************************
00009 * COPYRIGHT NOTICE : 
00010 * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00011 * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00012 * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00013 * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00014 * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00015 * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00016 * ***********************************************************************
00017 * ==================================================== [(c)Elc] ======= *
00018 * ==================================================== ======== ======= */
00019 
00020 #ifndef _ugeom_hpp_
00021 #define _ugeom_hpp_
00022 //pragma ident  "@(#)ugeom.hpp  ubit:05.05.00"
00023 #include <ubit/uobject.hpp>
00024 namespace ubit {
00025   
00026 /* ==================================================== ===== ======= */
00027 
00028 struct UPoint {
00029   float x, y;
00030   
00031   UPoint() : x(0), y(0) {}
00032   UPoint(float _x, float _y) : x(_x), y(_y) {}
00033   
00034   float getX() const {return x;}
00035   float getY() const {return y;}
00036   
00037   void set(float _x, float _y) {x = _x, y = _y;}
00038   void set(const UPoint& p) {*this = p;}
00039 };
00040 
00041 /* ==================================================== ===== ======= */
00042 
00043 struct UDimension {
00044   float width, height;
00045   
00046   UDimension() : width(0), height(0) {}
00047   UDimension(float _w, float _h) : width(_w), height(_h) {}
00048   
00049   float getWidth()  const {return width;}
00050   float getHeight() const {return height;}
00051   
00052   void set(float _w, float _h) {width = _w, height = _h;}
00053   void set(const UDimension& d) {*this = d;}
00054 };
00055 
00056 /* ==================================================== ===== ======= */
00057 
00058 class UShape : public UObject {  
00059 public:
00060   virtual void getBounds(URect&) const = 0;
00061   
00062   virtual void set(const UPoint& p1, const UPoint& p2) = 0;
00063 
00064   //virtual bool contains(const UPoint& p) const;  
00065   virtual bool contains(float x, float y) const = 0;
00066   virtual bool contains(float x, float y, float w, float h) const = 0;
00067 
00068   
00069 private:
00070   friend class UGraph;
00071   virtual void drawImpl(UGraph&) const = 0;
00072 };
00073 
00074 /* ==================================================== ===== ======= */
00075 
00076 struct ULine : public UShape {
00077   float x1, y1, x2, y2;
00078   
00079   ULine();
00080   ULine(float x1, float y1, float x2, float y2);
00081   ULine(const UPoint& p1, const UPoint& p2);
00082 
00083   virtual float getX1() const {return x1;}
00084   virtual float getY1() const {return y1;}
00085   virtual float getX2() const {return x2;}
00086   virtual float getY2() const {return y2;}
00087   virtual void getBounds(URect&) const;
00088 
00089   virtual void set(float x1, float y1, float x2, float y2);
00090   virtual void set(const UPoint& p1, const UPoint& p2);
00091   virtual void set(const ULine& l) {*this = l;}
00092   
00093   virtual bool contains(float x, float y) const {return false;}
00094   virtual bool contains(float x, float y, float w, float h) const {return false;}
00095   
00096 private:
00097   virtual void drawImpl(UGraph&) const;
00098 };
00099 
00100 /* ==================================================== ===== ======= */
00101 
00102 struct URect : public UShape {
00103   float x, y, width, height;
00104   
00105   URect();
00106   URect(float x, float y, float w, float h);
00107   URect(const UPoint& p1, const UPoint& p2);
00108   
00109   virtual float getX() const {return x;}
00110   virtual float getY() const {return y;}
00111   virtual float getWidth()  const {return width;}
00112   virtual float getHeight() const {return height;}
00113   virtual void getBounds(URect&) const;
00114 
00115   virtual void set(float x, float y, float width, float height);
00116   virtual void set(const UPoint& p1, const UPoint& p2);
00117   virtual void set(const URect& r) {*this = r;}
00118   
00119   virtual bool contains(float x, float y) const;
00120   virtual bool contains(float x, float y, float w, float h) const;
00121   
00122 private:
00123     virtual void drawImpl(UGraph&) const;  
00124 };
00125 
00126 /* ==================================================== ===== ======= */
00127 
00128 struct UEllipse : public UShape {
00129   float x, y, width, height;
00130   
00131   UEllipse();
00132   UEllipse(float _x, float _y, float _weight, float _height);
00133   UEllipse(const URect&);
00134 
00135   virtual float getX() const {return x;}
00136   virtual float getY() const {return y;}
00137   virtual float getWidth()  const {return width;}
00138   virtual float getHeight() const {return height;}
00139   virtual void getBounds(URect&) const;
00140 
00141   virtual void set(float x, float y, float width, float height);
00142   virtual void set(const UPoint& p1, const UPoint& p2);
00143   virtual void set(const URect&);
00144   virtual void set(const UEllipse& e) {*this = e;}
00145   
00146   virtual bool contains(float x, float y) const;
00147   virtual bool contains(float x, float y, float w, float h) const;
00148   
00149 private:
00150     virtual void drawImpl(UGraph&) const;  
00151 };
00152 
00153 /* ==================================================== ===== ======= */
00154 
00155 struct UArc : public UShape {
00156   float x, y, width, height, start, extent;
00157   
00158   UArc();
00159   UArc(float _x, float _y, float _weight, float _height, 
00160        float _start, float _extent, int _type = 0);
00161   UArc(const URect&, float _start, float _extent, int _type = 0);
00162   
00163   virtual float getX() const {return x;}
00164   virtual float getY() const {return y;}
00165   virtual float getWidth()  const {return width;}
00166   virtual float getHeight() const {return height;}
00167   virtual float getStart()  const {return start;}
00168   virtual float getExtent() const {return extent;}
00169   virtual void getBounds(URect&) const;
00170 
00171   virtual void set(float _x, float _y, float _weight, float _height,
00172                    float _start, float _extent, int _type = 0);
00173   virtual void set(const UPoint& p1, const UPoint& p2);
00174   virtual void set(const UPoint& p1, const UPoint& p2, float start, float extent, int type = 0);
00175   virtual void set(const UArc& a) {*this = a;}
00176   virtual void setStart(float angle)  {start = angle;}
00177   virtual void setExtent(float angle) {extent = angle;}
00178   
00179   virtual bool contains(float x, float y) const;
00180   virtual bool contains(float x, float y, float w, float h) const;
00181   
00182 private:
00183     virtual void drawImpl(UGraph&) const;  
00184 };
00185 
00186 /* ==================================================== ===== ======= */
00187 /* ==================================================== ===== ======= */
00190 struct UMargins {
00191   short top, right, bottom, left;
00192   
00193   UMargins() {}
00194   UMargins(short hmargins, short vmargins); 
00196   
00197   void set(short hmargins, short vmargins);
00199 
00200   void setH(short l_margin, short r_margin);
00201   void setV(short t_margins, short b_margins);
00202   void incr(const UMargins&);
00203 };
00204 
00205 /* ==================================================== ===== ======= */
00208 struct URegion {
00209   int x, y, width, height;
00210 
00211   URegion() {};
00212   URegion(int _x, int _y, int _w, int _h) : x(_x), y(_y), width(_w), height(_h) {}
00213 
00214   void set(const URegion& r) {*this = r;}
00215   void set(int _x, int _y, int _w, int _h) {x = _x, y = _y, width = _w, height = _h;}
00216   
00217   bool inter(const URegion& rect2);
00218   bool inter(int x, int y, int w, int h);
00226   void closure(const URegion& rect2);
00227   void closure(int x, int y, int w, int h);
00232 };
00233 
00234 }
00235 #endif
00236 /* ==================================================== [TheEnd] ======= */
00237 /* ==================================================== [(c)Elc] ======= */

Generated on Mon Jan 29 00:20:38 2007 for Ubit by  doxygen 1.4.7