AddRef()!
namespace win32 { namespace gui { namespace detail { // base of the ipicture_painters. note how the exception is specified for the Derived class ;-) template <class Derived> struct ipicture_painter_base : painter_base { typedef ipicture_painter_base_impl::param0 param0; // exceptions typedef bg_wnd::general_exception<Derived, 0> file_not_found; void load_file(const std::string& file_name); const bg_wnd::ipicture& get_ipicture() const; }; } // namespace detail // ========================================================================================================= // class ipicture_painter : public detail::ipicture_painter_base<ipicture_painter> { public: // c'tor ipicture_painter(const std::string& file_name = ""); // virtual functions of painter_base ipicture_painter* clone() const; void draw(HDC hDC, int cx, int cy); }; } } // namespace win32::gui
get_ipicture() returns a const reference to the bg_wnd::ipicture-object on which this painter is based load_file() or the c'tor doesn't exist an ipicture_painter::file_not_found-exception is thrown (but note an empty string will not throw) try { add_painter<ipicture_painter> ("c:\pic1.gif"); add_painter<tile_ipicture_painter> ("c:\pic2.gif"); } catch (ipicture_painter::file_not_found&) { // first line has thrown. react in an appropiate manner ... } catch (tile_ipicture_painter::file_not_found&) { // second line has thrown. react in an appropiate manner ... }
add_painter<ipicture_painter> ("c:\\img1.jpg");
The result is as follows
namespace win32 { namespace gui { class tile_ipicture_painter : public detail::ipicture_painter_base<tile_ipicture_painter> { public: typedef SIZE param1; // c'tor tile_ipicture_painter(const std::string& file_name = ""); tile_ipicture_painter(const std::string& file_name, SIZE tile_size); // virtual functions of painter_base tile_ipicture_painter* clone() const; void draw(HDC hDC, int cx, int cy); // own functions void tile_size(SIZE tile_size); SIZE tile_size() const; }; } } // namespace win32::gui
tile_size() sets and returns the current tile size. If the image is larger it will be clipped. By default the tile size is cx = 0, cy = 0 which means the painter shall determine the size of the image and use that sizeconst SIZE tile_size = ...; add_painter<tile_ipicture_painter> ("c:\\img1.jpg", tile_size);
The result is as follows
|
|
| tile_size = { 100, 100 } | tile_size = { 0, 0 } (determine resource size) |
|
by Steven Weiss. You can contact me at steven11@gmx.de. |