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;
}

View File

@ -528,124 +528,25 @@ namespace nana
return (px_color().value != other.px_color().value);
}
color operator+(const color& x, const color& y)
{
double a = x.a_ + y.a_;
auto r = static_cast<unsigned>(x.r_ + y.r_);
auto g = static_cast<unsigned>(x.g_ + y.g_);
auto b = static_cast<unsigned>(x.b_ + y.b_);
return color{
r > 255 ? 255 : r,
g > 255 ? 255 : g,
b > 255 ? 255 : b,
a > 1.0 ? 1.0 : a };
}
//end class color
//struct point
point::point():x(0), y(0){}
point::point(int x, int y):x(x), y(y){}
point::point(const rectangle& r)
: x(r.x), y(r.y)
{}
point& point::operator=(const rectangle& r)
{
x = r.x;
y = r.y;
return *this;
}
bool point::operator==(const point& rhs) const
{
return ((x == rhs.x) && (y == rhs.y));
}
bool point::operator!=(const point& rhs) const
{
return ((x != rhs.x) || (y != rhs.y));
}
bool point::operator<(const point& rhs) const
{
return ((y < rhs.y) || (y == rhs.y && x < rhs.x));
}
bool point::operator<=(const point& rhs) const
{
return ((y < rhs.y) || (y == rhs.y && x <= rhs.x));
}
bool point::operator>(const point& rhs) const
{
return ((y > rhs.y) || (y == rhs.y && x > rhs.x));
}
bool point::operator>=(const point& rhs) const
{
return ((y > rhs.y) || (y == rhs.y && x >= rhs.x));
}
point point::operator-(const point& rhs) const
{
return{x - rhs.x, y - rhs.y};
}
point point::operator+(const point& rhs) const
{
return{ x + rhs.x, y + rhs.y };
}
point& point::operator-=(const point& rhs)
{
x -= rhs.x;
y -= rhs.y;
return *this;
}
point& point::operator+=(const point& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
//end struct point
//struct upoint
upoint::upoint():x(0), y(0){}
upoint::upoint(unsigned x, unsigned y):x(x), y(y){}
bool upoint::operator==(const upoint& rhs) const
{
return ((x == rhs.x) && (y == rhs.y));
}
bool upoint::operator!=(const upoint& rhs) const
{
return ((x != rhs.x) || (y != rhs.y));
}
bool upoint::operator<(const upoint& rhs) const
{
return ((y < rhs.y) || (y == rhs.y && x < rhs.x));
}
bool upoint::operator<=(const upoint& rhs) const
{
return ((y < rhs.y) || (y == rhs.y && x <= rhs.x));
}
bool upoint::operator>(const upoint& rhs) const
{
return ((y > rhs.y) || (y == rhs.y && x > rhs.x));
}
bool upoint::operator>=(const upoint& rhs) const
{
return ((y > rhs.y) || (y == rhs.y && x >= rhs.x));
}
//end struct upoint
//struct size
size::size():width(0), height(0){}
size::size(value_type width, value_type height) : width(width), height(height){}
size::size(const rectangle& r)
: width(r.width), height(r.height)
{}
size& size::operator=(const rectangle& r)
{
width = r.width;
height = r.height;
return *this;
}
bool size::empty() const
{
@ -657,6 +558,12 @@ namespace nana
return (0 <= pos.x && pos.x < static_cast<int>(width) && 0 <= pos.y && pos.y < static_cast<int>(height));
}
size& size::shift()
{
std::swap(width, height);
return *this;
}
bool size::operator==(const size& rhs) const
{
return (width == rhs.width) && (height == rhs.height);
@ -714,19 +621,38 @@ namespace nana
return *this;
}
rectangle& rectangle::set_pos(const point& pos)
point rectangle::position() const
{
x = pos.x;
y = pos.y;
return{ x, y };
}
rectangle& rectangle::position(const point& p)
{
x = p.x;
y = p.y;
return *this;
}
size rectangle::dimension() const
{
return{width, height};
}
rectangle& rectangle::dimension(const size& sz)
{
width = sz.width;
height = sz.height;
return *this;
}
/*
rectangle& rectangle::set_size(const size& sz)
{
width = sz.width;
height = sz.height;
return *this;
}
*/
rectangle& rectangle::pare_off(int pixels)
{
@ -763,6 +689,13 @@ namespace nana
{
return (0 == width) || (0 == height);
}
rectangle& rectangle::shift()
{
std::swap(x, y);
std::swap(width, height);
return *this;
}
//end struct rectangle
//class rectangle_rotator

View File

@ -354,8 +354,8 @@ namespace nana
void basic_window::_m_init_pos_and_size(basic_window* parent, const rectangle& r)
{
pos_owner = pos_root = r;
dimension = r;
pos_owner = pos_root = r.position();
dimension = r.dimension();
if (parent)
pos_root += parent->pos_root;

View File

@ -999,7 +999,7 @@ namespace detail
if (msgwnd->dimension.is_hit(arg.pos))
{
msgwnd->set_action(mouse_action::over);
msgwnd->set_action(mouse_action::hovered);
if ((::nana::mouse::left_button == arg.button) && (pressed_wd == msgwnd))
{
click_arg.window_handle = reinterpret_cast<window>(msgwnd);
@ -1065,7 +1065,7 @@ namespace detail
if (pressed_wd == msgwnd)
msgwnd->set_action(mouse_action::pressed);
else if (mouse_action::pressed != msgwnd->flags.action)
msgwnd->set_action(mouse_action::over);
msgwnd->set_action(mouse_action::hovered);
}
arg_mouse arg;
assign_arg(arg, msgwnd, message, pmdec);
@ -1084,7 +1084,7 @@ namespace detail
if (pressed_wd == msgwnd)
msgwnd->set_action(mouse_action::pressed);
else if (mouse_action::pressed != msgwnd->flags.action)
msgwnd->set_action(mouse_action::over);
msgwnd->set_action(mouse_action::hovered);
hovered_wd = msgwnd;
arg.evt_code = event_code::mouse_enter;

View File

@ -1300,7 +1300,7 @@ namespace nana
if (stretch_all_)
{
if (from_r.width == to_r.width && from_r.height == to_r.height)
method_->paste(from_r, dst, to_r);
method_->paste(from_r, dst, to_r.position());
else
method_->stretch(from_r, dst, to_r);
@ -1392,7 +1392,7 @@ namespace nana
if (top_)
{
src_r.height = top_;
method_->paste(src_r, dst, to_r);
method_->paste(src_r, dst, to_r.position());
}
if (bottom_)
{

View File

@ -135,7 +135,7 @@ namespace nana
if (!x_pointed_)
return;
x_state_ = ::nana::mouse_action::over;
x_state_ = ::nana::mouse_action::hovered;
refresh(graph);
API::dev::lazy_refresh();
@ -387,7 +387,7 @@ namespace nana
}
panels_.emplace_back();
widget * w=wdg.get();
auto wdg = wdg.get();
panels_.back().widget_ptr.swap(wdg);
for (auto & pn : panels_)
@ -395,7 +395,7 @@ namespace nana
if (pn.widget_ptr)
pn.widget_ptr->move(r);
}
return w;
return wdg;
}
return nullptr;
}

View File

@ -1358,7 +1358,7 @@ namespace API
{
case nana::mouse_action::normal:
return (is_focused ? nana::element_state::focus_normal : nana::element_state::normal);
case nana::mouse_action::over:
case nana::mouse_action::hovered:
return (is_focused ? nana::element_state::focus_hovered : nana::element_state::hovered);
case nana::mouse_action::pressed:
return nana::element_state::pressed;

View File

@ -89,7 +89,7 @@ namespace nana
if(ui_el_.what == ui_el_.item_root)
{
_m_item_bground(graph, r.x + 1, r.y, r.width - 2, r.height, (state == mouse_action::pressed ? mouse_action::pressed : mouse_action::over));
_m_item_bground(graph, r.x + 1, r.y, r.width - 2, r.height, (state == mouse_action::pressed ? mouse_action::pressed : mouse_action::hovered));
graph.rectangle(r, false, static_cast<color_rgb>(0x3C7FB1));
if(state == mouse_action::pressed)
{
@ -114,8 +114,8 @@ namespace nana
mouse_action state_arrow, state_name;
if(mouse_action::pressed != state)
{
state_arrow = (ui_el_.what == ui_el_.item_arrow ? mouse_action::over : mouse_action::normal);
state_name = (ui_el_.what == ui_el_.item_name ? mouse_action::over : mouse_action::normal);
state_arrow = (ui_el_.what == ui_el_.item_arrow ? mouse_action::hovered : mouse_action::normal);
state_name = (ui_el_.what == ui_el_.item_name ? mouse_action::hovered : mouse_action::normal);
}
else
{
@ -170,7 +170,7 @@ namespace nana
nana::color clr_top(static_cast<color_rgb>(0xEAEAEA)), clr_bottom(static_cast<color_rgb>(0xDCDCDC));
switch(state)
{
case mouse_action::over:
case mouse_action::hovered:
clr_top.from_rgb(0xdf, 0xf2, 0xfc);
clr_bottom.from_rgb(0xa9, 0xda, 0xf5);
break;

View File

@ -1270,7 +1270,7 @@ namespace nana
if(size.width > attr.area.width || size.height > attr.area.height)
{
nana::size fit_size;
nana::fit_zoom(size, attr.area, fit_size);
nana::fit_zoom(size, attr.area.dimension(), fit_size);
attr.area.x += (attr.area.width - fit_size.width) / 2;
attr.area.y += (attr.area.height - fit_size.height) / 2;
@ -1444,6 +1444,7 @@ namespace nana
attr.area = node_r_;
if (impl_->data.comp_placer->locate(comp, node_attr_, &attr.area))
{
attr.mouse_pointed = node_attr_.mouse_pointed;
attr.area.x += pos_.x;
attr.area.y += pos_.y;
return true;