GG
Protected Attributes

GG::DynamicGraphic Class Reference

A control that replays images in sequence, forwards or backwards, animated or one frame at a time. More...

#include <DynamicGraphic.h>

Inheritance diagram for GG::DynamicGraphic:
GG::Control GG::Wnd

List of all members.

Protected Attributes

const unsigned int m_margin
const X m_frame_width
const Y m_frame_height

Signal Types

typedef boost::signal< void(std::size_t)> StoppedSignalType
typedef boost::signal< void(std::size_t)> EndFrameSignalType

Structors

 DynamicGraphic (X x, Y y, X w, Y h, bool loop, X frame_width, Y frame_height, unsigned int margin, const std::vector< boost::shared_ptr< Texture > > &textures, Flags< GraphicStyle > style=GRAPHIC_NONE, std::size_t frames=ALL_FRAMES, Flags< WndFlag > flags=Flags< WndFlag >())
 DynamicGraphic ()

Accessors

StoppedSignalType StoppedSignal
EndFrameSignalType EndFrameSignal
std::size_t Frames () const
bool Playing () const
bool Looping () const
double FPS () const
std::size_t FrameIndex () const
unsigned int TimeIndex () const
std::size_t StartFrame () const
std::size_t EndFrame () const
unsigned int Margin () const
X FrameWidth () const
Y FrameHeight () const
Flags< GraphicStyle > Style () const
std::size_t FramesInTexture (const Texture *t) const
const std::vector< FrameSet > & Textures () const
std::size_t CurrentTexture () const
std::size_t CurrentSubTexture () const
unsigned int FirstFrameTime () const
unsigned int LastFrameTime () const

Mutators

virtual void Render ()
void AddFrames (const Texture *texture, std::size_t frames=ALL_FRAMES)
void AddFrames (const boost::shared_ptr< Texture > &texture, std::size_t frames=ALL_FRAMES)
void AddFrames (const std::vector< boost::shared_ptr< Texture > > &textures, std::size_t frames=ALL_FRAMES)
void Play ()
void Pause ()
void NextFrame ()
void PrevFrame ()
void Stop ()
void Loop (bool b=true)
void SetFPS (double fps)
void SetFrameIndex (std::size_t idx)
void SetTimeIndex (unsigned int time)
void SetStartFrame (std::size_t idx)
void SetEndFrame (std::size_t idx)
void SetStyle (Flags< GraphicStyle > style)
virtual void DefineAttributes (WndEditor *editor)

Exceptions

 GG_ABSTRACT_EXCEPTION (Exception)
 GG_CONCRETE_EXCEPTION (CannotAddFrame, GG::DynamicGraphic, Exception)

Detailed Description

A control that replays images in sequence, forwards or backwards, animated or one frame at a time.

Frames of animation are stored in GG::Textures. The frames are assumed to be laid out in rows from right to left, top to bottom, like text. The location of each frame is calculated by DynamicGraphic; the user just needs to lay out the frames in the right order in the Texture(s) and give them to DynamicGraphic. If a Texture is to be used that has "dead space" where there are no frames, that space must be at the end of the Texture, and the number of frames in the Texture should be supplied when the Texture is added. When laying out the frames in the textures, the user can leave a margin between the frames and between the frames and the edge of the overall image, to make Texture creation and editing easier. The width of this margin must be supplied to DynamicGraphic's ctor, and is constant once set. The margin applies to the top and left of each image, so the margins at the right and bottom edges of the texture are optional. The multiple-Texture ctor assumes that all Textures but the last are packed with frames; if you need to specify multiple Textures with dead space, construct with an empty textures parameter and use AddFrames(). Note that DynamicGraphic doesn't have "animated" in its name; it can replay images at any speed, and moreover it can be used as a sort of slideshow, and doesn't necessarily need to be animated at all.

Note:
This is a situation in which the "last+1" idiom used throughout GG does not apply; when you set the end frame index to N, the last frame to be shown will be N, not N - 1. Also, while this control does not need to be the same size as the frames replayed within it, the size of the frames is taken from the size of the control when it is contructed.

Definition at line 68 of file DynamicGraphic.h.


Member Typedef Documentation

typedef boost::signal<void (std::size_t)> GG::DynamicGraphic::StoppedSignalType

Emitted whenever playback ends because the last frame was reached and Looping() == false; the argument is the index of the last frame (may be the first frame, if playing in reverse).

Note:
Unlike most other signals, this one is emitted during the execution of Render(), so keep this in mind when processing this signal.

Definition at line 77 of file DynamicGraphic.h.

typedef boost::signal<void (std::size_t)> GG::DynamicGraphic::EndFrameSignalType

Emitted whenever the last frame of animation is reached; the argument is the index of the last frame (may be the first frame, if playing in reverse).

Note:
Unlike most other signals, this one is emitted during the execution of Render(), so keep this in mind when processing this signal.

Definition at line 84 of file DynamicGraphic.h.


Constructor & Destructor Documentation

GG::DynamicGraphic::DynamicGraphic ( X  x,
Y  y,
X  w,
Y  h,
bool  loop,
X  frame_width,
Y  frame_height,
unsigned int  margin,
const std::vector< boost::shared_ptr< Texture > > &  textures,
Flags< GraphicStyle >  style = GRAPHIC_NONE,
std::size_t  frames = ALL_FRAMES,
Flags< WndFlag >  flags = Flags< WndFlag >() 
)

Ctor taking a vector of GG::Textures and the number of frames in those Textures. The default frames value ALL_FRAMES indicates all possible area is considered to contain valid frames. Regardless of the value of frames, all Textures but the last are assumed to have the maximum number of frames based on their sizes. This ctor allows specification of a frame size different from the size of the DynamicGraphic's size.


Member Function Documentation

std::size_t GG::DynamicGraphic::StartFrame ( ) const

Returns the index of the earliest frame to be shown during playback.

Note:
when playing backwards this will be the last frame shown.
std::size_t GG::DynamicGraphic::EndFrame ( ) const

Returns the index of the latest frame to be shown during playback.

Note:
when playing backwards this will be the first frame shown.
Flags<GraphicStyle> GG::DynamicGraphic::Style ( ) const

Returns the style of the DynamicGraphic

See also:
GraphicStyle
virtual void GG::DynamicGraphic::Render ( ) [virtual]

Draws this Wnd. Note that Wnds being dragged for a drag-and-drop operation are rendered twice -- once in-place as normal, once in the location of the drag operation, attached to the cursor. Such Wnds may wish to render themselves differently in those two cases. To determine which render is being performed, they can call GUI::GetGUI()->RenderingDragDropWnds().

Implements GG::Control.

void GG::DynamicGraphic::AddFrames ( const Texture texture,
std::size_t  frames = ALL_FRAMES 
)

Adds a set of frames from Texture texture to the animation. If frames == ALL_FRAMES, the Texture is assumed to contain the maximum possible number of frames based on its size and the frame size.

Warning:
Calling code must not delete texture; texture becomes the property of a shared_ptr inside the DynamicGraphic.
Exceptions:
GG::DynamicGraphic::CannotAddFrameThrows if texture is not large enough to contain any frames.
void GG::DynamicGraphic::AddFrames ( const boost::shared_ptr< Texture > &  texture,
std::size_t  frames = ALL_FRAMES 
)

Adds a set of frames from Texture texture to the animation. If frames == ALL_FRAMES, the Texture is assumed to contain the maximum possible number of frames based on its size and the frame size.

Exceptions:
GG::DynamicGraphic::CannotAddFrameThrows if texture is not large enough to contain any frames.
void GG::DynamicGraphic::AddFrames ( const std::vector< boost::shared_ptr< Texture > > &  textures,
std::size_t  frames = ALL_FRAMES 
)

Adds a set of frames from Texture texture to the animation. If frames == ALL_FRAMES, the Textures are assumed to contain the maximum possible number of frames based on its size and the frame size. Regardless of the value of frames, all Textures but the last are assumed to have the maximum number of frames based on their sizes.

Exceptions:
GG::DynamicGraphic::CannotAddFrameThrows if no texture in textures is large enough to contain any frames.
void GG::DynamicGraphic::SetFPS ( double  fps)

Sets the frames per second playback speed (default is 15.0 FPS). Negative rates indicate reverse playback.

Note:
Calling SetFPS(0.0) is equivalent to calling Pause().
void GG::DynamicGraphic::SetTimeIndex ( unsigned int  time)

Sets the frame index to the frame nearest time index idx, where idx measures time in ms from the beginning of the animation ( value is locked to range [0, Frames() * FPS()) ).

Note:
If looping is enabled, the time index may be any value >= 0.0, and values will "wrap" around the length of a loop. If looping is disabled, any time index idx that is later than Frames() * FPS() is mapped to the last frame.
void GG::DynamicGraphic::SetStartFrame ( std::size_t  idx)

Sets the index of the first frame to be shown during playback ( value is locked to range [0, Frames()] ).

Note:
when playing backwards this will be the last frame shown.
void GG::DynamicGraphic::SetEndFrame ( std::size_t  idx)

Sets the index of the last frame to be shown during playback ( value is locked to range [0, Frames()] ).

Note:
when playing backwards this will be the first frame shown.
void GG::DynamicGraphic::SetStyle ( Flags< GraphicStyle >  style)

Sets the style flags, and perfroms sanity checking

See also:
GraphicStyle
virtual void GG::DynamicGraphic::DefineAttributes ( WndEditor *  editor) [virtual]

Provides the attributes of this object that are appropriate for a user to edit in a WndEditor; see WndEditor for details.

Reimplemented from GG::Control.

GG::DynamicGraphic::GG_ABSTRACT_EXCEPTION ( Exception  )

The base class for DynamicGraphic exceptions.

Reimplemented from GG::Wnd.

GG::DynamicGraphic::GG_CONCRETE_EXCEPTION ( CannotAddFrame  ,
GG::DynamicGraphic  ,
Exception   
)

Thrown when an attempt is made to add a frame to a DynamicGraphic from a texture smaller than a single frame.


The documentation for this class was generated from the following file: