//----------------------------------------------------------------------------// 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)); }
//----------------------------------------------------------------------------// 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) { }
/************************************************************************* 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 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); }
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; }
/************************************************************************* SAX2 Handler methods *************************************************************************/ void Font_xmlHandler::elementStart(const String& element, const XMLAttributes& attributes) { // handle a Mapping element if (element == MappingElement) { if (!d_font->d_freetype) { String image_name(attributes.getValueAsString(MappingImageAttribute)); utf32 codepoint = (utf32)attributes.getValueAsInteger(MappingCodepointAttribute); int horzAdvance = attributes.getValueAsInteger(MappingHorzAdvanceAttribute, -1); Font::glyphDat mapDat; mapDat.d_image = &d_font->d_glyph_images->getImage(image_name); // calculate advance width if it was not specified if (horzAdvance == AutoGenerateHorzAdvance) { horzAdvance = (int)(mapDat.d_image->getWidth() + mapDat.d_image->getOffsetX()); } mapDat.d_horz_advance_unscaled = horzAdvance; mapDat.d_horz_advance = (uint)(((float)horzAdvance) * (d_font->d_autoScale ? d_font->d_horzScaling : 1.0f)); d_font->d_cp_map[codepoint] = mapDat; } else { Logger::getSingleton().logEvent((utf8*)"Mapping element encountered. This element is invalid for dynamic fonts.", Informative); } } // handle root Font element else if (element == FontElement) { // get name of font we are creating String font_name(attributes.getValueAsString(FontNameAttribute)); // get filename for the font String filename(attributes.getValueAsString(FontFilenameAttribute)); // get resource group for font file. String resourceGroup(attributes.getValueAsString(FontResourceGroupAttribute)); Logger::getSingleton().logEvent("Started creation of Font '" + font_name + "' via XML file.", Informative); // // load auto-scaling configuration // float hres, vres; bool auto_scale; // get native horizontal resolution hres = (float)attributes.getValueAsInteger(FontNativeHorzResAttribute, 640); // get native vertical resolution vres = (float)attributes.getValueAsInteger(FontNativeVertResAttribute, 480); // get auto-scaling setting auto_scale = attributes.getValueAsBool(FontAutoScaledAttribute, false); // // get type of font // String font_type(attributes.getValueAsString(FontTypeAttribute)); // dynamic (ttf) font if (font_type == FontTypeDynamic) { // get size of font uint size = (uint)attributes.getValueAsInteger(FontSizeAttribute, 12); // extract codepoint range utf32 first_codepoint = (utf32)attributes.getValueAsInteger(FontFirstCodepointAttribute, 32); utf32 last_codepoint = (utf32)attributes.getValueAsInteger(FontLastCodepointAttribute, 127); // build string containing the required code-points. for (; first_codepoint <= last_codepoint; ++first_codepoint) { d_glyphSet += first_codepoint; } uint flags = attributes.getValueAsBool(FontAntiAliasedAttribute, true) ? 0 : NoAntiAlias; // perform pre-initialisation d_font->setNativeResolution(Size(hres, vres)); d_font->setAutoScalingEnabled(auto_scale); // Finalise construction of font without glyphs. // Glyphs will defined after we know which ones we need. d_font->constructor_impl(font_name, filename, resourceGroup, size, flags, String("")); } // static (Imageset based) font else if (font_type == FontTypeStatic) { d_font->d_name = font_name; d_font->d_freetype = false; // load the Imageset d_font->d_glyph_images = ImagesetManager::getSingleton().createImageset(filename, resourceGroup); d_font->setNativeResolution(Size(hres, vres)); d_font->setAutoScalingEnabled(auto_scale); } // error (should never happen) else { throw FileIOException("Font::xmlHandler::startElement - The unknown Font:Type attribute value '" + font_type + "' was encountered while processing the Font file."); } d_font->d_sourceFilename = filename; } // Glyph element else if (element == GlyphElement) { if (d_font->d_freetype) { utf32 codepoint = (utf32)attributes.getValueAsInteger(GlyphCodepointAttribute); if (d_glyphSet.find(codepoint) == String::npos) { d_glyphSet.append(1, codepoint); } } else { Logger::getSingleton().logEvent((utf8*)"Glyph element encountered. This element is invalid for static fonts.", Informative); } } // GlyphRange element else if (element == GlyphRangeElement) { if (d_font->d_freetype) { utf32 start = (utf32)attributes.getValueAsInteger(GlyphRangeStartCodepointAttribute); utf32 end = (utf32)attributes.getValueAsInteger(GlyphRangeEndCodepointAttribute); for (utf32 codepoint = start; codepoint <= end; ++codepoint) { if (d_glyphSet.find(codepoint) == String::npos) { d_glyphSet.append(1, codepoint); } } } else { Logger::getSingleton().logEvent((utf8*)"GlyphRange element encountered. This element is invalid for static fonts.", Informative); } } // GlyphSet element else if (element == GlyphSetElement) { if (d_font->d_freetype) { String glyphs(attributes.getValueAsString(GlyphSetGlyphsAttribute)); for (String::size_type i = 0; i < glyphs.length(); ++i) { utf32 codepoint = glyphs[i]; if (d_glyphSet.find(codepoint) == String::npos) { d_glyphSet.append(1, codepoint); } } } else { Logger::getSingleton().logEvent((utf8*)"GlyphSet element encountered. This element is invalid for static fonts.", Informative); } } // anything else is an error which *should* have already been caught by XML validation else { throw FileIOException("Font::xmlHandler::startElement - Unexpected data was found while parsing the Font file: '" + element + "' is unknown."); } }