Skip to content

Commit

Permalink
nana::drawing is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
cnjinhao committed Jun 11, 2024
1 parent 9c344fa commit e778f41
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 46 deletions.
2 changes: 2 additions & 0 deletions include/nana/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 5 additions & 3 deletions include/nana/gui/animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -38,7 +40,7 @@ namespace nana
std::shared_ptr<impl> impl_;
};
/// Easy way to display an animation or create an animated GUI
class animation
class [[deprecated("Deprecated in 1.8")]] animation
{
struct branch_t
{
Expand Down
5 changes: 5 additions & 0 deletions include/nana/gui/detail/drawer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ namespace nana
void attached(widget&, drawer_trigger&);
drawer_trigger* detached();
public:
std::function<void(paint::graphics&)> drawing() const;
void drawing(std::function<void(paint::graphics&)>&&);

#ifndef NANA_DRAWING_REMOVED
void clear();
void* draw(std::function<void(paint::graphics&)> &&, bool diehard);
void erase(void* diehard);
#endif
private:
void _m_effect_bground_subsequent();
method_state& _m_mth_state(int pos);
Expand Down
7 changes: 6 additions & 1 deletion include/nana/gui/drawing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*
* @file: nana/gui/drawing.hpp
*/

#ifndef NANA_DRAWING_REMOVED

#ifndef NANA_GUI_DRAWING_HPP
#define NANA_GUI_DRAWING_HPP

Expand All @@ -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;
Expand Down Expand Up @@ -52,3 +55,5 @@ namespace nana

#include <nana/pop_ignore_diagnostic>
#endif

#endif //NANA_DRAWING_REMOVED
3 changes: 3 additions & 0 deletions include/nana/gui/programming_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(paint::graphics&)> drawing(window);
void drawing(window, std::function<void(paint::graphics&)>);
}//end namespace api

namespace API = api;
Expand Down
4 changes: 4 additions & 0 deletions include/nana/gui/widgets/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ namespace nana

operator dummy_bool_type() const;
operator window() const;

std::function<void(paint::graphics&)> drawing() const;
void drawing(std::function<void(paint::graphics&)>);

protected:
std::unique_ptr<::nana::detail::widget_notifier_interface> _m_wdg_notifier();
private:
Expand Down
14 changes: 0 additions & 14 deletions source/gui/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t(const std::string&, std::size_t, std::size_t&)> condition)
{
auto & br = impl_->branches[name];
br.frames = frms;
br.condition = condition;
}
*/

void animation::looped(bool enable)
{
if(impl_->looped != enable)
Expand Down
30 changes: 26 additions & 4 deletions source/gui/detail/drawer.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -228,7 +228,11 @@ namespace nana
drawer_trigger* realizer{ nullptr };
method_state mth_state[event_size];

std::function<void(paint::graphics&)> draw;

#ifndef NANA_DRAWING_REMOVED
std::vector<std::pair<std::function<void(paint::graphics&)>, bool>*> draws; //Drawing function and flag for clearable
#endif
};

drawer::drawer()
Expand All @@ -237,8 +241,10 @@ namespace nana

drawer::~drawer()
{
#ifndef NANA_DRAWING_REMOVED
for(auto p : data_impl_->draws)
delete p;
#endif

delete data_impl_;
}
Expand Down Expand Up @@ -416,11 +422,22 @@ namespace nana
return nullptr;
}

std::function<void(paint::graphics&)> drawer::drawing() const
{
return data_impl_->draw;
}

void drawer::drawing(std::function<void(paint::graphics&)>&& 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);
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 2 additions & 3 deletions source/gui/detail/virtual_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <nana/gui/widgets/textbox.hpp>
#include <nana/gui/element.hpp>
#include <nana/gui/compact.hpp>
#include <nana/gui/drawing.hpp>
#include <nana/gui/screen.hpp>
#include <nana/gui/detail/virtual_keyboard.hpp>
#include <nana/gui/programming_interface.hpp>
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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);
});

Expand Down
2 changes: 2 additions & 0 deletions source/gui/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @file: nana/gui/drawing.cpp
*/

#ifndef NANA_DRAWING_REMOVED
#include "detail/basic_window.hpp"
#include <nana/gui/drawing.hpp>
#include <nana/gui/programming_interface.hpp>
Expand Down Expand Up @@ -92,3 +93,4 @@ namespace nana
//end class drawing
}//end namespace nana

#endif //NANA_DRAWING_REMOVED
6 changes: 2 additions & 4 deletions source/gui/filebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions source/gui/msgbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <nana/gui/compact.hpp>
#include <nana/gui/msgbox.hpp>
#include <nana/gui/drawing.hpp>
#include <nana/gui/widgets/form.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp>
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions source/gui/place.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/panel.hpp>
#include <nana/gui/dragger.hpp>
#include <nana/gui/drawing.hpp>

#include "place_parts.hpp"

Expand Down Expand Up @@ -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<int>(host_size.width) / 2 - 16, static_cast<int>(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);
Expand Down Expand Up @@ -2228,8 +2227,7 @@ namespace nana
indicator_.dock_area.reset(new panel<true>(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);

Expand Down
4 changes: 2 additions & 2 deletions source/gui/place_parts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<form::appear::sizable>()));
drawing dw(container_->handle());
dw.draw([](paint::graphics& graph)

drawing([](paint::graphics& graph)
{
graph.rectangle(false, colors::coral);
});
Expand Down
18 changes: 18 additions & 0 deletions source/gui/programming_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,5 +1753,23 @@ namespace api
return false;
#endif
}

std::function<void(paint::graphics&)> drawing(window wd)
{
internal_scope_guard lock;
if (!is_window(wd))
return {};

return wd->drawer.drawing();
}

void drawing(window wd, std::function<void(paint::graphics&)> fn)
{
internal_scope_guard lock;
if (!is_window(wd))
return;

wd->drawer.drawing(std::move(fn));
}
}//end namespace api
}//end namespace nana
2 changes: 1 addition & 1 deletion source/gui/tooltip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 1 addition & 4 deletions source/gui/widgets/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <nana/gui/widgets/group.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/drawing.hpp>
#include <nana/gui/widgets/checkbox.hpp>

#define _THROW_IF_EMPTY()\
Expand Down Expand Up @@ -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.
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion source/gui/widgets/progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion source/gui/widgets/skeletons/content_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit e778f41

Please sign in to comment.