From 36095c91908f7ea6d8b37504e13b431f7480a70f Mon Sep 17 00:00:00 2001 From: besh81 Date: Fri, 14 Dec 2018 12:38:06 +0100 Subject: [PATCH 1/5] fix disabled checkbox square disabled checkbox square now looks like disabled textbox In addition found an unused instruction in text_editor.cpp: could be replaced or removed (or left as it is :) ) --- source/gui/element.cpp | 3 ++- source/gui/widgets/checkbox.cpp | 6 +++++- source/gui/widgets/skeletons/text_editor.cpp | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/source/gui/element.cpp b/source/gui/element.cpp index a67a7341..ea3b94a2 100644 --- a/source/gui/element.cpp +++ b/source/gui/element.cpp @@ -163,7 +163,8 @@ namespace nana bld_fgcolor = fgcolor.blend(highlighted, 0.6); break; case element_state::disabled: - bld_bgcolor = bld_fgcolor = static_cast(0xb2b7bc); + bld_bgcolor = static_cast(0xE0E0E0); + bld_fgcolor = static_cast(0x999A9E); break; default: //Leave things as they are diff --git a/source/gui/widgets/checkbox.cpp b/source/gui/widgets/checkbox.cpp index c458a4ac..a43cd908 100644 --- a/source/gui/widgets/checkbox.cpp +++ b/source/gui/widgets/checkbox.cpp @@ -85,9 +85,13 @@ namespace nana{ namespace drawerbase graph.text_metrics(txt_px, descent, ileading); txt_px += (descent + 2); + auto e_state = API::element_state(*wdg); + if(!wdg->enabled()) + e_state = element_state::disabled; + impl_->crook.draw(graph, impl_->scheme_ptr->square_bgcolor.get(wdg->bgcolor()), impl_->scheme_ptr->square_border_color.get(wdg->fgcolor()), - rectangle(0, txt_px > 16 ? (txt_px - 16) / 2 : 0, 16, 16), API::element_state(*wdg)); + rectangle(0, txt_px > 16 ? (txt_px - 16) / 2 : 0, 16, 16), e_state); } void drawer::mouse_down(graph_reference graph, const arg_mouse&) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 304ed929..72d26a2e 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -2002,7 +2002,7 @@ namespace nana { auto fgcolor = scheme_->foreground.get_color(); if (!API::window_enabled(window_)) - fgcolor.blend(bgcolor, 0.5); + fgcolor.blend(bgcolor, 0.5); // do nothing !!! should be replace with fgcolor = fgcolor.blend(bgcolor, 0.5); <\code> or removed if (API::widget_borderless(window_)) graph_.rectangle(false, bgcolor); From bed829fa26a666044eb6d66d333dea91e3e57ca3 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 29 Dec 2018 06:38:46 +0800 Subject: [PATCH 2/5] fix bug that line alorithm wrongly draws a line when fade_rate is zero --- source/gui/widgets/skeletons/text_editor.cpp | 2 +- source/paint/detail/image_process_provider.cpp | 2 +- .../nana => source}/paint/detail/image_processor.hpp | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) rename {include/nana => source}/paint/detail/image_processor.hpp (98%) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 72d26a2e..6a5251b4 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -2002,7 +2002,7 @@ namespace nana { auto fgcolor = scheme_->foreground.get_color(); if (!API::window_enabled(window_)) - fgcolor.blend(bgcolor, 0.5); // do nothing !!! should be replace with fgcolor = fgcolor.blend(bgcolor, 0.5); <\code> or removed + fgcolor = fgcolor.blend(bgcolor, 0.5); //Thank to besh81 for getting the fgcolor to be changed if (API::widget_borderless(window_)) graph_.rectangle(false, bgcolor); diff --git a/source/paint/detail/image_process_provider.cpp b/source/paint/detail/image_process_provider.cpp index 414d68dc..89324e04 100644 --- a/source/paint/detail/image_process_provider.cpp +++ b/source/paint/detail/image_process_provider.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include "image_processor.hpp" namespace nana { diff --git a/include/nana/paint/detail/image_processor.hpp b/source/paint/detail/image_processor.hpp similarity index 98% rename from include/nana/paint/detail/image_processor.hpp rename to source/paint/detail/image_processor.hpp index 1a412a2e..5e7e3548 100644 --- a/include/nana/paint/detail/image_processor.hpp +++ b/source/paint/detail/image_processor.hpp @@ -1,7 +1,7 @@ /* * Image Processor Algorithm Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -15,8 +15,8 @@ #ifndef NANA_PAINT_DETAIL_IMAGE_PROCESSOR_HPP #define NANA_PAINT_DETAIL_IMAGE_PROCESSOR_HPP -#include "../image_process_interface.hpp" #include +#include #include #include @@ -421,15 +421,19 @@ namespace detail { virtual void process(paint::pixel_buffer & pixbuf, const nana::point& pos_beg, const nana::point& pos_end, const ::nana::color& clr, double fade_rate) const { + //Return if it is completely transparent + if (fade_rate <= 0) + return; + auto rgb_color = clr.px_color().value; const std::size_t bytes_pl = pixbuf.bytes_per_line(); unsigned char * fade_table = nullptr; std::unique_ptr autoptr; nana::pixel_argb_t rgb_imd = {}; - if(fade_rate != 0.0) + if(fade_rate < 1) { - autoptr = detail::alloc_fade_table(1 - fade_rate); + autoptr = detail::alloc_fade_table(1.0 - fade_rate); fade_table = autoptr.get(); rgb_imd.value = rgb_color; rgb_imd = detail::fade_color_intermedia(rgb_imd, fade_table); From 345d65f6c9abe38c43daf90aad4ac63f81cd05a9 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 29 Dec 2018 07:08:49 +0800 Subject: [PATCH 3/5] add caption background mode for group --- include/nana/gui/widgets/group.hpp | 10 ++++++- source/gui/widgets/group.cpp | 48 ++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/include/nana/gui/widgets/group.hpp b/include/nana/gui/widgets/group.hpp index ba48928b..e0fdfc3b 100644 --- a/include/nana/gui/widgets/group.hpp +++ b/include/nana/gui/widgets/group.hpp @@ -42,6 +42,13 @@ namespace nana{ using field_reference = place::field_reference; constexpr static const std::size_t npos = static_cast(-1); + enum class background_mode + { + none, + transparent, + blending + }; + /// The default construction group(); @@ -66,7 +73,8 @@ namespace nana{ checkbox& add_option(::std::string); /// Modifies the alignment of the title - void caption_align(align position); + group& caption_align(align position); + group& caption_background_mode(background_mode mode); /// Enables/disables the radio mode which is single selection group& radio_mode(bool); diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index 6d697a62..d85d81a9 100644 --- a/source/gui/widgets/group.cpp +++ b/source/gui/widgets/group.cpp @@ -36,6 +36,7 @@ namespace nana{ { label caption; align caption_align{ align::left }; + background_mode caption_mode{ background_mode::blending }; place place_content; unsigned gap{2}; std::string usr_div_str; @@ -154,7 +155,7 @@ namespace nana{ return *impl_->options.back(); } - void group::caption_align(align position) + group& group::caption_align(align position) { if (position != impl_->caption_align) { @@ -163,6 +164,32 @@ namespace nana{ impl_->place_content.collocate(); API::refresh_window(*this); } + return *this; + } + + group& group::caption_background_mode(background_mode mode) + { + if (mode != impl_->caption_mode) + { + impl_->caption_mode = mode; + switch (mode) + { + case background_mode::none: + impl_->caption.bgcolor(this->bgcolor()); + impl_->caption.transparent(false); + break; + case background_mode::blending: + impl_->caption.transparent(true); + impl_->caption.bgcolor(API::bgcolor(this->parent()).blend(colors::black, 0.025)); + break; + case background_mode::transparent: + impl_->caption.transparent(true); + impl_->caption.bgcolor(API::bgcolor(this->parent()).blend(colors::black, 0.025)); + break; + } + API::refresh_window(*this); + } + return *this; } group& group::radio_mode(bool enable) @@ -289,17 +316,20 @@ namespace nana{ ), 3, 3, this->scheme().border, true, this->bgcolor()); - auto opt_r = API::window_rectangle(impl_->caption); - if (opt_r) + if (background_mode::blending == impl_->caption_mode) { - rectangle grad_r{ opt_r->position(), nana::size{ opt_r->width + 4, static_cast(top_round_line - opt_r->y) } }; + auto opt_r = API::window_rectangle(impl_->caption); + if (opt_r) + { + rectangle grad_r{ opt_r->position(), nana::size{ opt_r->width + 4, static_cast(top_round_line - opt_r->y) } }; - grad_r.y += top_round_line*2 / 3; - grad_r.x -= 2; + grad_r.y += top_round_line * 2 / 3; + grad_r.x -= 2; - graph.gradual_rectangle(grad_r, - API::bgcolor(this->parent()), this->bgcolor(), true - ); + graph.gradual_rectangle(grad_r, + API::bgcolor(this->parent()), this->bgcolor(), true + ); + } } }); } From e963c29646085f709782a89f5eab98b64e3517fe Mon Sep 17 00:00:00 2001 From: Jinhao Date: Fri, 4 Jan 2019 21:58:48 +0800 Subject: [PATCH 4/5] fix crash occurs when switch between radio button to checkbox(#375) --- include/nana/gui/widgets/checkbox.hpp | 1 + source/gui/widgets/checkbox.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/nana/gui/widgets/checkbox.hpp b/include/nana/gui/widgets/checkbox.hpp index 57239d20..1a75c91a 100644 --- a/include/nana/gui/widgets/checkbox.hpp +++ b/include/nana/gui/widgets/checkbox.hpp @@ -104,6 +104,7 @@ namespace drawerbase struct element_tag { checkbox * uiobj; + event_handle eh_clicked; event_handle eh_checked; event_handle eh_destroy; event_handle eh_keyboard; diff --git a/source/gui/widgets/checkbox.cpp b/source/gui/widgets/checkbox.cpp index a43cd908..3148ee88 100644 --- a/source/gui/widgets/checkbox.cpp +++ b/source/gui/widgets/checkbox.cpp @@ -216,6 +216,7 @@ namespace nana{ namespace drawerbase { e.uiobj->radio(false); e.uiobj->react(true); + API::umake_event(e.eh_clicked); API::umake_event(e.eh_checked); API::umake_event(e.eh_destroy); API::umake_event(e.eh_keyboard); @@ -232,7 +233,7 @@ namespace nana{ namespace drawerbase el.uiobj = &uiobj; - uiobj.events().checked.connect_unignorable([this](const arg_checkbox& arg) + el.eh_checked = uiobj.events().checked.connect_unignorable([this](const arg_checkbox& arg) { if (arg.widget->checked()) { @@ -244,7 +245,7 @@ namespace nana{ namespace drawerbase } }, true); - el.eh_checked = uiobj.events().click.connect_unignorable([this](const arg_click& arg) + el.eh_clicked = uiobj.events().click.connect_unignorable([this](const arg_click& arg) { for (auto & i : ui_container_) i.uiobj->check(arg.window_handle == i.uiobj->handle()); From 96f62a7b0835b323aa09ca8d20792418cef7d1cf Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 6 Jan 2019 08:29:43 +0800 Subject: [PATCH 5/5] fix bug that text_editor::text use \n\r as end of line --- source/gui/widgets/skeletons/text_editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 6a5251b4..f53a5837 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1,7 +1,7 @@ /* * A text editor implementation * Nana C++ Library(http://www.nanapro.org) -* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) +* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -1728,7 +1728,7 @@ namespace nana { str = impl_->textbase.getline(0); for (std::size_t i = 1; i < lines; ++i) { - str += L"\n\r"; + str += L"\r\n"; str += impl_->textbase.getline(i); } }