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); /// //Introduces some implement-specific flags of ISO C++ Library @@ -195,8 +191,18 @@ # endif #endif -#if (!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603) -# ifndef _enable_std_clamp +//Detects the feature 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 +// But nana still avoids introducing on MSVC. +# ifndef _MSC_VER +# include +# endif + +# if ((!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603)) && (!defined(_enable_std_clamp)) # define _enable_std_clamp # endif #endif diff --git a/include/nana/gui/detail/native_window_interface.hpp b/include/nana/gui/detail/native_window_interface.hpp index 737423bf..c80d51f1 100644 --- a/include/nana/gui/detail/native_window_interface.hpp +++ b/include/nana/gui/detail/native_window_interface.hpp @@ -16,6 +16,8 @@ #include "../basis.hpp" #include +#include + namespace nana { namespace detail diff --git a/include/nana/paint/pixel_buffer.hpp b/include/nana/paint/pixel_buffer.hpp index 6b6a4994..9ca86090 100644 --- a/include/nana/paint/pixel_buffer.hpp +++ b/include/nana/paint/pixel_buffer.hpp @@ -1,7 +1,7 @@ /* * Pixel Buffer Implementation * 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. * (See accompanying file LICENSE_1_0.txt or copy at diff --git a/source/basic_types.cpp b/source/basic_types.cpp index 01bc5ef6..69c6fa78 100644 --- a/source/basic_types.cpp +++ b/source/basic_types.cpp @@ -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(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); diff --git a/source/paint/pixel_buffer.cpp b/source/paint/pixel_buffer.cpp index 8502754f..4297c476 100644 --- a/source/paint/pixel_buffer.cpp +++ b/source/paint/pixel_buffer.cpp @@ -1,7 +1,7 @@ /* * Pixel Buffer Implementation * 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. * (See accompanying file LICENSE_1_0.txt or copy at @@ -328,10 +328,14 @@ namespace nana{ namespace paint else if(16 == depth) { //The format of Xorg 16bits depth is 565 - std::unique_ptr table_holder(new unsigned short[256]); - unsigned short * const fast_table = table_holder.get(); + std::unique_ptr table_5_6bit_holder(new unsigned short[512]); + 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) - fast_table[i] = i * 31 / 255; + { + table_5bit[i] = i * 31 / 255; + table_6bit[i] = i * 63 / 255; + } 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) { - *(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) @@ -355,7 +359,7 @@ namespace nana{ namespace paint { 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) @@ -511,10 +515,14 @@ namespace nana{ namespace paint else if(16 == image->depth) { //The format of Xorg 16bits depth is 565 - std::unique_ptr table_holder(new unsigned[32]); - unsigned * const fast_table = table_holder.get(); - for(unsigned i = 0; i < 32; ++i) - fast_table[i] = (i * 255 / 31); + std::unique_ptr table_holder{new unsigned[96]}; + auto * const table_5bit = table_holder.get(); + for(std::size_t i = 0; i < 32; ++i) + 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.y - want_r.y) * want_r.width; @@ -525,9 +533,9 @@ namespace nana{ namespace paint for(int x = 0; x < image->width; ++x) { - pixbuf[x].element.red = fast_table[(px_data[x] >> 11) & 0x1F]; - pixbuf[x].element.green = (px_data[x] >> 5) & 0x3F; - pixbuf[x].element.blue = fast_table[px_data[x] & 0x1F]; + pixbuf[x].element.red = table_5bit[(px_data[x] >> 11) & 0x1F]; + pixbuf[x].element.green = table_6bit[(px_data[x] >> 5) & 0x3F]; + pixbuf[x].element.blue = table_5bit[px_data[x] & 0x1F]; pixbuf[x].element.alpha_channel = 0; } img_data += image->bytes_per_line;