Merge branch 'develop'

This commit is contained in:
Jinhao 2017-07-03 22:59:35 +08:00
commit b77c2b2eac
8 changed files with 65 additions and 39 deletions

View File

@ -445,7 +445,13 @@ namespace nana
size dimension() const noexcept; size dimension() const noexcept;
rectangle& dimension(const size&) 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); /// Pares the specified pixels off the rectangle.
/**
* It's equal to x += pixels; y + pixels; width -= (pixels << 1); height -= (pixels << 1);
* @param pixels The number of pixels to be pared. If the number that multiples pixels twice is larger than width/height, the width/height will be zero. If the pixels is a negative number, the width/height is add the number that multiple pixels twice.
* @return The reference of *this.
*/
rectangle& pare_off(int pixels);
int right() const noexcept; int right() const noexcept;
int bottom() const noexcept; int bottom() const noexcept;

View File

@ -112,10 +112,6 @@
# define STD_CODECVT_NOT_SUPPORTED # define STD_CODECVT_NOT_SUPPORTED
# endif // _MSC_VER == 1900 # endif // _MSC_VER == 1900
# if (_MSC_VER < 1910) //VS2017 RTM
# define _enable_std_clamp
# endif
#elif defined(__clang__) //Clang #elif defined(__clang__) //Clang
#include <iosfwd> //Introduces some implement-specific flags of ISO C++ Library #include <iosfwd> //Introduces some implement-specific flags of ISO C++ Library
@ -195,8 +191,18 @@
# endif # endif
#endif #endif
#if (!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603) //Detects the feature std::clamp
# ifndef _enable_std_clamp
//Visual C++ 2017 with /std:c++latest provides the std::clamp
#if !defined(_MSVC_LANG) || (_MSVC_LANG < 201403L)
// std::clamp's feature test macro is defined inside <algorithm>
// But nana still avoids introducing <algorithm> on MSVC.
# ifndef _MSC_VER
# include <algorithm>
# endif
# if ((!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603)) && (!defined(_enable_std_clamp))
# define _enable_std_clamp # define _enable_std_clamp
# endif # endif
#endif #endif

View File

@ -16,6 +16,8 @@
#include "../basis.hpp" #include "../basis.hpp"
#include <nana/paint/image.hpp> #include <nana/paint/image.hpp>
#include <functional>
namespace nana namespace nana
{ {
namespace detail namespace detail

View File

@ -1,7 +1,7 @@
/* /*
* Pixel Buffer Implementation * Pixel Buffer Implementation
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at

View File

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

View File

@ -294,7 +294,7 @@ namespace nana
void drawer::refresh() 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_->refreshing = true;
data_impl_->realizer->refresh(graphics); data_impl_->realizer->refresh(graphics);

View File

@ -1196,7 +1196,11 @@ namespace paint
#elif defined(NANA_X11) #elif defined(NANA_X11)
if (nullptr == impl_->handle) return; 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; double r, g, b;
const double delta_r = (to.r() - (r = from.r())) / deltapx; const double delta_r = (to.r() - (r = from.r())) / deltapx;
const double delta_g = (to.g() - (g = from.g())) / 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(); Display * disp = nana::detail::platform_spec::instance().open_display();
impl_->handle->set_color(static_cast<color_rgb>(last_color)); impl_->handle->set_color(static_cast<color_rgb>(last_color));
impl_->handle->update_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 (endpos > 0)
{ {
if (vertical) if (vertical)
{ {
int x1 = rct.x, x2 = rct.right(); int x1 = good_rct.x, x2 = good_rct.right();
auto y = rct.y; auto y = good_rct.y;
for (; y < endpos; ++y) for (; y < endpos; ++y)
{ {
::XDrawLine(disp, impl_->handle->pixmap, impl_->handle->context, x1, y, x2, y); ::XDrawLine(disp, impl_->handle->pixmap, impl_->handle->context, x1, y, x2, y);
@ -1228,8 +1232,8 @@ namespace paint
} }
else else
{ {
int y1 = rct.y, y2 = rct.bottom(); int y1 = good_rct.y, y2 = good_rct.bottom();
auto x = rct.x; auto x = good_rct.x;
for (; x < endpos; ++x) for (; x < endpos; ++x)
{ {
::XDrawLine(disp, impl_->handle->pixmap, impl_->handle->context, x, y1, x, y2); ::XDrawLine(disp, impl_->handle->pixmap, impl_->handle->context, x, y1, x, y2);

View File

@ -1,7 +1,7 @@
/* /*
* Pixel Buffer Implementation * Pixel Buffer Implementation
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -328,10 +328,14 @@ namespace nana{ namespace paint
else if(16 == depth) else if(16 == depth)
{ {
//The format of Xorg 16bits depth is 565 //The format of Xorg 16bits depth is 565
std::unique_ptr<unsigned short[]> table_holder(new unsigned short[256]); std::unique_ptr<unsigned short[]> table_5_6bit_holder(new unsigned short[512]);
unsigned short * const fast_table = table_holder.get(); auto * const table_5bit = table_5_6bit_holder.get();
auto * const table_6bit = table_5_6bit_holder.get() + 256;
for(int i = 0; i < 256; ++i) for(int i = 0; i < 256; ++i)
fast_table[i] = i * 31 / 255; {
table_5bit[i] = i * 31 / 255;
table_6bit[i] = i * 63 / 255;
}
std::size_t length = width * height; std::size_t length = width * height;
@ -342,7 +346,7 @@ namespace nana{ namespace paint
{ {
for(auto i = raw_pixel_buffer, end = raw_pixel_buffer + length; i != end; ++i) for(auto i = raw_pixel_buffer, end = raw_pixel_buffer + length; i != end; ++i)
{ {
*(pixbuf_16bits++) = (fast_table[i->element.red] << 11) | ( (i->element.green * 63 / 255) << 6) | fast_table[i->element.blue]; *(pixbuf_16bits++) = (table_5bit[i->element.red] << 11) | ( (table_6bit[i->element.green] << 5) | table_5bit[i->element.blue]);
} }
} }
else if(height) else if(height)
@ -355,7 +359,7 @@ namespace nana{ namespace paint
{ {
for(auto i = sp, end = sp + width; i != end; ++i) for(auto i = sp, end = sp + width; i != end; ++i)
{ {
*(pixbuf_16bits++) = (fast_table[i->element.red] << 11) | ((i->element.green * 63 / 255) << 6) | fast_table[i->element.blue]; *(pixbuf_16bits++) = (table_5bit[i->element.red] << 11) | (table_6bit[i->element.green] << 5) | table_5bit[i->element.blue];
} }
if(++top < height) if(++top < height)
@ -511,10 +515,14 @@ namespace nana{ namespace paint
else if(16 == image->depth) else if(16 == image->depth)
{ {
//The format of Xorg 16bits depth is 565 //The format of Xorg 16bits depth is 565
std::unique_ptr<unsigned[]> table_holder(new unsigned[32]); std::unique_ptr<unsigned[]> table_holder{new unsigned[96]};
unsigned * const fast_table = table_holder.get(); auto * const table_5bit = table_holder.get();
for(unsigned i = 0; i < 32; ++i) for(std::size_t i = 0; i < 32; ++i)
fast_table[i] = (i * 255 / 31); table_5bit[i] = (i * 255 / 31);
auto * const table_6bit = table_holder.get() + 32;
for(std::size_t i = 0; i < 64; ++i)
table_6bit[i] = (i* 255 / 63);
pixbuf += (r.x - want_r.x); pixbuf += (r.x - want_r.x);
pixbuf += (r.y - want_r.y) * want_r.width; pixbuf += (r.y - want_r.y) * want_r.width;
@ -525,9 +533,9 @@ namespace nana{ namespace paint
for(int x = 0; x < image->width; ++x) for(int x = 0; x < image->width; ++x)
{ {
pixbuf[x].element.red = fast_table[(px_data[x] >> 11) & 0x1F]; pixbuf[x].element.red = table_5bit[(px_data[x] >> 11) & 0x1F];
pixbuf[x].element.green = (px_data[x] >> 5) & 0x3F; pixbuf[x].element.green = table_6bit[(px_data[x] >> 5) & 0x3F];
pixbuf[x].element.blue = fast_table[px_data[x] & 0x1F]; pixbuf[x].element.blue = table_5bit[px_data[x] & 0x1F];
pixbuf[x].element.alpha_channel = 0; pixbuf[x].element.alpha_channel = 0;
} }
img_data += image->bytes_per_line; img_data += image->bytes_per_line;