SPoint.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #include "../../lib/int3.h"
  3. #include <SDL_events.h>
  4. /*
  5. * SPoint.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  13. // A point with x/y coordinate, used mostly for graphic rendering
  14. struct SPoint
  15. {
  16. int x, y;
  17. //constructors
  18. SPoint()
  19. {
  20. x = y = 0;
  21. };
  22. SPoint(int X, int Y)
  23. :x(X),y(Y)
  24. {};
  25. SPoint(const int3 &a)
  26. :x(a.x),y(a.y)
  27. {}
  28. SPoint(const SDL_MouseMotionEvent &a)
  29. :x(a.x),y(a.y)
  30. {}
  31. template<typename T>
  32. SPoint operator+(const T &b) const
  33. {
  34. return SPoint(x+b.x,y+b.y);
  35. }
  36. template<typename T>
  37. SPoint operator*(const T &mul) const
  38. {
  39. return SPoint(x*mul, y*mul);
  40. }
  41. template<typename T>
  42. SPoint& operator+=(const T &b)
  43. {
  44. x += b.x;
  45. y += b.y;
  46. return *this;
  47. }
  48. template<typename T>
  49. SPoint operator-(const T &b) const
  50. {
  51. return SPoint(x - b.x, y - b.y);
  52. }
  53. template<typename T>
  54. SPoint& operator-=(const T &b)
  55. {
  56. x -= b.x;
  57. y -= b.y;
  58. return *this;
  59. }
  60. bool operator<(const SPoint &b) const //product order
  61. {
  62. return x < b.x && y < b.y;
  63. }
  64. template<typename T> SPoint& operator=(const T &t)
  65. {
  66. x = t.x;
  67. y = t.y;
  68. return *this;
  69. }
  70. template<typename T> bool operator==(const T &t) const
  71. {
  72. return x == t.x && y == t.y;
  73. }
  74. template<typename T> bool operator!=(const T &t) const
  75. {
  76. return !(*this == t);
  77. }
  78. };