//----------------------------------------------------------------------------// //----------------------------------------------------------------------------// AnimationDefinitionHandler::AnimationDefinitionHandler( const XMLAttributes& attributes, const String& name_prefix) : d_anim(0) { const String anim_name(name_prefix + attributes.getValueAsString(NameAttribute)); Logger::getSingleton().logEvent( "Defining animation named: " + anim_name + " Duration: " + attributes.getValueAsString(DurationAttribute) + " Replay mode: " + attributes.getValueAsString(ReplayModeAttribute) + " Auto start: " + attributes.getValueAsString(AutoStartAttribute, "false")); d_anim = AnimationManager::getSingleton().createAnimation(anim_name); d_anim->setDuration(attributes.getValueAsFloat(DurationAttribute)); const String replayMode(attributes.getValueAsString(ReplayModeAttribute, ReplayModeLoop)); if (replayMode == ReplayModeOnce) d_anim->setReplayMode(Animation::RM_Once); else if (replayMode == ReplayModeBounce) d_anim->setReplayMode(Animation::RM_Bounce); else d_anim->setReplayMode(Animation::RM_Loop); d_anim->setAutoStart(attributes.getValueAsBool(AutoStartAttribute)); }
//----------------------------------------------------------------------------// void Config_xmlHandler::handleResourceDirectoryElement(const XMLAttributes& attr) { ResourceDirectory ob; ob.group = attr.getValueAsString(GroupAttribute, ""); ob.directory = attr.getValueAsString(DirectoryAttribute, "./"); d_resourceDirectories.push_back(ob); }
//----------------------------------------------------------------------------// void Config_xmlHandler::handleScriptingElement(const XMLAttributes& attr) { d_scriptingInitScript = attr.getValueAsString(InitScriptAttribute, ""); d_scriptingTerminateScript = attr.getValueAsString(TerminateScriptAttribute, ""); }
//----------------------------------------------------------------------------// void Config_xmlHandler::handleDefaultResourceGroupElement(const XMLAttributes& attr) { DefaultResourceGroup ob; ob.type = stringToResourceType(attr.getValueAsString(TypeAttribute, "")); ob.group = attr.getValueAsString(GroupAttribute, ""); d_defaultResourceGroups.push_back(ob); }
//----------------------------------------------------------------------------// void Imageset_xmlHandler::elementImagesetStart(const XMLAttributes& attributes) { // get name of the imageset. const String name(attributes.getValueAsString(ImagesetNameAttribute)); // get texture image filename const String filename( attributes.getValueAsString(ImagesetImageFileAttribute)); // get resource group to use for image file. const String resource_group( attributes.getValueAsString(ImagesetResourceGroupAttribute)); Logger& logger(Logger::getSingleton()); logger.logEvent("Started creation of Imageset from XML specification:"); logger.logEvent("---- CEGUI Imageset name: " + name); logger.logEvent("---- Source texture file: " + filename + " in resource group: " + (resource_group.empty() ? "(Default)" : resource_group)); // Create imageset object from image file d_imageset = new Imageset(name, filename, resource_group); // set native resolution for imageset const float native_hres = static_cast<float>( attributes.getValueAsInteger(ImagesetNativeHorzResAttribute, 640)); const float native_vres = static_cast<float>( attributes.getValueAsInteger(ImagesetNativeVertResAttribute, 480)); d_imageset->setNativeResolution(Size(native_hres, native_vres)); // set auto-scaling as needed d_imageset->setAutoScalingEnabled( attributes.getValueAsBool(ImagesetAutoScaledAttribute, false)); }
void XMLHandler::elementStart(const std::string& element, const XMLAttributes& attributes) { if(_stricmp(element.c_str(), AgentElement.c_str()) == 0) // <Agent ... { m_stackWork.push(WS_Agent); m_bAgentSpace = true; m_pTemplate->m_strDesc = attributes.getValueAsString(DescAttribute).c_str(); } else if(_stricmp(element.c_str(), ScriptsElement.c_str()) == 0 && m_bAgentSpace) // <Scripts ... { m_stackWork.push(WS_Scripts); } else if(_stricmp(element.c_str(), ScriptElement.c_str()) == 0 && m_bAgentSpace) // <Script ... { m_pTemplate->m_vScriptFiles.push_back(attributes.getValueAsString(NameAttribute)); m_stackWork.push(WS_Script); } else if(_stricmp(element.c_str(), VariablesElement.c_str()) == 0 && m_bAgentSpace) // <Variables ... { m_stackWork.push(WS_Variables); } else if(_stricmp(element.c_str(), VariableElement.c_str()) == 0 && m_bAgentSpace) // <Variable ... { m_pTemplate->m_vVariables.push_back( std::make_pair( attributes.getValueAsString(NameAttribute), attributes.getValueAsString(DefaultAttribute))); m_stackWork.push(WS_Variable); } else { m_stackWork.push(WS_Unknown); } }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementWindowAliasStart(const XMLAttributes& attributes) { Scheme::AliasMapping alias; alias.aliasName = attributes.getValueAsString(AliasAttribute); alias.targetName = attributes.getValueAsString(TargetAttribute); d_scheme->d_aliasMappings.push_back(alias); }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementLookNFeelStart(const XMLAttributes& attributes) { Scheme::LoadableUIElement lnf; lnf.filename = attributes.getValueAsString(FilenameAttribute); lnf.resourceGroup = attributes.getValueAsString(ResourceGroupAttribute); d_scheme->d_looknfeels.push_back(lnf); }
//----------------------------------------------------------------------------// void Config_xmlHandler::handleAutoLoadElement(const XMLAttributes& attr) { AutoLoadResource ob; ob.type_string = attr.getValueAsString(TypeAttribute, ""); ob.type = stringToResourceType(ob.type_string); ob.pattern = attr.getValueAsString(PatternAttribute, "*"); ob.group = attr.getValueAsString(GroupAttribute, ""); d_autoLoadResources.push_back(ob); }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementFontStart(const XMLAttributes& attributes) { Scheme::LoadableUIElement font; font.name = attributes.getValueAsString(NameAttribute); font.filename = attributes.getValueAsString(FilenameAttribute); font.resourceGroup = attributes.getValueAsString(ResourceGroupAttribute); d_scheme->d_fonts.push_back(font); }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementImagesetStart(const XMLAttributes& attributes) { Scheme::LoadableUIElement imageset; imageset.name = attributes.getValueAsString(NameAttribute); imageset.filename = attributes.getValueAsString(FilenameAttribute); imageset.resourceGroup = attributes.getValueAsString(ResourceGroupAttribute); d_scheme->d_imagesets.push_back(imageset); }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementFalagardMappingStart( const XMLAttributes& attributes) { Scheme::FalagardMapping fmap; fmap.windowName = attributes.getValueAsString(WindowTypeAttribute); fmap.targetName = attributes.getValueAsString(TargetTypeAttribute); fmap.lookName = attributes.getValueAsString(LookNFeelAttribute); fmap.rendererName = attributes.getValueAsString(WindowRendererAttribute); d_scheme->d_falagardMappings.push_back(fmap); }
//----------------------------------------------------------------------------// void Config_xmlHandler::handleLoggingElement(const XMLAttributes& attr) { d_logFileName = attr.getValueAsString(FilenameAttribute, ""); const String logLevel(attr.getValueAsString(LevelAttribute, "")); if (logLevel == "Errors") d_logLevel = Errors; else if (logLevel == "Informative") d_logLevel = Informative; else if (logLevel == "Insane") d_logLevel = Insane; else d_logLevel = Standard; }
//----------------------------------------------------------------------------// void ImageManager::elementImageStart(const XMLAttributes& attributes) { const String image_name(s_texture->getName() + '/' + attributes.getValueAsString(ImageNameAttribute)); if (isDefined(image_name)) { Logger::getSingleton().logEvent( "[ImageManager] WARNING: Using existing image :" + image_name); return; } XMLAttributes rw_attrs(attributes); // rewrite the name attribute to include the texture name rw_attrs.add(ImageNameAttribute, image_name); if (!rw_attrs.exists(ImageTextureAttribute)) rw_attrs.add(ImageTextureAttribute, s_texture->getName()); if (!rw_attrs.exists(ImagesetAutoScaledAttribute)) rw_attrs.add(ImagesetAutoScaledAttribute, PropertyHelper<AutoScaledMode>::toString(s_autoScaled)); if (!rw_attrs.exists(ImagesetNativeHorzResAttribute)) rw_attrs.add(ImagesetNativeHorzResAttribute, PropertyHelper<float>::toString(s_nativeResolution.d_width)); if (!rw_attrs.exists(ImagesetNativeVertResAttribute)) rw_attrs.add(ImagesetNativeVertResAttribute, PropertyHelper<float>::toString(s_nativeResolution.d_height)); d_deleteChaniedHandler = false; d_chainedHandler = &create(rw_attrs); }
//----------------------------------------------------------------------------// SVGImage::SVGImage(const XMLAttributes& attributes) : Image(attributes.getValueAsString(ImageNameAttribute), glm::vec2(static_cast<float>(attributes.getValueAsInteger(ImageXOffsetAttribute, 0)), static_cast<float>(attributes.getValueAsInteger(ImageYOffsetAttribute, 0))), Rectf(glm::vec2(static_cast<float>(attributes.getValueAsInteger(ImageXPosAttribute, 0)), static_cast<float>(attributes.getValueAsInteger(ImageYPosAttribute, 0))), Sizef(static_cast<float>(attributes.getValueAsInteger(ImageWidthAttribute, 0)), static_cast<float>(attributes.getValueAsInteger(ImageHeightAttribute, 0)))), PropertyHelper<AutoScaledMode>::fromString(attributes.getValueAsString(ImageAutoScaledAttribute)), Sizef(static_cast<float>(attributes.getValueAsInteger(ImageNativeHorzResAttribute, 640)), static_cast<float>(attributes.getValueAsInteger(ImageNativeVertResAttribute, 480)))), d_svgData(&SVGDataManager::getSingleton().getSVGData( attributes.getValueAsString(ImageSVGDataAttribute))), d_useGeometryAntialiasing(true) { }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementWindowRendererFactoryStart( const XMLAttributes& attributes) { d_scheme-> d_windowRendererModules[d_scheme->d_windowRendererModules.size() - 1]. types.push_back(attributes.getValueAsString(NameAttribute)); }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------// AnimationSubscriptionHandler::AnimationSubscriptionHandler( const XMLAttributes& attributes, Animation& anim) { Logger::getSingleton().logEvent( "\tAdding subscription to event: " + attributes.getValueAsString(EventAttribute) + " Action: " + attributes.getValueAsString(ActionAttribute)); anim.defineAutoSubscription( attributes.getValueAsString(EventAttribute), attributes.getValueAsString(ActionAttribute)); d_completed = true; }
//----------------------------------------------------------------------------// void ImageManager::elementImagesetStart(const XMLAttributes& attributes) { // get name of the imageset. const String name(attributes.getValueAsString(ImagesetNameAttribute)); // get texture image filename const String filename( attributes.getValueAsString(ImagesetImageFileAttribute)); // get resource group to use for image file. const String resource_group( attributes.getValueAsString(ImagesetResourceGroupAttribute)); Logger& logger(Logger::getSingleton()); logger.logEvent("[ImageManager] Started creation of Imageset from XML specification:"); logger.logEvent("[ImageManager] ---- CEGUI Imageset name: " + name); logger.logEvent("[ImageManager] ---- Source texture file: " + filename); logger.logEvent("[ImageManager] ---- Source texture resource group: " + (resource_group.empty() ? "(Default)" : resource_group)); validateImagesetFileVersion(attributes); Renderer* const renderer = System::getSingleton().getRenderer(); // if the texture already exists, if (renderer->isTextureDefined(name)) { Logger::getSingleton().logEvent( "[ImageManager] WARNING: Using existing texture: " + name); s_texture = &renderer->getTexture(name); } else { // create texture from image s_texture = &renderer->createTexture(name, filename, resource_group.empty() ? d_imagesetDefaultResourceGroup : resource_group); } // set native resolution for imageset s_nativeResolution = Sizef( attributes.getValueAsFloat(ImagesetNativeHorzResAttribute, 640), attributes.getValueAsFloat(ImagesetNativeVertResAttribute, 480)); // set auto-scaling as needed s_autoScaled = PropertyHelper<AutoScaledMode>::fromString( attributes.getValueAsString(ImagesetAutoScaledAttribute, "false")); }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------// AnimationAffectorHandler::AnimationAffectorHandler( const XMLAttributes& attributes, Animation& anim) : d_affector(0) { Logger::getSingleton().logEvent( "\tAdding affector for property: " + attributes.getValueAsString(PropertyAttribute) + " Interpolator: " + attributes.getValueAsString(InterpolatorAttribute) + " Application method: " + attributes.getValueAsString(ApplicationMethodAttribute, "absolute")); d_affector = anim.createAffector( attributes.getValueAsString(PropertyAttribute), attributes.getValueAsString(InterpolatorAttribute)); if (attributes.getValueAsString(ApplicationMethodAttribute) == ApplicationMethodRelative) { d_affector->setApplicationMethod(Affector::AM_Relative); } else if (attributes.getValueAsString(ApplicationMethodAttribute) == ApplicationMethodRelativeMultiply) { d_affector->setApplicationMethod(Affector::AM_RelativeMultiply); } else { d_affector->setApplicationMethod(Affector::AM_Absolute); } }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementWindowSetStart(const XMLAttributes& attributes) { Scheme::UIModule module; module.name = attributes.getValueAsString(FilenameAttribute); module.dynamicModule = 0; module.factoryModule = 0; d_scheme->d_widgetModules.push_back(module); }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementWindowRendererSetStart( const XMLAttributes& attributes) { Scheme::WRModule module; module.name = attributes.getValueAsString(FilenameAttribute); module.dynamicModule = 0; module.wrModule = 0; d_scheme->d_windowRendererModules.push_back(module); }
Font::Font (const XMLAttributes& attributes) : d_name (attributes.getValueAsString (FontNameAttribute)), d_fileName (attributes.getValueAsString (FontFilenameAttribute)), d_resourceGroup (attributes.getValueAsString (FontResourceGroupAttribute)), d_ascender (0), d_descender (0), d_height (0), d_autoScale (attributes.getValueAsBool(FontAutoScaledAttribute, false)), d_nativeHorzRes (static_cast< float >( attributes.getValueAsInteger (FontNativeHorzResAttribute, int (DefaultNativeHorzRes)))), d_nativeVertRes (static_cast< float >( attributes.getValueAsInteger (FontNativeVertResAttribute, int (DefaultNativeVertRes)))), d_maxCodepoint (0), d_glyphPageLoaded (0) { addFontProperties (); Size size = System::getSingleton ().getRenderer()->getSize (); d_horzScaling = size.d_width / d_nativeHorzRes; d_vertScaling = size.d_height / d_nativeVertRes; }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementGUISchemeStart(const XMLAttributes& attributes) { const String name(attributes.getValueAsString(NameAttribute)); Logger& logger(Logger::getSingleton()); logger.logEvent("Started creation of Scheme from XML specification:"); logger.logEvent("---- CEGUI GUIScheme name: " + name); // create empty scheme with desired name d_scheme = new Scheme(name); }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::elementWindowFactoryStart( const XMLAttributes& attributes) { Scheme::UIElementFactory factory; factory.name = attributes.getValueAsString(NameAttribute); d_scheme->d_widgetModules[d_scheme-> d_widgetModules.size() - 1].factories.push_back(factory); }
/************************************************************************* SAX2 Handler methods *************************************************************************/ void Animate_xmlHandler::elementStart(const String& element, const XMLAttributes& attributes) { // handle an Animate element (extract all element attributes and use data to define an Animate) if(element == AnimateManagerElement) { } else if(element == AnimateElement) { String name(attributes.getValueAsString(AnimateNameAttribute)); bool loop = attributes.getValueAsBool(AnimatePlayLoop); int id = attributes.getValueAsInteger(AnimateID, -1); int totalTime = attributes.getValueAsInteger(AnimateTime, -1); bool alpha = attributes.getValueAsBool( AnimateAlphaMode ); int loopType = attributes.getValueAsInteger(AnimateAlphaType, 1 ); d_animate = AnimateManager::getSingleton().createAnimate(name, id, loop, totalTime, alpha, loopType ); } else if (element == AniamteItemElement ) { if(d_animate == 0) { throw GenericException("Aniamte::xmlHandler::startElement - Invalid file struct."); } const Image* pImage = PropertyHelper::stringToImage(attributes.getValueAsString(AniamteImage)); if(pImage) { d_animate->defineAnimateKey(pImage); AnimateManager::getSingleton().addAnimateImageset(pImage->getImagesetName()); } } else { throw FileIOException("Aniamte::xmlHandler::startElement - Unexpected data was found while parsing the animatefile: '" + element + "' is unknown."); } }
//----------------------------------------------------------------------------// BasicImage::BasicImage(const XMLAttributes& attributes) : d_name(attributes.getValueAsString(ImageNameAttribute)), d_texture(&System::getSingleton().getRenderer()->getTexture( attributes.getValueAsString(ImageTextureAttribute))), d_pixelSize(static_cast<float>(attributes.getValueAsInteger(ImageWidthAttribute, 0)), static_cast<float>(attributes.getValueAsInteger(ImageHeightAttribute, 0))), d_area(Vector2f(static_cast<float>(attributes.getValueAsInteger(ImageXPosAttribute, 0)), static_cast<float>(attributes.getValueAsInteger(ImageYPosAttribute, 0))), d_pixelSize), d_pixelOffset(Vector2f( static_cast<float>(attributes.getValueAsInteger(ImageXOffsetAttribute, 0)), static_cast<float>(attributes.getValueAsInteger(ImageYOffsetAttribute, 0)))), d_nativeResolution(Sizef( static_cast<float>(attributes.getValueAsInteger(ImageNativeHorzResAttribute, 640)), static_cast<float>(attributes.getValueAsInteger(ImageNativeVertResAttribute, 480)))) { d_autoScaled = PropertyHelper<AutoScaledMode>::fromString(attributes.getValueAsString(ImageAutoScaledAttribute)); // force initialisation of the autoscaling fields. notifyDisplaySizeChanged( System::getSingleton().getRenderer()->getDisplaySize()); }
//----------------------------------------------------------------------------// void Scheme_xmlHandler::validateSchemeFileVersion(const XMLAttributes& attrs) { const String version(attrs.getValueAsString(SchemeVersionAttribute, "unknown")); if (version == NativeVersion) return; CEGUI_THROW(InvalidRequestException( "You are attempting to load a GUI scheme of version '" + version + "' but this CEGUI version is only meant to load GUI schemes of version '" + NativeVersion + "'. Consider using the migrate.py script bundled with " "CEGUI Unified Editor to migrate your data.")); }
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------// SampleDataHandler::SampleDataHandler( const XMLAttributes& attributes, const String& name_prefix, SamplesFramework* samplesFramework) : d_samplesFramework(samplesFramework) { const String sampleName(attributes.getValueAsString(NameAttribute)); const String summary(attributes.getValueAsString(SummaryAttribute)); const String description(attributes.getValueAsString(DescriptionAttribute)); const String sampleType(attributes.getValueAsString(SampleTypeAttribute)); const String credits(attributes.getValueAsString(CreditsAttribute)); CEGUI_LOGINSANE( "Defining sample named: " + sampleName + " Summary: " + summary + " Description: " + description + " Sample Type: " + sampleType + " Credits: " + credits ); SampleType sampleTypeEnum; if (sampleType == SampleTypeCppModule) sampleTypeEnum = ST_Module; else if(sampleType == SampleTypePython) sampleTypeEnum = ST_Python; else sampleTypeEnum = ST_Lua; d_samplesFramework->addSampleDataCppModule(sampleName, summary, description, sampleTypeEnum, credits); }
void Config_xmlHandler::elementStart(const String& element, const XMLAttributes& attributes) { // handle root CEGUIConfig element if (element == CEGUIConfigElement) { d_logFilename = attributes.getValueAsString(ConfigLogfileAttribute); d_schemeFilename = attributes.getValueAsString(ConfigSchemeAttribute); d_layoutFilename = attributes.getValueAsString(ConfigLayoutAttribute); d_initScriptFilename = attributes.getValueAsString(ConfigInitScriptAttribute); d_termScriptFilename = attributes.getValueAsString(ConfigTerminateScriptAttribute); d_defaultFontName = attributes.getValueAsString(ConfigDefaultFontAttribute); d_defaultResourceGroup = attributes.getValueAsString(ConfigDefaultResourceGroupAttribute); // handle logging level String logLevelStr = attributes.getValueAsString(ConfigLoggingLevelAttribute, "Standard"); if (logLevelStr == "Errors") { d_logLevel = Errors; } else if (logLevelStr == "Warnings") { d_logLevel = Warnings; } else if (logLevelStr == "Informative") { d_logLevel = Informative; } else if (logLevelStr == "Insane") { d_logLevel = Insane; } else { d_logLevel = Standard; } } // anything else is an error which *should* have already been caught by XML validation else { String message("Config_xmlHandler::startElement - Unexpected data was found while parsing the configuration file: '" + element + "' is unknown."); // throw a std::exception (because it won't try and use logger) throw message.c_str(); } }
//----------------------------------------------------------------------------// void Imageset_xmlHandler::elementImageStart(const XMLAttributes& attributes) { if (!d_imageset) throw InvalidRequestException("Imageset_xmlHandler::elementImageStart: " "Attempt to access null object."); const String name(attributes.getValueAsString(ImageNameAttribute)); Rect rect; rect.d_left = static_cast<float>(attributes.getValueAsInteger(ImageXPosAttribute)); rect.d_top = static_cast<float>(attributes.getValueAsInteger(ImageYPosAttribute)); rect.setWidth( static_cast<float>(attributes.getValueAsInteger(ImageWidthAttribute))); rect.setHeight( static_cast<float>(attributes.getValueAsInteger(ImageHeightAttribute))); const Point offset( static_cast<float>(attributes.getValueAsInteger(ImageXOffsetAttribute, 0)), static_cast<float>(attributes.getValueAsInteger(ImageYOffsetAttribute, 0))); d_imageset->defineImage(name, rect, offset); }