OSDN Git Service

fix cmake/Macros.cmake
[moflib/moflib.git] / moflib-1.0 / moflib / moflib / mof / widget / OverlapLayout.cpp
1 #include <mof/widget/OverlapLayout.hpp>
2 #include <mof/utilities.hpp>
3 #include <mof/widgets.hpp>
4 #include <mof/streams.hpp>
5 #include <algorithm>
6 #include <vector>
7 #include <mof/ConsoleIO.hpp>
8
9 using std::shared_ptr;
10 using mof::widget::WidgetView;
11 //{{{ Impl
12 struct mof::widget::OverlapLayout::Impl
13 {
14         
15     int width , height;
16     size_t length;
17     std::vector< shared_ptr<WidgetView> > views;
18
19         Impl( const mof::Vector2D& size )
20         : 
21                 width(size.x) , height(size.y) , length(0)
22         {}
23         
24
25         ~Impl()
26     {
27         }
28 };
29 //}}}
30 //{{{ OverlapLayout
31 mof::widget::OverlapLayout::OverlapLayout( const mof::Vector2D& size )
32 : m_pImpl( new Impl( size ) )
33 {
34 }
35 //}}}
36 //{{{ ~OverlapLayout
37 mof::widget::OverlapLayout::~OverlapLayout( )
38 {
39 }
40 //}}}
41 //{{{ add
42 void mof::widget::OverlapLayout::add(shared_ptr<WidgetView> pView)
43 {
44     /*if(m_pImpl->length == 0 ){
45             m_pImpl->width = mof::real2int(size.x);
46             m_pImpl->width = mof::real2int(size.y);
47     }*/
48     m_pImpl->length++;
49     m_pImpl->views.push_back(pView);
50 }
51 //}}}
52 //{{{ getLength
53 size_t mof::widget::OverlapLayout::getLength() const
54 {
55     return m_pImpl->length;
56 }
57 //}}}
58 //{{{ getPreferredSize
59 mof::Vector2D mof::widget::OverlapLayout::getPreferredSize() const
60 {
61     return mof::Vector2D(m_pImpl->width , m_pImpl->height);
62 }
63 //}}}
64 //{{{ connect
65 void mof::widget::OverlapLayout::connect(WidgetView* pParentView) 
66 {
67     size_t i = 0;
68     foreach(shared_ptr<WidgetView> pView , m_pImpl->views) 
69     {
70         pView->getPositionStream() << pParentView->getPositionStream();
71         pView->getSizeStream() << pParentView->getSizeStream() << - pView->getSizeStream().value();
72     }
73 }
74 //}}}
75 //{{{ getAdjacencyAsUp
76 int mof::widget::OverlapLayout::getAdjacencyAsUp(int index) const
77 {
78     return mof::rotation_mod(index-1 , m_pImpl->length);
79 }
80 //}}}
81 //{{{ getAdjacencyAsDown
82 int mof::widget::OverlapLayout::getAdjacencyAsDown(int index) const
83 {
84     return mof::rotation_mod(index+1 , m_pImpl->length );
85 }
86 //}}}
87 //{{{ getAdjacencyAsLeft
88 int mof::widget::OverlapLayout::getAdjacencyAsLeft(int index) const
89 {
90     return mof::rotation_mod(index-1 , m_pImpl->length );
91 }
92 //}}}
93 //{{{ getAdjacencyAsRight
94 int mof::widget::OverlapLayout::getAdjacencyAsRight(int index) const
95 {
96     return mof::rotation_mod(index+1 , m_pImpl->length );
97 }
98 //}}}