Basic.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. namespace Gfx
  3. {
  4. struct Point
  5. {
  6. si32 x;
  7. si32 y;
  8. Point() : x(0), y(0) {};
  9. Point(si32 _x, si32 _y) : x(_x), y(_y) {};
  10. bool operator==(const Point &p) const
  11. {
  12. return (x == p.x) && (y == p.y);
  13. }
  14. bool operator!=(const Point &p) const
  15. {
  16. return !(*this == p);
  17. }
  18. Point& operator+=(const Point &p)
  19. {
  20. x += p.x;
  21. y += p.y;
  22. return *this;
  23. }
  24. Point& operator-=(const Point &p)
  25. {
  26. x -= p.x;
  27. y -= p.y;
  28. return *this;
  29. }
  30. };
  31. struct Rect : Point
  32. {
  33. ui32 w;
  34. ui32 h;
  35. Rect() : w(0), h(0) {};
  36. Rect(const Point & lt) : Point(lt), w(0), h(0) {};
  37. Rect(const Point & lt, const Point & sz) : Point(lt), w(sz.x), h(sz.y) {};
  38. Rect(si32 _x, si32 _y, ui32 _w, ui32 _h) : Point(_x, _y), w(_w), h(_h) {};
  39. Rect& operator=(const Point &p)
  40. {
  41. x = p.x;
  42. y = p.y;
  43. return *this;
  44. }
  45. si32 leftX() const { return x; };
  46. si32 centerX() const { return x+w/2; };
  47. si32 rightX() const { return x+w; };
  48. si32 topY() const { return y; };
  49. si32 centerY() const { return y+h/2; }
  50. si32 bottomY() const { return y+h; };
  51. //top left corner of this rect
  52. Point topLeft() const { return *this; }
  53. //top right corner of this rect
  54. Point topRight() const { return Point(x+w, y); }
  55. //bottom left corner of this rect
  56. Point bottomLeft() const { return Point(x, y+h); }
  57. //bottom right corner of this rect
  58. Point bottomRight() const { return Point(x+w, y+h); }
  59. //add x,y and copy w,h from p
  60. void addOffs_copySize(const Rect &p);
  61. //rect intersection
  62. Rect Rect::operator&(const Rect &p) const;
  63. };
  64. /* Color transform matrix for: grayscale, clone, bloodlust, etc */
  65. typedef float ColorMatrix[3][3];
  66. }