diff --git a/include/nana/gui/widgets/picture.hpp b/include/nana/gui/widgets/picture.hpp index 33c67552..f4ba4f22 100644 --- a/include/nana/gui/widgets/picture.hpp +++ b/include/nana/gui/widgets/picture.hpp @@ -34,7 +34,7 @@ namespace nana void attached(widget_reference, graph_reference) override; private: void refresh(graph_reference) override; - void _m_draw_background(); + void _m_draw_background(unsigned,unsigned); private: implement * const impl_; }; diff --git a/include/nana/paint/image.hpp b/include/nana/paint/image.hpp index d8200293..b335a4fe 100644 --- a/include/nana/paint/image.hpp +++ b/include/nana/paint/image.hpp @@ -1,6 +1,7 @@ /* * Paint Image Implementation - * Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) + * Nana C++ Library(http://www.nanapro.org) + * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -39,6 +40,8 @@ namespace paint bool empty() const; operator unspecified_bool_t() const; void close(); + + bool alpha() const; nana::size size() const; void paste(graphics& dst, int x, int y) const; void paste(const nana::rectangle& r_src, graphics& dst, const point& p_dst) const;///< Paste the area of picture specified by r_src into the destination graphics specified by dst at position p_dst. diff --git a/source/gui/widgets/picture.cpp b/source/gui/widgets/picture.cpp index b9912cc7..db067155 100644 --- a/source/gui/widgets/picture.cpp +++ b/source/gui/widgets/picture.cpp @@ -109,8 +109,7 @@ namespace nana } } - if (fit_size.width < graphsize.width || fit_size.height < graphsize.height) - _m_draw_background(); + _m_draw_background(fit_size.width, fit_size.height); backimg.image.stretch(valid_area, graph, { pos, fit_size }); } @@ -141,14 +140,15 @@ namespace nana break; } - if (valid_area.width < graphsize.width || valid_area.height < graphsize.height) - _m_draw_background(); + _m_draw_background(valid_area.width, valid_area.height); backimg.image.paste(valid_area, graph, pos); } } else { + _m_draw_background(graphsize.width, graphsize.height); + color invalid_clr_for_call; backimg.bground->draw(graph, invalid_clr_for_call, invalid_clr_for_call, graphsize, element_state::normal); } @@ -156,18 +156,22 @@ namespace nana graph.setsta(); } - void drawer::_m_draw_background() + void drawer::_m_draw_background(unsigned w, unsigned h) { auto graph = impl_->graph_ptr; + if (graph && (bground_mode::basic != API::effects_bground_mode(*impl_->wdg_ptr))) { - auto & bground = impl_->gradual_bground; - if (bground.gradual_from.invisible() || bground.gradual_to.invisible()) - graph->rectangle(true, impl_->wdg_ptr->bgcolor()); - else if (bground.gradual_from == bground.gradual_to) - graph->rectangle(true, bground.gradual_from); - else - graph->gradual_rectangle(graph->size(), bground.gradual_from, bground.gradual_to, !bground.horizontal); + if (w < graph->size().width || h < graph->size().width || impl_->backimg.image.alpha()) + { + auto & bground = impl_->gradual_bground; + if (bground.gradual_from.invisible() || bground.gradual_to.invisible()) + graph->rectangle(true, impl_->wdg_ptr->bgcolor()); + else if (bground.gradual_from == bground.gradual_to) + graph->rectangle(true, bground.gradual_from); + else + graph->gradual_rectangle(graph->size(), bground.gradual_from, bground.gradual_to, !bground.horizontal); + } } } //end class drawer diff --git a/source/paint/image.cpp b/source/paint/image.cpp index ec471d6a..a6fcd598 100644 --- a/source/paint/image.cpp +++ b/source/paint/image.cpp @@ -250,6 +250,11 @@ namespace paint image_ptr_.reset(); } + bool image::alpha() const + { + return (image_ptr_ ? image_ptr_->alpha_channel() : false); + } + nana::size image::size() const { return (image_ptr_ ? image_ptr_->size() : nana::size());