From afd8225875d43167c6060fdb13db4d4ab499e38e Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 1 Jul 2017 07:32:45 +0800 Subject: [PATCH] fix bugs that button renderer generated bad values if it zero-size --- include/nana/basic_types.hpp | 8 +++++++- source/basic_types.cpp | 22 +++++++++++----------- source/gui/detail/drawer.cpp | 2 +- source/paint/graphics.cpp | 16 ++++++++++------ 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/nana/basic_types.hpp b/include/nana/basic_types.hpp index af9faa26..b190ea42 100644 --- a/include/nana/basic_types.hpp +++ b/include/nana/basic_types.hpp @@ -445,7 +445,13 @@ namespace nana size dimension() const noexcept; rectangle& dimension(const size&) noexcept; - rectangle& pare_off(int pixels); /// static_cast(width)) + width = 0; + else + width -= px_twice; + + if (px_twice > static_cast(height)) + height = 0; + else + height -= px_twice; + return *this; } diff --git a/source/gui/detail/drawer.cpp b/source/gui/detail/drawer.cpp index c6619076..f73cb3ee 100644 --- a/source/gui/detail/drawer.cpp +++ b/source/gui/detail/drawer.cpp @@ -294,7 +294,7 @@ namespace nana void drawer::refresh() { - if (data_impl_->realizer && !data_impl_->refreshing) + if (data_impl_->realizer && (!(data_impl_->refreshing || graphics.size().empty()))) { data_impl_->refreshing = true; data_impl_->realizer->refresh(graphics); diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 21aa4948..62940369 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -1196,7 +1196,11 @@ namespace paint #elif defined(NANA_X11) if (nullptr == impl_->handle) return; - double deltapx = double(vertical ? rct.height : rct.width); + nana::rectangle good_rct; + if(!nana::overlap(nana::rectangle{ size() }, rct, good_rct)) + return; + + double deltapx = double(vertical ? good_rct.height : good_rct.width); double r, g, b; const double delta_r = (to.r() - (r = from.r())) / deltapx; const double delta_g = (to.g() - (g = from.g())) / deltapx; @@ -1207,13 +1211,13 @@ namespace paint Display * disp = nana::detail::platform_spec::instance().open_display(); impl_->handle->set_color(static_cast(last_color)); impl_->handle->update_color(); - const int endpos = deltapx + (vertical ? rct.y : rct.x); + const int endpos = deltapx + (vertical ? good_rct.y : good_rct.x); if (endpos > 0) { if (vertical) { - int x1 = rct.x, x2 = rct.right(); - auto y = rct.y; + int x1 = good_rct.x, x2 = good_rct.right(); + auto y = good_rct.y; for (; y < endpos; ++y) { ::XDrawLine(disp, impl_->handle->pixmap, impl_->handle->context, x1, y, x2, y); @@ -1228,8 +1232,8 @@ namespace paint } else { - int y1 = rct.y, y2 = rct.bottom(); - auto x = rct.x; + int y1 = good_rct.y, y2 = good_rct.bottom(); + auto x = good_rct.x; for (; x < endpos; ++x) { ::XDrawLine(disp, impl_->handle->pixmap, impl_->handle->context, x, y1, x, y2);