gui::sprite Class Reference

Use to draw a texture on the screen. More...

#include <gui_sprite.hpp>

List of all members.

Public Member Functions

 sprite (const manager *pManager, utils::refptr< material > pMat)
 Constructor.
 sprite (const manager *pManager, utils::refptr< material > pMat, float fWidth, float fHeight)
 Constructor.
 sprite (const manager *pManager, utils::refptr< material > pMat, float fU, float fV, float fWidth, float fHeight)
 Constructor.
virtual ~sprite ()
 Destructor.
virtual void render (float fX, float fY) const
 Renders this sprite on the current render target.
virtual void render_ex (float fX, float fY, float fRot, float fHScale=1.0f, float fVScale=1.0f) const
 Deforms this sprite and render it on the current render target.
virtual void render_2v (float fX1, float fY1, float fX3, float fY3)
 Stretches this this sprite and render it on the current render target.
virtual void render_4v (float fX1, float fY1, float fX2, float fY2, float fX3, float fY3, float fX4, float fY4)
 Stretches this this sprite and render it on the current render target.
virtual void render_static () const
 Renders this sprite with the same parameter than the last render call.
virtual void render_quads (const std::vector< std::array< vertex, 4 >> &lQuadsArray) const
 Renders a set of quads using this sprite's material.
virtual void set_quad (const std::array< vertex, 4 > &lVertexArray)
 Sets this sprite's internal quad.
virtual void set_color (const color &mColor, uint uiIndex=(uint)(-1))
 Changes the color of this sprite.
virtual void set_desaturated (bool bDesaturated)
 Makes this sprite colorless.
virtual void set_blend_mode (blend_mode mBlendMode)
 Sets the blending mode of this sprite.
virtual void set_hot_spot (const vector2f &mHotSpot)
 Changes this sprite's center.
virtual void set_hot_spot (float fX, float fY)
 Changes this sprite's center.
virtual void set_texture_rect (const std::array< float, 4 > &lTextureRect, bool bNormalized=false)
 Changes this sprite's texture rectangle.
virtual void set_texture_rect (float fX1, float fY1, float fX3, float fY3, bool bNormalized=false)
 Changes this sprite's texture rectangle.
virtual void set_texture_coords (const std::array< float, 8 > &lTextureCoords, bool bNormalized=false)
 Changes this sprite's texture coordinates.
virtual void set_texture_coords (float fX1, float fY1, float fX2, float fY2, float fX3, float fY3, float fX4, float fY4, bool bNormalized=false)
 Changes this sprite's texture coordinates.
virtual void set_dimensions (float fWidth, float fHeight)
 Changes this sprite's dimensions.
virtual float get_width () const
 Returns this sprite's width.
virtual float get_height () const
 Returns this sprite's height.
virtual color get_color () const
 Returns this sprite's color.
virtual blend_mode get_blend_mode () const
 Returns this sprite's blend mode.
virtual std::array< float, 4 > get_texture_rect () const
 Returns this sprite's texture rectangle.
virtual std::array< float, 8 > get_texture_coords (bool bNormalized=false) const
 Returns this sprite's texture coordinates.

Detailed Description

Use to draw a texture on the screen.

This class is meant to simplify rendering of 2D elements. Everything can be done with a quad struct, but it's really not simple to use.
Thanks to this class, the only thing you have to do to acheive interesting effects is calling 2 or 3 functions and let the magic do the rest.

Note:
This is a virtual class, that *can* be inherited from if needed, and created by manager_impl.

Definition at line 63 of file gui_sprite.hpp.


Constructor & Destructor Documentation

gui::sprite::sprite ( const manager pManager,
utils::refptr< material pMat 
)

Constructor.

Definition at line 16 of file gui_sprite.cpp.

gui::sprite::sprite ( const manager pManager,
utils::refptr< material pMat,
float  fWidth,
float  fHeight 
)

Constructor.

Definition at line 37 of file gui_sprite.cpp.

gui::sprite::sprite ( const manager pManager,
utils::refptr< material pMat,
float  fU,
float  fV,
float  fWidth,
float  fHeight 
)

Constructor.

Definition at line 58 of file gui_sprite.cpp.

gui::sprite::~sprite (  )  [virtual]

Destructor.

Definition at line 81 of file gui_sprite.cpp.


Member Function Documentation

blend_mode gui::sprite::get_blend_mode (  )  const [virtual]

Returns this sprite's blend mode.

Returns:
This sprite's blend mode

Definition at line 300 of file gui_sprite.cpp.

color gui::sprite::get_color (  )  const [virtual]

Returns this sprite's color.

Returns:
This sprite's color

Definition at line 295 of file gui_sprite.cpp.

float gui::sprite::get_height (  )  const [virtual]

Returns this sprite's height.

Returns:
This sprite's height

Definition at line 290 of file gui_sprite.cpp.

std::array< float, 8 > gui::sprite::get_texture_coords ( bool  bNormalized = false  )  const [virtual]

Returns this sprite's texture coordinates.

Parameters:
bNormalized 'true' to get coordinates converted to texture space
Returns:
This sprite's texture coordinates

Definition at line 310 of file gui_sprite.cpp.

std::array< float, 4 > gui::sprite::get_texture_rect (  )  const [virtual]

Returns this sprite's texture rectangle.

Returns:
This sprite's texture rectangle

Definition at line 305 of file gui_sprite.cpp.

float gui::sprite::get_width (  )  const [virtual]

Returns this sprite's width.

Returns:
This sprite's width

Definition at line 285 of file gui_sprite.cpp.

void gui::sprite::render ( float  fX,
float  fY 
) const [virtual]

Renders this sprite on the current render target.

Parameters:
fX The horizontal position
fY The vertical position
Note:
Must be called between begin() and end().

Definition at line 85 of file gui_sprite.cpp.

void gui::sprite::render_2v ( float  fX1,
float  fY1,
float  fX3,
float  fY3 
) [virtual]

Stretches this this sprite and render it on the current render target.

Parameters:
fX1 The top-left corner horizontal position
fY1 The top-left corner vertical position
fX3 The bottom-right corner horizontal position
fY3 The bottom-right corner vertical position
Note:
This function doesn't store the deformation.
Must be called between begin() and end().

Definition at line 123 of file gui_sprite.cpp.

void gui::sprite::render_4v ( float  fX1,
float  fY1,
float  fX2,
float  fY2,
float  fX3,
float  fY3,
float  fX4,
float  fY4 
) [virtual]

Stretches this this sprite and render it on the current render target.

Parameters:
fX1 The top-left corner horizontal position
fY1 The top-left corner vertical position
fX2 The top-right corner horizontal position
fY2 The top-right corner vertical position
fX3 The bottom-right corner horizontal position
fY3 The bottom-right corner vertical position
fX4 The bottom-left corner horizontal position
fY4 The bottom-left corner vertical position
Note:
This function doesn't store the deformation.
Must be called between begin() and end().

Definition at line 133 of file gui_sprite.cpp.

void gui::sprite::render_ex ( float  fX,
float  fY,
float  fRot,
float  fHScale = 1.0f,
float  fVScale = 1.0f 
) const [virtual]

Deforms this sprite and render it on the current render target.

Parameters:
fX The horizontal position
fY The vertical position
fRot The rotation to apply (angle in radian)
fHScale The horizontal scale to apply
fVScale The vertical scale to apply
Note:
This function doesn't store the deformation.
Must be called between begin() and end().

Definition at line 95 of file gui_sprite.cpp.

void gui::sprite::render_quads ( const std::vector< std::array< vertex, 4 >> &  lQuadsArray  )  const [virtual]

Renders a set of quads using this sprite's material.

Parameters:
lQuadsArray The set of quads you want to render.
Note:
It is always much more efficient to use this method rather than calling render_XXX() repeatedly, as it allows for batch count reduction. The actual improvement depends on implementation.

Definition at line 146 of file gui_sprite.cpp.

void gui::sprite::render_static (  )  const [virtual]

Renders this sprite with the same parameter than the last render call.

Note:
This function is here for performance, when you want to set the internal quad once and for all.

Definition at line 151 of file gui_sprite.cpp.

void gui::sprite::set_blend_mode ( blend_mode  mBlendMode  )  [virtual]

Sets the blending mode of this sprite.

Parameters:
mBlendMode The new blending mode
Note:
See blend_mode.

Definition at line 178 of file gui_sprite.cpp.

void gui::sprite::set_color ( const color mColor,
uint  uiIndex = (uint)(-1) 
) [virtual]

Changes the color of this sprite.

Parameters:
mColor The new color
uiIndex The index of the vertice to change
Note:
If you provide an index, this function will only change a single vertex's color.
Index 0 is for top left, index 1 is for top right, ...

Definition at line 161 of file gui_sprite.cpp.

void gui::sprite::set_desaturated ( bool  bDesaturated  )  [virtual]

Makes this sprite colorless.

Parameters:
bDesaturated 'true' to desaturate the texture/color
Note:
Depending on the implementation, this method may resort to using pixel shaders.

Definition at line 174 of file gui_sprite.cpp.

void gui::sprite::set_dimensions ( float  fWidth,
float  fHeight 
) [virtual]

Changes this sprite's dimensions.

Parameters:
fWidth The new width
fHeight The new height
Note:
If you adjust texture coordinates, you texture won't be deformed. Else, it will be streched to fit the new dimensions.

Definition at line 279 of file gui_sprite.cpp.

void gui::sprite::set_hot_spot ( float  fX,
float  fY 
) [virtual]

Changes this sprite's center.

Parameters:
fX The new center's horizontal position
fY The new center's vertical position
Note:
HotSpot is used to rotate and scale your sprite with render_ex().
It is also considered as the reference point when you call render() (same goes for render_ex()).

Definition at line 188 of file gui_sprite.cpp.

void gui::sprite::set_hot_spot ( const vector2f mHotSpot  )  [virtual]

Changes this sprite's center.

Parameters:
mHotSpot A 2D point containing the new center's position
Note:
HotSpot is used to rotate and scale your sprite with render_ex().
It is also considered as the reference point when you call render() (same goes for render_ex()).

Definition at line 183 of file gui_sprite.cpp.

void gui::sprite::set_quad ( const std::array< vertex, 4 > &  lVertexArray  )  [virtual]

Sets this sprite's internal quad.

Parameters:
lVertexArray 
Note:
This quad will be overwritten by any render_XXX() call. If you want to render it, call render_static().

Definition at line 156 of file gui_sprite.cpp.

void gui::sprite::set_texture_coords ( float  fX1,
float  fY1,
float  fX2,
float  fY2,
float  fX3,
float  fY3,
float  fX4,
float  fY4,
bool  bNormalized = false 
) [virtual]

Changes this sprite's texture coordinates.

Parameters:
fX1 The sprites's top left horizontal position
fY1 The sprites's top left vertical position
fX2 The sprites's top right horizontal position
fY2 The sprites's top right vertical position
fX3 The sprites's bottom right horizontal position
fY3 The sprites's bottom right vertical position
fX4 The sprites's bottom left horizontal position
fY4 The sprites's bottom left vertical position
bNormalized 'true' if the coords are already converted to texture space
Note:
Texture rectangle is the zone of the texture you want to display.
Note that it doesn't need to be adjusted to this sprite's dimensions. The texture will then be stretched to fit the sprite's dimensions.

Definition at line 257 of file gui_sprite.cpp.

void gui::sprite::set_texture_coords ( const std::array< float, 8 > &  lTextureCoords,
bool  bNormalized = false 
) [virtual]

Changes this sprite's texture coordinates.

Parameters:
lTextureCoords The new texture coordinates
bNormalized 'true' if the coords are already converted to texture space
Note:
Texture rectangle is the zone of the texture you want to display.
Note that it doesn't need to be adjusted to this sprite's dimensions. The texture will then be stretched to fit the sprite's dimensions.

Definition at line 236 of file gui_sprite.cpp.

void gui::sprite::set_texture_rect ( float  fX1,
float  fY1,
float  fX3,
float  fY3,
bool  bNormalized = false 
) [virtual]

Changes this sprite's texture rectangle.

Parameters:
fX1 The rect's top left horizontal position
fY1 The rect's top left vertical position
fX3 The rect's bottom right horizontal position
fY3 The rect's bottom right vertical position
bNormalized 'true' if the coords are already clamped to [0, 1]
Note:
Texture rectangle is the zone of the texture you want to display.
Note that it doesn't need to be adjusted to this sprite's dimensions. The texture will then be stretched to fit the sprite's dimensions.

Definition at line 215 of file gui_sprite.cpp.

void gui::sprite::set_texture_rect ( const std::array< float, 4 > &  lTextureRect,
bool  bNormalized = false 
) [virtual]

Changes this sprite's texture rectangle.

Parameters:
lTextureRect The new texture rect
bNormalized 'true' if the coords are already clamped to [0, 1]
Note:
Texture rectangle is the zone of the texture you want to display.
Note that it doesn't need to be adjusted to this sprite's dimensions. The texture will then be stretched to fit the sprite's dimensions.

Definition at line 194 of file gui_sprite.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Tue Jan 1 21:58:12 2013 for gui by  doxygen 1.6.1