Size.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include <AK/AKString.h>
  3. struct WSAPI_Size;
  4. class Size {
  5. public:
  6. Size() { }
  7. Size(int w, int h) : m_width(w), m_height(h) { }
  8. Size(const WSAPI_Size&);
  9. bool is_null() const { return !m_width && !m_height; }
  10. bool is_empty() const { return m_width <= 0 || m_height <= 0; }
  11. int width() const { return m_width; }
  12. int height() const { return m_height; }
  13. int area() const { return width() * height(); }
  14. void set_width(int w) { m_width = w; }
  15. void set_height(int h) { m_height = h; }
  16. bool operator==(const Size& other) const
  17. {
  18. return m_width == other.m_width &&
  19. m_height == other.m_height;
  20. }
  21. bool operator!=(const Size& other) const
  22. {
  23. return !(*this == other);
  24. }
  25. Size& operator-=(const Size& other)
  26. {
  27. m_width -= other.m_width;
  28. m_height -= other.m_height;
  29. return *this;
  30. }
  31. operator WSAPI_Size() const;
  32. String to_string() const { return String::format("[%d,%d]", m_width, m_height); }
  33. private:
  34. int m_width { 0 };
  35. int m_height { 0 };
  36. };