From 358c0f662eb8853953ea6c24356596280c10e8cf Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 19 Jul 2015 14:29:59 +0800 Subject: [PATCH] image::paste may make a graphics if the graphics object is empty --- include/nana/gui/widgets/group.hpp | 5 ++-- source/gui/widgets/group.cpp | 27 +++++++++++----------- source/paint/image.cpp | 37 +++++++++++++----------------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/include/nana/gui/widgets/group.hpp b/include/nana/gui/widgets/group.hpp index 0b956380..aa2b6a96 100644 --- a/include/nana/gui/widgets/group.hpp +++ b/include/nana/gui/widgets/group.hpp @@ -37,7 +37,7 @@ namespace nana{ /// The construction that creates the widget and set the titel or caption group(window parent, ///< - string titel_ /*= { STR("") }*/, ///< + ::nana::string titel, ///< bool format = false, ///< Use a formated label? unsigned gap = 2, ///< betwen the content and the external limit rectangle r = {} , ///< @@ -67,11 +67,10 @@ namespace nana{ } private: void _m_add_child(const char* field, widget*); - + void _m_init(); void _m_complete_creation() override; ::nana::string _m_caption() const override; void _m_caption(::nana::string&&) override; - void init(); private: std::unique_ptr impl_; }; diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index aae4a58c..a97848d8 100644 --- a/source/gui/widgets/group.cpp +++ b/source/gui/widgets/group.cpp @@ -28,20 +28,21 @@ namespace nana{ unsigned gap{2}; + + implement() = default; + implement(window grp_panel, ::nana::string titel, bool vsb, unsigned gap=2) + : caption (grp_panel, std::move(titel), vsb), + place_content{grp_panel}, + gap{gap} + { + } + void create(window pnl) { caption.create(pnl); caption.caption(STR("")); place_content.bind(pnl); } - - implement() = default; - implement(window grp_panel, string titel, bool format, unsigned gap=2) - : caption (grp_panel, std::move(titel), format), - place_content{grp_panel}, - gap{gap} - { - } }; group::group() @@ -56,17 +57,17 @@ namespace nana{ } group::group( window parent, ///< - string titel_ /*={}*/, ///< + ::nana::string titel /*={}*/, ///< bool format /*=false*/, ///< unsigned gap /*=2*/, ///< rectangle r /*={} */, ///< bool vsb /*= true */ ///< ) : panel(parent, r, vsb), - impl_(new implement(*this, std::move(titel_), vsb)) + impl_(new implement(*this, std::move(titel), vsb, gap)) { impl_->caption.format(format); - init(); + _m_init(); } @@ -114,7 +115,7 @@ namespace nana{ impl_->place_content[field] << wdg->handle(); } - void group::init() + void group::_m_init() { this->div(nullptr); @@ -153,7 +154,7 @@ namespace nana{ impl_->create(handle()); - init(); + _m_init(); } ::nana::string group::_m_caption() const diff --git a/source/paint/image.cpp b/source/paint/image.cpp index 2312c9c6..e2661b44 100644 --- a/source/paint/image.cpp +++ b/source/paint/image.cpp @@ -263,38 +263,33 @@ namespace paint void image::paste(graphics& dst, const point& p_dst) const { - if(image_ptr_ && !dst.empty()) - image_ptr_->paste(::nana::rectangle{ image_ptr_->size() }, dst, p_dst); - - if (!image_ptr_) - throw std::runtime_error("image is empty"); - - if (dst.empty()) - throw std::invalid_argument("graphics is empty"); + this->paste(rectangle{ this->size() }, dst, p_dst); } - void image::paste(const nana::rectangle& r_src, graphics & dst, const nana::point& p_dst) const + void image::paste(const rectangle& r_src, graphics & dst, const point& p_dst) const { - if(image_ptr_ && !dst.empty()) + if (image_ptr_) + { + if (dst.empty()) + dst.make({ r_src.width, r_src.height }); //throws if failed to create + image_ptr_->paste(r_src, dst, p_dst); - - if (!image_ptr_) + } + else throw std::runtime_error("image is empty"); - - if (dst.empty()) - throw std::invalid_argument("graphics is empty"); } void image::stretch(const nana::rectangle& r_src, graphics& dst, const nana::rectangle & r_dst) const { - if(image_ptr_ && !dst.empty()) + if (image_ptr_) + { + if (dst.empty()) + dst.make({ r_src.width, r_src.height }); //throws if failed to create + image_ptr_->stretch(r_src, dst, r_dst); - - if (!image_ptr_) + } + else throw std::runtime_error("image is empty"); - - if (dst.empty()) - throw std::invalid_argument("graphics is empty"); } //end class image