fix bugs that button renderer generated bad values if it zero-size

This commit is contained in:
Jinhao
2017-07-01 07:32:45 +08:00
parent fa80519526
commit afd8225875
4 changed files with 29 additions and 19 deletions

View File

@@ -591,21 +591,21 @@ namespace nana
return *this;
}
/*
rectangle& rectangle::set_size(const size& sz)
{
width = sz.width;
height = sz.height;
return *this;
}
*/
rectangle& rectangle::pare_off(int pixels)
{
x += pixels;
y += pixels;
width -= (pixels << 1);
height -= (pixels << 1);
auto const px_twice = (pixels << 1);
if (px_twice > static_cast<int>(width))
width = 0;
else
width -= px_twice;
if (px_twice > static_cast<int>(height))
height = 0;
else
height -= px_twice;
return *this;
}

View File

@@ -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);

View File

@@ -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<color_rgb>(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);