From: <wrt...@us...> - 2008-02-11 12:58:40
|
Revision: 7857 http://armagetronad.svn.sourceforge.net/armagetronad/?rev=7857&view=rev Author: wrtlprnft Date: 2008-02-11 04:58:40 -0800 (Mon, 11 Feb 2008) Log Message: ----------- Added some support for textures in cockpits and for resource textures in general :-) The map background texture I committed is temporary and just a demonstration and an example. It's waiting for a better design :-) Modified Paths: -------------- armagetronad/trunk/armagetronad/resource/proto/Anonymous/original/original.cockpit.xml armagetronad/trunk/armagetronad/resource/proto/cockpit.dtd armagetronad/trunk/armagetronad/resource/proto/resource.dtd armagetronad/trunk/armagetronad/src/render/rGradient.cpp armagetronad/trunk/armagetronad/src/render/rGradient.h armagetronad/trunk/armagetronad/src/render/rTexture.cpp armagetronad/trunk/armagetronad/src/render/rTexture.h armagetronad/trunk/armagetronad/src/tools/tResourceManager.cpp armagetronad/trunk/armagetronad/src/tools/tResourceManager.h armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.cpp armagetronad/trunk/armagetronad/src/tron/cockpit/cMap.cpp armagetronad/trunk/armagetronad/src/tron/cockpit/cRectangle.cpp armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.cpp armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.h Modified: armagetronad/trunk/armagetronad/resource/proto/Anonymous/original/original.cockpit.xml =================================================================== --- armagetronad/trunk/armagetronad/resource/proto/Anonymous/original/original.cockpit.xml 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/resource/proto/Anonymous/original/original.cockpit.xml 2008-02-11 12:58:40 UTC (rev 7857) @@ -270,8 +270,11 @@ <Position x="0.73" y="-0.72" /> <Size height="0.25" width="0.25" /> <Background> + <Image scale_x="2" scale_y="2"> + <Graphic category="" author="wrtlprnft" version="1" name="wood_512" extension="jpg" uri="http://wrtlprnft.ath.cx/wood512.jpg" /> + </Image> <Solid> - <Color r="1." g="1." b="1." alpha=".2" /> + <Color r="1." g="1." b="1." alpha=".5" /> </Solid> </Background> <MapModes toggleKey="1"> Modified: armagetronad/trunk/armagetronad/resource/proto/cockpit.dtd =================================================================== --- armagetronad/trunk/armagetronad/resource/proto/cockpit.dtd 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/resource/proto/cockpit.dtd 2008-02-11 12:58:40 UTC (rev 7857) @@ -166,13 +166,25 @@ <!-- Graphic is a regular graphic file, like something.png. ResourceGraphic is a resource xml file that contains more information on the image and may be a case of YouMightNeedThis --> <!ELEMENT Image (Graphic?,ResourceGraphic?)> +<!ATTLIST Image + scale_x CDATA '1' + scale_y CDATA '1' +> +<!ELEMENT Graphic EMPTY> +<!ATTLIST Graphic + name CDATA #REQUIRED + author CDATA 'Anonymous' + version CDATA #REQUIRED + category CDATA 'unsorted' + extension CDATA 'png' + uri CDATA "" +> + <!ELEMENT Solid (Color?)> <!ELEMENT Gradient (Color+)> <!ATTLIST Gradient orientation (horizontal | vertical | value) "value"> -<!ELEMENT Graphic (Location?)> - <!ELEMENT ResourceGraphic (Location?)> <!ELEMENT Color EMPTY> Modified: armagetronad/trunk/armagetronad/resource/proto/resource.dtd =================================================================== --- armagetronad/trunk/armagetronad/resource/proto/resource.dtd 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/resource/proto/resource.dtd 2008-02-11 12:58:40 UTC (rev 7857) @@ -3,8 +3,8 @@ <!ATTLIST Resource type CDATA "%ResourceType;" name CDATA #REQUIRED - author CDATA #REQUIRED - version CDATA 'Anonymous' + author CDATA 'Anonymous' + version CDATA #REQUIRED category CDATA 'unsorted' commissioner CDATA #IMPLIED > Modified: armagetronad/trunk/armagetronad/src/render/rGradient.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/render/rGradient.cpp 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/render/rGradient.cpp 2008-02-11 12:58:40 UTC (rev 7857) @@ -32,10 +32,12 @@ #include <deque> #include <utility> -rGradient::rGradient() : m_dir(value) { +rGradient::rGradient() : m_dir(value), m_texScale(1,1), m_tex() { //(*this)[0.]=rColor(); //make sure the beginning and end are defined //(*this)[1.]=rColor(); } +rGradient::~rGradient() { +} //! @param edge1 the first edge of the gradient (preferably bottom- left) //! @param edge2 the second edge of the gradient (preferably top- right) @@ -107,16 +109,21 @@ #endif } +void rGradient::DrawAt(tCoord const &where) { + GetColor(GetGradientPt(where)).Apply(); + if(m_tex.Tex()) { + glTexCoord2f((where.x-m_origin.x)/m_dimensions.x/m_texScale.x, (where.y-m_origin.y)/m_dimensions.y/m_texScale.y); + } +} + //! @param edge1 one edge of the rectangle //! @param edge2 the opposite edge void rGradient::DrawAtomicRect(tCoord const &edge1, tCoord const &edge2) { #ifndef DEDICATED - BeginQuads(); DrawPoint(edge1); DrawPoint(tCoord(edge1.x, edge2.y)); DrawPoint(edge2); DrawPoint(tCoord(edge2.x, edge1.y)); - RenderEnd(); #endif } @@ -126,6 +133,8 @@ #ifndef DEDICATED float tCoord::*x; //those are correct for horizontal gradients, float tCoord::*y; //vertical ones just get turned around + BeginDraw(); + BeginQuads(); switch(m_dir) { case horizontal: x = &tCoord::x; @@ -137,6 +146,7 @@ break; default: DrawAtomicRect(edge1, edge2); + RenderEnd(); return; } tCoord const &left = (edge1.*x < edge2.*x) ? edge1 : edge2; @@ -161,13 +171,21 @@ todraw.*x = last; todraw.*y = left.*y; DrawAtomicRect(todraw, right); + RenderEnd(); #endif } +void se_glFloorTexture(); +void rGradient::BeginDraw() { + if(m_tex.Tex()) { + m_tex.Tex()->Select(); + } +} + //! @param where the point the color should be taken from and drawn void rGradient::DrawPoint(tCoord const &where) { #ifndef DEDICATED - GetColor(where).Apply(); + DrawAt(where); Vertex(where.x, where.y); #endif } Modified: armagetronad/trunk/armagetronad/src/render/rGradient.h =================================================================== --- armagetronad/trunk/armagetronad/src/render/rGradient.h 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/render/rGradient.h 2008-02-11 12:58:40 UTC (rev 7857) @@ -31,6 +31,7 @@ #include "defs.h" #include "rColor.h" #include "tCoord.h" +#include "rTexture.h" #include <map> #include <deque> #include <utility> @@ -41,14 +42,18 @@ float m_at; //!< current value, used when m_dir == value tCoord m_origin; //!< bottom-left point of the gradient tCoord m_dimensions; //!< width and height of it + tCoord m_texScale; //!< scale factor of the texture //! return the relevant value (x, y or m_at) depending on m_dir float GetGradientPt(tCoord const &where); //! get the color for a given point on the gradient, using only //! the relevant coordinate (as returned by GetGradientPt) rColor GetColor(float where); + + rResourceTexture m_tex; public: rGradient(); //!< Constructor + ~rGradient(); //!< Destructor //! Enum for describing the direction of the gradient enum direction { @@ -58,24 +63,30 @@ }; //! Sets the type/direction of the gradient //! @param dir the desired type/direction - void SetDir(direction dir) { m_dir = dir; }; + void SetDir(direction dir) { m_dir = dir; } //! set the value, only used when the type is "value" //! @param at the value, 1 should be the maximum and 0 the minimum - void SetValue(float at) { m_at = at; }; + void SetValue(float at) { m_at = at; } //! set the boundaries of the gradient void SetGradientEdges(tCoord const &edge1, tCoord const edge2); - //! get the color at a certain point + //! set the color and texture coordinate at the given point //! @param where the point in the gradient. If it lies outside the edges of the gradient the nearest possible point will be used - //! @returns the color at the specific point - rColor GetColor(tCoord const &where) { return GetColor(GetGradientPt(where)); }; + void DrawAt(tCoord const &where); //! Draw a rectangle using only the colors of the edges void DrawAtomicRect(tCoord const &edge1, tCoord const &edge2); //!Draw a rectangle, but split it up into multiple rectangles if necessary void DrawRect(tCoord const &edge1, tCoord const &edge2); - //! call Color() with the color at the given coordinate and then call Vertex() on it + //! Send a single vertex with the correct color and texture information to OpenGL void DrawPoint(tCoord const &where); + + //! Initialize OpenGL for drawing with this gradient + void BeginDraw(); + + //! Set the texture to be overlaid with the gradient + void SetTexture(rResourceTexture const &tex) {m_tex = tex;} + void SetTextureScale(tCoord const &scale) {m_texScale = scale;} }; #endif Modified: armagetronad/trunk/armagetronad/src/render/rTexture.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/render/rTexture.cpp 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/render/rTexture.cpp 2008-02-11 12:58:40 UTC (rev 7857) @@ -96,10 +96,10 @@ //! // ****************************************************************************************** -rSurface::rSurface( char const * fileName ) +rSurface::rSurface( char const * fileName, tPath const * path ) { Init(); - Create( fileName ); + Create( fileName, path ); } // ****************************************************************************************** @@ -213,19 +213,23 @@ //! // ****************************************************************************************** -void rSurface::Create( char const * fileName ) +void rSurface::Create( char const * fileName, tPath const *path ) { #ifndef DEDICATED sr_LockSDL(); - // find path of image - // tString s = tResourceManager::locateResource("", fileName); - tString s = tDirectories::Data().GetReadPath( fileName ); - - // Load image IMG_InvertAlpha(true); - Create( IMG_Load(s) ); + // find path of image and load it + SDL_Surface *surface; + if(path) { + tString s = path->GetReadPath( fileName ); + surface = IMG_Load(s); + } else { + surface = IMG_Load(fileName); + } + Create(surface); + //if ( surface_ ) // std::cerr << "loaded surface " << fileName << "\n"; @@ -650,9 +654,10 @@ //! // ****************************************************************************************** -rFileTexture::rFileTexture( int group, char const * fileName, bool repx, bool repy, bool storeAlpha ) +rFileTexture::rFileTexture( int group, char const * fileName, bool repx, bool repy, bool storeAlpha, tPath const *path ) : rISurfaceTexture( group, repx, repy, storeAlpha ) , fileName_( fileName ) + , path_(path) { } @@ -682,7 +687,7 @@ { #ifndef DEDICATED // std::cerr << "loading texture " << fileName_ << "\n"; - rSurface surface( fileName_ ); + rSurface surface( fileName_, path_ ); if ( surface.GetSurface() ) { this->Upload( surface ); @@ -773,3 +778,46 @@ static rCallbackBeforeScreenModeChange unload(&rITexture::UnloadAll); // static rCallbackAfterScreenModeChange load(&rITexture::LoadAll); + +rResourceTexture::texlist_t rResourceTexture::textures; + +rResourceTexture rResourceTexture::GetTexture(tResourcePath const &path) { + for(texlist_t::iterator iter = textures.begin(); iter != textures.end(); ++iter) { + if((*iter)->path_ == path) { + ++(*iter)->use_; + return *iter; + } + } + return new tex_t(path); +} + +rResourceTexture::InternalTex::InternalTex(tResourcePath const &path) : rFileTexture(rTextureGroups::TEX_OBJ, tResourceManager::locateResource(path.Path().c_str()).c_str(), true, true, true, 0), use_(0), path_(path) { + textures.push_back(this); +} + +void rResourceTexture::InternalTex::Release() { + if(--use_ < 1) { + for(texlist_t::iterator iter = textures.begin(); iter != textures.end(); ++iter) { + if((*iter)->path_ == path_) { + textures.erase(iter); + break; + } + } + Unload(); + delete this; + } +} + +rResourceTexture &rResourceTexture::operator=(rResourceTexture const &other) { + if(tex_ != other.tex_) { + if(tex_) { + tex_->Release(); + } + tex_ = other.tex_; + if(tex_) { + tex_->Use(); + } + } + return *this; +} + Modified: armagetronad/trunk/armagetronad/src/render/rTexture.h =================================================================== --- armagetronad/trunk/armagetronad/src/render/rTexture.h 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/render/rTexture.h 2008-02-11 12:58:40 UTC (rev 7857) @@ -29,9 +29,12 @@ #define ArmageTron_TEXTURE_H #include "tString.h" +#include "tResourceManager.h" +#include "tDirectories.h" #include "tList.h" #include "rGL.h" #include "rGLuintObject.h" +#include <list> struct SDL_Surface; @@ -57,7 +60,7 @@ class rSurface { public: - explicit rSurface( char const * fileName ); //!< constructor creating the surface from a file + explicit rSurface( char const * fileName, tPath const *path = &tDirectories::Data() ); //!< constructor creating the surface from a file ~rSurface(); //!< destructor rSurface( rSurface const & other ); //!< copy constructor rSurface & operator = ( rSurface const & other ); //!< copy operator @@ -65,7 +68,7 @@ rSurface(); //!< default constructor, not creating a real surface void Init(); //!< initialize data members void Clear(); //!< destroys data members - void Create( char const * fileName ); //!< create surface from file + void Create( char const * fileName, tPath const *path = &tDirectories::Data() ); //!< create surface from file void Create( SDL_Surface * surface ); //!< take ownership of surface private: @@ -160,13 +163,14 @@ { public: rFileTexture(int group, char const * fileName, bool repx=0, bool repy=0, - bool storeAlpha=false); //!< constructor setting flags + bool storeAlpha=false, tPath const *path = &tDirectories::Data()); //!< constructor setting flags virtual ~rFileTexture(); //!< destructor protected: virtual void OnSelect(); //!< Selects the texture for rendering (core part) private: tString fileName_; //!< the texture's filename + tPath const *path_; public: inline tString const & GetFileName( void ) const; //!< Gets the texture's filename @@ -176,6 +180,49 @@ inline rFileTexture & SetFileName( tString const & fileName ); //!< Sets the texture's filename }; +class rResourceTextureWrapper; + +//! Class that implements fetching and caching textures from resource paths. +//! +//! This class manages its own usecount and is therefore safe to copy and move around. +class rResourceTexture +{ + class InternalTex; + friend class InternalTex; + class InternalTex : public rFileTexture + { + public: + int use_; + tResourcePath path_; + + InternalTex(tResourcePath const &path); + + void Release(); + void Use() {++use_;} + }; + typedef InternalTex tex_t; // don't ask me why this is needed. InteralTex just won't cut it in some places + typedef std::list<InternalTex *> texlist_t; + static texlist_t textures; + InternalTex *tex_; + rResourceTexture(InternalTex *tex) : tex_(tex) { tex->Use();} +public: + //! Use this if you want to create an empty texture object (ie if you're not sure if you actually want to store a texture) + rResourceTexture() : tex_(0) {} + //! Copy constructor + rResourceTexture(rResourceTexture const &other) : tex_(other.tex_) {if(tex_) tex_->Use();} + //! Assignment is safe + rResourceTexture &operator=(rResourceTexture const &other); + //! This releases the texture if it's not used anymore + ~rResourceTexture() {if(tex_) tex_->Release();} + //! Get the actual texture. This object retains ownership of the texture, though + rFileTexture *Tex() {return tex_;} + //! Get the path this texture was fetched from + tResourcePath const &Path() {return tex_->path_;} + + //! Get a resource from a path. This is the only way to obtain a new rResourceTexture + static rResourceTexture GetTexture(tResourcePath const &path); +}; + // ****************************************************************************************** //! texture class getting its data from a surface @@ -389,5 +436,3 @@ } #endif - - Modified: armagetronad/trunk/armagetronad/src/tools/tResourceManager.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tools/tResourceManager.cpp 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/tools/tResourceManager.cpp 2008-02-11 12:58:40 UTC (rev 7857) @@ -242,3 +242,36 @@ static tConfItemFunc s_RInclude("RINCLUDE", &RInclude); +tResourcePath::tResourcePath(tString const &Author, + tString const &Category, + tString const &Name, + tString const &Version, + tString const &Type, + tString const &Extension, + tString const &URI) : + m_Author (Author ), + m_Category (Category ), + m_Name (Name ), + m_Version (Version ), + m_Type (Type ), + m_Extension(Extension), + m_URI (URI ) { + // TODO: check for illegal characters + m_Path << Author << '/'; + if(!Category.empty()) { + m_Path << Category << '/'; + } + m_Path << Name << '-' << Version << '.' << Type << '.' << Extension; + if(!URI.empty()) { + m_Path << '(' << URI << ')'; + } +} + +bool tResourcePath::operator==(tResourcePath const &other) const { + return m_Author == other.m_Author && + m_Category == other.m_Category && + m_Name == other.m_Name && + m_Version == other.m_Version && + m_Type == other.m_Type && + m_Extension == other.m_Extension; +} Modified: armagetronad/trunk/armagetronad/src/tools/tResourceManager.h =================================================================== --- armagetronad/trunk/armagetronad/src/tools/tResourceManager.h 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/tools/tResourceManager.h 2008-02-11 12:58:40 UTC (rev 7857) @@ -45,4 +45,37 @@ static void RegisterLoader(); }; +//! helper class to construct a resource path +class tResourcePath +{ + tString m_Author; //!< the author of the resource + tString m_Category; //!< the category of the resource + tString m_Name; //!< the name of the resource + tString m_Version; //!< the version of the resource + tString m_Type; //!< the type of the resource + tString m_Extension;//!< the extension (like xml or png) + tString m_URI; //!< the URI to the file, if any + tString m_Path; //!< the full path of the resource +public: + tString const &Author () const {return m_Author ;} //!< get the author of the resource + tString const &Category () const {return m_Category ;} //!< get the category of the resource + tString const &Name () const {return m_Name ;} //!< get the name of the resource + tString const &Version () const {return m_Version ;} //!< get the version of the resource + tString const &Type () const {return m_Type ;} //!< get the type of the resource + tString const &Extension() const {return m_Extension;} //!< get the extension (like xml or png) + tString const &URI () const {return m_URI ;} //!< get the URI to the file, if any + tString const &Path () const {return m_Path ;} //!< get the full path of the resource + + //! construct the path from the given arguments + tResourcePath(tString const &Author, + tString const &Category, + tString const &Name, + tString const &Version, + tString const &Type, + tString const &Extension, + tString const &URI); + + bool operator==(tResourcePath const &other) const; +}; + #endif //ArmageTron_RESOURCEMANAGER_H Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.cpp 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cGauges.cpp 2008-02-11 12:58:40 UTC (rev 7857) @@ -200,7 +200,7 @@ BeginLines(); m_foreground.SetValue((factor * ((val-min)/(max-min)*2. - 1.)+1.)/2.); - m_foreground.GetColor(tCoord(0.,0.)).Apply(); + m_foreground.DrawAt(tCoord(0.,0.)); Vertex(-.1*x*m_size.x+m_position.x,.1*y*m_size.y+m_position.y,0); Vertex(-x*m_size.x+m_position.x,y*m_size.y+m_position.y,0); RenderEnd(); Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cMap.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cMap.cpp 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cMap.cpp 2008-02-11 12:58:40 UTC (rev 7857) @@ -81,14 +81,14 @@ glClipPlane(GL_CLIP_PLANE3, pl3); glEnable(GL_CLIP_PLANE3); // Add frame ... - map.m_foreground.GetColor(tCoord(0.,0.)).Apply(); + map.m_foreground.BeginDraw(); glBegin(GL_LINE_STRIP); //TODO: this should use a function of the rGradient. - glVertex2f(e1.x, e1.y); - glVertex2f(e2.x, e1.y); - glVertex2f(e2.x, e2.y); - glVertex2f(e1.x, e2.y); - glVertex2f(e1.x, e1.y); + map.m_foreground.DrawPoint(e1); + map.m_foreground.DrawPoint(tCoord(e2.x, e1.y)); + map.m_foreground.DrawPoint(e2); + map.m_foreground.DrawPoint(tCoord(e1.x, e2.y)); + map.m_foreground.DrawPoint(e1); glEnd(); map.m_background.SetGradientEdges(e1, e2); map.m_background.DrawRect(e1, e2); @@ -150,7 +150,7 @@ for(int i = 0; i < m_edges; ++i) { float t = (i+1)*stepsize; tCoord next(centre.x+ab.x*cos(t), centre.y-ab.y*sin(t)); - map.m_foreground.GetColor(tCoord(0.,0.)).Apply(); + map.m_foreground.DrawAt(tCoord(0.,0.)); glBegin(GL_LINES); //TODO: this should use a function of the rGradient. glVertex2f(next.x, next.y); @@ -382,12 +382,14 @@ void Map::DrawRimWalls( tList<eWallRim> &list ) { if(sr_alphaBlend && m_mode == MODE_STD) { - m_background.GetColor(tCoord(0.,0.)).Apply(); + const eRectangle &bounds = eWallRim::GetBounds(); + m_background.SetGradientEdges(bounds.GetLow(), bounds.GetHigh()); + m_background.BeginDraw(); glBegin(GL_POLYGON); for(std::vector<tCoord>::iterator iter = se_rimWallRubberBand.begin(); iter != se_rimWallRubberBand.end(); ++iter) { - glVertex2f(iter->x, iter->y); + m_background.DrawPoint(*iter); } - glVertex2f(se_rimWallRubberBand.front().x, se_rimWallRubberBand.front().y); + m_background.DrawPoint(se_rimWallRubberBand.front()); glEnd(); } glColor4f(1, 1, 1, .5); Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cRectangle.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cRectangle.cpp 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cRectangle.cpp 2008-02-11 12:58:40 UTC (rev 7857) @@ -64,6 +64,7 @@ m_foreground.SetValue(where); m_background.SetValue(where); + m_background.BeginDraw(); m_background.DrawRect(edge1, edge2); } Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.cpp =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.cpp 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.cpp 2008-02-11 12:58:40 UTC (rev 7857) @@ -28,6 +28,7 @@ #include "cockpit/cWidgetBase.h" #include "cockpit/cCockpit.h" #include "tValueParser.h" +#include "tResourceManager.h" #ifndef DEDICATED @@ -397,6 +398,12 @@ tERR_WARN("Gradient orientation '" + cur.GetProp("orientation") + "' unknown!"); } ProcessGradientCore(cur, ret); + } else if(name == "Image") { + tCoord scale; + cur.GetProp("scale_x", scale.x); + cur.GetProp("scale_y", scale.y); + ret.SetTextureScale(scale); + ProcessImage(cur, ret); } } return ret; @@ -416,6 +423,23 @@ } } +void WithColorFunctions::ProcessImage(tXmlParser::node cur, rGradient &gradient) { + for(cur = cur.GetFirstChild(); cur; ++cur) { + if(cur.IsOfType("Graphic")) { + tResourcePath path( + cur.GetProp("author"), + cur.GetProp("category"), + cur.GetProp("name"), + cur.GetProp("version"), + tString("aatex"), + cur.GetProp("extension"), + cur.GetProp("uri") + ); + gradient.SetTexture(rResourceTexture::GetTexture(path)); + } + } +} + bool WithForeground::Process(tXmlParser::node cur) { if(cur.IsOfType("Foreground")) { m_foreground = ProcessGradient(cur); Modified: armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.h =================================================================== --- armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.h 2008-02-11 11:34:46 UTC (rev 7856) +++ armagetronad/trunk/armagetronad/src/tron/cockpit/cWidgetBase.h 2008-02-11 12:58:40 UTC (rev 7857) @@ -36,6 +36,7 @@ #include "tXmlParser.h" #define DONTDOIT #include "rGradient.h" +#include "rTexture.h" #include <memory> #include "tSafePTR.h" @@ -156,6 +157,7 @@ protected: rGradient ProcessGradient(tXmlParser::node cur); //!< Processes the inside of a nodes like Foreground or Background void ProcessGradientCore(tXmlParser::node cur, rGradient &gradient); //!< Processes the inside of a Solid or Gradient nodes + void ProcessImage(tXmlParser::node cur, rGradient &gradient); //!< Processes the inside of an Image node public: bool Process(tXmlParser::node cur); //!< just passes on to Base::Process() }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |