/* * Elements of GUI Gadgets * Nana C++ Library(http://www.nanapro.org) * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file: nana/gui/element.hpp */ #ifndef NANA_GUI_ELEMENT_HPP #define NANA_GUI_ELEMENT_HPP #include #include #include #include namespace nana { namespace paint { //forward declaration class image; } namespace element { class element_interface { public: typedef paint::graphics & graph_reference; virtual ~element_interface() {} virtual bool draw(graph_reference, const nana::color& bgcolor, const nana::color& fgcolor, const nana::rectangle&, element_state) = 0; }; class crook_interface { public: typedef paint::graphics & graph_reference; typedef checkstate state; struct data { state check_state; bool radio; }; virtual ~crook_interface() {} virtual bool draw(graph_reference, const nana::color& bgcolor, const nana::color& fgcolor, const nana::rectangle&, element_state, const data&) = 0; }; class provider { public: template struct factory_interface { virtual ~factory_interface(){} virtual ElementInterface* create() const = 0; virtual void destroy(ElementInterface*) const = 0; }; template class factory : public factory_interface { public: typedef factory_interface interface_type; ElementInterface * create() const override { return (new Element); } void destroy(ElementInterface * p) const override { delete p; } }; void add_crook(const std::string& name, const pat::cloneable>&); crook_interface* const * keeper_crook(const std::string& name); }; template void add_crook(const std::string& name) { typedef provider::factory factory_t; provider().add_crook(name, pat::cloneable(factory_t())); } class crook; }//end namespace element template class facade; template<> class facade : public element::element_interface { public: typedef ::nana::paint::graphics & graph_reference; typedef element::crook_interface::state state; facade(); facade(const char* name); facade & reverse(); facade & check(state); state checked() const; facade& radio(bool); bool radio() const; void switch_to(const char*); public: //Implement element_interface bool draw(graph_reference, const nana::color& bgcolor, const nana::color& fgcolor, const nana::rectangle& r, element_state) override; private: element::crook_interface::data data_; element::crook_interface* const * keeper_; }; namespace element { void set_bground(const char* name, const pat::cloneable&); void set_bground(const char* name, pat::cloneable &&); class cite_bground { public: typedef paint::graphics& graph_reference; typedef pat::cloneable cloneable_element; cite_bground(const char*); void set(const cloneable_element&); void set(const char*); bool draw(graph_reference, const nana::color& bgcolor, const nana::color& fgcolor, const nana::rectangle&, element_state); private: cloneable_element holder_; element_interface * place_ptr_; element_interface * const * ref_ptr_; }; class bground : public element_interface { public: typedef paint::graphics& graph_reference; bground(); bground(const bground&); ~bground(); bground& operator=(const bground&); bground& image(const paint::image&, bool vertical, const nana::rectangle& valid_area); ///< Set a picture for the background bground& image(const paint::graphics&, bool vertical, const nana::rectangle& valid_area); ///< Set a picture for the background void states(const std::vector &); ///< Set the state sequence of the background picture. void states(std::vector &&); ///< Set the state sequence of the background picture. void reset_states(); void join(element_state target, element_state joiner); void stretch_parts(unsigned left, unsigned top, unsigned right, unsigned bottom); //Implement the methods of element_interface. virtual bool draw(graph_reference, const nana::color& bgcolor, const nana::color& fgcolor, const nana::rectangle&, element_state); private: struct draw_method; struct draw_image; struct draw_graph; draw_method * method_; bool vertical_; nana::rectangle valid_area_; std::vector states_; std::map join_; bool stretch_all_; unsigned left_, top_, right_, bottom_; }; //end class bground }//end namespace element }//end namespace nana #endif //NANA_GUI_ELEMENT_HPP