From e0259e6254431f28b989d316ebbd4d11b3fbd499 Mon Sep 17 00:00:00 2001 From: cnjinhao Date: Thu, 29 Jan 2015 03:26:35 +0800 Subject: [PATCH] fixed a bground effect refresh issue. --- include/nana/gui/detail/basic_window.hpp | 5 +-- include/nana/gui/detail/effects_renderer.hpp | 4 +-- source/gui/detail/basic_window.cpp | 1 + source/gui/detail/window_layout.cpp | 8 ++++- source/gui/programming_interface.cpp | 33 +++++++++++++------- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/nana/gui/detail/basic_window.hpp b/include/nana/gui/detail/basic_window.hpp index 49ba4369..d8fb880a 100644 --- a/include/nana/gui/detail/basic_window.hpp +++ b/include/nana/gui/detail/basic_window.hpp @@ -163,7 +163,8 @@ namespace detail bool dropable :1; //Whether the window has make mouse_drop event. bool fullscreen :1; //When the window is maximizing whether it fit for fullscreen. bool borderless :1; - unsigned Reserved :22; + bool make_bground_declared : 1; //explicitly make bground for bground effects + unsigned Reserved :21; unsigned char tab; //indicate a window that can receive the keyboard TAB mouse_action action; }flags; @@ -175,7 +176,7 @@ namespace detail general_events* attached_events; }together; - widget_colors* expr_colors{ nullptr }; + widget_colors* scheme{ nullptr }; struct { diff --git a/include/nana/gui/detail/effects_renderer.hpp b/include/nana/gui/detail/effects_renderer.hpp index 3489dbaf..91daf849 100644 --- a/include/nana/gui/detail/effects_renderer.hpp +++ b/include/nana/gui/detail/effects_renderer.hpp @@ -119,12 +119,12 @@ namespace nana{ good_r.x = good_r.y = 1; good_r.width = r.width - 2; good_r.height = r.height - 2; - pixbuf.rectangle(good_r, wd->expr_colors->activated.get_color(), 0.95, false); + pixbuf.rectangle(good_r, wd->scheme->activated.get_color(), 0.95, false); good_r.x = good_r.y = 0; good_r.width = r.width; good_r.height = r.height; - pixbuf.rectangle(good_r, wd->expr_colors->activated.get_color(), 0.4, false); + pixbuf.rectangle(good_r, wd->scheme->activated.get_color(), 0.4, false); pixbuf.pixel(0, 0, px0); pixbuf.pixel(r.width - 1, 0, px1); diff --git a/source/gui/detail/basic_window.cpp b/source/gui/detail/basic_window.cpp index 16545934..f751b755 100644 --- a/source/gui/detail/basic_window.cpp +++ b/source/gui/detail/basic_window.cpp @@ -339,6 +339,7 @@ namespace nana flags.refreshing = false; flags.destroying = false; flags.borderless = false; + flags.make_bground_declared = false; visible = false; diff --git a/source/gui/detail/window_layout.cpp b/source/gui/detail/window_layout.cpp index 6c52bebb..99ab04ab 100644 --- a/source/gui/detail/window_layout.cpp +++ b/source/gui/detail/window_layout.cpp @@ -308,8 +308,14 @@ namespace nana { if (is_redraw || called_by_notify) { - if (called_by_notify) + //The background is made by more than calling by notification(such as redraw of parent, + //redraw of siblings which are covered by wd), sometimes it should be remade when an attribute + //of the wd is changed(such as its background color is changed). + if (called_by_notify || wd->flags.make_bground_declared) + { make_bground(wd); + wd->flags.make_bground_declared = false; + } wd->flags.refreshing = true; wd->drawer.refresh(); diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 7330d4d9..ab3a4384 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -110,6 +110,10 @@ namespace API iwd->effect.bground = new_effect_ptr; iwd->effect.bground_fade_rate = fade_rate; restrict::window_manager.enable_effects_bground(iwd, true); + + if (fade_rate < 0.01) + iwd->flags.make_bground_declared = true; + API::refresh_window(wd); } } @@ -155,14 +159,14 @@ namespace API auto iwd = reinterpret_cast(wd); internal_scope_guard lock; if (restrict::window_manager.available(iwd)) - iwd->expr_colors = wdg_colors; + iwd->scheme = wdg_colors; } widget_colors* get_scheme(window wd) { auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - return (restrict::window_manager.available(iwd) ? iwd->expr_colors : nullptr); + return (restrict::window_manager.available(iwd) ? iwd->scheme : nullptr); } void attach_drawer(widget& wd, drawer_trigger& dr) @@ -172,7 +176,7 @@ namespace API if(restrict::window_manager.available(iwd)) { iwd->drawer.graphics.make(iwd->dimension); - iwd->drawer.graphics.rectangle(true, iwd->expr_colors->background.get_color()); + iwd->drawer.graphics.rectangle(true, iwd->scheme->background.get_color()); iwd->drawer.attached(wd, dr); iwd->drawer.refresh(); //Always redrawe no matter it is visible or invisible. This can make the graphics data correctly. } @@ -805,7 +809,7 @@ namespace API { internal_scope_guard lock; if (restrict::window_manager.available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->expr_colors->foreground.get_color(); + return reinterpret_cast(wd)->scheme->foreground.get_color(); return{}; } @@ -815,10 +819,10 @@ namespace API internal_scope_guard lock; if (restrict::window_manager.available(iwd)) { - auto prev = iwd->expr_colors->foreground.get_color(); + auto prev = iwd->scheme->foreground.get_color(); if (prev != clr) { - iwd->expr_colors->foreground = clr; + iwd->scheme->foreground = clr; restrict::window_manager.update(iwd, true, false); } return prev; @@ -830,7 +834,7 @@ namespace API { internal_scope_guard lock; if (restrict::window_manager.available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->expr_colors->background.get_color(); + return reinterpret_cast(wd)->scheme->background.get_color(); return{}; } @@ -840,10 +844,15 @@ namespace API internal_scope_guard lock; if (restrict::window_manager.available(iwd)) { - auto prev = iwd->expr_colors->background.get_color(); + auto prev = iwd->scheme->background.get_color(); if (prev != clr) { - iwd->expr_colors->background = clr; + iwd->scheme->background = clr; + + //If the bground mode of this window is basic, it should remake the background + if (iwd->effect.bground && iwd->effect.bground_fade_rate < 0.01) // fade rate < 0.01 means it is basic mode + iwd->flags.make_bground_declared = true; + restrict::window_manager.update(iwd, true, false); } return prev; @@ -855,7 +864,7 @@ namespace API { internal_scope_guard lock; if (restrict::window_manager.available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->expr_colors->activated.get_color(); + return reinterpret_cast(wd)->scheme->activated.get_color(); return{}; } @@ -865,10 +874,10 @@ namespace API internal_scope_guard lock; if (restrict::window_manager.available(iwd)) { - auto prev = iwd->expr_colors->activated.get_color(); + auto prev = iwd->scheme->activated.get_color(); if (prev != clr) { - iwd->expr_colors->activated = clr; + iwd->scheme->activated = clr; restrict::window_manager.update(iwd, true, false); } return prev;