My Project
ParaMargins.h
1 #pragma once
2 
3 namespace ParaEngine
4 {
5  class QMargins
6  {
7  public:
8  QMargins();
9  QMargins(int left, int top, int right, int bottom);
10 
11  bool isNull() const;
12 
13  int left() const;
14  int top() const;
15  int right() const;
16  int bottom() const;
17 
18  void setLeft(int left);
19  void setTop(int top);
20  void setRight(int right);
21  void setBottom(int bottom);
22 
23  QMargins &operator+=(const QMargins &margins);
24  QMargins &operator-=(const QMargins &margins);
25  QMargins &operator+=(int);
26  QMargins &operator-=(int);
27  QMargins &operator*=(int);
28  QMargins &operator/=(int);
29  QMargins &operator*=(float);
30  QMargins &operator/=(float);
31 
32  private:
33  int m_left;
34  int m_top;
35  int m_right;
36  int m_bottom;
37 
38  friend inline bool operator==(const QMargins &, const QMargins &);
39  friend inline bool operator!=(const QMargins &, const QMargins &);
40  };
41 
42 
43  /*****************************************************************************
44  QMargins inline functions
45  *****************************************************************************/
46 
47  inline QMargins::QMargins() : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
48 
49  inline QMargins::QMargins(int aleft, int atop, int aright, int abottom)
50  : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
51 
52  inline bool QMargins::isNull() const
53  {
54  return m_left == 0 && m_top == 0 && m_right == 0 && m_bottom == 0;
55  }
56 
57  inline int QMargins::left() const
58  {
59  return m_left;
60  }
61 
62  inline int QMargins::top() const
63  {
64  return m_top;
65  }
66 
67  inline int QMargins::right() const
68  {
69  return m_right;
70  }
71 
72  inline int QMargins::bottom() const
73  {
74  return m_bottom;
75  }
76 
77 
78  inline void QMargins::setLeft(int aleft)
79  {
80  m_left = aleft;
81  }
82 
83  inline void QMargins::setTop(int atop)
84  {
85  m_top = atop;
86  }
87 
88  inline void QMargins::setRight(int aright)
89  {
90  m_right = aright;
91  }
92 
93  inline void QMargins::setBottom(int abottom)
94  {
95  m_bottom = abottom;
96  }
97 
98  inline bool operator==(const QMargins &m1, const QMargins &m2)
99  {
100  return
101  m1.m_left == m2.m_left &&
102  m1.m_top == m2.m_top &&
103  m1.m_right == m2.m_right &&
104  m1.m_bottom == m2.m_bottom;
105  }
106 
107  inline bool operator!=(const QMargins &m1, const QMargins &m2)
108  {
109  return
110  m1.m_left != m2.m_left ||
111  m1.m_top != m2.m_top ||
112  m1.m_right != m2.m_right ||
113  m1.m_bottom != m2.m_bottom;
114  }
115 
116  inline QMargins operator+(const QMargins &m1, const QMargins &m2)
117  {
118  return QMargins(m1.left() + m2.left(), m1.top() + m2.top(),
119  m1.right() + m2.right(), m1.bottom() + m2.bottom());
120  }
121 
122  inline QMargins operator-(const QMargins &m1, const QMargins &m2)
123  {
124  return QMargins(m1.left() - m2.left(), m1.top() - m2.top(),
125  m1.right() - m2.right(), m1.bottom() - m2.bottom());
126  }
127 
128  inline QMargins operator+(const QMargins &lhs, int rhs)
129  {
130  return QMargins(lhs.left() + rhs, lhs.top() + rhs,
131  lhs.right() + rhs, lhs.bottom() + rhs);
132  }
133 
134  inline QMargins operator+(int lhs, const QMargins &rhs)
135  {
136  return QMargins(rhs.left() + lhs, rhs.top() + lhs,
137  rhs.right() + lhs, rhs.bottom() + lhs);
138  }
139 
140  inline QMargins operator-(const QMargins &lhs, int rhs)
141  {
142  return QMargins(lhs.left() - rhs, lhs.top() - rhs,
143  lhs.right() - rhs, lhs.bottom() - rhs);
144  }
145 
146  inline QMargins operator*(const QMargins &margins, int factor)
147  {
148  return QMargins(margins.left() * factor, margins.top() * factor,
149  margins.right() * factor, margins.bottom() * factor);
150  }
151 
152  inline QMargins operator*(int factor, const QMargins &margins)
153  {
154  return QMargins(margins.left() * factor, margins.top() * factor,
155  margins.right() * factor, margins.bottom() * factor);
156  }
157 
158  inline QMargins operator*(const QMargins &margins, float factor)
159  {
160  return QMargins(Math::Round(margins.left() * factor), Math::Round(margins.top() * factor),
161  Math::Round(margins.right() * factor), Math::Round(margins.bottom() * factor));
162  }
163 
164  inline QMargins operator*(float factor, const QMargins &margins)
165  {
166  return QMargins(Math::Round(margins.left() * factor), Math::Round(margins.top() * factor),
167  Math::Round(margins.right() * factor), Math::Round(margins.bottom() * factor));
168  }
169 
170  inline QMargins operator/(const QMargins &margins, int divisor)
171  {
172  return QMargins(margins.left() / divisor, margins.top() / divisor,
173  margins.right() / divisor, margins.bottom() / divisor);
174  }
175 
176  inline QMargins operator/(const QMargins &margins, float divisor)
177  {
178  return QMargins(Math::Round(margins.left() / divisor), Math::Round(margins.top() / divisor),
179  Math::Round(margins.right() / divisor), Math::Round(margins.bottom() / divisor));
180  }
181 
182  inline QMargins &QMargins::operator+=(const QMargins &margins)
183  {
184  return *this = *this + margins;
185  }
186 
187  inline QMargins &QMargins::operator-=(const QMargins &margins)
188  {
189  return *this = *this - margins;
190  }
191 
192  inline QMargins &QMargins::operator+=(int margin)
193  {
194  m_left += margin;
195  m_top += margin;
196  m_right += margin;
197  m_bottom += margin;
198  return *this;
199  }
200 
201  inline QMargins &QMargins::operator-=(int margin)
202  {
203  m_left -= margin;
204  m_top -= margin;
205  m_right -= margin;
206  m_bottom -= margin;
207  return *this;
208  }
209 
210  inline QMargins &QMargins::operator*=(int factor)
211  {
212  return *this = *this * factor;
213  }
214 
215  inline QMargins &QMargins::operator/=(int divisor)
216  {
217  return *this = *this / divisor;
218  }
219 
220  inline QMargins &QMargins::operator*=(float factor)
221  {
222  return *this = *this * factor;
223  }
224 
225  inline QMargins &QMargins::operator/=(float divisor)
226  {
227  return *this = *this / divisor;
228  }
229 
230  inline QMargins operator+(const QMargins &margins)
231  {
232  return margins;
233  }
234 
235  inline QMargins operator-(const QMargins &margins)
236  {
237  return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
238  }
239 
240 
241 
242  class QMarginsF
243  {
244  public:
245  QMarginsF();
246  QMarginsF(float left, float top, float right, float bottom);
247  QMarginsF(const QMargins &margins);
248 
249  bool isNull() const;
250 
251  float left() const;
252  float top() const;
253  float right() const;
254  float bottom() const;
255 
256  void setLeft(float left);
257  void setTop(float top);
258  void setRight(float right);
259  void setBottom(float bottom);
260 
261  QMarginsF &operator+=(const QMarginsF &margins);
262  QMarginsF &operator-=(const QMarginsF &margins);
263  QMarginsF &operator+=(float addend);
264  QMarginsF &operator-=(float subtrahend);
265  QMarginsF &operator*=(float factor);
266  QMarginsF &operator/=(float divisor);
267 
268  inline QMargins toMargins() const;
269 
270  private:
271  float m_left;
272  float m_top;
273  float m_right;
274  float m_bottom;
275  };
276 
277 
278  /*****************************************************************************
279  QMarginsF inline functions
280  *****************************************************************************/
281 
282  inline QMarginsF::QMarginsF() : m_left(0), m_top(0), m_right(0), m_bottom(0) {}
283 
284  inline QMarginsF::QMarginsF(float aleft, float atop, float aright, float abottom)
285  : m_left(aleft), m_top(atop), m_right(aright), m_bottom(abottom) {}
286 
287  inline QMarginsF::QMarginsF(const QMargins &margins)
288  : m_left((float)margins.left()), m_top((float)margins.top()), m_right((float)margins.right()), m_bottom((float)margins.bottom()) {}
289 
290  inline bool QMarginsF::isNull() const
291  {
292  return Math::FuzzyIsNull(m_left) && Math::FuzzyIsNull(m_top) && Math::FuzzyIsNull(m_right) && Math::FuzzyIsNull(m_bottom);
293  }
294 
295  inline float QMarginsF::left() const
296  {
297  return m_left;
298  }
299 
300  inline float QMarginsF::top() const
301  {
302  return m_top;
303  }
304 
305  inline float QMarginsF::right() const
306  {
307  return m_right;
308  }
309 
310  inline float QMarginsF::bottom() const
311  {
312  return m_bottom;
313  }
314 
315 
316  inline void QMarginsF::setLeft(float aleft)
317  {
318  m_left = aleft;
319  }
320 
321  inline void QMarginsF::setTop(float atop)
322  {
323  m_top = atop;
324  }
325 
326  inline void QMarginsF::setRight(float aright)
327  {
328  m_right = aright;
329  }
330 
331  inline void QMarginsF::setBottom(float abottom)
332  {
333  m_bottom = abottom;
334  }
335 
336  inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs)
337  {
338  return Math::FuzzyCompare(lhs.left(), rhs.left())
339  && Math::FuzzyCompare(lhs.top(), rhs.top())
340  && Math::FuzzyCompare(lhs.right(), rhs.right())
341  && Math::FuzzyCompare(lhs.bottom(), rhs.bottom());
342  }
343 
344  inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs)
345  {
346  return !operator==(lhs, rhs);
347  }
348 
349  inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs)
350  {
351  return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
352  lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom());
353  }
354 
355  inline QMarginsF operator-(const QMarginsF &lhs, const QMarginsF &rhs)
356  {
357  return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(),
358  lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom());
359  }
360 
361  inline QMarginsF operator+(const QMarginsF &lhs, float rhs)
362  {
363  return QMarginsF(lhs.left() + rhs, lhs.top() + rhs,
364  lhs.right() + rhs, lhs.bottom() + rhs);
365  }
366 
367  inline QMarginsF operator+(float lhs, const QMarginsF &rhs)
368  {
369  return QMarginsF(rhs.left() + lhs, rhs.top() + lhs,
370  rhs.right() + lhs, rhs.bottom() + lhs);
371  }
372 
373  inline QMarginsF operator-(const QMarginsF &lhs, float rhs)
374  {
375  return QMarginsF(lhs.left() - rhs, lhs.top() - rhs,
376  lhs.right() - rhs, lhs.bottom() - rhs);
377  }
378 
379  inline QMarginsF operator*(const QMarginsF &lhs, float rhs)
380  {
381  return QMarginsF(lhs.left() * rhs, lhs.top() * rhs,
382  lhs.right() * rhs, lhs.bottom() * rhs);
383  }
384 
385  inline QMarginsF operator*(float lhs, const QMarginsF &rhs)
386  {
387  return QMarginsF(rhs.left() * lhs, rhs.top() * lhs,
388  rhs.right() * lhs, rhs.bottom() * lhs);
389  }
390 
391  inline QMarginsF operator/(const QMarginsF &lhs, float divisor)
392  {
393  return QMarginsF(lhs.left() / divisor, lhs.top() / divisor,
394  lhs.right() / divisor, lhs.bottom() / divisor);
395  }
396 
397  inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins)
398  {
399  return *this = *this + margins;
400  }
401 
402  inline QMarginsF &QMarginsF::operator-=(const QMarginsF &margins)
403  {
404  return *this = *this - margins;
405  }
406 
407  inline QMarginsF &QMarginsF::operator+=(float addend)
408  {
409  m_left += addend;
410  m_top += addend;
411  m_right += addend;
412  m_bottom += addend;
413  return *this;
414  }
415 
416  inline QMarginsF &QMarginsF::operator-=(float subtrahend)
417  {
418  m_left -= subtrahend;
419  m_top -= subtrahend;
420  m_right -= subtrahend;
421  m_bottom -= subtrahend;
422  return *this;
423  }
424 
425  inline QMarginsF &QMarginsF::operator*=(float factor)
426  {
427  return *this = *this * factor;
428  }
429 
430  inline QMarginsF &QMarginsF::operator/=(float divisor)
431  {
432  return *this = *this / divisor;
433  }
434 
435  inline QMarginsF operator+(const QMarginsF &margins)
436  {
437  return margins;
438  }
439 
440  inline QMarginsF operator-(const QMarginsF &margins)
441  {
442  return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
443  }
444 
445  inline QMargins QMarginsF::toMargins() const
446  {
447  return QMargins(Math::Round(m_left), Math::Round(m_top), Math::Round(m_right), Math::Round(m_bottom));
448  }
449 }
static int Round(float fValue)
get the closest integer near the specified float number.
Definition: ParaMath.h:609
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ParaMargins.h:5
Definition: ParaMargins.h:242