VirtualSurface Class Reference
[C++ Wrapper for SDL]

Container for Surface.Other surface (any class derived from Surface) may be attached to VirtualSurface, in a father-child relationship. Rendering is done automatically, using this VirtualSurface as an intermediate SDL_Surface, in a efficient way. More...

#include <VirtualSurface.hh>

Inheritance diagram for VirtualSurface:
Inheritance graph
[legend]

List of all members.

Classes

struct  TraverseCallback

Public Member Functions

 VirtualSurface (const std::string &name, SDL_Surface *surf)
 VirtualSurface (const std::string &name, int width, int height)
void addChild (Surface *child)
 Add a child to this VirtualSurface.
void removeChild (Surface *child)
 Remove a child to this VirtualSurface.
int getChildrenNb () const
 Get the number of children currently contained by this VirtualSurface.
void updateChildZOrder ()
 Private method, you shouldn't need that.
virtual void enable ()
 Enable this widget.
virtual void show ()
 Show this surface on the screen.
virtual void setZoom (double zoom)
virtual void update ()
 Method called each frame, to perfom user custom code.
virtual void render ()
 Private method.
void invalidate (const Rect &zone)
 Set a marker on a rectangle that must be redrawn next time.
void invalidate (const Point &pos, const Point &size)
 Set a marker on a rectangle that must be redrawn next time.
template<class Class >
void traverse (VirtualSurface *root, Class *object, typename TraverseCallback< Class >::Method method)

Protected Types

typedef std::vector< Surface * > SurfaceList
typedef std::vector< RectRectList

Protected Member Functions

void unlockChildrenList ()
 Unlock the list of children, remove obsolete children, add new ones, and update children Z-order if necessary.

Protected Attributes

SurfaceList children_list_
RectList invalidated_surf_
bool children_list_lock_
 Whether the list of children is locked or not.
bool sort_children_
 Whether children have to be sorted or not.
SurfaceList children_to_add_
 Children to be added after updating current ones.
std::string name_

Detailed Description

Container for Surface.

Other surface (any class derived from Surface) may be attached to VirtualSurface, in a father-child relationship. Rendering is done automatically, using this VirtualSurface as an intermediate SDL_Surface, in a efficient way.


Member Function Documentation

void VirtualSurface::addChild ( Surface child  ) 

Add a child to this VirtualSurface.

Parameters:
child Child to add.
Note:
You can add the same child multiple times, so take care.

References children_list_lock_, children_to_add_, and updateChildZOrder().

Referenced by sdlvisu::Map::addPlayer(), sdlvisu::CmdButton::CmdButton(), and sdlvisu::Map::drawPath().

void VirtualSurface::enable (  )  [virtual]

Enable this widget.

Note:
This is the default.

Reimplemented from Surface.

Reimplemented in sdlvisu::DialogBox.

References Surface::getSize(), invalidate(), and Surface::isEnabled().

int VirtualSurface::getChildrenNb (  )  const

Get the number of children currently contained by this VirtualSurface.

Returns:
The current number of children this VS contains.

References children_to_add_.

void VirtualSurface::invalidate ( const Point pos,
const Point size 
)

Set a marker on a rectangle that must be redrawn next time.

To call when a visual change has occured in this rectangle (like adding, moving, resizing or removing a sprite).

Parameters:
pos A top-left point relative to this VirtualSurface position.
size The size of the invalidated rectangle.

References invalidate(), TPoint< T >::x, and TPoint< T >::y.

void VirtualSurface::invalidate ( const Rect zone  ) 

Set a marker on a rectangle that must be redrawn next time.

To call when a visual change has occured in this rectangle (like adding, moving, resizing or removing a sprite).

Parameters:
zone A rectangle relative to this VirtualSurface position.

Referenced by SDLWindow::clearScreen(), Surface::create(), Surface::disable(), enable(), invalidate(), Surface::load(), Sprite::move(), removeChild(), show(), Sprite::stopMove(), update(), VirtualScrollableSurface::update(), Surface::update(), and Sprite::update().

void VirtualSurface::removeChild ( Surface child  ) 

Remove a child to this VirtualSurface.

Parameters:
child Child to remove.

References children_list_lock_, children_to_add_, Surface::getRect(), and invalidate().

Referenced by Surface::free().

void VirtualSurface::render (  )  [virtual]

Private method.

Called after update round, to effectively render images. Don't override it, should only be used by VirtualSurface.

Reimplemented from Surface.

References for_all(), Surface::isEnabled(), and Surface::render().

Referenced by SDLWindow::processOneFrame().

void VirtualSurface::show (  )  [virtual]

Show this surface on the screen.

Note:
This is the default.

Reimplemented from Surface.

Reimplemented in sdlvisu::ActionPopup.

References Surface::getSize(), invalidate(), and Surface::isEnabled().

void VirtualSurface::unlockChildrenList (  )  [protected]

Unlock the list of children, remove obsolete children, add new ones, and update children Z-order if necessary.

References children_list_lock_, children_to_add_, sort_children_, and updateChildZOrder().

Referenced by update(), and VirtualScrollableSurface::update().

void VirtualSurface::update (  )  [virtual]

Method called each frame, to perfom user custom code.

You should override it.

Since a parent is assigned to the surface (and this parent is itself attached by other means to the root screen), this method is called at each frame. It is not called if this surface or one of its parent is disabled. In this method you can do what you want with your object, like processing input, updating other programs attributes, changing surface property, ...

Note:
Don't forget to call update for the base class at the end of your function , otherwise strange things will happen.

Reimplemented from Surface.

Reimplemented in VirtualScrollableSurface, sdlvisu::ActionPopup, sdlvisu::DialogBox, sdlvisu::InfoBar, sdlvisu::Map, and sdlvisu::Panel.

References children_list_lock_, Surface::getPos(), invalidate(), Surface::isEnabled(), and unlockChildrenList().

Referenced by SDLWindow::processOneFrame().

void VirtualSurface::updateChildZOrder (  ) 

Private method, you shouldn't need that.

Update child Z-order in children vector, when a child change its Z attribute.

References children_list_lock_, and sort_children_.

Referenced by addChild(), and unlockChildrenList().


The documentation for this class was generated from the following files:
Generated on Mon Apr 5 21:17:53 2010 for Stechec/TBT by  doxygen 1.6.3