diff --git a/panda/src/pgui/pgFrameStyle.I b/panda/src/pgui/pgFrameStyle.I index c15fdcb01a..8477e76ea1 100644 --- a/panda/src/pgui/pgFrameStyle.I +++ b/panda/src/pgui/pgFrameStyle.I @@ -38,6 +38,7 @@ INLINE PGFrameStyle:: PGFrameStyle(const PGFrameStyle ©) : _type(copy._type), _color(copy._color), + _texture(copy._texture), _width(copy._width) { } @@ -51,6 +52,7 @@ INLINE void PGFrameStyle:: operator = (const PGFrameStyle ©) { _type = copy._type; _color = copy._color; + _texture = copy._texture; _width = copy._width; } @@ -113,6 +115,49 @@ get_color() const { return _color; } +//////////////////////////////////////////////////////////////////// +// Function: PGFrameStyle::set_texture +// Access: Published +// Description: Specifies a texture that should be applied to the +// frame. +//////////////////////////////////////////////////////////////////// +INLINE void PGFrameStyle:: +set_texture(Texture *texture) { + _texture = texture; +} + +//////////////////////////////////////////////////////////////////// +// Function: PGFrameStyle::has_texture +// Access: Published +// Description: Returns true if a texture has been applied to the +// frame. +//////////////////////////////////////////////////////////////////// +INLINE bool PGFrameStyle:: +has_texture() const { + return !_texture.is_null(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PGFrameStyle::get_texture +// Access: Published +// Description: Returns the texture that has been applied to the +// frame, or NULL if no texture has been applied. +//////////////////////////////////////////////////////////////////// +INLINE Texture *PGFrameStyle:: +get_texture() const { + return _texture; +} + +//////////////////////////////////////////////////////////////////// +// Function: PGFrameStyle::clear_texture +// Access: Published +// Description: Removes the texture from the frame. +//////////////////////////////////////////////////////////////////// +INLINE void PGFrameStyle:: +clear_texture() { + _texture.clear(); +} + //////////////////////////////////////////////////////////////////// // Function: PGFrameStyle::set_width // Access: Published diff --git a/panda/src/pgui/pgFrameStyle.cxx b/panda/src/pgui/pgFrameStyle.cxx index 5c402dfc2b..1913d8be26 100644 --- a/panda/src/pgui/pgFrameStyle.cxx +++ b/panda/src/pgui/pgFrameStyle.cxx @@ -24,6 +24,14 @@ #include "transparencyAttrib.h" #include "pointerTo.h" #include "nodePath.h" +#include "textureAttrib.h" +#include "renderState.h" + +// Specifies the UV range of textures applied to the frame. Maybe +// we'll have a reason to make this a parameter of the frame style one +// day, but for now it's hardcoded to fit the entire texture over the +// rectangular frame. +static const LVecBase4f uv_range = LVecBase4f(0.0f, 1.0f, 0.0f, 1.0f); ostream & operator << (ostream &out, PGFrameStyle::Type type) { @@ -58,6 +66,9 @@ operator << (ostream &out, PGFrameStyle::Type type) { void PGFrameStyle:: output(ostream &out) const { out << _type << " color = " << _color << " width = " << _width; + if (has_texture()) { + out << " texture = " << *get_texture(); + } } //////////////////////////////////////////////////////////////////// @@ -167,7 +178,7 @@ generate_flat_geom(const LVecBase4f &frame) { float bottom = frame[2]; float top = frame[3]; - PTA_int lengths=PTA_int::empty_array(0); + PTA_int lengths; lengths.push_back(4); PTA_Vertexf verts; @@ -184,6 +195,25 @@ generate_flat_geom(const LVecBase4f &frame) { PTA_Colorf colors; colors.push_back(_color); geom->set_colors(colors, G_OVERALL); + + if (has_texture()) { + // Generate UV's. + left = uv_range[0]; + right = uv_range[1]; + bottom = uv_range[2]; + top = uv_range[3]; + + PTA_TexCoordf uvs; + uvs.push_back(TexCoordf(left, top)); + uvs.push_back(TexCoordf(left, bottom)); + uvs.push_back(TexCoordf(right, top)); + uvs.push_back(TexCoordf(right, bottom)); + geom->set_texcoords(uvs, G_PER_VERTEX); + + CPT(RenderState) state = + RenderState::make(TextureAttrib::make(get_texture())); + gnode->set_geom_state(0, state); + } return gnode.p(); } @@ -344,6 +374,9 @@ generate_bevel_geom(const LVecBase4f &frame, bool in) { geom->set_lengths(lengths); geom->set_coords(verts); geom->set_colors(colors, G_PER_COMPONENT); + + // For now, beveled and grooved geoms don't support textures. Easy + // to add if anyone really wants this. return gnode.p(); } @@ -573,6 +606,9 @@ generate_groove_geom(const LVecBase4f &frame, bool in) { geom->set_lengths(lengths); geom->set_coords(verts); geom->set_colors(colors, G_PER_COMPONENT); + + // For now, beveled and grooved geoms don't support textures. Easy + // to add if anyone really wants this. return gnode.p(); } diff --git a/panda/src/pgui/pgFrameStyle.h b/panda/src/pgui/pgFrameStyle.h index f6144afc09..133fb2e46e 100644 --- a/panda/src/pgui/pgFrameStyle.h +++ b/panda/src/pgui/pgFrameStyle.h @@ -22,6 +22,8 @@ #include "pandabase.h" #include "luse.h" +#include "texture.h" +#include "pointerTo.h" class PandaNode; class NodePath; @@ -54,6 +56,11 @@ PUBLISHED: INLINE void set_color(const Colorf &color); INLINE const Colorf &get_color() const; + INLINE void set_texture(Texture *texture); + INLINE bool has_texture() const; + INLINE Texture *get_texture() const; + INLINE void clear_texture(); + INLINE void set_width(float x, float y); INLINE void set_width(const LVecBase2f &width); INLINE const LVecBase2f &get_width() const; @@ -72,6 +79,7 @@ private: private: Type _type; Colorf _color; + PT(Texture) _texture; LVecBase2f _width; };