Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

## ipicture_painter

The ipicture_painter implements the COM IPicture-Interface which allows loading bmp, jpg and gif image files. The class draws the image on a background_wnd. If the drawing-rectangle of the painter is smaller than the image the image will be clipped. Copying an ipicture is a non-expensive operation - it's just a call to `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

Note:
  - `get_ipicture()` returns a const reference to the bg_wnd::ipicture-object on which this painter is based
  - If the filename passed to `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)
  - ipicture_painter is derived from ipicture_painter_base which implements the loading and drawing of the ipicture. tile_ipicture_base is also derived from this class. ipicture_painter_base is a template to achieve different exception-classes. With this in mind you can separate between exceptions of the two classes because they're distinct:

        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
             ...
        }

Example:

    add_painter<ipicture_painter> ("c:\\img1.jpg");

The result is as follows

## tile_ipicture_painter

The tile_ipicture_painter does the same as the ipicture_painter with the difference that the image loaded from the file will be displayed in tiles. You can optionally set the size of the tiles.

    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

Note:
  - The same as for ipicture_painter applies to this class
  - `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 size

Example:

    const 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.