From e778f4133279d43262b475baf85e4396db5b0e2b Mon Sep 17 00:00:00 2001 From: cnjinhao Date: Tue, 11 Jun 2024 23:55:59 +0800 Subject: [PATCH] nana::drawing is deprecated --- include/nana/gui.hpp | 2 ++ include/nana/gui/animation.hpp | 8 +++-- include/nana/gui/detail/drawer.hpp | 5 ++++ include/nana/gui/drawing.hpp | 7 ++++- include/nana/gui/programming_interface.hpp | 3 ++ include/nana/gui/widgets/widget.hpp | 4 +++ source/gui/animation.cpp | 14 --------- source/gui/detail/drawer.cpp | 30 ++++++++++++++++--- source/gui/detail/virtual_keyboard.cpp | 5 ++-- source/gui/drawing.cpp | 2 ++ source/gui/filebox.cpp | 6 ++-- source/gui/msgbox.cpp | 5 ++-- source/gui/place.cpp | 8 ++--- source/gui/place_parts.hpp | 4 +-- source/gui/programming_interface.cpp | 18 +++++++++++ source/gui/tooltip.cpp | 2 +- source/gui/widgets/group.cpp | 5 +--- source/gui/widgets/progress.cpp | 2 +- source/gui/widgets/skeletons/content_view.cpp | 2 +- source/gui/widgets/widget.cpp | 10 +++++++ 20 files changed, 96 insertions(+), 46 deletions(-) diff --git a/include/nana/gui.hpp b/include/nana/gui.hpp index 09c2f7b9a..d00c232d5 100644 --- a/include/nana/gui.hpp +++ b/include/nana/gui.hpp @@ -18,7 +18,9 @@ #include "gui/compact.hpp" #include "gui/screen.hpp" #include "gui/widgets/form.hpp" +#ifndef NANA_DRAWING_REMOVED #include "gui/drawing.hpp" +#endif #include "gui/msgbox.hpp" #include "gui/place.hpp" diff --git a/include/nana/gui/animation.hpp b/include/nana/gui/animation.hpp index bf318e1c0..6b00a4ce7 100644 --- a/include/nana/gui/animation.hpp +++ b/include/nana/gui/animation.hpp @@ -21,9 +21,11 @@ namespace nana { - class animation; + class [[deprecated("Deprecated in 1.8")]] animation; /// Holds the frames and frame builders. Have reference semantics for efficiency. - class frameset + + + class [[deprecated("Deprecated in 1.8")]] frameset { friend class animation; public: @@ -38,7 +40,7 @@ namespace nana std::shared_ptr impl_; }; /// Easy way to display an animation or create an animated GUI - class animation + class [[deprecated("Deprecated in 1.8")]] animation { struct branch_t { diff --git a/include/nana/gui/detail/drawer.hpp b/include/nana/gui/detail/drawer.hpp index 4636ea5d9..c17c35e04 100644 --- a/include/nana/gui/detail/drawer.hpp +++ b/include/nana/gui/detail/drawer.hpp @@ -152,9 +152,14 @@ namespace nana void attached(widget&, drawer_trigger&); drawer_trigger* detached(); public: + std::function drawing() const; + void drawing(std::function&&); + +#ifndef NANA_DRAWING_REMOVED void clear(); void* draw(std::function &&, bool diehard); void erase(void* diehard); +#endif private: void _m_effect_bground_subsequent(); method_state& _m_mth_state(int pos); diff --git a/include/nana/gui/drawing.hpp b/include/nana/gui/drawing.hpp index 8badef6b8..58e423c66 100644 --- a/include/nana/gui/drawing.hpp +++ b/include/nana/gui/drawing.hpp @@ -9,6 +9,9 @@ * * @file: nana/gui/drawing.hpp */ + +#ifndef NANA_DRAWING_REMOVED + #ifndef NANA_GUI_DRAWING_HPP #define NANA_GUI_DRAWING_HPP @@ -20,7 +23,7 @@ namespace nana /// \brief Draw pictures on a widget by specifying a drawing method that will be employed every time the widget refreshes. /// By the end of drawing, the picture may not be displayed immediately. /// If a picture need to be displayed immediately call nana::gui::api::refresh_window() . - class [[deprecated("Deprecated in 1.8")]] drawing + class [[deprecated("Deprecated in 1.8, please use widget::drawing instead")]] drawing :private nana::noncopyable { struct draw_fn_handle; @@ -52,3 +55,5 @@ namespace nana #include #endif + +#endif //NANA_DRAWING_REMOVED \ No newline at end of file diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index 3ce6e4d7a..33a8bdd80 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -533,6 +533,9 @@ namespace api /// Configures the numeric keyboard. It returns true if virtual keyboard is enabled and /// the specified window is a text editor window, false otherwise. bool keyboard_numeric(window, bool padding); + + std::function drawing(window); + void drawing(window, std::function); }//end namespace api namespace API = api; diff --git a/include/nana/gui/widgets/widget.hpp b/include/nana/gui/widgets/widget.hpp index 8660a579e..715462d3f 100644 --- a/include/nana/gui/widgets/widget.hpp +++ b/include/nana/gui/widgets/widget.hpp @@ -127,6 +127,10 @@ namespace nana operator dummy_bool_type() const; operator window() const; + + std::function drawing() const; + void drawing(std::function); + protected: std::unique_ptr<::nana::detail::widget_notifier_interface> _m_wdg_notifier(); private: diff --git a/source/gui/animation.cpp b/source/gui/animation.cpp index ccd514fd9..e447b99d8 100644 --- a/source/gui/animation.cpp +++ b/source/gui/animation.cpp @@ -771,20 +771,6 @@ namespace nana } } - /* - void branch(const std::string& name, const frameset& frms) - { - impl_->branches[name].frames = frms; - } - - void branch(const std::string& name, const frameset& frms, std::function condition) - { - auto & br = impl_->branches[name]; - br.frames = frms; - br.condition = condition; - } - */ - void animation::looped(bool enable) { if(impl_->looped != enable) diff --git a/source/gui/detail/drawer.cpp b/source/gui/detail/drawer.cpp index fdf68e4ce..352010bb6 100644 --- a/source/gui/detail/drawer.cpp +++ b/source/gui/detail/drawer.cpp @@ -1,7 +1,7 @@ /* * A Drawer Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2020 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2024 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -228,7 +228,11 @@ namespace nana drawer_trigger* realizer{ nullptr }; method_state mth_state[event_size]; + std::function draw; + +#ifndef NANA_DRAWING_REMOVED std::vector, bool>*> draws; //Drawing function and flag for clearable +#endif }; drawer::drawer() @@ -237,8 +241,10 @@ namespace nana drawer::~drawer() { +#ifndef NANA_DRAWING_REMOVED for(auto p : data_impl_->draws) delete p; +#endif delete data_impl_; } @@ -416,11 +422,22 @@ namespace nana return nullptr; } + std::function drawer::drawing() const + { + return data_impl_->draw; + } + + void drawer::drawing(std::function&& fn) + { + data_impl_->draw = std::move(fn); + } + +#ifndef NANA_DRAWING_REMOVED void drawer::clear() { - for(auto i = data_impl_->draws.cbegin(); i != data_impl_->draws.cend();) + for (auto i = data_impl_->draws.cbegin(); i != data_impl_->draws.cend();) { - if((*i)->second) + if ((*i)->second) { delete (*i); i = data_impl_->draws.erase(i); @@ -453,13 +470,18 @@ namespace nana } } } - +#endif void drawer::_m_effect_bground_subsequent() { + if (data_impl_->draw) + data_impl_->draw(graphics); + auto & effect = data_impl_->window_handle->effect; +#ifndef NANA_DRAWING_REMOVED for (auto * dw : data_impl_->draws) dw->first(graphics); +#endif if (effect.bground) { diff --git a/source/gui/detail/virtual_keyboard.cpp b/source/gui/detail/virtual_keyboard.cpp index b65ed2c9c..53adb4565 100644 --- a/source/gui/detail/virtual_keyboard.cpp +++ b/source/gui/detail/virtual_keyboard.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -76,7 +75,7 @@ namespace nana::detail _m_adjust_size(padding); - nana::drawing{ *this }.draw([this](nana::paint::graphics& graph) { + this->drawing([this](nana::paint::graphics& graph) { _m_render(graph); }); @@ -328,7 +327,7 @@ namespace nana::detail cntpart_.graph.make(r.dimension()); - nana::drawing{ *this }.draw([this](nana::paint::graphics& graph) { + this->drawing([this](nana::paint::graphics& graph) { _m_render(graph); }); diff --git a/source/gui/drawing.cpp b/source/gui/drawing.cpp index 7ce6b4568..49cb002be 100644 --- a/source/gui/drawing.cpp +++ b/source/gui/drawing.cpp @@ -10,6 +10,7 @@ * @file: nana/gui/drawing.cpp */ +#ifndef NANA_DRAWING_REMOVED #include "detail/basic_window.hpp" #include #include @@ -92,3 +93,4 @@ namespace nana //end class drawing }//end namespace nana +#endif //NANA_DRAWING_REMOVED \ No newline at end of file diff --git a/source/gui/filebox.cpp b/source/gui/filebox.cpp index 2388940f9..2eb8b3143 100644 --- a/source/gui/filebox.cpp +++ b/source/gui/filebox.cpp @@ -711,9 +711,7 @@ namespace nana { file_container_.clear(); - drawing dw{ls_file_}; - dw.clear(); - dw.draw([](paint::graphics& graph){ + drawing([](paint::graphics& graph){ std::string text = "Permission denied to access the directory"; auto txt_sz = graph.text_extent_size(text); auto sz = graph.size(); @@ -746,7 +744,7 @@ namespace nana void _m_list_fs() { - drawing{ls_file_}.clear(); + ls_file_.drawing({}); auto filter = filter_.caption(); ls_file_.auto_draw(false); diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index 017069b1b..5581d8873 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -53,8 +52,8 @@ namespace nana owner_(wd), pick_(msgbox::pick_yes) { this->caption(title); - drawing dw(*this); - dw.draw([this](paint::graphics& graph) + + this->drawing([this](paint::graphics& graph) { graph.rectangle(rectangle{0, 0, graph.width(), graph.height() - 50}, true, colors::white); if(ico_.empty() == false) diff --git a/source/gui/place.cpp b/source/gui/place.cpp index c8654bae0..dc7567a62 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include "place_parts.hpp" @@ -2188,8 +2187,8 @@ namespace nana { auto host_size = api::window_size(impl_ptr_->window_handle); indicator_.docker.reset(new form(impl_ptr_->window_handle, { static_cast(host_size.width) / 2 - 16, static_cast(host_size.height) / 2 - 16, 32, 32 }, form::appear::bald<>())); - drawing dw(indicator_.docker->handle()); - dw.draw([](paint::graphics& graph) + + indicator_.docker->drawing([](paint::graphics& graph) { graph.rectangle(false, colors::midnight_blue); graph.rectangle({ 1, 1, 30, 30 }, true, colors::light_sky_blue); @@ -2228,8 +2227,7 @@ namespace nana indicator_.dock_area.reset(new panel(impl_ptr_->window_handle, {}, false)); indicator_.dock_area->move(this->field_area); - ::nana::drawing dw(indicator_.dock_area->handle()); - dw.draw([this](paint::graphics& graph) + indicator_.dock_area->drawing([this](paint::graphics& graph) { indicator_.graph.paste(this->field_area, graph, 0, 0); diff --git a/source/gui/place_parts.hpp b/source/gui/place_parts.hpp index cda28f56d..6f851a4d2 100644 --- a/source/gui/place_parts.hpp +++ b/source/gui/place_parts.hpp @@ -361,8 +361,8 @@ namespace nana rectangle r{ pos() + move_pos, size() }; container_.reset(new form(host_window_, r.pare_off(-1), form::appear::bald())); - drawing dw(container_->handle()); - dw.draw([](paint::graphics& graph) + + drawing([](paint::graphics& graph) { graph.rectangle(false, colors::coral); }); diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 859789e73..318addcd7 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -1753,5 +1753,23 @@ namespace api return false; #endif } + + std::function drawing(window wd) + { + internal_scope_guard lock; + if (!is_window(wd)) + return {}; + + return wd->drawer.drawing(); + } + + void drawing(window wd, std::function fn) + { + internal_scope_guard lock; + if (!is_window(wd)) + return; + + wd->drawer.drawing(std::move(fn)); + } }//end namespace api }//end namespace nana diff --git a/source/gui/tooltip.cpp b/source/gui/tooltip.cpp index 0a1d3b127..2e9fbe5a9 100644 --- a/source/gui/tooltip.cpp +++ b/source/gui/tooltip.cpp @@ -328,7 +328,7 @@ namespace nana void tooltip::set(window wd, const std::string& text) { internal_scope_guard lock; - if(false == api::empty_window(wd)) + if(api::is_window(wd)) ctrl::instance()->set(wd, text); } diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index 6accf6aa9..cffc787ca 100644 --- a/source/gui/widgets/group.cpp +++ b/source/gui/widgets/group.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #define _THROW_IF_EMPTY()\ @@ -311,8 +310,6 @@ group::~group() this->bgcolor(pbg.blend(colors::black, 0.05)); - drawing dw(*this); - //When the group is resized, the drawing is called before moving the caption, but //the drawing of group requires the latest position of caption for gradual rectangle. //For the requirement, a move event handler is required for listening the change of caption's position. @@ -322,7 +319,7 @@ group::~group() }); // This drawing function is owner by the owner of dw (the outer panel of the group widget), not by dw !! - dw.draw([this](paint::graphics& graph) + drawing([this](paint::graphics& graph) { auto gap_px = impl_->gap - 1; diff --git a/source/gui/widgets/progress.cpp b/source/gui/widgets/progress.cpp index 0affbb571..83417dae5 100644 --- a/source/gui/widgets/progress.cpp +++ b/source/gui/widgets/progress.cpp @@ -231,7 +231,7 @@ namespace nana unsigned progress::value(unsigned val) { internal_scope_guard lock; - if(api::empty_window(this->handle()) == false) + if(api::is_window(this->handle())) return get_drawer_trigger().progress()->value(&val); return 0; } diff --git a/source/gui/widgets/skeletons/content_view.cpp b/source/gui/widgets/skeletons/content_view.cpp index ad0a85493..29935be95 100644 --- a/source/gui/widgets/skeletons/content_view.cpp +++ b/source/gui/widgets/skeletons/content_view.cpp @@ -89,7 +89,7 @@ namespace nana { auto const scroll = cv_scroll->scroll(arg.which); - if (scroll && (!api::empty_window(arg.window_handle))) + if (scroll && api::is_window(arg.window_handle)) { auto align_px = (scroll->value() % scroll->step()); if (align_px) diff --git a/source/gui/widgets/widget.cpp b/source/gui/widgets/widget.cpp index f1eb45d54..af8a523d1 100644 --- a/source/gui/widgets/widget.cpp +++ b/source/gui/widgets/widget.cpp @@ -293,6 +293,16 @@ namespace nana return handle(); } + std::function widget::drawing() const + { + return api::drawing(handle()); + } + + void widget::drawing(std::function draw_fn) + { + api::drawing(handle(), std::move(draw_fn)); + } + std::unique_ptr<::nana::detail::widget_notifier_interface> widget::_m_wdg_notifier() { return std::unique_ptr<::nana::detail::widget_notifier_interface>(new inner_widget_notifier(*this));