예제 #1
0
파일: panel.cpp 프로젝트: fiddleplum/ve
	template <typename T> Ptr<T> Panel::createWidget()
	{
		Ptr<T> widget = widgets.appendNew<T>(getScene(), getShader());
		widget->setDepth(depth + 1);
		widgetInfos.insert({widget, WidgetInfo()});
		updateWidgetBounds(widget);
		return widget;
	}
예제 #2
0
	void GuiMgrParser::OnXmlElement( TiXmlElement* element )
	{
		if(!element) return;

		TiXmlAttribute* pAttrib = element->FirstAttribute();


		if(strcmp(element->Value(), "listener") == 0)
		{
			std::string name = "default";
			while (pAttrib)
			{
				if(strcmp(pAttrib->Name(),"name") == 0) {
					name = pAttrib->Value();
				} else {
					error_log("Unhandled attribute when loading ui! %s", pAttrib->Name());
				}
				pAttrib = pAttrib->Next();
			}
			currentListener = name;
			m_tagLoc.push(Listener);
		} else if(strcmp(element->Value(),"widget") == 0) {
			switch(GetTagLocation())
			{
			case None:
			{
				Widget* temp = NULL;
				//it's a create widget xml syntax! 
				std::string widgetName; 
				int widgetType = WIDGET;
				while (pAttrib)
				{
					if(strcmp(pAttrib->Name(),"name") == 0)
						widgetName = pAttrib->Value();
					else if(strcmp(pAttrib->Name(),"type") == 0) {
						pAttrib->QueryIntValue(&widgetType);
					} else {
						error_log("Unhandled attribute when loading ui! %s", pAttrib->Name());
					}
					pAttrib = pAttrib->Next();
				}
				if(!m_loadLayout) {
					bool created = false;
					for(uint32 i=0; i<m_gui->m_factories.size(); i++) {
						if(m_gui->m_factories[i]->CanCreateWidget((uint32)widgetType)) {
							temp = m_gui->m_factories[i]->CreateWidget((uint32)widgetType);
							if(temp) {
								created = true;
								temp->SetName(widgetName);
								temp->SetLoading(true);
							}
							
							break;						
						}
					}
					if(!created) {
						error_log("No factory was able to create a widget of type: %u!", widgetType);
					} else {
						m_widgetInfos.push(WidgetInfo(temp,(uint32)widgetType));
					}
				} else {
					Widget* temp = NULL;
					if(m_widgets.size()) {
						Widget*	parent = m_widgets.top();
						temp = parent->FindChildByName(widgetName);
						if(!temp) {
							debug_log("Couldn't find widget %s while loading layout!", widgetName.c_str());
						} else {
							m_widgets.push(temp);
						}
					} else {
						Widget* temp = NULL;
						temp = m_gui->GetWidgetByName(widgetName);
						if(!temp) {
							debug_log("Couldn't find widget %s while loading layout!", widgetName.c_str());
						} else {
							m_widgets.push(temp);
						}
					}
				}
			} break;
			case Listener:
			{
				std::string widgetName; int eventType(0);
				while (pAttrib)
				{
					if(strcmp(pAttrib->Name(),"name") == 0)
						widgetName = pAttrib->Value();
					else if(strcmp(pAttrib->Name(),"event") == 0) {
						pAttrib->QueryIntValue(&eventType);
					} else {
						error_log("Unhandled attribute when loading ui! %s", pAttrib->Name());
					}
					pAttrib = pAttrib->Next();
				}
				//if inside a <widget> tag
				if(m_widgetInfos.size()) {
					WidgetInfo& w = m_widgetInfos.top();
					if(w.m_listenerInfo.find(currentListener) != w.m_listenerInfo.end()) {
						ListenerInfo& li = w.m_listenerInfo[currentListener];
						li[eventType].push_back(widgetName);
					} else {
						ListenerInfo& li = w.m_listenerInfo[currentListener];
						li[eventType].push_back(widgetName);
					}
				} else {
					ListenerInfo& li = m_guiInfo.m_listenerInfos[currentListener];
					li[eventType].push_back(widgetName);
				}
			} break;
			default: break;
			} 
		} else if(strcmp(element->Value(),"property") == 0) { 
			if(!m_loadLayout) {
				if(!m_widgetInfos.size()) {
					debug_log("Tried to load properties, but no widget was found!");
				} else {
					Widget* widget = m_widgetInfos.top().m_widget;
					widget->m_settings.Load(element);
					widget->ReloadSettings();
				}
			} else {
				if(!m_widgets.size()) {
					debug_log("Tried to load properties, but no widget was found!");
				} else {
					m_widgets.top()->m_settings.Load(element);
					m_widgets.top()->ReloadSettings();
				}
			}
		} else if(strcmp(element->Value(),"theme") == 0) {
			std::string themeName;
			while (pAttrib)
			{
				if(strcmp(pAttrib->Name(),"name") == 0) {
					themeName = pAttrib->Value(); 
				} else {
					error_log("Unhandled attribute when loading theme! %s", pAttrib->Name());
				}
				pAttrib = pAttrib->Next();
			}			
			Theme* theme = new Theme(themeName);
			theme->LoadFromXml(element);	//load user-defined data

			m_gui->SetTheme(theme);
		} else {
			//debug_log("Unhandled tag-case %s", element->Value());
		}
	}