OSDN Git Service

rm latex/
[moflib/moflib.git] / oldmof / Container2D.cpp
1 #include "mof/Container2D.h"
2 #include "mof/ConsoleIO.h"
3
4
5
6 mof::Container2D::Container2D(int nColumns)
7 : mof::Component2D()  , m_margin(0) , m_paddingX(0) , m_paddingY(0)
8 {
9         m_nColumns = nColumns;
10 }
11
12
13 mof::Container2D::~Container2D(){
14
15         for(int i = 0 ; i < m_children.size() ; i ++){
16                 delete m_children.at(i);
17         }
18 }
19
20 bool mof::Container2D::update(){
21
22         for(int i = 0 ; i < m_children.size() ; i ++){
23                 m_children.at(i)->update();
24         }
25
26
27         //setPosition(getAnimationSet()->getPosition(getPosition()));
28         setPosition(getAnimationSet()->getPosition());
29         getAnimationSet()->update();
30         return true;
31 }
32
33
34 bool mof::Container2D::draw(){
35         
36         for(int i = 0 ; i < m_children.size() ; i ++){
37                 m_children.at(i)->draw();
38         }
39         return true;
40 }
41
42
43 /*
44 bool mof::Container2D::draw(mof::Matrix3D& transform){
45         transform = m_worldTransform * transform;
46         for(int i = 0 ; i < m_children.size() ; i ++){
47                 m_children.at(i)->draw(transform);
48         }
49         return true;
50 }*/
51
52
53 void mof::Container2D::add(mof::Component2D* component){
54         m_children.push_back(component);
55 }
56
57 bool mof::Container2D::remove(mof::Component2D* component){
58         for(std::vector<mof::Component2D*>::iterator itr = m_children.begin() ; itr !=m_children.end() ; ++itr){
59                 if((*itr) == component){
60                         delete component;
61                         return true;
62                 }
63         }
64         return false;
65 }
66
67 int mof::Container2D::indexOf(mof::Component2D* component){
68         for(int i = 0 ; i < m_children.size() ; ++i){
69                 if(m_children.at(i) == component)return i;
70         }
71         return -1;
72 }
73
74 void mof::Container2D::set(int index , mof::Component2D* component){
75         delete m_children.at(index);
76         m_children.at(index) = component;
77 }
78
79 mof::Component2D* mof::Container2D::get(int index){
80         return m_children.at(index);
81 }
82
83 mof::Vector2D mof::Container2D::getPositionOf(int index){
84         return get(index)->getPosition();/* * m_worldTransform;*/
85         //return get(index)->getPosition();
86 }
87
88 void mof::Container2D::setPosition(Vector2D& _position){
89         mof::Vector2D position = _position;
90         m_position = position;
91         position.x += m_margin;
92         position.y += m_margin;
93         
94         int* maxWidthArray = new int[m_nColumns];
95         
96         //\97ñ\96\88\82É\8dÅ\91å\95\9d\82ð\8b\81\82ß\82é
97         for(int i = 0 ; i < m_nColumns ; i++){
98                 maxWidthArray[i] = 0 ;
99                 for(int j = i ; j < m_children.size() ; j += m_nColumns){
100                         int width = get(j)->getWidth();
101                         if(maxWidthArray[i] < width)maxWidthArray[i] = width;
102                 }
103         }
104
105         for(int i = 0 ; i < m_children.size() ; i++){
106                 get(i)->setPosition(position);
107                 if(i % m_nColumns == m_nColumns -1){
108                         position.y += get(i)->getHeight() + m_paddingY;
109                         position.x = m_position.x + m_margin;
110                 }
111                 else position.x += maxWidthArray[i % m_nColumns] + m_paddingX;
112         }
113         
114         delete[] maxWidthArray;
115 }
116
117 mof::Vector2D mof::Container2D::getPosition(){
118         return m_position;
119 }
120                 
121 void mof::Container2D::setVisible(bool visible){
122
123
124 }
125
126 int mof::Container2D::getWidth(){
127         int* maxWidthArray = new int[m_nColumns];
128         //\97ñ\96\88\82É\8dÅ\91å\95\9d\82ð\8b\81\82ß\82é
129         for(int i = 0 ; i < m_nColumns ; i++){
130                 maxWidthArray[i] = 0 ;
131                 for(int j = i ; j < m_children.size() ; j += m_nColumns){
132                         int width = get(j)->getWidth();
133                         if(maxWidthArray[i] < width)maxWidthArray[i] = width;
134                 }
135         }
136         int sumWidth = 0;
137         for(int i = 0 ; i < m_nColumns ; i++)sumWidth += maxWidthArray[i];
138         delete[] maxWidthArray;
139         return sumWidth + (m_nColumns-1)* m_paddingX + getMargin()*2;
140 }
141
142 int mof::Container2D::getHeight(){
143         int sumHeight = 0;
144         for(int i = 0 ; i < m_children.size() ; i++){
145                 if(i % m_nColumns == 0)sumHeight += m_children.at(i)->getHeight() + m_paddingY;
146         }
147         return sumHeight + getMargin() *2;
148 }
149                 
150
151 mof::RectangleModel mof::Container2D::getBounds(){
152         return mof::RectangleModel(getPosition().x , getPosition().y , getWidth() , getHeight());
153 }
154
155 void mof::Container2D::setLayout(){
156         mof::Vector2D position = getPosition();
157         position.x += m_margin;
158         position.y += m_margin;
159         //DEBUG_PRINT(position.x << _T(",") << position.y);
160         setPosition(getPosition());
161 }
162