diff -r 346150d854bd lib/irrlicht/include/IGUIEnvironment.h --- a/lib/irrlicht/include/IGUIEnvironment.h Tue Jun 02 05:44:42 2009 +0200 +++ b/lib/irrlicht/include/IGUIEnvironment.h Wed Jun 03 06:47:16 2009 +0200 @@ -33,6 +33,7 @@ namespace gui { +class IGUIFontFactory; class IGUIElement; class IGUIFont; class IGUISpriteBank; @@ -156,19 +157,30 @@ virtual IGUIImageList* createImageList( video::ITexture* texture, core::dimension2d imageSize, bool useAlphaChannel ) = 0; - //! Returns pointer to the font with the specified filename. + //! Returns pointer to the font with the specified fontname /** Loads the font if it was not loaded before. - \param filename Filename of the Font. + \param fontname Fontname, usually the filename of the font. \return Pointer to the font. Returns 0 if the font could not be loaded. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ - virtual IGUIFont* getFont(const core::string& filename) = 0; + virtual IGUIFont* getFont(const core::string& fontname) = 0; //! Returns the default built-in font. /** \return Pointer to the default built-in font. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ virtual IGUIFont* getBuiltInFont() const = 0; + + //! Adds a font factory to the gui environment. + /** Use this to extend the gui environment with new fonts which it should be + able to create automaticaly, for example when loading data from xml files. */ + virtual void registerGUIFontFactory(IGUIFontFactory* factoryToAdd) = 0; + + //! Returns amount of registered font factories. + virtual u32 getRegisteredGUIFontFactoryCount() const = 0; + + //! Returns a font factory by index + virtual IGUIFontFactory* getGUIFontFactory(u32 index) const = 0; //! Returns pointer to the sprite bank with the specified file name. /** Loads the bank if it was not loaded before. @@ -184,9 +196,9 @@ virtual IGUISpriteBank* addEmptySpriteBank(const core::string& name) = 0; //! Returns the root gui element. - /** This is the first gui element, the (direct or indirect) parent of all - other gui elements. It is a valid IGUIElement, with dimensions the same - size as the screen. You should not need to use this method directly, unless + /** This is the first gui element, the (direct or indirect) parent of all + other gui elements. It is a valid IGUIElement, with dimensions the same + size as the screen. You should not need to use this method directly, unless you wish to reparent GUI elements to the top level. \return Pointer to the root element of the GUI. The returned pointer should not be dropped. See IReferenceCounted::drop() for more diff -r 346150d854bd lib/irrlicht/include/IGUIFont.h --- a/lib/irrlicht/include/IGUIFont.h Tue Jun 02 05:44:42 2009 +0200 +++ b/lib/irrlicht/include/IGUIFont.h Wed Jun 03 06:47:16 2009 +0200 @@ -8,6 +8,7 @@ #include "IReferenceCounted.h" #include "SColor.h" #include "rect.h" +#include "irrString.h" namespace irr { @@ -94,6 +95,15 @@ \param invisible: string of symbols, which are not send down to the videodriver */ virtual void setInvisibleCharacters( const wchar_t *s ) = 0; + + //! Access the font name + core::string& getName() + { + return Name; + } + +protected: + core::string Name; }; } // end namespace gui diff -r 346150d854bd lib/irrlicht/include/IGUIFontFactory.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/irrlicht/include/IGUIFontFactory.h Wed Jun 03 06:47:16 2009 +0200 @@ -0,0 +1,42 @@ +// Copyright (C) 2002-2007 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#ifndef __I_GUI_FONT_FACTORY_H_INCLUDED__ +#define __I_GUI_FONT_FACTORY_H_INCLUDED__ + +#include "IReferenceCounted.h" +#include "EGUIElementTypes.h" + +namespace irr +{ + + +namespace gui +{ + class IGUIFont; + + //! Interface making it possible to dynamicly create fonts + /** To be able to add custom fonts to Irrlicht and to make it possible for the + scene manager to save and load them, simply implement this interface and register it + in your gui environment via IGUIEnvironment::registerGUIFontFactory. + Note: When implementing your own font factory, don't call IGUIEnvironment::grab() to + increase the reference counter of the environment. This is not necessary because the + it will grab() the factory anyway, and otherwise cyclic references will be created. + */ + class IGUIFontFactory : public virtual IReferenceCounted + { + public: + virtual ~IGUIFontFactory() {}; + + //! adds a font to the GUI Environment based on its name + /** \param fontName: Usually filename of the font to add. But specific factories might use this name otherwise. + \return Returns pointer to the new font or null if not successful. */ + virtual IGUIFont* addGUIFont(const core::string& fontName) = 0; + }; + + +} // end namespace gui +} // end namespace irr + +#endif // __I_GUI_FONT_FACTORY_H_INCLUDED__ diff -r 346150d854bd lib/irrlicht/include/irrlicht.h --- a/lib/irrlicht/include/irrlicht.h Tue Jun 02 05:44:42 2009 +0200 +++ b/lib/irrlicht/include/irrlicht.h Wed Jun 03 06:47:16 2009 +0200 @@ -79,6 +79,7 @@ #include "IGUIElement.h" #include "IGUIElementFactory.h" #include "IGUIEnvironment.h" +#include "IGUIFontFactory.h" #include "IGUIFileOpenDialog.h" #include "IGUIFont.h" #include "IGUIFontBitmap.h" diff -r 346150d854bd lib/irrlicht/source/Irrlicht/CGUIEnvironment.cpp --- a/lib/irrlicht/source/Irrlicht/CGUIEnvironment.cpp Tue Jun 02 05:44:42 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CGUIEnvironment.cpp Wed Jun 03 06:47:16 2009 +0200 @@ -39,6 +39,7 @@ #include "CDefaultGUIElementFactory.h" #include "IWriteFile.h" #include "IXMLWriter.h" +#include "IGUIFontFactory.h" #include "BuiltInFont.h" #include "os.h" @@ -153,6 +154,9 @@ // remove all factories for (i=0; idrop(); + + for (i=0; idrop(); } @@ -603,6 +607,32 @@ skin->setSpriteBank(bank); return skin; +} + + +//! Adds a font factory to the gui environment. +void CGUIEnvironment::registerGUIFontFactory(IGUIFontFactory* factoryToAdd) +{ + if (factoryToAdd) + { + factoryToAdd->grab(); + GUIFontFactoryList.push_back(factoryToAdd); + } +} + +//! Returns amount of registered font factories. +u32 CGUIEnvironment::getRegisteredGUIFontFactoryCount() const +{ + return GUIFontFactoryList.size(); +} + +//! Returns a font factory by index +IGUIFontFactory* CGUIEnvironment::getGUIFontFactory(u32 index) const +{ + if (index& rectangle, +IGUITreeView* CGUIEnvironment::addTreeView(const core::rect& rectangle, IGUIElement* parent, s32 id, bool drawBackground, bool scrollBarVertical, bool scrollBarHorizontal) @@ -1319,72 +1349,78 @@ if (index != -1) return Fonts[index].Font; - // font doesn't exist, attempt to load it + // check if one of the factories can create it + for (s32 i=0; i<(int)GUIFontFactoryList.size() && !ifont; ++i) + { + ifont = GUIFontFactoryList[i]->addGUIFont(filename); + } + // try the traditional way (without factories, but we could maybe add a default factory for this someday) + if ( !ifont ) + { + // font doesn't exist, attempt to load it - // does the file exist? + // does the file exist? + if (!FileSystem->existFile(filename)) + { + os::Printer::log("Could not load font because the file does not exist", f.Filename.c_str(), ELL_ERROR); + return 0; + } + io::IXMLReader *xml = FileSystem->createXMLReader(filename); + if (xml) + { + // this is an XML font, but we need to know what type + EGUI_FONT_TYPE t = EGFT_CUSTOM; - if (!FileSystem->existFile(filename)) - { - os::Printer::log("Could not load font because the file does not exist", f.Filename, ELL_ERROR); - return 0; - } - - io::IXMLReader *xml = FileSystem->createXMLReader(filename ); - if (xml) - { - // this is an XML font, but we need to know what type - EGUI_FONT_TYPE t = EGFT_CUSTOM; - - bool found=false; - while(xml->read() && !found) - { - if (xml->getNodeType() == io::EXN_ELEMENT) + bool found=false; + while(xml->read() && !found) { - if (core::stringw(L"font") == xml->getNodeName()) + if (xml->getNodeType() == io::EXN_ELEMENT) { - if (core::stringw(L"vector") == xml->getAttributeValue(L"type")) + if (core::stringw(L"font") == xml->getNodeName()) { - t = EGFT_VECTOR; - found=true; + if (core::stringw(L"vector") == xml->getAttributeValue(L"type")) + { + t = EGFT_VECTOR; + found=true; + } + else if (core::stringw(L"bitmap") == xml->getAttributeValue(L"type")) + { + t = EGFT_BITMAP; + found=true; + } + else found=true; } - else if (core::stringw(L"bitmap") == xml->getAttributeValue(L"type")) - { - t = EGFT_BITMAP; - found=true; - } - else found=true; } } + if (t==EGFT_BITMAP) + { + CGUIFont* font = new CGUIFont(this, filename); + ifont = (IGUIFont*)font; + // change working directory, for loading textures + core::string workingDir = FileSystem->getWorkingDirectory(); + FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.Filename).c_str()); + + // load the font + if (!font->load(xml)) + { + font->drop(); + font = 0; + ifont = 0; + } + // change working dir back again + FileSystem->changeWorkingDirectoryTo( workingDir.c_str()); + } + else if (t==EGFT_VECTOR) + { + // todo: vector fonts + os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.Filename.c_str(), ELL_ERROR); + + //CGUIFontVector* font = new CGUIFontVector(Driver); + //ifont = (IGUIFont*)font; + //if (!font->load(xml)) + } + xml->drop(); } - - if (t==EGFT_BITMAP) - { - CGUIFont* font = new CGUIFont(this, filename); - ifont = (IGUIFont*)font; - // change working directory, for loading textures - core::string workingDir = FileSystem->getWorkingDirectory(); - FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.Filename)); - - // load the font - if (!font->load(xml)) - { - font->drop(); - font = 0; - ifont = 0; - } - // change working dir back again - FileSystem->changeWorkingDirectoryTo( workingDir ); - } - else if (t==EGFT_VECTOR) - { - // todo: vector fonts - os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.Filename.c_str(), ELL_ERROR); - - //CGUIFontVector* font = new CGUIFontVector(Driver); - //ifont = (IGUIFont*)font; - //if (!font->load(xml)) - } - xml->drop(); } @@ -1402,6 +1438,7 @@ // add to fonts. + ifont->getName() = filename; f.Font = ifont; Fonts.push_back(f); @@ -1465,7 +1502,7 @@ } //! Creates the image list from the given texture. -IGUIImageList* CGUIEnvironment::createImageList( video::ITexture* texture, +IGUIImageList* CGUIEnvironment::createImageList( video::ITexture* texture, core::dimension2d imageSize, bool useAlphaChannel ) { CGUIImageList* imageList = new CGUIImageList( Driver ); @@ -1478,7 +1515,7 @@ return imageList; } -//! Returns the root gui element. +//! Returns the root gui element. IGUIElement* CGUIEnvironment::getRootGUIElement() { return this; diff -r 346150d854bd lib/irrlicht/source/Irrlicht/CGUIEnvironment.h --- a/lib/irrlicht/source/Irrlicht/CGUIEnvironment.h Tue Jun 02 05:44:42 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CGUIEnvironment.h Wed Jun 03 06:47:16 2009 +0200 @@ -71,8 +71,8 @@ virtual IGUISkin* createSkin(EGUI_SKIN_TYPE type); //! Creates the image list from the given texture. - virtual IGUIImageList* createImageList( video::ITexture* texture, - core::dimension2d imageSize, bool useAlphaChannel ); + virtual IGUIImageList* createImageList( video::ITexture* texture, + core::dimension2d imageSize, bool useAlphaChannel ); //! returns the font virtual IGUIFont* getFont(const core::string& filename); @@ -185,6 +185,17 @@ //! returns default font virtual IGUIFont* getBuiltInFont() const; + //! Adds a font factory to the gui environment. + /** Use this to extend the gui environment with new fonts which it should be + able to create automaticaly, for example when loading data from xml files. */ + virtual void registerGUIFontFactory(IGUIFontFactory* factoryToAdd); + + //! Returns amount of registered font factories. + virtual u32 getRegisteredGUIFontFactoryCount() const; + + //! Returns a font factory by index + virtual IGUIFontFactory* getGUIFontFactory(u32 index) const; + //! Adds an element for fading in or out. virtual IGUIInOutFader* addInOutFader(const core::rect* rectangle=0, IGUIElement* parent=0, s32 id=-1); @@ -286,6 +297,7 @@ SToolTip ToolTip; core::array GUIElementFactoryList; + core::array GUIFontFactoryList; core::array Fonts; core::array Banks;