diff --git a/include/nana/basic_types.hpp b/include/nana/basic_types.hpp index 4d13b6ec..adbf55da 100644 --- a/include/nana/basic_types.hpp +++ b/include/nana/basic_types.hpp @@ -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 + 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; + using upoint = basic_point; 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); ///(wd->effect.edge_nimbus) & static_cast(effects::edge_nimbus::active))) return true; - else if((static_cast(wd->effect.edge_nimbus) & static_cast(effects::edge_nimbus::over)) && (wd->flags.action == mouse_action::over)) + else if((static_cast(wd->effect.edge_nimbus) & static_cast(effects::edge_nimbus::over)) && (wd->flags.action == mouse_action::hovered)) return true; return false; } diff --git a/source/basic_types.cpp b/source/basic_types.cpp index c8bd2c34..5820c3cf 100644 --- a/source/basic_types.cpp +++ b/source/basic_types.cpp @@ -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(x.r_ + y.r_); + auto g = static_cast(x.g_ + y.g_); + auto b = static_cast(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(width) && 0 <= pos.y && pos.y < static_cast(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 diff --git a/source/gui/detail/basic_window.cpp b/source/gui/detail/basic_window.cpp index 6e592a0e..5c149ec3 100644 --- a/source/gui/detail/basic_window.cpp +++ b/source/gui/detail/basic_window.cpp @@ -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; diff --git a/source/gui/detail/bedrock_windows.cpp b/source/gui/detail/bedrock_windows.cpp index 098f7556..b84549bd 100644 --- a/source/gui/detail/bedrock_windows.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -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(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; diff --git a/source/gui/element.cpp b/source/gui/element.cpp index e1f4b649..48adbbfc 100644 --- a/source/gui/element.cpp +++ b/source/gui/element.cpp @@ -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_) { diff --git a/source/gui/place_parts.hpp b/source/gui/place_parts.hpp index 1c969884..5f777e3b 100644 --- a/source/gui/place_parts.hpp +++ b/source/gui/place_parts.hpp @@ -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; } diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 6dcfc63a..133b8326 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -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; diff --git a/source/gui/widgets/categorize.cpp b/source/gui/widgets/categorize.cpp index a79073d4..cf29e267 100644 --- a/source/gui/widgets/categorize.cpp +++ b/source/gui/widgets/categorize.cpp @@ -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(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(0xEAEAEA)), clr_bottom(static_cast(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; diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index 11b4508f..e319b54f 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -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; @@ -1442,8 +1442,9 @@ namespace nana virtual bool comp_attribute(component_t comp, comp_attribute_t& attr) const override { attr.area = node_r_; - if(impl_->data.comp_placer->locate(comp, node_attr_, &attr.area)) + 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;