From 03642b8e3fb9289b73679a921f8b71faef18c872 Mon Sep 17 00:00:00 2001 From: Ray Kim Date: Mon, 26 Jun 2017 03:05:23 +0900 Subject: [PATCH 1/7] Fixed build error compiler didn't understand std::function include `````` --- include/nana/gui/detail/native_window_interface.hpp | 2 ++ 1 file changed, 2 insertions(+) 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 From 4d2921e31b4342e7c2edfae2553089468c66b912 Mon Sep 17 00:00:00 2001 From: Ray Kim Date: Tue, 27 Jun 2017 02:59:58 +0900 Subject: [PATCH 2/7] Fixed stdc++.hpp build error on gcc 7 included algorithm in c++defines.hpp this fixes std::clamp's feature test which was not working. --- include/nana/c++defines.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/nana/c++defines.hpp b/include/nana/c++defines.hpp index a9381f23..980e98a0 100644 --- a/include/nana/c++defines.hpp +++ b/include/nana/c++defines.hpp @@ -195,6 +195,8 @@ # endif #endif +// std::clamp's feature test macro is defined inside +#include #if (!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603) # ifndef _enable_std_clamp # define _enable_std_clamp From afd8225875d43167c6060fdb13db4d4ab499e38e Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 1 Jul 2017 07:32:45 +0800 Subject: [PATCH 3/7] 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); From 3b737c01a2245df311b8f831a8dc5a417e24e2b0 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 1 Jul 2017 12:21:19 +0800 Subject: [PATCH 4/7] fix issue that pixel_buffer generates wrong color in 16bits depth --- source/paint/pixel_buffer.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/source/paint/pixel_buffer.cpp b/source/paint/pixel_buffer.cpp index 8502754f..207905d1 100644 --- a/source/paint/pixel_buffer.cpp +++ b/source/paint/pixel_buffer.cpp @@ -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,15 @@ 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_5bit_holder{new unsigned[32]}; + auto * const table_5bit = table_5bit_holder.get(); + for(std::size_t i = 0; i < 32; ++i) + table_5bit[i] = (i * 255 / 31); + + std::unique_ptr table_6bit_holder{new unsigned[64]}; + auto * const table_6bit = table_6bit_holder.get(); + 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 +534,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; From 9ff1ea4605da620bb1b6cd4ec9ee591c11a9e606 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 2 Jul 2017 13:01:53 +0800 Subject: [PATCH 5/7] avoid introducing for MSVC --- include/nana/c++defines.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/nana/c++defines.hpp b/include/nana/c++defines.hpp index 980e98a0..7782e305 100644 --- a/include/nana/c++defines.hpp +++ b/include/nana/c++defines.hpp @@ -195,11 +195,13 @@ # endif #endif +#ifndef _MSC_VER // std::clamp's feature test macro is defined inside -#include -#if (!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603) -# ifndef _enable_std_clamp -# define _enable_std_clamp +# include +# if (!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603) +# ifndef _enable_std_clamp +# define _enable_std_clamp +# endif # endif #endif From 4bc03d038a2d71b43358d67824005d65ff76ade1 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 2 Jul 2017 13:05:33 +0800 Subject: [PATCH 6/7] code refined --- include/nana/paint/pixel_buffer.hpp | 2 +- source/paint/pixel_buffer.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) 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/paint/pixel_buffer.cpp b/source/paint/pixel_buffer.cpp index 207905d1..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 @@ -515,13 +515,12 @@ namespace nana{ namespace paint else if(16 == image->depth) { //The format of Xorg 16bits depth is 565 - std::unique_ptr table_5bit_holder{new unsigned[32]}; - auto * const table_5bit = table_5bit_holder.get(); + 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); - std::unique_ptr table_6bit_holder{new unsigned[64]}; - auto * const table_6bit = table_6bit_holder.get(); + auto * const table_6bit = table_holder.get() + 32; for(std::size_t i = 0; i < 64; ++i) table_6bit[i] = (i* 255 / 63); From 735de4f0325bc46ecb93a52257f88cbc7f131ecf Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 2 Jul 2017 22:58:31 +0800 Subject: [PATCH 7/7] fix logical error on detecting std::clamp feature --- include/nana/c++defines.hpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/include/nana/c++defines.hpp b/include/nana/c++defines.hpp index 7782e305..a849dfaa 100644 --- a/include/nana/c++defines.hpp +++ b/include/nana/c++defines.hpp @@ -112,10 +112,6 @@ # define STD_CODECVT_NOT_SUPPORTED # endif // _MSC_VER == 1900 -# if (_MSC_VER < 1910) //VS2017 RTM -# define _enable_std_clamp -# endif - #elif defined(__clang__) //Clang #include //Introduces some implement-specific flags of ISO C++ Library @@ -195,13 +191,19 @@ # endif #endif -#ifndef _MSC_VER -// std::clamp's feature test macro is defined inside -# include -# if (!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603) -# ifndef _enable_std_clamp -# define _enable_std_clamp -# endif +//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