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

# ipicture_painter.cpp

    00001 // ipicture_painter.cpp
    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 #include <background_wnd/painters/ipicture_painter.hpp>
    00016
    00017
    00018 namespace win32 { namespace gui {
    00019
    00020 namespace detail {
    00021
    00022      bool ipicture_painter_base_impl::load_file(param0 file_name)
    00023      {
    00024           _ASSERTE(!file_name.empty());                     // you must specify a valid file_name
    00025
    00026           return picture_.load_from_file(file_name);
    00027      }
    00028
    00029      void ipicture_painter_base_impl::draw_picture(HDC hDC, int x, int y, int cx, int cy)
    00030      {
    00031           // Possible bug in IPicture::Render(), if the image is larer than the region in which shall be drawn.
    00032           // Instead of the top-left edge the origin (0|0) is at the bottom-left edge. Therefore ySrc must be
    00033           // adjusted manually here
    00034           SIZE size = { 0 };
    00035           picture_.get_size(size);
    00036           int ySrc = 0;
    00037           if (size.cy > cy)
    00038                ySrc = cy - size.cy;
    00039
    00040           // Adjust size (it's possible that the DC is to small or the image is too small. Without the adjustment the
    00041           // image would be stretched...)
    00042           size.cx = min(cx, size.cx);
    00043           size.cy = min(cy, size.cy - ySrc);
    00044
    00045           picture_.draw(hDC, x, y, size.cx, size.cy, 0, ySrc, size.cx, size.cy);
    00046      }
    00047
    00048      const bg_wnd::ipicture& ipicture_painter_base_impl::get_ipicture() const
    00049      {
    00050           return picture_;
    00051      }
    00052
    00053 }    // namespace detail
    00054
    00055 // ========================================================================================================= //
    00056
    00063 ipicture_painter::ipicture_painter(param0 file_name) : Base(file_name)
    00064 {}
    00065
    00066 ipicture_painter* ipicture_painter::clone() const
    00067 {
    00068      return new ipicture_painter(*this);
    00069 }
    00070
    00071 void ipicture_painter::draw(HDC hDC, int cx, int cy)
    00072 {
    00073      draw_picture(hDC, 0, 0, cx, cy);
    00074 }
    00075
    00076 // ========================================================================================================= //
    00077
    00084 tile_ipicture_painter::tile_ipicture_painter(param0 file_name) : Base(file_name)
    00085 {
    00086      tile_size_.cx = 0;
    00087      tile_size_.cy = 0;
    00088 }
    00089
    00090 tile_ipicture_painter::tile_ipicture_painter(param0 file_name, param1 tile_size) : Base(file_name), tile_size_(tile_size)
    00091 {}
    00092
    00093 tile_ipicture_painter* tile_ipicture_painter::clone() const
    00094 {
    00095      return new tile_ipicture_painter(*this);
    00096 }
    00097
    00098 void tile_ipicture_painter::draw(HDC hDC, int cx, int cy)
    00099 {
    00100      SIZE size = tile_size_;
    00101      if (tile_size_.cx == 0 && tile_size_.cy == 0)
    00102           get_ipicture().get_size(size);
    00103
    00104      _ASSERTE(size.cx != 0 && size.cy != 0);                // infinite loop if one is 0
    00105      for (int x = 0; x < cx; x += size.cx) {
    00106           for (int y = 0; y < cy; y += size.cy) {
    00107                draw_picture(hDC, x, y, cx - x, cy - y);
    00108           }
    00109      }
    00110 }
    00111
    00116 void tile_ipicture_painter::tile_size(SIZE tile_size)
    00117 {
    00118      tile_size_ = tile_size;
    00119 }
    00120
    00122 SIZE tile_ipicture_painter::tile_size() const
    00123 {
    00124      return tile_size_;
    00125 }
    00126
    00127
    00128 } }  // namespace win32::gui