remove conversion constructors of point,size and rectangle

This commit is contained in:
Jinhao
2016-05-22 02:48:00 +08:00
parent ceff7c0c27
commit 9947d0c511
10 changed files with 147 additions and 176 deletions

View File

@@ -84,7 +84,7 @@ namespace nana
enum class mouse_action
{
begin, normal = begin, over, pressed, end
begin, normal = begin, hovered, pressed, end
};
enum class element_state
@@ -337,6 +337,8 @@ namespace nana
bool operator==(const color& other) const;
bool operator!=(const color& other) const;
friend color operator+(const color&, const color&);
private:
double r_{ 0.0 };
double g_{ 0.0 };
@@ -344,60 +346,91 @@ namespace nana
double a_{ 0.0 }; //invisible
};
struct rectangle;
struct point
template<typename T>
struct basic_point
{
point();
point(int x, int y);
point(const rectangle&);
//typedef-names
using value_type = T;
point& operator=(const rectangle&);
bool operator==(const point&) const;
bool operator!=(const point&) const;
bool operator<(const point&) const;
bool operator<=(const point&) const;
bool operator>(const point&) const;
bool operator>=(const point&) const;
//data member
value_type x{};
value_type y{};
point operator-(const point&) const;
point operator+(const point&) const;
point& operator-=(const point&);
point& operator+=(const point&);
//member functions
basic_point() = default;
int x;
int y;
basic_point(value_type x, value_type y)
: x{ x }, y{y}
{}
bool operator==(const basic_point& other) const noexcept
{
return (x == other.x && y == other.y);
}
bool operator!=(const basic_point& other) const noexcept
{
return (x != other.x || y != other.y);
}
bool operator<(const basic_point& other) const noexcept
{
return ((y < other.y) || (y == other.y && x < other.x));
}
bool operator<=(const basic_point& other) const noexcept
{
return ((y < other.y) || (y == other.y && x <= other.x));
}
bool operator>(const basic_point& other) const noexcept
{
return ((y > other.y) || (y == other.y && x > other.x));
}
bool operator>=(const basic_point& other) const noexcept
{
return ((y > other.y) || (y == other.y && x >= other.x));
}
basic_point operator-(const basic_point& other) const noexcept
{
return{ x - other.x, y - other.y };
}
basic_point operator+(const basic_point& other) const noexcept
{
return{ x + other.x, y + other.y };
}
basic_point& operator-=(const basic_point& other) noexcept
{
x -= other.x;
y -= other.y;
return *this;
}
basic_point& operator+=(const basic_point& other) noexcept
{
x += other.x;
y += other.y;
return *this;
}
};
struct upoint
{
typedef unsigned value_type;
upoint();
upoint(value_type x, value_type y);
bool operator==(const upoint&) const;
bool operator!=(const upoint&) const;
bool operator<(const upoint&) const;
bool operator<=(const upoint&) const;
bool operator>(const upoint&) const;
bool operator>=(const upoint&) const;
value_type x;
value_type y;
};
using point = basic_point<int>;
using upoint = basic_point<unsigned>;
struct size
{
using value_type = unsigned;
size();
size(value_type width, value_type height);
size(const rectangle&);
size& operator=(const rectangle&);
bool empty() const; ///< true if width * height == 0
bool is_hit(const point&) const; ///< Assume it is a rectangle at (0,0), and check whether a specified position is in the rectange.
size& shift();
bool operator==(const size& rhs) const;
bool operator!=(const size& rhs) const;
size operator+(const size&) const;
@@ -419,8 +452,11 @@ namespace nana
rectangle& operator=(const point&);
rectangle& operator=(const size&);
rectangle& set_pos(const point&);
rectangle& set_size(const size&);
point position() const noexcept;
rectangle& position(const point&) noexcept;
size dimension() const noexcept;
rectangle& dimension(const size&) noexcept;
rectangle& pare_off(int pixels); ///<Pares the specified pixels off the rectangle. It's equal to x += pixels; y + pixels; width -= (pixels << 1); height -= (pixels << 1);
@@ -428,7 +464,8 @@ namespace nana
int bottom() const;
bool is_hit(int x, int y) const;
bool is_hit(const point& pos) const;
bool empty() const; ///< true if width * height == 0
bool empty() const; ///< true if width * height == 0.
rectangle& shift(); ///< Swap position x and y, size width and height.
int x;
int y;

View File

@@ -144,7 +144,7 @@ namespace nana{
{
if((focused_wd == wd) && (static_cast<unsigned>(wd->effect.edge_nimbus) & static_cast<unsigned>(effects::edge_nimbus::active)))
return true;
else if((static_cast<unsigned>(wd->effect.edge_nimbus) & static_cast<unsigned>(effects::edge_nimbus::over)) && (wd->flags.action == mouse_action::over))
else if((static_cast<unsigned>(wd->effect.edge_nimbus) & static_cast<unsigned>(effects::edge_nimbus::over)) && (wd->flags.action == mouse_action::hovered))
return true;
return false;
}