OSDN Git Service

fix build system ofmoflib1 and saisei1
[moflib/moflib.git] / saisei-1.0 / src / oldcode / tmp.cpp
1 #include "mof/Menu.hpp"
2 #include "mof/Effect.hpp"
3 #include "mof/utilities.hpp"
4 #include "mof/LayoutManager.hpp"
5 #include <boost/scoped_array.hpp>
6 #include "mof/ConsoleIO.hpp"
7 #include "mof/WidgetView.hpp"
8 #include "mof/GraphicsDevice.hpp"
9 #include "mof/mofAnimations.hpp"
10
11
12 struct mof::Menu::Impl{
13     mof::WidgetView* pBackgroundView;
14     mof::LayoutManager* pLayout;
15     std::shared_ptr<mof::Matrix2D> pTranslation;
16     int width;
17     int height;
18     
19     MenuItem* items;
20     int size;
21     int indicator;
22
23     Impl( const mof::Rectangle<int>& _bounds)
24         : pBackgroundView(NULL) , 
25         width(_bounds.endX - _bounds.beginX) , height(_bounds.endY - _bounds.beginY) ,
26         items(NULL) , size(0) , indicator(0) , pLayout(NULL) {
27             pTranslation = std::shared_ptr<mof::Matrix2D>(
28                 new mof::Matrix2D(
29                         mof::Matrix2D::createTranslation(
30                                 mof::Vector2D(_bounds.beginX , _bounds.beginY )
31                                 )
32                         )
33                 );
34     }
35
36     ~Impl(){
37         for(int i = 0 ; i < size ; ++i){
38             delete items[i].pView;
39         }
40         delete[] items;
41         delete pLayout;
42         delete pBackgroundView;
43     }
44
45
46     
47 };
48
49
50 mof::Menu::Menu
51 (
52     mof::WidgetView* pBackgroundView ,
53     const mof::Menu::MenuItem & front ,
54     const mof::Menu::MenuItem& back ,
55     const mof::Rectangle<int>& bounds ,
56     mof::LayoutManager* pLayout
57 )
58 : m_pImpl(new Impl(bounds))
59 {
60     m_pImpl->pLayout = pLayout;
61     m_pImpl->pBackgroundView = pBackgroundView;
62
63     m_pImpl->size = &back - &front + 1;
64     if(m_pImpl->size <= 0)throw std::invalid_argument("the length of front-back is less than zero");
65
66     m_pImpl->items = new MenuItem[m_pImpl->size];
67     boost::scoped_array<mof::Rectangle<int> > boundList(new mof::Rectangle<int>[m_pImpl->size]);
68     
69     for(int i = 0 ; i < m_pImpl->size ; ++i){
70         m_pImpl->items[i] = (&front)[i];
71         mof::Rectangle<int> bounds = m_pImpl->items[i].pView->initialize();
72         boundList[i] = bounds;
73     }
74
75     m_pImpl->pLayout->replace(m_pImpl->width , m_pImpl->height , boundList[0] , boundList[m_pImpl->size-1]);
76
77     //TODO: LayoutAnimation\82ð\82Â\82­\82é
78     for(int i = 0 ; i < m_pImpl->size ; ++i){
79         const mof::Animation<mof::Matrix2D>::Handler children[] = 
80         {
81             mof::makeParametricHandler(m_pImpl->pTranslation) ,
82             mof::makeConstantHandler
83             (
84                 mof::Matrix2D::createTranslation( m_pImpl->pLayout->getPosition(i))
85             )
86         };
87         
88         m_pImpl->items[i].pView->setPosition
89         (
90             mof::Animation<mof::Matrix2D>::Handler
91             (
92                 new mof::CascadingAnimation<mof::Matrix2D>(children[0] , children[1])
93             )
94         );
95     }
96     m_pImpl->pBackgroundView->setBounds(bounds);
97     
98 }
99
100
101 mof::Menu::~Menu(){
102
103 }
104
105 void mof::Menu::show(){
106     m_pImpl->pBackgroundView->show();
107     for(int i = 0 ; i < m_pImpl->size ; ++i){
108         m_pImpl->items[i].pView->show();
109     }
110 }
111
112 void mof::Menu::close(){
113     m_pImpl->pBackgroundView->close();
114     for(int i = 0 ; i < m_pImpl->size ; ++i){
115         m_pImpl->items[i].pView->close();
116     }
117 }
118
119 void mof::Menu::up(){
120     mof::Menu::MenuItem* pItem = &m_pImpl->items[m_pImpl->indicator];
121     pItem->pView->blur();
122
123     m_pImpl->indicator--;
124     if(m_pImpl->indicator == -1)m_pImpl->indicator = m_pImpl->size -1;
125
126     pItem = &m_pImpl->items[m_pImpl->indicator];
127     pItem->pView->focus();
128 }
129
130 void mof::Menu::down(){
131     mof::Menu::MenuItem* pItem = &m_pImpl->items[m_pImpl->indicator];
132     pItem->pView->blur();
133
134     m_pImpl->indicator++;
135     if(m_pImpl->indicator == m_pImpl->size)m_pImpl->indicator = 0;
136
137     pItem = &m_pImpl->items[m_pImpl->indicator];
138     pItem->pView->focus();
139 }
140
141
142
143 void mof::Menu::left() {
144
145 }
146
147 void mof::Menu::right(){
148
149 }
150
151 void mof::Menu::performAction() const{
152     if(!m_pImpl->items[m_pImpl->indicator].action)return;
153     m_pImpl->items[m_pImpl->indicator].action();
154 }
155
156 void mof::Menu::draw() const{
157     m_pImpl->pBackgroundView->draw();
158     mof::GraphicsDevice::setViewport(m_pImpl->pBackgroundView->getBounds());
159     for(int i = 0 ; i < m_pImpl->size ; ++i){
160         m_pImpl->items[i].pView->getEffect()->draw();
161     }
162     mof::GraphicsDevice::setViewport(mof::Rectangle<int>(0 , 0 , 640 , 480));//TODO
163 }
164
165
166 void mof::Menu::update() {
167     m_pImpl->pBackgroundView->update();
168     for(int i = 0 ; i < m_pImpl->size ; ++i){
169         m_pImpl->items[i].pView->update();
170     }
171 }