distance.h

Go to the documentation of this file.
00001 /* === S Y N F I G ========================================================= */
00021 /* ========================================================================= */
00022 
00023 /* === S T A R T =========================================================== */
00024 
00025 #ifndef __SYNFIG_DISTANCE_H
00026 #define __SYNFIG_DISTANCE_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include "real.h"
00031 #include "string.h"
00032 
00033 /* === M A C R O S ========================================================= */
00034 
00035 /* === T Y P E D E F S ===================================================== */
00036 
00037 /* === C L A S S E S & S T R U C T S ======================================= */
00038 
00039 namespace synfig {
00040 
00041 class RendDesc;
00042 
00043 class Distance
00044 {
00045 public:
00046     typedef Real value_type;
00047 
00048     enum System
00049     {
00050         SYSTEM_UNITS,       
00051         SYSTEM_PIXELS,      
00052 
00053         SYSTEM_POINTS,      
00054         SYSTEM_INCHES,      
00055         SYSTEM_METERS,      
00056         SYSTEM_MILLIMETERS, 
00057         SYSTEM_CENTIMETERS, 
00058 
00059         SYSTEM_END          
00060     };
00061 
00062     class BadSystem { };
00063 
00064 private:
00065     value_type value_;
00066 
00067     System system_;
00068 
00069 
00070 public:
00071 
00072     Distance(){ }
00073     Distance(const value_type& value, System system):value_(value),system_(system) { }
00074     explicit Distance(const synfig::String& string);
00075 
00076     operator Real()const { return value_; }
00077 
00078     Distance& operator=(const Real& rhs) { value_=rhs; return *this; }
00079 
00080     Distance& operator=(const synfig::String& rhs);
00081 
00082     synfig::String get_string(int digits=4)const;
00083 
00084     const System& get_system()const { return system_; }
00085 
00086     const Real& get()const { return value_; }
00087 
00088     Real get(System system, const RendDesc& rend_desc)const;
00089 
00090     void convert(System system, const RendDesc& rend_desc);
00091 
00092     Real meters()const;
00093     Real meters(const RendDesc& rend_desc)const;
00094     Real units(const RendDesc& rend_desc)const;
00095 
00096     static Real meters_to_system(Real x, System target_system);
00097     static System ident_system(const synfig::String& str);
00098     static synfig::String system_name(System system);
00099     static synfig::String system_local_name(System system);
00100 
00101     const Distance& operator+=(const Distance &rhs) { value_+=meters_to_system(rhs.meters(),system_); return *this; }
00102     const Distance& operator-=(const Distance &rhs) { value_-=meters_to_system(rhs.meters(),system_); return *this; }
00103 
00104     const Distance& operator+=(const float &rhs) { value_+=rhs; return *this; }
00105     const Distance& operator-=(const float &rhs) { value_-=rhs; return *this; }
00106     const Distance& operator*=(const float &rhs) { value_*=rhs; return *this; }
00107     const Distance& operator/=(const float &rhs) { value_/=rhs; return *this; }
00108 
00109 /*
00110     template<typename U> const Time& operator+=(const U &rhs) { value_+=rhs; return *this; }
00111     template<typename U> const Time& operator-=(const U &rhs) { value_-=rhs; return *this; }
00112     template<typename U> const Time& operator*=(const U &rhs) { value_*=rhs; return *this; }
00113     template<typename U> const Time& operator/=(const U &rhs) { value_/=rhs; return *this; }
00114 
00115     template<typename U> Time operator+(const U &rhs)const { return value_+rhs; }
00116     template<typename U> Time operator-(const U &rhs)const { return value_-rhs; }
00117     template<typename U> Time operator*(const U &rhs)const { return value_*rhs; }
00118     template<typename U> Time operator/(const U &rhs)const { return value_/rhs; }
00119 
00120     Time operator-()const { return -value_; }
00121 */
00122 }; // END of class Distance
00123 
00124 }; // END of namespace synfig
00125 
00126 /* === E N D =============================================================== */
00127 
00128 #endif

Generated on Wed Aug 15 05:00:23 2007 for synfig by  doxygen 1.5.3