moreupdates
[synfig.git] / synfig-core / trunk / src / synfig / distance.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file distance.h
3 **      \brief Template Header
4 **
5 **      $Id: distance.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SYNFIG_DISTANCE_H
25 #define __SYNFIG_DISTANCE_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include "real.h"
30 #include "string.h"
31
32 /* === M A C R O S ========================================================= */
33
34 /* === T Y P E D E F S ===================================================== */
35
36 /* === C L A S S E S & S T R U C T S ======================================= */
37
38 namespace synfig {
39
40 class RendDesc;
41
42 class Distance
43 {
44 public:
45         typedef Real value_type;
46         
47         enum System
48         {
49                 SYSTEM_UNITS,           //!<
50                 SYSTEM_PIXELS,          //!<
51                 
52                 SYSTEM_POINTS,          //!<
53                 SYSTEM_INCHES,          //!<
54                 SYSTEM_METERS,          //!<
55                 SYSTEM_MILLIMETERS,     //!<
56                 SYSTEM_CENTIMETERS,     //!<
57
58                 SYSTEM_END                      //!< \internal
59         };
60
61         class BadSystem { };
62
63 private:        
64         value_type value_;
65                 
66         System system_;
67
68         
69 public:
70
71         Distance(){ }
72         Distance(const value_type& value, System system):value_(value),system_(system) { }
73         explicit Distance(const synfig::String& string);
74         
75         operator Real()const { return value_; }
76
77         Distance& operator=(const Real& rhs) { value_=rhs; return *this; }
78
79         Distance& operator=(const synfig::String& rhs);
80
81         synfig::String get_string(int digits=4)const;
82         
83         const System& get_system()const { return system_; }
84
85         const Real& get()const { return value_; }
86
87         Real get(System system, const RendDesc& rend_desc)const;
88         
89         void convert(System system, const RendDesc& rend_desc);
90         
91         Real meters()const;
92         Real meters(const RendDesc& rend_desc)const;
93         Real units(const RendDesc& rend_desc)const;
94         
95         static Real meters_to_system(Real x, System target_system);
96         static System ident_system(const synfig::String& str);
97         static synfig::String system_name(System system);
98         static synfig::String system_local_name(System system);
99
100         const Distance& operator+=(const Distance &rhs) { value_+=meters_to_system(rhs.meters(),system_); return *this; }
101         const Distance& operator-=(const Distance &rhs) { value_-=meters_to_system(rhs.meters(),system_); return *this; }
102
103         const Distance& operator+=(const float &rhs) { value_+=rhs; return *this; }
104         const Distance& operator-=(const float &rhs) { value_-=rhs; return *this; }
105         const Distance& operator*=(const float &rhs) { value_*=rhs; return *this; }
106         const Distance& operator/=(const float &rhs) { value_/=rhs; return *this; }
107         
108 /*
109         template<typename U> const Time& operator+=(const U &rhs) { value_+=rhs; return *this; }
110         template<typename U> const Time& operator-=(const U &rhs) { value_-=rhs; return *this; }
111         template<typename U> const Time& operator*=(const U &rhs) { value_*=rhs; return *this; }
112         template<typename U> const Time& operator/=(const U &rhs) { value_/=rhs; return *this; }
113
114         template<typename U> Time operator+(const U &rhs)const { return value_+rhs; }
115         template<typename U> Time operator-(const U &rhs)const { return value_-rhs; }
116         template<typename U> Time operator*(const U &rhs)const { return value_*rhs; }
117         template<typename U> Time operator/(const U &rhs)const { return value_/rhs; }
118         
119         Time operator-()const { return -value_; }
120 */
121 }; // END of class Distance
122         
123 }; // END of namespace synfig
124
125 /* === E N D =============================================================== */
126
127 #endif