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

# background_wnd/painters/ipicture_painter.hpp

    00001 // ipicture_painter.hpp
    00002
    00003 // Copyright (C) 2004 Steven Weiß (steven11@gmx.de)
    00004 //
    00005 // Permission to copy, use, sell and distribute this software is granted
    00006 // provided this copyright notice appears in all copies.
    00007 // Permission to modify the code and to distribute modified code is granted
    00008 // provided this copyright notice appears in all copies, and a notice
    00009 // that the code was modified is included with the copyright notice.
    00010 //
    00011 // This software is provided "as is" without express or implied warranty,
    00012 // and with no claim as to its suitability for any purpose.
    00013
    00014
    00015 #pragma once
    00016 #include <background_wnd/detail/include.hpp>
    00017 #include <background_wnd/painter_base.hpp>
    00018 #include <background_wnd/detail/ipicture.hpp>
    00019 #include <background_wnd/detail/general_exception.hpp>
    00020
    00021
    00022 namespace win32 { namespace gui {
    00023
    00024 namespace detail {
    00025
    00026      // implementation of ipicture_painter_base
    00027      struct ipicture_painter_base_impl
    00028      {
    00029           typedef const std::string& param0;
    00030
    00031           bool load_file(const std::string& file_name);
    00032           const bg_wnd::ipicture& get_ipicture() const;
    00033           void draw_picture(HDC hDC, int x, int y, int cx, int cy);
    00034
    00035      private:
    00036           bg_wnd::ipicture picture_;
    00037      };
    00038
    00039      // base of the ipicture_painters. note how the exception is specified for the Derived class ;-)
    00040      template <class Derived>
    00041      struct ipicture_painter_base : painter_base
    00042      {
    00043           typedef ipicture_painter_base_impl::param0 param0;
    00044
    00045           // exceptions
    00046           typedef bg_wnd::general_exception<Derived, 0> file_not_found;
    00047
    00048           ipicture_painter_base(const std::string& file_name)
    00049           {
    00050                load_file(file_name);
    00051           }
    00052
    00053           virtual ~ipicture_painter_base()
    00054           {}
    00055
    00059           void load_file(const std::string& file_name)
    00060           {
    00061                if (!file_name.empty() && impl_.load_file(file_name) == false)
    00062                     throw file_not_found(static_cast<Derived&> (*this));   // class is abstract (draw() not implemented)
    00063           }                                                                               // so this is safe
    00064
    00066           const bg_wnd::ipicture& get_ipicture() const
    00067           {
    00068                return impl_.get_ipicture();
    00069           }
    00070
    00071      protected:
    00072           void draw_picture(HDC hDC, int x, int y, int cx, int cy)
    00073           {
    00074                impl_.draw_picture(hDC, x, y, cx, cy);
    00075           }
    00076
    00077      private:
    00078           ipicture_painter_base_impl impl_;
    00079      };
    00080
    00081 }    // namespace detail
    00082
    00083 // ========================================================================================================= //
    00084
    00085 class ipicture_painter : public detail::ipicture_painter_base<ipicture_painter>
    00086 {
    00087      typedef detail::ipicture_painter_base<ipicture_painter> Base;
    00088
    00089 public:
    00090      // c'tor
    00091      ipicture_painter(const std::string& file_name = "");
    00092
    00093      // virtual functions of painter_base
    00094      ipicture_painter* clone() const;
    00095      void draw(HDC hDC, int cx, int cy);
    00096 };
    00097
    00098 // ========================================================================================================= //
    00099
    00100 class tile_ipicture_painter : public detail::ipicture_painter_base<tile_ipicture_painter>
    00101 {
    00102      typedef detail::ipicture_painter_base<tile_ipicture_painter> Base;
    00103      SIZE tile_size_;
    00104
    00105 public:
    00106      typedef SIZE param1;
    00107
    00108      // c'tor
    00109      tile_ipicture_painter(const std::string& file_name = "");
    00110      tile_ipicture_painter(const std::string& file_name, SIZE tile_size);
    00111
    00112      // virtual functions of painter_base
    00113      tile_ipicture_painter* clone() const;
    00114      void draw(HDC hDC, int cx, int cy);
    00115
    00116      // own functions
    00117      void tile_size(SIZE tile_size);
    00118      SIZE tile_size() const;
    00119 };
    00120
    00121 } }  // namespace win32::gui