Changeset 415 for cafu/trunk

Show
Ignore:
Timestamp:
10/30/11 14:15:06 (7 months ago)
Author:
Carsten
Message:

GuiSys: Refactored the management of shared GUI resources (fonts and models).

Until now,

  • fonts were kept in GuiManImplT instances (which GUI windows had to access via the global cf::GuiSys::GuiMan pointer),
  • models (for ModelWindowT windows) were managed by the ModelProxyT class (which kept things globally as well and is now obsolete).

This has now been externalized and made explizit in the new class GuiResourcesT.

  • GuiImplT instances are now fully independent from the global cf::GuiSys::GuiMan.
  • Windows can now aquire both fonts and models through their parent GUI (GuiImplT).
  • It's much easier now to understand how fonts and models are shared, and to make related changes, whenever necessary.
Location:
cafu/trunk
Files:
26 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/Ca3DE/MainCanvas.cpp

    r359 r415  
    4141#include "MaterialSystem/Renderer.hpp" 
    4242#include "MaterialSystem/TextureMap.hpp" 
     43#include "Models/ModelManager.hpp" 
    4344#include "OpenGL/OpenGLWindow.hpp"  // For CaMouseEventT and CaKeyboardEventT. 
    4445#include "SoundSystem/SoundShaderManager.hpp" 
     
    113114      m_GLContext(NULL), 
    114115      m_RendererDLL(NULL), 
     116      m_ModelManager(NULL), 
     117      m_GuiResources(NULL), 
    115118      m_SoundSysDLL(NULL), 
    116119      m_GameDLL(NULL), 
     
    184187        FreeLibrary(m_SoundSysDLL); 
    185188        m_SoundSysDLL=NULL; 
     189    } 
     190 
     191 
     192    // Release the GUI resources. 
     193    if (m_GuiResources) 
     194    { 
     195        delete m_GuiResources; 
     196        m_GuiResources=NULL; 
     197    } 
     198 
     199 
     200    // Release the model manager. 
     201    if (m_ModelManager) 
     202    { 
     203        delete m_ModelManager; 
     204        m_ModelManager=NULL; 
    186205    } 
    187206 
     
    316335            case 2: MatSys::TextureMapManager->SetMaxTextureSize(128); break; 
    317336        } 
     337 
     338 
     339        // Initialize the model manager and the GUI resources. 
     340        m_ModelManager=new ModelManagerT(); 
     341        m_GuiResources=new cf::GuiSys::GuiResourcesT(*m_ModelManager); 
    318342 
    319343 
     
    373397        //   - It has to be done *before* the game is initialized, because even the server needs access to it 
    374398        //     when it loads static detail model entities that have world/entity-GUIs. 
    375         cf::GuiSys::GuiMan=new cf::GuiSys::GuiManImplT; 
     399        cf::GuiSys::GuiMan=new cf::GuiSys::GuiManImplT(*m_GuiResources); 
    376400 
    377401 
     
    397421        // Note that in the line below, the call to gui:setMousePos() is important, because it sets "MouseOverWindow" in the GUI properly to "Cl". 
    398422        // Without this, a left mouse button click that was not preceeded by a mouse movement would erroneously remove the input focus from "Cl". 
    399         cf::GuiSys::GuiImplT* ClientGui   =new cf::GuiSys::GuiImplT("Cl=gui:new('ClientWindowT'); gui:SetRootWindow(Cl); gui:showMouse(false); gui:setMousePos(320, 240); gui:setFocus(Cl); Cl:SetName('Client');", true); 
     423        cf::GuiSys::GuiImplT* ClientGui   =new cf::GuiSys::GuiImplT(*m_GuiResources, "Cl=gui:new('ClientWindowT'); gui:SetRootWindow(Cl); gui:showMouse(false); gui:setMousePos(320, 240); gui:setFocus(Cl); Cl:SetName('Client');", true); 
    400424        cf::GuiSys::WindowT*  ClientWindow=ClientGui->GetRootWindow()->Find("Client"); 
    401425        ClientWindowT*        ClWin       =dynamic_cast<ClientWindowT*>(ClientWindow); 
     
    409433        if (MainMenuGui==NULL) 
    410434        { 
    411             MainMenuGui=new cf::GuiSys::GuiImplT("Err=gui:new('WindowT'); gui:SetRootWindow(Err); gui:activate(true); gui:setInteractive(true); gui:showMouse(true); Err:set('rect', 0, 0, 640, 480); Err:set('text', 'Error loading MainMenu_main.cgui,\\nsee console <F1> for details.');", true); 
     435            MainMenuGui=new cf::GuiSys::GuiImplT(*m_GuiResources, "Err=gui:new('WindowT'); gui:SetRootWindow(Err); gui:activate(true); gui:setInteractive(true); gui:showMouse(true); Err:set('rect', 0, 0, 640, 480); Err:set('text', 'Error loading MainMenu_main.cgui,\\nsee console <F1> for details.');", true); 
    412436            cf::GuiSys::GuiMan->Register(MainMenuGui); 
    413437        } 
  • cafu/trunk/Ca3DE/MainCanvas.hpp

    r285 r415  
    3737class ServerT; 
    3838class SvGuiCallbT; 
     39class ModelManagerT; 
     40namespace cf { namespace GuiSys { class GuiResourcesT; } } 
    3941namespace cf { class ConsoleI; } 
    4042 
     
    7577    void OnKeyChar(wxKeyEvent& KE); 
    7678 
    77     MainFrameT*   m_Parent; 
    78     InitStateT    m_InitState;      ///< Indicates whether initialization is still required, was attempted but failed, or completed successfully. 
    79     wxGLContext*  m_GLContext;      ///< The OpenGL rendering context that represents our app-global OpenGL state. 
    80     HMODULE       m_RendererDLL; 
    81     HMODULE       m_SoundSysDLL; 
    82     HMODULE       m_GameDLL; 
    83     ClientT*      m_Client; 
    84     ServerT*      m_Server; 
    85     SvGuiCallbT*  m_SvGuiCallback; 
    86     cf::ConsoleI* m_ConByGuiWin;    ///< This points to an instance of cf::GuiSys::ConsoleByWindowT. 
    87     TimerT        m_Timer; 
    88     double        m_TotalTime; 
    89     LastMousePosT m_LastMousePos;   ///< Used to prevent unwanted changes to the players heading and pitch when we're switching back from a 2D GUI to the 3D client view. 
     79    MainFrameT*                m_Parent; 
     80    InitStateT                 m_InitState;     ///< Indicates whether initialization is still required, was attempted but failed, or completed successfully. 
     81    wxGLContext*               m_GLContext;     ///< The OpenGL rendering context that represents our app-global OpenGL state. 
     82    HMODULE                    m_RendererDLL; 
     83    ModelManagerT*             m_ModelManager; 
     84    cf::GuiSys::GuiResourcesT* m_GuiResources; 
     85    HMODULE                    m_SoundSysDLL; 
     86    HMODULE                    m_GameDLL; 
     87    ClientT*                   m_Client; 
     88    ServerT*                   m_Server; 
     89    SvGuiCallbT*               m_SvGuiCallback; 
     90    cf::ConsoleI*              m_ConByGuiWin;   ///< This points to an instance of cf::GuiSys::ConsoleByWindowT. 
     91    TimerT                     m_Timer; 
     92    double                     m_TotalTime; 
     93    LastMousePosT              m_LastMousePos;  ///< Used to prevent unwanted changes to the players heading and pitch when we're switching back from a 2D GUI to the 3D client view. 
    9094 
    9195    DECLARE_EVENT_TABLE() 
  • cafu/trunk/CaWE/AppCaWE.cpp

    r370 r415  
    5353#include "ConsoleCommands/ConFunc.hpp" 
    5454#include "FileSys/FileManImpl.hpp" 
    55 #include "GuiSys/GuiMan.hpp" 
    5655#include "GuiSys/Window.hpp" 
    5756#include "MaterialSystem/MaterialManagerImpl.hpp" 
     
    7574ConsoleInterpreterI* ConsoleInterpreter=NULL; 
    7675MaterialManagerI*    MaterialManager   =NULL; 
    77 cf::GuiSys::GuiManI* cf::GuiSys::GuiMan=NULL; 
    7876 
    7977 
  • cafu/trunk/CaWE/GameConfig.cpp

    r414 r415  
    3737      ModDir(ModDir_), 
    3838      m_MatMan(*this), 
     39      m_ModelMan(), 
     40      m_GuiResources(m_ModelMan), 
    3941      m_MaxMapCoord(8192) 
    4042{ 
  • cafu/trunk/CaWE/GameConfig.hpp

    r414 r415  
    2424 
    2525#include "EditorMaterialManager.hpp" 
     26#include "GuiSys/GuiImpl.hpp" 
    2627#include "Math3D/BoundingBox.hpp" 
    2728#include "Models/ModelManager.hpp" 
     
    6364    const CafuModelT* GetModel(const wxString& FileName, wxString* ErrorMsg=NULL) const; 
    6465 
     66    /// All GUIs that are created in this game config (no matter if in the Map Editor, the Gui Editor, or the Model Editor) 
     67    /// share their font and model resources via the returned GuiResourcesT instance. 
     68    cf::GuiSys::GuiResourcesT& GetGuiResources() { return m_GuiResources; } 
     69 
    6570    int GetMaxMapCoord() const { return  m_MaxMapCoord; } 
    6671    int GetMinMapCoord() const { return -m_MaxMapCoord; } 
     
    9297    EditorMatManT                     m_MatMan;                 ///< The material manager for this game config. 
    9398    ModelManagerT                     m_ModelMan;               ///< The model manager for this game config. 
     99    cf::GuiSys::GuiResourcesT         m_GuiResources;           ///< The provider for resources (fonts and models) for all GUIs in this game config (no matter if in the Map Editor, the Gui Editor, or the Model Editor). 
    94100    int                               m_MaxMapCoord; 
    95101}; 
  • cafu/trunk/CaWE/GuiEditor/ChildFrame.cpp

    r375 r415  
    674674            try 
    675675            { 
    676                 cf::GuiSys::GuiImplT* Gui=new cf::GuiSys::GuiImplT(std::string(MainScriptFileName)); 
     676                cf::GuiSys::GuiImplT* Gui=new cf::GuiSys::GuiImplT(m_GameConfig->GetGuiResources(), std::string(MainScriptFileName)); 
    677677 
    678678                if (Gui->GetScriptInitResult()!="") 
  • cafu/trunk/CaWE/GuiEditor/Commands/ModifyWindow.cpp

    r388 r415  
    2424#include "../Windows/EditorWindow.hpp" 
    2525 
    26 #include "GuiSys/GuiMan.hpp" 
    2726#include "GuiSys/GuiImpl.hpp" 
    2827#include "GuiSys/WindowModel.hpp" 
     
    125124        m_Window->BackRenderMat=m_Window->BackRenderMatName.empty() ? NULL : MatSys::Renderer->RegisterMaterial(m_GuiDocument->GetGui()->GetMaterialManager().GetMaterial(m_Window->BackRenderMatName)); 
    126125    } 
    127     else if (m_PropertyName=="FontName") 
    128     { 
    129         m_OldString=m_Window->Font->GetName(); 
    130  
    131         m_Window->Font=cf::GuiSys::GuiMan->GetFont(m_NewString); 
    132     } 
    133126    else if (m_PropertyName=="Model") 
    134127    { 
     
    200193        m_Window->BackRenderMat=m_Window->BackRenderMatName.empty() ? NULL : MatSys::Renderer->RegisterMaterial(m_GuiDocument->GetGui()->GetMaterialManager().GetMaterial(m_Window->BackRenderMatName)); 
    201194    } 
    202     else if (m_PropertyName=="FontName") 
    203     { 
    204         m_Window->Font=cf::GuiSys::GuiMan->GetFont(m_OldString); 
    205     } 
    206195    else if (m_PropertyName=="Model") 
    207196    { 
  • cafu/trunk/CaWE/GuiEditor/Commands/SetWinProp.cpp

    r378 r415  
    7676 
    7777 
     78namespace cf { class TrueTypeFontT; } 
     79 
    7880template class CommandSetWinPropT< ArrayT<std::string> >; 
     81template class CommandSetWinPropT< cf::TrueTypeFontT* >; 
  • cafu/trunk/CaWE/GuiEditor/GuiDocument.cpp

    r388 r415  
    5757        const std::string gifn(GuiInitFileName); 
    5858 
    59         m_Gui=new cf::GuiSys::GuiImplT(gifn); 
     59        m_Gui=new cf::GuiSys::GuiImplT(GameConfig->GetGuiResources(), gifn); 
    6060 
    6161        if (m_Gui->GetScriptInitResult()!="") 
     
    7777    else 
    7878    { 
    79         m_Gui=new cf::GuiSys::GuiImplT("Win=gui:new('WindowT'); gui:SetRootWindow(Win); gui:showMouse(false); gui:setFocus(Win); Win:SetName('Root'); Win:set(\"rect\", 0, 0, 640, 480);", true); 
     79        m_Gui=new cf::GuiSys::GuiImplT(GameConfig->GetGuiResources(), 
     80            "Win=gui:new('WindowT'); gui:SetRootWindow(Win); gui:showMouse(false); gui:setFocus(Win); Win:SetName('Root'); Win:set(\"rect\", 0, 0, 640, 480);", true); 
    8081 
    8182        m_GuiProperties=GuiPropertiesT(*m_Gui); 
  • cafu/trunk/CaWE/GuiEditor/GuiDocument.hpp

    r388 r415  
    2424 
    2525#include "ObserverPattern.hpp" 
    26  
    2726#include "wx/wx.h" 
    2827 
  • cafu/trunk/CaWE/GuiEditor/LivePreview.cpp

    r285 r415  
    2424#include "../AppCaWE.hpp" 
    2525 
    26 #include "GuiSys/GuiMan.hpp"        // For virtual screen sizes. 
    2726#include "GuiSys/GuiImpl.hpp" 
    2827#include "OpenGL/OpenGLWindow.hpp"  // For CaMouseEventT and CaKeyboardEventT. 
  • cafu/trunk/CaWE/GuiEditor/RenderWindow.cpp

    r374 r415  
    2828 
    2929#include "MaterialSystem/Renderer.hpp" 
    30 #include "GuiSys/GuiMan.hpp" // For virtual screen sizes. 
     30#include "GuiSys/Gui.hpp" 
    3131#include "GuiSys/Window.hpp" 
    3232 
  • cafu/trunk/CaWE/GuiEditor/Windows/EditorWindow.cpp

    r389 r415  
    2424#include "../GuiDocument.hpp" 
    2525#include "../Commands/ModifyWindow.hpp" 
     26#include "../Commands/SetWinProp.hpp" 
    2627#include "../../EditorMaterial.hpp" 
    2728#include "../../MaterialBrowser/DocAccess.hpp" 
     
    322323    else if (PropName=="FontName") 
    323324    { 
    324         // Specially treated by command. 
    325         ChildFrame->SubmitCommand(new CommandModifyWindowT(m_GuiDoc, m_Win, PropName, DummyVar, Prop->GetValueAsString())); 
     325        cf::TrueTypeFontT* NewFont=m_Win->GetGui().GetGuiResources().GetFont(std::string(Prop->GetValueAsString())); 
     326 
     327        ChildFrame->SubmitCommand(new CommandSetWinPropT<cf::TrueTypeFontT*>(m_GuiDoc, this, PropName, m_Win->Font, NewFont)); 
    326328    } 
    327329    else if (PropName=="Text") 
  • cafu/trunk/CaWE/ModelEditor/ModelDocument.cpp

    r408 r415  
    7171      m_AnimState(*m_Model), 
    7272      m_Submodels(), 
    73       m_Gui(new cf::GuiSys::GuiImplT("Win1=gui:new('WindowT'); gui:SetRootWindow(Win1); gui:activate(true); " 
     73      m_Gui(new cf::GuiSys::GuiImplT(GameConfig->GetGuiResources(), 
     74          "Win1=gui:new('WindowT'); gui:SetRootWindow(Win1); gui:activate(true); " 
    7475          "gui:setInteractive(true); gui:showMouse(true); Win1:set('rect', 0, 0, 640, 480); " 
    7576          "Win1:set('backColor', 150/255, 170/255, 204/255, 0.8); " 
  • cafu/trunk/CaWE/Options.cpp

    r285 r415  
    3434OptionsT::~OptionsT() 
    3535{ 
    36     for (unsigned long i=0; i<GameConfigs.Size(); i++) 
    37         delete GameConfigs[i]; 
     36    DeleteGameConfigs(); 
    3837} 
    3938 
     
    221220    } 
    222221} 
     222 
     223 
     224void OptionsT::DeleteGameConfigs() 
     225{ 
     226    for (unsigned long i=0; i<GameConfigs.Size(); i++) 
     227        delete GameConfigs[i]; 
     228 
     229    GameConfigs.Clear(); 
     230} 
  • cafu/trunk/CaWE/Options.hpp

    r285 r415  
    102102    void Init(); 
    103103    void Write() const; 
     104    void DeleteGameConfigs(); 
    104105 
    105106    GeneralT             general; 
  • cafu/trunk/CaWE/ParentFrame.cpp

    r376 r415  
    3636#include "FileSys/FileManImpl.hpp" 
    3737#include "GuiSys/GuiImpl.hpp"   // Needed to catch InitErrorT if GUI document creation fails. 
    38 #include "GuiSys/GuiManImpl.hpp" 
    3938#include "MaterialSystem/MapComposition.hpp" 
    4039#include "MaterialSystem/Renderer.hpp" 
     
    185184    m_FileHistory.Save(*wxConfigBase::Get()); 
    186185 
    187     // Release the GuiManager (BEFORE the renderer). 
    188     if (cf::GuiSys::GuiMan!=NULL) 
    189     { 
    190         delete cf::GuiSys::GuiMan; 
    191         cf::GuiSys::GuiMan=NULL; 
    192     } 
     186    // Release the resources in the game configs before releasing the material system below. 
     187    Options.DeleteGameConfigs(); 
    193188 
    194189    // Release the Cafu Material System. 
     
    305300        MatSys::Renderer->SetCurrentLightMap(m_WhiteTexture); 
    306301        MatSys::Renderer->SetCurrentLightDirMap(NULL);  // The MatSys provides a default for LightDirMaps when NULL is set. 
    307  
    308  
    309         // Initialize the GUI manager. 
    310         // This has to be done after all materials are loaded (AppCaWE::OnInit()) and after the MatSys::Renderer has been initialized, 
    311         // so that the GuiManager finds its default material and can register it for rendering. 
    312         // (This is no longer exactly true: each GUI has now its own local material manager! See r359 from 2011-08-29 for details.) 
    313         cf::GuiSys::GuiMan=new cf::GuiSys::GuiManImplT(); 
    314302    } 
    315303} 
  • cafu/trunk/Libs/GuiSys/Gui.hpp

    r367 r415  
    3636    namespace GuiSys 
    3737    { 
     38        /// Note that it is very difficult to change these constants later, because then all GUI scripts 
     39        /// in the world had to be changed too (and in a non-trivial way)! 
     40        const float VIRTUAL_SCREEN_SIZE_X=640.0f; 
     41        const float VIRTUAL_SCREEN_SIZE_Y=480.0f; 
     42 
     43 
    3844        /// General GUI interface. 
    3945        class GuiI 
  • cafu/trunk/Libs/GuiSys/GuiImpl.cpp

    r364 r415  
    2121 
    2222#include "GuiImpl.hpp" 
    23 #include "GuiMan.hpp" 
    2423#include "Window.hpp" 
    2524#include "WindowCreateParams.hpp" 
     
    2726#include "ConsoleCommands/Console_Lua.hpp" 
    2827#include "ConsoleCommands/ConsoleInterpreter.hpp" 
     28#include "Fonts/FontTT.hpp" 
    2929#include "MaterialSystem/Material.hpp" 
    3030#include "MaterialSystem/Mesh.hpp" 
    3131#include "MaterialSystem/Renderer.hpp" 
     32#include "Models/ModelManager.hpp" 
    3233#include "OpenGL/OpenGLWindow.hpp"  // Just for the Ca*EventT classes... 
    3334#include "String.hpp" 
     
    5758 
    5859 
     60GuiResourcesT::GuiResourcesT(ModelManagerT& ModelMan) 
     61    : m_ModelMan(ModelMan) 
     62{ 
     63} 
     64 
     65 
     66GuiResourcesT::~GuiResourcesT() 
     67{ 
     68    for (unsigned long FontNr=0; FontNr<m_Fonts.Size(); FontNr++) 
     69        delete m_Fonts[FontNr]; 
     70} 
     71 
     72 
     73cf::TrueTypeFontT* GuiResourcesT::GetFont(const std::string& FontName) 
     74{ 
     75    // See if FontName has been loaded successfully before. 
     76    for (unsigned long FontNr=0; FontNr<m_Fonts.Size(); FontNr++) 
     77        if (m_Fonts[FontNr]->GetName()==FontName) 
     78            return m_Fonts[FontNr]; 
     79 
     80    // See if FontName has been loaded UNsuccessfully before. 
     81 // for (unsigned long FontNr=0; FontNr<m_FontsFailed.Size(); FontNr++) 
     82 //     if (m_FontsFailed[FontNr]==FontName) 
     83 //         return NULL; 
     84 
     85    // FontName has never been attempted to be loaded, try now. 
     86    try 
     87    { 
     88        m_Fonts.PushBack(new cf::TrueTypeFontT(FontName)); 
     89        return m_Fonts[m_Fonts.Size()-1]; 
     90    } 
     91    catch (const TextParserT::ParseError&) { } 
     92 
     93    Console->Warning(std::string("Failed to load font \"")+FontName+"\".\n"); 
     94 // FontsFailed.PushBack(FontName); 
     95    return m_Fonts.Size()>0 ? m_Fonts[0] : NULL; 
     96} 
     97 
     98 
     99const CafuModelT* GuiResourcesT::GetModel(const std::string& FileName, std::string& ErrorMsg) 
     100{ 
     101    return m_ModelMan.GetModel(FileName, ErrorMsg); 
     102} 
     103 
     104 
    59105GuiImplT::InitErrorT::InitErrorT(const std::string& Message) 
    60106    : std::runtime_error(Message) 
     
    63109 
    64110 
    65 GuiImplT::GuiImplT(const std::string& GuiScriptName, bool IsInlineCode) 
     111GuiImplT::GuiImplT(GuiResourcesT& GuiRes, const std::string& GuiScriptName, bool IsInlineCode) 
    66112    : ScriptName(IsInlineCode ? "" : GuiScriptName), 
    67113      LuaState(NULL), 
     
    70116      m_GuiDefaultRM(NULL), 
    71117      m_GuiPointerRM(NULL), 
     118      m_GuiResources(GuiRes), 
    72119      RootWindow(NULL), 
    73120      FocusWindow(NULL), 
  • cafu/trunk/Libs/GuiSys/GuiImpl.hpp

    r367 r415  
    3232 
    3333namespace cf { namespace TypeSys { class TypeInfoT; } } 
     34namespace cf { class TrueTypeFontT; } 
    3435namespace MatSys { class RenderMaterialT; } 
     36class CafuModelT; 
     37class ModelManagerT; 
    3538struct lua_State; 
    3639 
     
    4043    namespace GuiSys 
    4144    { 
     45        /// This class manages and provides resources (fonts and models) for GuiImplT instances. 
     46        /// One GuiResourcesT can be commonly used for several GuiImplT instances at once. 
     47        class GuiResourcesT 
     48        { 
     49            public: 
     50 
     51            /// The constructor. 
     52            GuiResourcesT(ModelManagerT& ModelMan); 
     53 
     54            /// The destructor. 
     55            ~GuiResourcesT(); 
     56 
     57            /// Returns (a pointer to) a font instance for the given filename. 
     58            /// The returned font instance is possibly shared with other users, and must not be deleted. 
     59            /// @param FontName   The name of the font to return. 
     60            /// @returns A pointer to the specified font, or NULL if there was an error (e.g. the font could not be loaded). 
     61            TrueTypeFontT* GetFont(const std::string& FontName); 
     62 
     63            /// Returns (a pointer to) a model instance for the given filename. 
     64            /// @see ModelManagerT::GetModel() for more details. 
     65            const CafuModelT* GetModel(const std::string& FileName, std::string& ErrorMsg); 
     66 
     67 
     68            private: 
     69 
     70            GuiResourcesT(const GuiResourcesT&);        ///< Use of the Copy Constructor    is not allowed. 
     71            void operator = (const GuiResourcesT&);     ///< Use of the Assignment Operator is not allowed. 
     72 
     73            ArrayT<TrueTypeFontT*> m_Fonts;     ///< The fonts that are used within the GUIs. 
     74            ModelManagerT&         m_ModelMan;  ///< The model manager from which any models that occur in the GUIs are aquired. 
     75        }; 
     76 
     77 
    4278        /// This class implements the GuiI interface. 
    4379        /// TODO / FIXME: 
     
    5591 
    5692            /// Constructor for creating a window hierarchy (=="a GUI") from the GUI script file GuiScriptName. 
    57             /// @param GuiScriptName The file name of the GUI script to load or inline script code (depending on IsInlineCode). 
    58             /// @param IsInlineCode Whether GuIScriptName is inline script code or a filename. 
     93            /// @param GuiRes          The provider for resources (fonts and models) that are used in this GUI. 
     94            /// @param GuiScriptName   The file name of the GUI script to load or inline script code (depending on IsInlineCode). 
     95            /// @param IsInlineCode    Whether GuiScriptName is inline script code or a filename. 
    5996            /// @throws an InitErrorT object on problems initializing the GUI. 
    60             GuiImplT(const std::string& GuiScriptName, bool IsInlineCode=false); 
     97            GuiImplT(GuiResourcesT& GuiRes, const std::string& GuiScriptName, bool IsInlineCode=false); 
    6198 
    6299            /// The destructor. 
     
    76113            /// Returns the (default) RenderMaterialT for the mouse pointer. 
    77114            MatSys::RenderMaterialT* GetPointerRM() const; 
     115 
     116            /// Returns the resource provider for fonts and models that are used in this GUI. 
     117            GuiResourcesT& GetGuiResources() const { return m_GuiResources; } 
    78118 
    79119 
     
    133173            MatSys::RenderMaterialT* m_GuiDefaultRM;    ///< Used for the window borders and the backgrounds if no other material is specified. 
    134174            MatSys::RenderMaterialT* m_GuiPointerRM;    ///< Used for the mouse pointer. 
     175            GuiResourcesT&           m_GuiResources;    ///< The provider for resources (fonts and models) that are used in this GUI. 
    135176 
    136177            WindowPtrT               RootWindow;        ///< The root window of the window hierarchy that forms this GUI. 
  • cafu/trunk/Libs/GuiSys/GuiMan.hpp

    r359 r415  
    3232namespace cf 
    3333{ 
    34     class TrueTypeFontT; 
    35  
    36  
    3734    namespace GuiSys 
    3835    { 
    3936        class GuiI; 
    40  
    41         /// Note that it is very difficult to change these constants later, because then all GUI scripts 
    42         /// in the world had to be changed too (and in a non-trivial way)! 
    43         const float VIRTUAL_SCREEN_SIZE_X=640.0f; 
    44         const float VIRTUAL_SCREEN_SIZE_Y=480.0f; 
    4537 
    4638 
     
    9789            virtual void DistributeClockTickEvents(float t)=0; 
    9890 
    99             /// Returns (a pointer to) the font with name FontName. 
    100             /// The returned pointer is valid throughout the lifetime of the implementation of this GuiManI, 
    101             /// and must not be freed (the GuiMan retains the ownership of the font). 
    102             /// @param FontName Name of the font to get. 
    103             /// @returns a pointer to the desired font, or NULL if there was an error (e.g. the font could not be loaded). 
    104             virtual TrueTypeFontT* GetFont(const std::string& FontName)=0; 
    105  
    10691            /// The destructor. 
    10792            /// This ABC does neither have nor need a destructor, because no implementation will ever be deleted via a pointer to a GuiManI. 
  • cafu/trunk/Libs/GuiSys/GuiManImpl.cpp

    r359 r415  
    2828#include "MaterialSystem/Renderer.hpp" 
    2929#include "Math3D/Matrix.hpp" 
    30 #include "Fonts/FontTT.hpp"                     // For dealing with the default font. 
    3130#include "OpenGL/OpenGLWindow.hpp"              // Just for the Ca*EventT classes... 
    3231 
     
    3938 
    4039 
    41 GuiManImplT::GuiManImplT() 
    42     : SuppressNextChar(false) 
     40GuiManImplT::GuiManImplT(GuiResourcesT& GuiRes) 
     41    : m_GuiResources(GuiRes), 
     42      SuppressNextChar(false) 
    4343{ 
    4444    assert(MatSys::Renderer!=NULL); 
     
    5151    for (unsigned long GuiNr=0; GuiNr<Guis.Size(); GuiNr++) 
    5252        delete Guis[GuiNr]; 
    53  
    54     // Free the Fonts. 
    55     for (unsigned long FontNr=0; FontNr<Fonts.Size(); FontNr++) 
    56         delete Fonts[FontNr]; 
    5753} 
    5854 
     
    6258    try 
    6359    { 
    64         Guis.PushBack(new GuiImplT(GuiScriptName)); 
     60        Guis.PushBack(new GuiImplT(m_GuiResources, GuiScriptName)); 
    6561 
    6662        return Guis[Guis.Size()-1]; 
     
    139135        try 
    140136        { 
    141             GuiI* Reloaded=new GuiImplT(Guis[GuiNr]->GetScriptName()); 
     137            GuiI* Reloaded=new GuiImplT(m_GuiResources, Guis[GuiNr]->GetScriptName()); 
    142138 
    143139            delete Guis[GuiNr]; 
     
    236232    } 
    237233} 
    238  
    239  
    240 cf::TrueTypeFontT* GuiManImplT::GetFont(const std::string& FontName) 
    241 { 
    242     // See if FontName has been loaded successfully before. 
    243     for (unsigned long FontNr=0; FontNr<Fonts.Size(); FontNr++) 
    244         if (Fonts[FontNr]->GetName()==FontName) 
    245             return Fonts[FontNr]; 
    246  
    247     // See if FontName has been loaded UNsuccessfully before. 
    248  // for (unsigned long FontNr=0; FontNr<FontsFailed.Size(); FontNr++) 
    249  //     if (FontsFailed[FontNr]==FontName) 
    250  //         return NULL; 
    251  
    252     // FontName has never been attempted to be loaded, try now. 
    253     try 
    254     { 
    255         Fonts.PushBack(new cf::TrueTypeFontT(FontName)); 
    256         return Fonts[Fonts.Size()-1]; 
    257     } 
    258     catch (const TextParserT::ParseError&) { } 
    259  
    260     Console->Warning(std::string("Failed to load font \"")+FontName+"\".\n"); 
    261  // FontsFailed.PushBack(FontName); 
    262     return Fonts.Size()>0 ? Fonts[0] : NULL; 
    263 } 
  • cafu/trunk/Libs/GuiSys/GuiManImpl.hpp

    r359 r415  
    3131    namespace GuiSys 
    3232    { 
     33        class GuiResourcesT; 
     34 
     35 
    3336        /// This class implements the GuiManI interface. 
    3437        class GuiManImplT : public GuiManI 
     
    3841            /// The constructor. 
    3942            /// The MatSys *must* be initialized *before* this constructor is called (i.e. a GuiManImplT is instantiated)! 
    40             GuiManImplT(); 
     43            GuiManImplT(GuiResourcesT& GuiRes); 
    4144 
    4245            /// The destructor. 
     
    5659            void ProcessDeviceEvent(const CaMouseEventT& ME); 
    5760            void DistributeClockTickEvents(float t); 
    58             TrueTypeFontT* GetFont(const std::string& FontName); 
    5961 
    6062 
     
    6466            void operator = (const GuiManImplT&);       ///< Use of the Assignment Operator is not allowed. 
    6567 
    66             ArrayT<GuiI*>          Guis; 
    67             ArrayT<TrueTypeFontT*> Fonts;               ///< The fonts that are used with the GUIs. We manage a GuiMan-global pool here in order to avoid instance duplication if multiple GUIs use the same font. 
    68          // ArrayT<std::string>    FontsFailed;         ///< The fonts that have been attempted to load, but failed (kept in order to avoid retries). 
    69             bool                   SuppressNextChar;    ///< Whether the next character (CaKeyboardEventT::CKE_CHAR) event should be suppressed. This is true whenever the preceeding CaKeyboardEventT::CKE_KEYDOWN event was positively processed. 
     68            GuiResourcesT& m_GuiResources;      ///< The provider for resources (fonts and models) that are used in the GUIs created by this GuiMan. 
     69            ArrayT<GuiI*>  Guis; 
     70            bool           SuppressNextChar;    ///< Whether the next character (CaKeyboardEventT::CKE_CHAR) event should be suppressed. This is true whenever the preceeding CaKeyboardEventT::CKE_KEYDOWN event was positively processed. 
    7071        }; 
    7172    } 
  • cafu/trunk/Libs/GuiSys/Window.cpp

    r386 r415  
    106106      BorderWidth(0.0f), 
    107107   // BorderColor(), 
    108       Font(GuiMan->GetFont(DEFAULT_FONT_NAME)), 
     108      Font(Params.Gui.GetGuiResources().GetFont(DEFAULT_FONT_NAME)), 
    109109      Text(""), 
    110110      TextScale(1.0f), 
     
    140140      BackRenderMatName(Window.BackRenderMatName), 
    141141      BorderWidth(Window.BorderWidth), 
    142       Font(GuiMan->GetFont(Window.Font->GetName())), 
     142      Font(Window.Font), 
    143143      Text(Window.Text), 
    144144      TextScale(Window.TextScale), 
     
    727727            const std::string FontName=luaL_checkstring(LuaState, 3); 
    728728 
    729             Win->Font=GuiMan->GetFont(FontName); 
     729            Win->Font=Win->m_Gui.GetGuiResources().GetFont(FontName); 
    730730            return 0; 
    731731        } 
  • cafu/trunk/Libs/Models/AnimPose.hpp

    r406 r415  
    105105    ~AnimPoseT(); 
    106106 
    107     /// @param SequenceNr   The number of the animation sequence to use, -1 for the bind pose. 
     107    /// @param SequNr   The number of the animation sequence to use, -1 for the bind pose. 
    108108    void SetSequNr(int SequNr); 
    109109 
  • cafu/trunk/Libs/Models/ModelManager.hpp

    r414 r415  
    2424 
    2525#include <map> 
     26#include <string> 
    2627 
    2728