position.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/position.h
  3. // Purpose: Common structure and methods for positional information.
  4. // Author: Vadim Zeitlin, Robin Dunn, Brad Anderson, Bryan Petty
  5. // Created: 2007-03-13
  6. // Copyright: (c) 2007 The wxWidgets Team
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_POSITION_H_
  10. #define _WX_POSITION_H_
  11. #include "wx/gdicmn.h"
  12. class WXDLLIMPEXP_CORE wxPosition
  13. {
  14. public:
  15. wxPosition() : m_row(0), m_column(0) {}
  16. wxPosition(int row, int col) : m_row(row), m_column(col) {}
  17. // default copy ctor and assignment operator are okay.
  18. int GetRow() const { return m_row; }
  19. int GetColumn() const { return m_column; }
  20. int GetCol() const { return GetColumn(); }
  21. void SetRow(int row) { m_row = row; }
  22. void SetColumn(int column) { m_column = column; }
  23. void SetCol(int column) { SetColumn(column); }
  24. bool operator==(const wxPosition& p) const
  25. { return m_row == p.m_row && m_column == p.m_column; }
  26. bool operator!=(const wxPosition& p) const
  27. { return !(*this == p); }
  28. wxPosition& operator+=(const wxPosition& p)
  29. { m_row += p.m_row; m_column += p.m_column; return *this; }
  30. wxPosition& operator-=(const wxPosition& p)
  31. { m_row -= p.m_row; m_column -= p.m_column; return *this; }
  32. wxPosition& operator+=(const wxSize& s)
  33. { m_row += s.y; m_column += s.x; return *this; }
  34. wxPosition& operator-=(const wxSize& s)
  35. { m_row -= s.y; m_column -= s.x; return *this; }
  36. wxPosition operator+(const wxPosition& p) const
  37. { return wxPosition(m_row + p.m_row, m_column + p.m_column); }
  38. wxPosition operator-(const wxPosition& p) const
  39. { return wxPosition(m_row - p.m_row, m_column - p.m_column); }
  40. wxPosition operator+(const wxSize& s) const
  41. { return wxPosition(m_row + s.y, m_column + s.x); }
  42. wxPosition operator-(const wxSize& s) const
  43. { return wxPosition(m_row - s.y, m_column - s.x); }
  44. private:
  45. int m_row;
  46. int m_column;
  47. };
  48. #endif // _WX_POSITION_H_