/*! * \brief * Creates a new T object from a string and adds it to the collection. * * Use an instance of the xml resource loading class \a U to process the * XML source thereby creating an instance of class \a T and add it to the collection under * the name specified in the XML file. * * \param source * String holding the XML source to be used when creating the * new object instance. * * \param action * One of the XMLResourceExistsAction enumerated values indicating what * action should be taken when an object with the specified name * already exists within the collection. */ public T CreateFromString(string source, XMLResourceExistsAction action = XMLResourceExistsAction.XREA_RETURN) { var xmlLoader = new U(); xmlLoader.HandleString(source); return(DoExistingObjectAction(xmlLoader.GetObjectName(), xmlLoader.GetObject(), action)); }
/// <summary> /// Creates a new T object from an XML file and adds it to the collection. /// <para> /// Use an instance of the xml resource loading class \a U to process the /// XML file \a xml_filename from resource group \a resource_group thereby /// creating an instance of class \a T and add it to the collection under /// the name specified in the XML file. /// </para> /// </summary> /// <param name="xmlFilename"> /// String holding the filename of the XML file to be used when creating the /// new object instance. /// </param> /// <param name="resourceGroup"> /// String holding the name of the resource group identifier to be used /// when loading the XML file described by \a xml_filename. /// </param> /// <param name="action"> /// One of the XMLResourceExistsAction enumerated values indicating what /// action should be taken when an object with the specified name /// already exists within the collection. /// </param> /// <returns></returns> public T CreateFromFile(string xmlFilename, string resourceGroup = "", XMLResourceExistsAction action = XMLResourceExistsAction.XREA_RETURN) { var xmlLoader = new U(); xmlLoader.HandleFile(xmlFilename, resourceGroup); return(DoExistingObjectAction(xmlLoader.GetObjectName(), xmlLoader.GetObject(), action)); }
/*! * \brief * Creates a new T object from a RawDataContainer and adds it to the collection. * * Use an instance of the xml resource loading class \a U to process the * XML source thereby creating an instance of class \a T and add it to the collection under * the name specified in the XML file. * * \param source * RawDataContainer holding the XML source to be used when creating the * new object instance. * * \param action * One of the XMLResourceExistsAction enumerated values indicating what * action should be taken when an object with the specified name * already exists within the collection. */ public T CreateFromContainer(RawDataContainer source, XMLResourceExistsAction action = XMLResourceExistsAction.XREA_RETURN) { var xmlLoader = new U(); xmlLoader.HandleContainer(source); return(DoExistingObjectAction(xmlLoader.GetObjectName(), xmlLoader.GetObject(), action)); }
/// <summary> /// function to enforce XMLResourceExistsAction policy. /// </summary> /// <param name="objectName"></param> /// <param name="object"></param> /// <param name="action"></param> /// <returns></returns> protected T DoExistingObjectAction(string objectName, T @object, XMLResourceExistsAction action) { EventHandler <ResourceEventArgs> handler; if (IsDefined(objectName)) { switch (action) { case XMLResourceExistsAction.XREA_RETURN: System.GetSingleton().Logger .LogEvent("---- Returning existing instance of " + _resourceType + " named '" + objectName + "'."); // delete any new object we already had created @object.Dispose(); // return existing instance of object. return(ObjectRegistry[objectName]); case XMLResourceExistsAction.XREA_REPLACE: System.GetSingleton().Logger .LogEvent("---- Replacing existing instance of " + _resourceType + " named '" + objectName + "' (DANGER!)."); Destroy(objectName); handler = ResourceReplaced; break; case XMLResourceExistsAction.XREA_THROW: // TODO: CEGUI_DELETE_AO object; throw new AlreadyExistsException("an object of type '" + _resourceType + "' named '" + objectName + "' already exists in the collection."); default: // TODO: CEGUI_DELETE_AO object; throw new InvalidRequestException("Invalid CEGUI::XMLResourceExistsAction was specified."); } } else { handler = ResourceCreated; } ObjectRegistry[objectName] = @object; DoPostObjectAdditionAction(@object); // fire event about this resource change if (handler != null) { handler(this, new ResourceEventArgs(_resourceType, objectName)); } return(@object); }
/*! * \brief * Creates a Pixmap type font. * * \param font_name * The name that the font will use within the CEGUI system. * * \param imageset_filename * The filename of an imageset to load that will be used as the source for * glyph images for this font. If \a resource_group is the special value * of "*", this parameter may instead refer to the name of an already * loaded Imagset. * * \param resource_group * The resource group identifier to use when loading the imageset file * specified by \a imageset_filename. If this group is set to the special * value of "*", then \a imageset_filename instead will refer to the name * of an existing Imageset. * * \param auto_scaled * Specifies whether the font imagery should be automatically scaled to * maintain the same physical size (which is calculated by using the * native resolution setting). * * \param native_horz_res * The horizontal native resolution value. This is only significant when * auto scaling is enabled. * * \param native_vert_res * The vertical native resolution value. This is only significant when * auto scaling is enabled. * * \param action * One of the XMLResourceExistsAction enumerated values indicating what * action should be taken when a Font with the specified name * already exists. * * \return * Reference to the newly create Font object. */ public Font CreatePixmapFont(string font_name, string imageset_filename, string resource_group, AutoScaledMode auto_scaled, Sizef native_res, XMLResourceExistsAction action) { Logger.LogInsane("Attempting to create Pixmap font '" + font_name + "' using imageset file '" + imageset_filename + "'."); // create new object ahead of time Font @object = new PixmapFont(font_name, imageset_filename, resource_group, auto_scaled, native_res); // return appropriate object instance (deleting any not required) return(DoExistingObjectAction(font_name, @object, action)); }
/*! * \brief * Creates a FreeType type font. * * \param font_name * The name that the font will use within the CEGUI system. * * \param point_size * Specifies the point size that the font is to be rendered at. * * \param anti_aliased * Specifies whether the font should be rendered using anti aliasing. * * \param font_filename * The filename of an font file that will be used as the source for * glyph images for this font. * * \param resource_group * The resource group identifier to use when loading the font file * specified by \a font_filename. * * \param auto_scaled * Specifies whether the font imagery should be automatically scaled to * maintain the same physical size (which is calculated by using the * native resolution setting). * * \param native_horz_res * The horizontal native resolution value. This is only significant when * auto scaling is enabled. * * \param native_vert_res * The vertical native resolution value. This is only significant when * auto scaling is enabled. * * \param action * One of the XMLResourceExistsAction enumerated values indicating what * action should be taken when a Font with the specified name * already exists. * * \return * Reference to the newly create Font object. */ public Font CreateFreeTypeFont(string font_name, float point_size, bool anti_aliased, string font_filename, string resource_group, AutoScaledMode auto_scaled, Sizef native_res, XMLResourceExistsAction action = XMLResourceExistsAction.XREA_RETURN) { #if CEGUI_HAS_FREETYPE Logger.LogInsane("Attempting to create FreeType font '" + font_name + "' using font file '" + font_filename + "'."); // create new object ahead of time var @object = new FreeTypeFont(font_name, point_size, anti_aliased, font_filename, resource_group, auto_scaled, native_res, 0f); // return appropriate object instance (deleting any not required) return(DoExistingObjectAction(font_name, @object, action)); #else throw new InvalidRequestException("CEGUI was compiled without freetype support."); #endif }