2018-10-12 10:29:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-02-10 10:07:13 +00:00
|
|
|
#include <AK/AKString.h>
|
|
|
|
|
2019-02-15 08:17:18 +00:00
|
|
|
struct WSAPI_Size;
|
2019-01-14 13:21:51 +00:00
|
|
|
|
2018-10-12 10:29:58 +00:00
|
|
|
class Size {
|
|
|
|
public:
|
2019-06-07 09:46:55 +00:00
|
|
|
Size() {}
|
|
|
|
Size(int w, int h)
|
|
|
|
: m_width(w)
|
|
|
|
, m_height(h)
|
|
|
|
{
|
|
|
|
}
|
2019-02-15 08:17:18 +00:00
|
|
|
Size(const WSAPI_Size&);
|
2018-10-12 10:29:58 +00:00
|
|
|
|
2019-02-20 23:21:23 +00:00
|
|
|
bool is_null() const { return !m_width && !m_height; }
|
|
|
|
bool is_empty() const { return m_width <= 0 || m_height <= 0; }
|
2018-10-12 10:29:58 +00:00
|
|
|
|
|
|
|
int width() const { return m_width; }
|
|
|
|
int height() const { return m_height; }
|
|
|
|
|
2019-02-07 22:13:47 +00:00
|
|
|
int area() const { return width() * height(); }
|
|
|
|
|
2019-01-16 16:54:06 +00:00
|
|
|
void set_width(int w) { m_width = w; }
|
|
|
|
void set_height(int h) { m_height = h; }
|
2018-10-12 10:29:58 +00:00
|
|
|
|
2019-01-09 01:06:04 +00:00
|
|
|
bool operator==(const Size& other) const
|
|
|
|
{
|
2019-06-07 09:46:55 +00:00
|
|
|
return m_width == other.m_width && m_height == other.m_height;
|
2019-01-09 01:06:04 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 10:19:38 +00:00
|
|
|
bool operator!=(const Size& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2019-02-10 10:07:13 +00:00
|
|
|
Size& operator-=(const Size& other)
|
|
|
|
{
|
|
|
|
m_width -= other.m_width;
|
|
|
|
m_height -= other.m_height;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-03-19 02:00:42 +00:00
|
|
|
Size& operator+=(const Size& other)
|
|
|
|
{
|
|
|
|
m_width += other.m_width;
|
|
|
|
m_height += other.m_height;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-02-15 08:17:18 +00:00
|
|
|
operator WSAPI_Size() const;
|
2019-01-14 13:21:51 +00:00
|
|
|
|
2019-03-21 04:24:42 +00:00
|
|
|
String to_string() const { return String::format("[%dx%d]", m_width, m_height); }
|
2019-02-10 10:07:13 +00:00
|
|
|
|
2018-10-12 10:29:58 +00:00
|
|
|
private:
|
|
|
|
int m_width { 0 };
|
|
|
|
int m_height { 0 };
|
|
|
|
};
|