1 #include "mof/Container2D.h"
2 #include "mof/ConsoleIO.h"
6 mof::Container2D::Container2D(int nColumns)
7 : mof::Component2D() , m_margin(0) , m_paddingX(0) , m_paddingY(0)
13 mof::Container2D::~Container2D(){
15 for(int i = 0 ; i < m_children.size() ; i ++){
16 delete m_children.at(i);
20 bool mof::Container2D::update(){
22 for(int i = 0 ; i < m_children.size() ; i ++){
23 m_children.at(i)->update();
27 //setPosition(getAnimationSet()->getPosition(getPosition()));
28 setPosition(getAnimationSet()->getPosition());
29 getAnimationSet()->update();
34 bool mof::Container2D::draw(){
36 for(int i = 0 ; i < m_children.size() ; i ++){
37 m_children.at(i)->draw();
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);
53 void mof::Container2D::add(mof::Component2D* component){
54 m_children.push_back(component);
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){
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;
74 void mof::Container2D::set(int index , mof::Component2D* component){
75 delete m_children.at(index);
76 m_children.at(index) = component;
79 mof::Component2D* mof::Container2D::get(int index){
80 return m_children.at(index);
83 mof::Vector2D mof::Container2D::getPositionOf(int index){
84 return get(index)->getPosition();/* * m_worldTransform;*/
85 //return get(index)->getPosition();
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;
94 int* maxWidthArray = new int[m_nColumns];
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;
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;
111 else position.x += maxWidthArray[i % m_nColumns] + m_paddingX;
114 delete[] maxWidthArray;
117 mof::Vector2D mof::Container2D::getPosition(){
121 void mof::Container2D::setVisible(bool visible){
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;
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;
142 int mof::Container2D::getHeight(){
144 for(int i = 0 ; i < m_children.size() ; i++){
145 if(i % m_nColumns == 0)sumHeight += m_children.at(i)->getHeight() + m_paddingY;
147 return sumHeight + getMargin() *2;
151 mof::RectangleModel mof::Container2D::getBounds(){
152 return mof::RectangleModel(getPosition().x , getPosition().y , getWidth() , getHeight());
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());