uboxGeom.hpp

00001 /* ==================================================== ======== ======= *
00002 *
00003 *  uboxGeom.hpp: layout properties
00004 *  Ubit Project
00005 *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006 *  (C) 1999-2006 EricLecolinet / 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 _uboxGeom_hpp_
00021 #define _uboxGeom_hpp_
00022 //pragma ident  "@(#)uboxGeom.hpp       ubit:05.05.00"
00023 #include <ubit/uprop.hpp>
00024 namespace ubit {
00025   
00026 /* ==================================================== ===== ======= */
00035 class UScale : public UProp {
00036 public:
00037   UBIT_ATTR_CLASS(UScale, UProp)
00038 
00039   UScale(float value = 1.);
00040   UScale(const UFloat&);
00041   
00042   friend UScale& uscale(float v = 1.)    {return *new UScale(v);}
00043   friend UScale& uscale(const UFloat& v) {return *new UScale(v);}
00044   
00045   operator float() const {return value;}
00047   
00048   UScale& operator=(float v)         {set(v); return *this;}
00049   UScale& operator=(const UFloat& v) {set(v); return *this;}
00050   UScale& operator=(const UScale& v) {set(v.value); return *this;}
00051   virtual void set(float);
00052   
00053   bool operator==(float v) const         {return v == value;}
00054   bool operator==(const UFloat& v) const {return v == value;}
00055   bool operator==(const UScale& v) const {return value == v.value;}
00056   
00057   virtual void mult(float);
00058   virtual void div(float);
00059   virtual void update();
00060   virtual void putProp(UContext*, UControl*);
00061   
00062 private:
00063   float value;
00064 };
00065   
00066 /* ==================================================== ===== ======= */
00088 class UPos : public UProp {
00089 public:
00090   UBIT_ATTR_CLASS(UPos, UProp)
00091 
00092   UPos();
00093   UPos(float x, float y);
00094   UPos(const UPos&);
00095   UPos(const UPoint&);
00096   virtual ~UPos() {destructs();}
00097   
00098   friend UPos& upos() {return *new UPos;}
00099   friend UPos& upos(float x, float y) {return *new UPos(x, y);}
00100     
00101   bool operator==(const UPos& p) const;
00102   
00103   UPos& operator=(const UPos& p)  {set(p); return *this;}
00104   UPos& operator=(const UPoint& p){set(p); return *this;}
00105   
00106   void setX(float _x)             {setImpl(_x, y,true);}
00107   void setY(float _y)             {setImpl(x, _y,true);}
00108   void set(float _x, float _y)    {setImpl(_x, _y,true);}
00109   void set(const UPos& p)         {setImpl(p.x, p.y, true);}
00110   void set(const UPoint& p)       {setImpl(p.x, p.y, true);}
00111   
00112   float getX() const {return x;}
00113   float getY() const {return y;}
00114   operator UPoint() const {return UPoint(x, y);}
00115 
00116   void setPercentMode(bool is_percent, bool is_adjusted);
00117   bool isPercent() const {return modes & PERCENT_MODE;}
00118   bool isAdjustedPercent() const {return modes & PERCENT_ADJUSTED_MODE;}
00120   
00121   bool isPos3d() const {return modes & POS_3D_MODE;}
00123   
00124   virtual void update();
00125   virtual void setImpl(float x, float y, bool update);
00126   virtual void putProp(UContext*, UControl*);
00127 
00128   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00129 #ifndef NO_DOC
00130   virtual void addingTo(UChild*, UGroup *parent);
00131   virtual void removingFrom(UChild*, UGroup *parent);
00133 protected:
00134   enum {PERCENT_MODE=1<<0, PERCENT_ADJUSTED_MODE=1<<1, POS_3D_MODE=1<<2};
00135   friend class UView;
00136   friend class UBox;
00137   friend class UWin;
00138   float x, y;      // NB: peuvent etre des proportions.
00139   unsigned short modes;
00140 #endif
00141 };
00142 
00143 /* ==================================================== ===== ======= */
00152 class UWidth : public UProp {
00153 public:
00154   UBIT_ATTR_CLASS(UWidth, UProp)
00155 
00156   static const int UNSPECIFIED = -1;
00157 
00158   UWidth(float value = UNSPECIFIED);   
00159   UWidth(const UWidth&);
00160 
00161   friend UWidth& uwidth()                {return *(new UWidth());}
00162   friend UWidth& uwidth(float v)         {return *(new UWidth(v));}
00163   friend UWidth& uwidth(const UWidth& v) {return *(new UWidth(v));}
00165 
00166   operator float() const {return def_value;}
00168 
00169   UWidth& operator=(float v)             {set(v); return *this;}
00170   UWidth& operator=(const UFloat& v)     {set(v); return *this;}
00171   UWidth& operator=(const UWidth& v)     {set(v); return *this;}
00172   virtual void set(float);
00173   virtual void set(const UWidth&);
00174 
00175   bool operator==(float) const;
00176   bool operator==(const UWidth&) const;
00177 
00178   bool isResizable() const {return is_resizable;}
00179   UWidth& resizable(bool state = true);
00189   bool isAdjustable() const {return is_adjustable;}
00190   UWidth& adjustable(bool = true);
00200   virtual void update();
00201   virtual void putProp(UContext*, UControl*);  
00202 
00203   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00204 protected:
00205   friend class UViewLayoutImpl;
00206   float def_value, actual_value;
00207   bool is_resizable, is_adjustable;
00208 };
00209 
00210 /* ==================================================== ===== ======= */
00216 class UHeight : public UProp {
00217 public:
00218   UBIT_ATTR_CLASS(UHeight, UProp)
00219 
00220   static const int UNSPECIFIED = -1;
00221 
00222   UHeight(float = UNSPECIFIED);
00223   UHeight(const UHeight&);
00224   
00225   friend UHeight& uheight()                 {return *(new UHeight());}
00226   friend UHeight& uheight(float v)          {return *(new UHeight(v));}
00227   friend UHeight& uheight(const UHeight& v) {return *(new UHeight(v));}
00229 
00230   UHeight& operator=(float v)             {set(v); return *this;}
00231   UHeight& operator=(const UFloat& v)     {set(v); return *this;}
00232   UHeight& operator=(const UHeight& v)    {set(v); return *this;}
00233   virtual void set(float);
00234   virtual void set(const UHeight&);
00235   
00236   operator float() const {return def_value;}
00238   
00239   bool operator==(float) const;
00240   bool operator==(const UHeight&) const;
00241   
00242   bool isResizable() const {return is_resizable;}
00243   UHeight& resizable(bool = true);
00245 
00246   bool isAdjustable() const {return is_adjustable;}
00247   UHeight& adjustable(bool = true);
00249 
00250   virtual void update();
00251   virtual void putProp(UContext*, UControl*);
00252 
00253   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00254 protected:
00255   friend class UViewLayoutImpl;
00256   float def_value, actual_value;
00257   bool is_resizable, is_adjustable;
00258 };
00259 
00260 /* ==================================================== [Elc] ======= */
00261 /* ==================================================== ===== ======= */
00264 struct UPosChooser : public UProp {
00265   UPosChooser(UPos& pos);
00267   
00268   virtual ~UPosChooser();
00269   
00270   void freezeX(bool b) {freeze_x = b;}
00271   void freezeY(bool b) {freeze_y = b;}
00272   
00273   // - - - impl - - - - -- - - - - - - - - - - - - - - - - - - - - - - -
00274 #ifndef NO_DOC
00275   virtual void putProp(UContext*, UControl*) {}
00276   virtual void addingTo(UChild*, UGroup* parent);
00277   virtual void removingFrom(UChild*, UGroup* parent);
00278   // NOTE that removingFrom() requires a destructor to be defined.
00279 protected:
00280   UView* moving_area;
00281   uptr<UPos> pos;
00282   uptr<UCall> drag_call, press_call, release_call;
00283   int x_in_movable, y_in_movable;
00284   bool freeze_x, freeze_y;
00285   virtual void drag(UMouseEvent&);
00286   virtual void press(UMouseEvent&);
00287   virtual void release(UMouseEvent&);
00288 #endif
00289 };
00290 
00291 /* ==================================================== ======== ======= */
00295 struct UMagicLensPosChooser : public UPosChooser {
00296   UMagicLensPosChooser(UPos&, UScrollpane& clip);
00297   
00298   // - - - impl - - - - -- - - - - - - - - - - - - - - - - - - - - - - -
00299 private:
00300   uptr<UScrollpane> clip;
00301   virtual void drag(UMouseEvent&);
00302 };
00303 
00304 /* ==================================================== ===== ======= */
00309 class UWidthChooser: public UWidth {
00310 public:
00311   UWidthChooser();
00312   UWidthChooser(float value);
00313   UWidthChooser(const UWidth&);
00314   virtual ~UWidthChooser();
00315   
00316   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00317 #ifndef NO_DOC
00318   void addingTo(UChild*, UGroup *parent);
00319   void removingFrom(UChild*, UGroup *parent);
00320 protected:
00321   virtual void constructs();
00322   virtual void press(UMouseEvent&);
00323   virtual void drag(UMouseEvent&);
00324 private:
00325   uptr<UBox> phandle;
00326   int curpos;
00327 #endif
00328 };
00329 
00330 /* ==================================================== ===== ======= */
00335 class UHeightChooser: public UHeight {
00336 public:
00337   UHeightChooser();
00338   UHeightChooser(float value);
00339   UHeightChooser(const UHeight&);
00340   virtual ~UHeightChooser();
00341   
00342   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00343 #ifndef NO_DOC
00344   void addingTo(UChild*, UGroup *parent);
00345   void removingFrom(UChild*, UGroup *parent);
00346 protected:
00347   virtual void constructs();
00348   virtual void press(UMouseEvent&);
00349   virtual void drag(UMouseEvent&);
00350 private:
00351   uptr<UBox> phandle;
00352   int curpos;
00353 #endif
00354 };
00355 
00356 }
00357 #endif
00358 /* ==================================================== [TheEnd] ======= */
00359 /* ==================================================== [(c)Elc] ======= */
00360 
00361 
00362 

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