• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_ControllerManager.cpp

Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009     
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014     
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019     
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_Gui.h"
00025 #include "MyGUI_ControllerManager.h"
00026 #include "MyGUI_WidgetManager.h"
00027 #include "MyGUI_Common.h"
00028 #include "MyGUI_FactoryManager.h"
00029 
00030 #include "MyGUI_ControllerEdgeHide.h"
00031 #include "MyGUI_ControllerFadeAlpha.h"
00032 #include "MyGUI_ControllerPosition.h"
00033 
00034 namespace MyGUI
00035 {
00036 
00037     MYGUI_INSTANCE_IMPLEMENT(ControllerManager);
00038 
00039     void ControllerManager::initialise()
00040     {
00041         MYGUI_ASSERT(false == mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
00042         MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);
00043 
00044         WidgetManager::getInstance().registerUnlinker(this);
00045 
00046         const std::string factory_type = "Controller";
00047 
00048         FactoryManager::getInstance().registryFactory<ControllerEdgeHide>(factory_type);
00049         FactoryManager::getInstance().registryFactory<ControllerFadeAlpha>(factory_type);
00050         FactoryManager::getInstance().registryFactory<ControllerPosition>(factory_type);
00051 
00052         MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
00053         mIsInitialise = true;
00054     }
00055 
00056     void ControllerManager::shutdown()
00057     {
00058         if (false == mIsInitialise) return;
00059         MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME);
00060 
00061         const std::string factory_type = "Controller";
00062 
00063         FactoryManager::getInstance().unregistryFactory<ControllerEdgeHide>(factory_type);
00064         FactoryManager::getInstance().unregistryFactory<ControllerFadeAlpha>(factory_type);
00065         FactoryManager::getInstance().unregistryFactory<ControllerPosition>(factory_type);
00066 
00067         WidgetManager::getInstance().unregisterUnlinker(this);
00068         clear();
00069 
00070         MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown");
00071         mIsInitialise = false;
00072     }
00073 
00074     void ControllerManager::clear()
00075     {
00076         for (ListControllerItem::iterator iter=mListItem.begin(); iter!=mListItem.end(); ++iter)
00077         {
00078             delete (*iter).second;
00079         }
00080         mListItem.clear();
00081     }
00082 
00083     ControllerItem* ControllerManager::createItem(const std::string& _type)
00084     {
00085         IObject* object = FactoryManager::getInstance().createObject("Controller", _type);
00086         return object->castType<ControllerItem>();
00087     }
00088 
00089     void ControllerManager::addItem(WidgetPtr _widget, ControllerItem * _item)
00090     {
00091         // если виджет первый, то подписываемся на кадры
00092         if (0 == mListItem.size()) Gui::getInstance().eventFrameStart += newDelegate(this, &ControllerManager::frameEntered);
00093 
00094         // подготавливаем
00095         _item->prepareItem(_widget);
00096 
00097         for (ListControllerItem::iterator iter=mListItem.begin(); iter!=mListItem.end(); ++iter)
00098         {
00099             // такой уже в списке есть
00100             if ((*iter).first == _widget)
00101             {
00102                 if ((*iter).second->getTypeName() == _item->getTypeName())
00103                 {
00104                     delete (*iter).second;
00105                     (*iter).second = _item;
00106                     return;
00107                 }
00108             }
00109         }
00110 
00111         // вставляем в самый конец
00112         mListItem.push_back(PairControllerItem(_widget, _item));
00113     }
00114 
00115     void ControllerManager::removeItem(WidgetPtr _widget)
00116     {
00117         // не удаляем из списка, а обнуляем, в цикле он будет удален
00118         for (ListControllerItem::iterator iter=mListItem.begin(); iter!=mListItem.end(); ++iter)
00119         {
00120             if ((*iter).first == _widget) (*iter).first = nullptr;
00121         }
00122     }
00123 
00124     void ControllerManager::_unlinkWidget(WidgetPtr _widget)
00125     {
00126         removeItem(_widget);
00127     }
00128 
00129     void ControllerManager::frameEntered(float _time)
00130     {
00131         for (ListControllerItem::iterator iter=mListItem.begin(); iter!=mListItem.end(); /*added in body*/)
00132         {
00133             if (nullptr == (*iter).first)
00134             {
00135                 delete (*iter).second;
00136                 // удаляем из списка, итератор не увеличиваем и на новый круг
00137                 iter = mListItem.erase(iter);
00138                 continue;
00139             }
00140 
00141             if ((*iter).second->addTime((*iter).first, _time))
00142             {
00143                 ++iter;
00144                 continue;
00145             }
00146 
00147             // на следующей итерации виджет вылетит из списка
00148             (*iter).first = nullptr;
00149         }
00150 
00151         if (0 == mListItem.size()) Gui::getInstance().eventFrameStart -= newDelegate(this, &ControllerManager::frameEntered);
00152     }
00153 
00154 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1