Dimension.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <etk/types.hpp>
9 #include <etk/math/Vector2D.hpp>
10 
11 namespace esvg {
12  enum distance {
25  };
30  class Dimension {
31  private:
32  vec2 m_data;
33  enum distance m_type;
34  public:
38  Dimension();
44  Dimension(const vec2& _size, enum esvg::distance _type=esvg::distance_pixel);
49  Dimension(const std::string& _config) :
50  m_data(0,0),
51  m_type(esvg::distance_pixel) {
52  set(_config);
53  };
59  Dimension(const std::string& _configX, const std::string& _configY) :
60  m_data(0,0),
61  m_type(esvg::distance_pixel) {
62  set(_configX, _configY);
63  };
67  ~Dimension();
68 
72  operator std::string() const;
73 
78  const vec2& getValue() const {
79  return m_data;
80  }
85  enum distance getType() const {
86  return m_type;
87  };
93  void set(const vec2& _size, enum distance _type);
94 
95  public:
100  void set(std::string _config);
106  void set(std::string _configX, std::string _configY);
107  public:
113  vec2 getPixel(const vec2& _upperSize) const;
114  /*****************************************************
115  * = assigment
116  *****************************************************/
117  const Dimension& operator= (const Dimension& _obj ) {
118  if (this!=&_obj) {
119  m_data = _obj.m_data;
120  m_type = _obj.m_type;
121  }
122  return *this;
123  }
124  /*****************************************************
125  * == operator
126  *****************************************************/
127  bool operator == (const Dimension& _obj) const {
128  if( m_data == _obj.m_data
129  && m_type == _obj.m_type) {
130  return true;
131  }
132  return false;
133  }
134  /*****************************************************
135  * != operator
136  *****************************************************/
137  bool operator!= (const Dimension& _obj) const {
138  if( m_data != _obj.m_data
139  || m_type != _obj.m_type) {
140  return true;
141  }
142  return false;
143  }
144  };
145  std::ostream& operator <<(std::ostream& _os, enum esvg::distance _obj);
146  std::ostream& operator <<(std::ostream& _os, const esvg::Dimension& _obj);
151  class Dimension1D {
152  private:
153  float m_data;
154  enum distance m_type;
155  public:
159  Dimension1D();
165  Dimension1D(float _size, enum esvg::distance _type=esvg::distance_pixel);
170  Dimension1D(const std::string& _config) :
171  m_data(0.0f),
172  m_type(esvg::distance_pixel) {
173  set(_config);
174  };
178  ~Dimension1D();
179 
183  operator std::string() const;
184 
189  const float& getValue() const {
190  return m_data;
191  }
196  enum distance getType() const {
197  return m_type;
198  };
204  void set(float _size, enum distance _type);
205 
206  public:
211  void set(std::string _config);
212  public:
218  float getPixel(float _upperSize) const;
219  /*****************************************************
220  * = assigment
221  *****************************************************/
222  const Dimension1D& operator= (const Dimension1D& _obj ) {
223  if (this!=&_obj) {
224  m_data = _obj.m_data;
225  m_type = _obj.m_type;
226  }
227  return *this;
228  }
229  /*****************************************************
230  * == operator
231  *****************************************************/
232  bool operator == (const Dimension1D& _obj) const {
233  if( m_data == _obj.m_data
234  && m_type == _obj.m_type) {
235  return true;
236  }
237  return false;
238  }
239  /*****************************************************
240  * != operator
241  *****************************************************/
242  bool operator!= (const Dimension1D& _obj) const {
243  if( m_data != _obj.m_data
244  || m_type != _obj.m_type) {
245  return true;
246  }
247  return false;
248  }
249  };
250  std::ostream& operator <<(std::ostream& _os, const esvg::Dimension1D& _obj);
251 }
252 
Main esvg namespace.
Definition: Base.hpp:24
"px"
Definition: Dimension.hpp:14
"%"
Definition: Dimension.hpp:13
Dimension(const std::string &_configX, const std::string &_configY)
Constructor.
Definition: Dimension.hpp:59
"cm"
Definition: Dimension.hpp:16
const vec2 & getValue() const
get the current dimention.
Definition: Dimension.hpp:78
vec2 getPixel(const vec2 &_upperSize) const
get the current dimention in pixel
"em"
Definition: Dimension.hpp:21
"pc"
Definition: Dimension.hpp:24
Dimension()
Constructor (default :0,0 mode pixel)
distance
Definition: Dimension.hpp:12
const float & getValue() const
get the current dimention.
Definition: Dimension.hpp:189
Dimension1D(const std::string &_config)
Constructor.
Definition: Dimension.hpp:170
enum distance getType() const
Definition: Dimension.hpp:85
"in"
Definition: Dimension.hpp:19
in the dimention class we store the data as the more usefull unit (pixel) but one case need to be dyn...
Definition: Dimension.hpp:30
in the dimention class we store the data as the more usefull unit (pixel) but one case need to be dyn...
Definition: Dimension.hpp:151
~Dimension()
Destructor.
"pt"
Definition: Dimension.hpp:23
"km"
Definition: Dimension.hpp:18
Dimension(const std::string &_config)
Constructor.
Definition: Dimension.hpp:49
"ex"
Definition: Dimension.hpp:22
"mm"
Definition: Dimension.hpp:17
"m"
Definition: Dimension.hpp:15
"ft"
Definition: Dimension.hpp:20