Page principale | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Composants | Déclarations | Pages associées

layout.h

Aller à la documentation de ce fichier.
00001 /* ***********************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
00017 *********************************************************************************** */
00018 
00023 #ifndef INCLUDE_LAYOUT_H
00024 #define INCLUDE_LAYOUT_H
00025 
00038 template <class T> class LayoutVar // T peut etre de preferance float ou double
00039 {
00040 public:
00041         T constValue;
00042         double percentValue;
00043 
00044 public:
00045         LayoutVar()
00046         {
00047                 Zero();
00048         }
00049 
00050         void Zero()
00051         {
00052                 constValue=0;
00053                 percentValue=0;
00054         }
00055 
00056         void operator=(LayoutVar &source)
00057         {
00058                 constValue = source.constValue;
00059                 percentValue = source.percentValue;
00060         }
00061 
00062         void Set(T _percentValue,T _constValue) 
00063         {
00064                 constValue = _constValue;
00065                 percentValue = _percentValue;
00066         }
00067 
00068         void Move(T delta)
00069         {
00070                 constValue+=delta;
00071         }
00072 
00073         void MoveTo(T value)
00074         {
00075                 constValue=value;
00076         }
00077 
00078         void Scale(T delta)
00079         {
00080                 percentValue*=(double)delta;
00081         }
00082 
00083         T Get(T base=0)
00084         {
00085                 return (double)base*percentValue+constValue;
00086         }
00087 };
00088 
00092 template <class T> class Layout // T peut etre de preferance float ou double
00093 {
00094 public:
00095         LayoutVar<T> xDeb,yDeb,xFin,yFin;
00096 
00097 public:
00098         Layout()
00099         {
00100         }
00101 
00102         void Zero()
00103         {
00104                 xDeb.Zero();
00105                 yDeb.Zero();
00106                 xFin.Zero();
00107                 yFin.Zero();
00108         }
00109 
00110         void operator=(Layout &src)
00111         {
00112                 xDeb = src.xDeb;
00113                 yDeb = src.yDeb;
00114                 xFin = src.xFin;
00115                 yFin = src.yFin;
00116         }
00117 
00118         void Set(double xDebPercent,T xDebConst,double yDebPercent,T yDebConst,GLdouble xFinPercent,T xFinConst,double yFinPercent,T yFinConst)
00119         {   
00120                 xDeb.Set(xDebPercent,xDebConst);
00121                 xFin.Set(xFinPercent,xFinConst);
00122                 yDeb.Set(yDebPercent,yDebConst);
00123                 yFin.Set(yFinPercent,yFinConst);
00124         }
00125 
00126         void SetFull()
00127         {
00128                 xDeb.Zero();
00129                 yDeb.Zero();
00130                 xFin.Set(1,0);
00131                 yFin.Set(1,0);
00132         }
00133 
00134         void Move(double deltaX,double deltaY)
00135         {
00136                 xDeb.Move(deltaX);
00137                 yDeb.Move(deltaY);
00138                 xFin.Move(deltaX);
00139                 yFin.Move(deltaY);
00140         }
00141 
00142         void MoveTo(double x,double y)
00143         {
00144                 T deltaX,deltaY;
00145                 deltaX=xFin.constValue-xDeb.constValue;
00146                 deltaY=yFin.constValue-yDeb.constValue;
00147                 xDeb.MoveTo(x);
00148                 yDeb.MoveTo(y);
00149                 xFin.MoveTo(x+deltaX);
00150                 yFin.MoveTo(y+deltaY);
00151         }
00152 
00153         void Scale(double deltaX,double deltaY)
00154         {
00155                 xDeb.Scale(deltaX);
00156                 yDeb.Scale(deltaY);
00157                 xFin.Scale(deltaX);
00158                 yFin.Scale(deltaY);
00159         }
00160 };
00161 
00162 #endif

Généré le Thu Apr 8 18:52:14 2004 pour 3D Controls par doxygen 1.3.6