TuttleOFX
1
|
00001 // Copyright Tom Brinkman 2008. Distributed under the Boost 00002 // Software License, Version 1.0. (See accompanying 00003 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00004 00005 #ifndef _aligned_hpp_ 00006 #define _aligned_hpp_ 00007 00008 #include <boost/gil/gil_all.hpp> 00009 #include <blend.hpp> 00010 00011 namespace layer 00012 { 00013 00014 template <typename view_t> 00015 struct aligned 00016 { 00017 enum 00018 { 00019 left = (0x1 << 0), 00020 center = (0x1 << 1), 00021 right = (0x1 << 2), 00022 top = (0x1 << 3), 00023 middle = (0x1 << 5), 00024 bottom = (0x1 << 7), 00025 }; 00026 00027 view_t& v2; 00028 int align; 00029 aligned(view_t v2, int align = center|middle) : v2(v2), align(align) {} 00030 00031 void operator()(view_t& view) 00032 { 00033 using namespace boost::gil; 00034 00035 int w = v2.width(); 00036 int h = v2.height(); 00037 00038 if (h > view.height() || w > view.width()) 00039 return; 00040 00041 int x = 0; 00042 if (align & center) 00043 x = (view.width()-w)/2; 00044 else if (align & right) 00045 x = view.width()-w; 00046 00047 int y = 0; 00048 if (align & middle) 00049 y = (view.height()-h)/2; 00050 else if (align & bottom) 00051 y = view.height()-h; 00052 00053 view_t v3 = subimage_view(view,x,y,w,h); 00054 boost::gil::copy_pixels(v2,v3); 00055 } 00056 }; 00057 00058 } 00059 00060 #endif