diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIEnvironment.h Irrlicht_starsonata/include/IGUIEnvironment.h --- irrlicht-svn-ss/trunk/include/IGUIEnvironment.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUIEnvironment.h 2008-05-31 04:53:40.000000000 +0200 @@ -34,4 +36,5 @@ namespace gui { +class IGUIFontFactory; // MICHA, StarSonata class IGUIElement; class IGUIFont; @@ -130,12 +135,12 @@ public: See IUnknown::drop() for more information. */ virtual IGUISkin* createSkin(EGUI_SKIN_TYPE type) = 0; - //! Returns pointer to the font with the specified file name. + //! Returns pointer to the font with the specified fontname (usually a filename) /** Loads the font if it was not loaded before. Returns 0 if the font could not be loaded. \return returns a pointer to the font. This pointer should not be dropped. See IUnknown::drop() for more information. */ - virtual IGUIFont* getFont(const c8* filename) = 0; + virtual IGUIFont* getFont(const c8* fontname) = 0; //! Returns the default built-in font. virtual IGUIFont* getBuiltInFont() = 0; @@ -386,6 +402,17 @@ public: //! Adds a GUI Element by its name virtual IGUIElement* addGUIElement(const c8* elementName, IGUIElement* parent=0) = 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 automaticly, for example when loading data from xml files. */ + virtual void registerGUIFontFactory(IGUIFontFactory* factoryToAdd) = 0; + + //! Returns amount of registered font factories. + virtual s32 getRegisteredGUIFontFactoryCount() = 0; + + //! Returns a font factory by index + virtual IGUIFontFactory* getGUIFontFactory(s32 index) = 0; + //! Saves the current gui into a file. //! \param filename: Name of the file. //! \param start: The GUIElement to start with. Root if 0. diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIFontFactory.h Irrlicht_starsonata/include/IGUIFontFactory.h --- irrlicht-svn-ss/trunk/include/IGUIFontFactory.h 1970-01-01 01:00:00.000000000 +0100 +++ Irrlicht_starsonata/include/IGUIFontFactory.h 2007-10-22 18:57:04.000000000 +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 "IUnknown.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 IUnknown + { + 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 c8* fontName) = 0; + }; + + +} // end namespace gui +} // end namespace irr + +#endif // __I_GUI_FONT_FACTORY_H_INCLUDED__ diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIFont.h Irrlicht_starsonata/include/IGUIFont.h --- irrlicht-svn-ss/trunk/include/IGUIFont.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUIFont.h 2007-10-22 18:57:04.000000000 +0200 @@ -9,6 +9,9 @@ #include "SColor.h" #include "rect.h" +// STARSONATA, MICHA - needed now for the name +#include "irrString.h" + namespace irr { namespace gui @@ -87,6 +90,15 @@ public: //! Returns the distance between letters virtual s32 getKerningHeight() = 0; + //! STARSONATA, MICHA: Access the font name + core::stringc & getName() + { + return Name; + } + +protected: + //! STARSONATA, MICHA + core::stringc Name; }; } // end namespace gui diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/irrlicht.h Irrlicht_starsonata/include/irrlicht.h --- irrlicht-svn-ss/trunk/include/irrlicht.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/irrlicht.h 2008-05-14 05:43:46.000000000 +0200 @@ -63,6 +63,7 @@ #include "IGUIElement.h" #include "IGUIEditBox.h" #include "IGUIEnvironment.h" +#include "IGUIFontFactory.h" #include "IGUIFileOpenDialog.h" #include "IGUIColorSelectDialog.h" #include "IGUIFont.h" diff -abBpNPwrU2 --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIEnvironment.cpp Irrlicht_starsonata/source/Irrlicht/CGUIEnvironment.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIEnvironment.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIEnvironment.cpp 2008-08-15 18:20:47.000000000 +0200 @@ -38,4 +41,6 @@ #include "os.h" +#include "IGUIFontFactory.h" + namespace irr { @@ -143,5 +157,6 @@ CGUIEnvironment::~CGUIEnvironment() for (i=0; idrop(); - + for (i=0; idrop(); } @@ -626,4 +663,29 @@ IGUIElement* CGUIEnvironment::addGUIElem } +//! 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. +s32 CGUIEnvironment::getRegisteredGUIFontFactoryCount() +{ + return GUIFontFactoryList.size(); +} + +//! Returns a font factory by index +IGUIFontFactory* CGUIEnvironment::getGUIFontFactory(s32 index) +{ + if (index>=0 && index<(int)GUIFontFactoryList.size()) + return GUIFontFactoryList[index]; + + return 0; +} + //! Saves the current gui into a file. @@ -1271,4 +1584,13 @@ IGUIFont* CGUIEnvironment::getFont(const return Fonts[index].Font; + // 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 @@ -1338,4 +1660,5 @@ IGUIFont* CGUIEnvironment::getFont(const xml->drop(); } + } @@ -1353,5 +1676,5 @@ IGUIFont* CGUIEnvironment::getFont(const // add to fonts. - + ifont->getName() = filename; f.Font = ifont; Fonts.push_back(f); diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIEnvironment.h Irrlicht_starsonata/source/Irrlicht/CGUIEnvironment.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIEnvironment.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIEnvironment.h 2008-05-31 04:51:06.000000000 +0200 @@ -190,6 +199,17 @@ public: //! Adds a GUI Element by its name virtual IGUIElement* addGUIElement(const c8* elementName, IGUIElement* parent=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 automaticly, for example when loading data from xml files. */ + virtual void registerGUIFontFactory(IGUIFontFactory* factoryToAdd); + + //! Returns amount of registered font factories. + virtual s32 getRegisteredGUIFontFactoryCount(); + + //! Returns a font factory by index + virtual IGUIFontFactory* getGUIFontFactory(s32 index); + //! Saves the current gui into a file. /** \param filename: Name of the file. \param start: The element to start saving from. @@ -266,4 +320,5 @@ private: core::array GUIElementFactoryList; + core::array GUIFontFactoryList; core::array Fonts;