From: <sv...@ww...> - 2007-04-27 11:23:33
|
Author: nsmoooose Date: 2007-04-27 04:23:21 -0700 (Fri, 27 Apr 2007) New Revision: 2087 Modified: branches/python_bindings_for_ui/csp/cspsim/wf/ControlGeometryBuilder.cpp branches/python_bindings_for_ui/csp/cspsim/wf/ResourceLocator.cpp branches/python_bindings_for_ui/csp/cspsim/wf/ResourceLocator.h branches/python_bindings_for_ui/csp/cspsim/wf/Serialization.cpp Log: Renamed the resource locater to ImageResourceLocator. Added a StringResourceLocator. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=2087 Modified: branches/python_bindings_for_ui/csp/cspsim/wf/ControlGeometryBuilder.cpp =================================================================== --- branches/python_bindings_for_ui/csp/cspsim/wf/ControlGeometryBuilder.cpp 2007-04-25 11:18:30 UTC (rev 2086) +++ branches/python_bindings_for_ui/csp/cspsim/wf/ControlGeometryBuilder.cpp 2007-04-27 11:23:21 UTC (rev 2087) @@ -231,7 +231,7 @@ // Try to locate the resource using a resource locator class. // The resource can be located in the theme directory or in // the datapath. - Ref<WindowResourceLocator> resourceLocator = new WindowResourceLocator(window); + Ref<ResourceLocator> resourceLocator = new ImageResourceLocator(window); std::string filePath = *style.backgroundImage; if(resourceLocator->locateResource(filePath)) { image = osgDB::readImageFile(filePath); Modified: branches/python_bindings_for_ui/csp/cspsim/wf/ResourceLocator.cpp =================================================================== --- branches/python_bindings_for_ui/csp/cspsim/wf/ResourceLocator.cpp 2007-04-25 11:18:30 UTC (rev 2086) +++ branches/python_bindings_for_ui/csp/cspsim/wf/ResourceLocator.cpp 2007-04-27 11:23:21 UTC (rev 2087) @@ -31,10 +31,10 @@ namespace wf { -WindowResourceLocator::WindowResourceLocator(const Window* window) : m_Window(window) { +ImageResourceLocator::ImageResourceLocator(const Window* window) : m_Window(window) { } -bool WindowResourceLocator::locateResource(std::string& file) const { +bool ImageResourceLocator::locateResource(std::string& file) const { // Build up the path to the file in order to be able to read it. std::string themesPath = ospath::join(getUIPath(), "themes"); std::string themePath = ospath::join(themesPath, m_Window->getTheme()); @@ -60,6 +60,35 @@ return false; } +StringResourceLocator::StringResourceLocator(const Window* window) : m_Window(window) { +} + +bool StringResourceLocator::locateResource(std::string& file) const { + // Build up the path to the file in order to be able to read it. + std::string themesPath = ospath::join(getUIPath(), "themes"); + std::string themePath = ospath::join(themesPath, m_Window->getTheme()); + std::string filePath = ospath::join(themePath, file); + + // Test to see if the file exists at all? + if(ospath::exists(filePath.c_str())) { + file = filePath; + return true; + } + else { + // As a secondary solution we look for the file in the specialized + // language directory. + std::string languagePath = ospath::join(getUIPath(), getUILanguage()); + std::string filePath = ospath::join(languagePath, file); + if(ospath::exists(filePath.c_str())) { + file = filePath; + return true; + } + } + + // Didn't find any file that is matching the resource asked for. + return false; +} + } // namespace wf CSP_NAMESPACE_END Modified: branches/python_bindings_for_ui/csp/cspsim/wf/ResourceLocator.h =================================================================== --- branches/python_bindings_for_ui/csp/cspsim/wf/ResourceLocator.h 2007-04-25 11:18:30 UTC (rev 2086) +++ branches/python_bindings_for_ui/csp/cspsim/wf/ResourceLocator.h 2007-04-27 11:23:21 UTC (rev 2087) @@ -40,9 +40,9 @@ virtual bool locateResource(std::string& file) const = 0; }; -class WindowResourceLocator : public ResourceLocator { +class ImageResourceLocator : public ResourceLocator { public: - WindowResourceLocator(const Window* window); + ImageResourceLocator(const Window* window); virtual bool locateResource(std::string& file) const; @@ -50,6 +50,16 @@ Ref<const Window> m_Window; }; +class StringResourceLocator : public ResourceLocator { +public: + StringResourceLocator(const Window* window); + + virtual bool locateResource(std::string& file) const; + +private: + Ref<const Window> m_Window; +}; + } // namespace wf CSP_NAMESPACE_END Modified: branches/python_bindings_for_ui/csp/cspsim/wf/Serialization.cpp =================================================================== --- branches/python_bindings_for_ui/csp/cspsim/wf/Serialization.cpp 2007-04-25 11:18:30 UTC (rev 2086) +++ branches/python_bindings_for_ui/csp/cspsim/wf/Serialization.cpp 2007-04-27 11:23:21 UTC (rev 2087) @@ -216,7 +216,7 @@ std::string includeNodeName = includeNode.getName(); if(includeNodeName == "StringTableInclude") { Ref<StringResourceManager> loadedResources = new StringResourceManager; - Ref<ResourceLocator> resourceLocator = new WindowResourceLocator(window); + Ref<ResourceLocator> resourceLocator = new ImageResourceLocator(window); loadedResources->loadFromFile(includeFile, resourceLocator.get()); window->getStringResourceManager()->merge(loadedResources.get()); } |