OSDN Git Service

0d255846c0d9891454d75188a4a25fdb81edb138
[moflib/moflib.git] / moflib-1.0 / moflib / moflib / mof / widget / ClippingView.cpp
1 #include <mof/widget/ClippingView.hpp>
2 #include <mof/GraphicsDevice.hpp>
3 #include <mof/ConsoleIO.hpp>
4     
5 namespace mof
6 {
7 namespace widget
8 {
9 //{{{ struct Impl
10     struct ClippingView::Impl
11     {
12         std::shared_ptr<WidgetView> pBody_; 
13                 mof::Vector2D preferredSize_;
14
15         Impl(std::shared_ptr<WidgetView> pBody)
16         : pBody_(pBody)
17         {
18         }
19     
20         ~Impl()
21         {
22         }
23     
24     };
25 //}}}
26 //{{{ constructor
27     ClippingView::ClippingView(std::shared_ptr<WidgetView> pBody)
28     : 
29         pImpl_(new Impl(pBody)) 
30     {
31         pImpl_->pBody_->getPositionStream() << getPositionStream(); 
32         pImpl_->pBody_->getColorStream()    << getColorStream(); 
33                 pImpl_->preferredSize_ = pImpl_->pBody_->getPreferredSize();// the initial scale depends on the body.
34         getSizeStream() << pImpl_->preferredSize_;
35         pImpl_->pBody_->getSizeStream() << getSizeStream() << mof::makeConstantHandler(-pImpl_->preferredSize_); 
36     }
37 //}}}
38 //{{{ destructor
39     ClippingView::~ClippingView()
40     {
41     }
42 //}}}
43 //{{{ update
44     void ClippingView::update( )
45     {
46         m_positionStream.update( );
47         m_sizeStream.update( );
48         m_colorStream.update( );
49         pImpl_->pBody_->update();
50     }
51 //}}}
52 //{{{ draw
53     void ClippingView::draw( ) const
54     {
55                 int width = mof::GraphicsDevice::getViewportWidth();
56                 int height = mof::GraphicsDevice::getViewportHeight();
57                 mof::Vector2D position = m_positionStream.value();
58                 mof::Vector2D scale = m_sizeStream.value();
59                 if (0 == scale.x || 0 == scale.y) return;// prevent the area of viewport from vanishing. 
60                 mof::GraphicsDevice::setViewport(mof::Rectangle<mof::real>(position.x, position.y, position.x + scale.x, position.y + scale.y));
61         pImpl_->pBody_->draw( );
62                 mof::GraphicsDevice::setViewport(mof::Rectangle<mof::real>(0, 0, width, height));// restore the viewport.
63     }
64 //}}}
65 //{{{ setVisible
66     void ClippingView::setVisible(bool visible)
67     {
68                 pImpl_->pBody_->setVisible(visible);
69     }
70 //}}}
71 //{{{ show
72     FrameNumber ClippingView::show(bool immediately) 
73     {
74         return pImpl_->pBody_->show(immediately);
75     }
76 //}}}
77 //{{{ hide
78     FrameNumber ClippingView::hide(bool immediately)
79     {
80         return pImpl_->pBody_->hide(immediately);
81     }
82 //}}}
83 //{{{ focus
84     FrameNumber ClippingView::focus(bool immediately) 
85     {
86         return pImpl_->pBody_->focus(immediately);
87     }
88 //}}}
89 //{{{ blur
90     FrameNumber ClippingView::blur(bool immediately)
91     {
92         return pImpl_->pBody_->blur(immediately);
93     }
94 //}}}
95 //{{{ click
96     FrameNumber ClippingView::click(bool immediately)
97     {
98         return pImpl_->pBody_->click(immediately);
99     }
100 //}}}
101 //{{{ getPreferredSize
102         mof::Vector2D ClippingView::getPreferredSize() const
103     {
104         return pImpl_->preferredSize_;
105     }
106 //}}}
107 }
108 } // namespace mof