OSDN Git Service

fix build system ofmoflib1 and saisei1
[moflib/moflib.git] / saisei-1.0 / src / widget / ImageTileWidgetView.cpp
1 #include "widget/ImageTileWidgetView.hpp"
2 #include "mof/GraphicsDevice.hpp"
3 #include "mof/Sprite.hpp"
4 #include "widget/Frame.hpp"
5 #include "mof/streams.hpp"
6 #include "mof/Font.hpp"
7
8
9
10 struct ImageTileWidgetView::Impl{
11
12     Frame* pFrame;
13     mof::Manipulator<bool>::Handler visible;
14     mof::FrameNumber frame;
15     mof::Rectangle<int> bounds;
16     //mof::Sprite* pCaption;
17     
18
19     Impl( )
20         :  pFrame(NULL) , frame(0)  
21     {
22     }
23
24     ~Impl(){
25         delete pFrame;
26     }
27 };
28
29
30 ImageTileWidgetView::ImageTileWidgetView
31 (
32     const mof::tstring& filepath 
33 )
34 : m_pImpl( new Impl( ) )
35 {
36
37     std::shared_ptr<mof::Texture> pTexture(new mof::Texture( filepath));
38     m_pImpl->pFrame = new Frame( pTexture );
39     //mof::Manipulator<mof::Matrix2D>::Handler t  = mof::makeConstantHandler( mof::Matrix2D::createIdentity() ) ;
40     //m_pImpl->transform = mof::makeJointHandler( t );
41     //m_pImpl->transform = mof::makeJointHandler< mof::Matrix2D >( mof::makeConstantHandler( mof::Matrix2D::createIdentity() ) );
42     
43     { //visible\82Ì\90Ý\92è
44         //m_pImpl->visible = mof::makeConstantHandler(false);
45     }
46
47     //m_pImpl->pCaption = mof::Sprite::createTextSprite( mof::Font(mof::Font::MS_P_GOTHIC , 25) , title );
48 }
49         
50 ImageTileWidgetView::~ImageTileWidgetView()
51 {
52
53 }
54
55
56
57
58 void ImageTileWidgetView::update( )
59 {
60     m_pImpl->frame++;
61     //m_pImpl->pCaption->update();
62     /*mof::Matrix2D transformMatrix = m_pImpl->transform->getValue(m_pImpl->frame);
63     mof::Vector2D begin = mof::Vector2D(0 , 0) * transformMatrix;
64     mof::Vector2D end = mof::Vector2D(1 , 1) * transformMatrix;
65     m_pImpl->pFrame->setRegion(mof::Rectangle<int>(begin.x , begin. y , end.x , end.y)); 
66     */
67 }
68         
69 void ImageTileWidgetView::draw() const
70 {
71     if(m_pImpl->visible->value(m_pImpl->frame))
72     {
73         m_pImpl->pFrame->draw();
74         //m_pImpl->pCaption->draw();
75     }
76 }
77
78
79
80 /*
81 #include "mof/ImageTileWidgetView.hpp"
82 #include "mof/GraphicsDevice.hpp"
83 #include "mof/Sprite.hpp"
84 #include "mof/Frame.hpp"
85 #include "mof/mofManipulators.hpp"
86 #include "mof/Font.hpp"
87
88 struct mof::ImageTileWidgetView::Impl{
89
90     mof::Frame* pFrame;
91     mof::Joint< mof::Matrix2D , mof::Matrix2D >::Handler transform;
92     mof::Manipulator<bool>::Handler visible;
93     mof::FrameNumber frame;
94     mof::Rectangle<int> bounds;
95     //mof::Sprite* pCaption;
96     
97
98     Impl( )
99         :  pFrame(NULL) , frame(0)  
100     {
101     }
102
103     ~Impl(){
104         delete pFrame;
105     }
106 };
107
108
109 mof::ImageTileWidgetView::ImageTileWidgetView(
110     const mof::tstring& filepath 
111     )
112     : m_pImpl( new Impl( ) ){
113
114     std::shared_ptr<mof::Texture> pTexture(new mof::Texture( filepath));
115     m_pImpl->pFrame = new mof::Frame( pTexture);
116     //mof::Manipulator<mof::Matrix2D>::Handler t  = mof::makeConstantHandler( mof::Matrix2D::createIdentity() ) ;
117     //m_pImpl->transform = mof::makeJointHandler( t );
118     m_pImpl->transform = mof::makeJointHandler< mof::Matrix2D >( mof::makeConstantHandler( mof::Matrix2D::createIdentity() ) );
119     {
120         //visible\82Ì\90Ý\92è
121         m_pImpl->visible = mof::makeConstantHandler(false);
122     }
123
124     //m_pImpl->pCaption = mof::Sprite::createTextSprite( mof::Font(mof::Font::MS_P_GOTHIC , 25) , title );
125 }
126         
127 mof::ImageTileWidgetView::~ImageTileWidgetView(){
128
129 }
130
131
132 void mof::ImageTileWidgetView::focus(){
133
134 }
135         
136 void mof::ImageTileWidgetView::blur(){
137
138 }
139
140 //{{{ show
141 void mof::ImageTileWidgetView::show(){
142     const int endWidth = m_pImpl->bounds.endX - m_pImpl->bounds.beginX;
143     const int beginWidth = static_cast<int>( static_cast<float>(endWidth ) / 10.0f );
144     const int endHeight = m_pImpl->bounds.endY - m_pImpl->bounds.beginY;
145     const int beginHeight = static_cast<int>( static_cast<float>(endHeight ) / 10.0f);
146     mof::KeyFrameManipulator<mof::Vector2D>::KeyFrame keyFrames1[] = {
147         mof::makeKeyFrame(0 , mof::Vector2D(beginWidth , beginHeight )) ,
148         mof::makeKeyFrame(10 , mof::Vector2D(endWidth , beginHeight )) ,
149         mof::makeKeyFrame(20 , mof::Vector2D(endWidth , endHeight))
150     };
151
152     const int beginCX = (m_pImpl->bounds.beginX + m_pImpl->bounds.endX - beginWidth) / 2;
153     const int beginCY = (m_pImpl->bounds.beginY + m_pImpl->bounds.endY - beginHeight) / 2;
154     mof::KeyFrameManipulator<mof::Vector2D>::KeyFrame keyFrames2[] = {
155         mof::makeKeyFrame(0 , mof::Vector2D(beginCX , beginCY )) ,
156         mof::makeKeyFrame(10 , mof::Vector2D(m_pImpl->bounds.beginX , beginCY )) ,
157         mof::makeKeyFrame(20 , mof::Vector2D(m_pImpl->bounds.beginX , m_pImpl->bounds.beginY))
158     };
159     mof::Manipulator<mof::Matrix2D>::Handler list[] = {
160         mof::Manipulator<mof::Matrix2D>::Handler(new mof::ScalingAnimation2D(keyFrames1[0] , keyFrames1[2])) ,
161         mof::Manipulator<mof::Matrix2D>::Handler(new mof::TranslationAnimation2D(keyFrames2[0] , keyFrames2[2])) ,
162     };
163     m_pImpl->transform->set( mof::Manipulator<mof::Matrix2D>::Handler(new mof::CascadingAnimation<mof::Matrix2D>(list[0] , list[1])) );
164
165     {
166         //title\8aÖ\8cW\82Ì\90Ý\92è
167         {
168             //world transform
169             mof::KeyFrameManipulator<mof::Vector2D>::KeyFrame keyFrames[] = {
170                 mof::makeKeyFrame(0 , mof::Vector2D(-10 , 0 ) ) ,
171                 mof::makeKeyFrame(20 , mof::Vector2D(-10 , 0 ) ) ,
172                 mof::makeKeyFrame(30 , mof::Vector2D(0 , 0 ) ) 
173             };
174             mof::Manipulator<mof::Matrix2D>::Handler tmp(new mof::TranslationAnimation2D(keyFrames[0] , keyFrames[2]));
175
176             mof::Manipulator<mof::Matrix2D>::Handler list[]= {
177                 mof::makeConstantHandler( mof::Matrix2D::createScaling( m_pImpl->pCaption->getWorldTransform().getDiagonal())) ,
178                 mof::makeConstantHandler( mof::Matrix2D::createTranslation(mof::Vector2D(m_pImpl->bounds.beginX + 20 , m_pImpl->bounds.beginY + 5 )) ) ,
179                 tmp
180             };
181             m_pImpl->pCaption->setWorldTransform(mof::Manipulator<mof::Matrix2D>::Handler(new mof::CascadingAnimation<mof::Matrix2D>(list[0] , list[2])));
182
183         }
184         mof::KeyFrameManipulator<mof::Color4f>::KeyFrame keyFrames[] = {
185             mof::makeKeyFrame(0 , mof::Color4f(0 , 1 , 1 , 1) ) ,
186             mof::makeKeyFrame(20 , mof::Color4f(0 , 1 , 1 , 1) ) ,
187             mof::makeKeyFrame(30 , mof::Color4f(1 , 1 , 1 , 1) ) 
188         };
189         m_pImpl->pCaption->setColor(mof::Manipulator<mof::Color4f>::Handler(new mof::KeyFrameAnimation<mof::Color4f>(keyFrames[0] , keyFrames[2])));
190         m_pImpl->pCaption->setFrameNumber(0);
191     }
192     {
193         //visible\82Ì\90Ý\92è
194         m_pImpl->visible = mof::makeConstantHandler(true);
195     }
196     m_pImpl->frame = 0;
197
198 }
199 //}}} 
200 //{{{ close
201 void mof::ImageTileWidgetView::close(){
202     const int beginWidth = m_pImpl->bounds.endX - m_pImpl->bounds.beginX;
203     const int endWidth = static_cast<int>( static_cast<float>(beginWidth ) / 10.0f );
204     const int beginHeight = m_pImpl->bounds.endY - m_pImpl->bounds.beginY;
205     const int endHeight = static_cast<int>( static_cast<float>(beginHeight ) / 10.0f);
206     mof::KeyFrameManipulator<mof::Vector2D>::KeyFrame keyFrames1[] = {
207         mof::makeKeyFrame(0 , mof::Vector2D(beginWidth , beginHeight )) ,
208         mof::makeKeyFrame(10 , mof::Vector2D(beginWidth , endHeight )) ,
209         mof::makeKeyFrame(20 , mof::Vector2D(endWidth , endHeight))
210     };
211
212     const int endCX = (m_pImpl->bounds.beginX + m_pImpl->bounds.endX - endWidth) / 2;
213     const int endCY = (m_pImpl->bounds.beginY + m_pImpl->bounds.endY - endHeight) / 2;
214     mof::KeyFrameManipulator<mof::Vector2D>::KeyFrame keyFrames2[] = {
215         mof::makeKeyFrame(0 , mof::Vector2D(m_pImpl->bounds.beginX , m_pImpl->bounds.beginY )) ,
216         mof::makeKeyFrame(10 , mof::Vector2D(m_pImpl->bounds.beginX , endCY)) ,
217         mof::makeKeyFrame(20 , mof::Vector2D(endCX , endCY ))
218     };
219     mof::Manipulator<mof::Matrix2D>::Handler list[] = {
220         mof::Manipulator<mof::Matrix2D>::Handler(new mof::ScalingAnimation2D(keyFrames1[0] , keyFrames1[2])) ,
221         mof::Manipulator<mof::Matrix2D>::Handler(new mof::TranslationAnimation2D(keyFrames2[0] , keyFrames2[2])) ,
222     };
223     m_pImpl->transform->set( mof::Manipulator<mof::Matrix2D>::Handler(new mof::CascadingAnimation<mof::Matrix2D>(list[0] , list[1])) );
224
225     {
226         //title\8aÖ\8cW\82Ì\90Ý\92è
227         //m_pImpl->pCaption->setColor(mof::Color4f(0 , 0 , 0 , 0));
228         //m_pImpl->pCaption->setFrameNumber(0);
229     }
230     {
231         //visible\82Ì\90Ý\92è
232         mof::KeyFrameManipulator<bool>::KeyFrame keyFrames[] = {
233             mof::makeKeyFrame(0 , true) ,
234             mof::makeKeyFrame(20 , false) 
235         };
236         m_pImpl->visible = mof::Manipulator<bool>::Handler(
237             new mof::KeyFrameManipulator<bool>(keyFrames[0] , keyFrames[1] , &mof::stepInterpolate<bool> )
238             );
239     }
240     m_pImpl->frame = 0;
241 }
242 //}}}
243 mof::Manipulator<mof::Vector2D>::Handler mof::ImageTileWidgetView::getPosition( ) const
244 {
245     return mof::dynamic::makeTranslation2DHandler( m_pImpl->transform );
246 }
247
248 mof::Manipulator<mof::Vector2D>::Handler mof::ImageTileWidgetView::getSize( ) const
249 {
250     return mof::dynamic::makeScaling2DHandler( m_pImpl->transform );
251 }
252
253
254 void mof::ImageTileWidgetView::setBounds(const mof::Rectangle<int>& bounds)
255 {
256     m_pImpl->bounds = bounds;
257 }
258
259 mof::Rectangle<int> mof::ImageTileWidgetView::getBounds() const
260 {
261     return m_pImpl->bounds;
262 }
263
264
265 void mof::ImageTileWidgetView::update( )
266 {
267     m_pImpl->frame++;
268     //m_pImpl->pCaption->update();
269     mof::Matrix2D transformMatrix = m_pImpl->transform->getValue(m_pImpl->frame);
270     mof::Vector2D begin = mof::Vector2D(0 , 0) * transformMatrix;
271     mof::Vector2D end = mof::Vector2D(1 , 1) * transformMatrix;
272     m_pImpl->pFrame->setRegion(mof::Rectangle<int>(begin.x , begin. y , end.x , end.y));
273 }
274         
275 void mof::ImageTileWidgetView::draw(){
276     if(m_pImpl->visible->getValue(m_pImpl->frame)){
277         m_pImpl->pFrame->draw();
278         //m_pImpl->pCaption->draw();
279     }
280 }
281 */