Surface Class Reference
[C++ Wrapper for SDL]

Basic encapsulation of SDL_Surface structure.This is the base class to display something (in rectangular shape) on the screen. More...

#include <Surface.hh>

Inheritance diagram for Surface:
Inheritance graph
[legend]

List of all members.

Classes

struct  ImgSort
struct  ZSort

Public Member Functions

 Surface (SDL_Surface *surf, double zoom=1., double angle=0., const std::string &filename="")
 Surface (const std::string filename, double zoom=1., double angle=0.)
 Surface (int width, int height)
 Surface (const Surface &s)
Surfaceoperator= (const Surface &s)
Point getPos () const
 Get the relative position of the surface.
Point getSize () const
 Get the size of the surface (width-height).
const RectgetRect () const
 Get the relative surface position.
virtual Rect getScreenRect () const
 Get the absolute surface from the point (0, 0) on the screen.
double getZoom () const
double getAngle () const
int getZ () const
SDL_Surface * getSDLSurface ()
virtual void setPos (const Point &pos)
void setPos (int x, int y)
void setSize (const Point &size)
virtual void setZoom (double zoom)
virtual void setAngle (double angle)
virtual void setZ (int z)
void setInheritAlpha (bool enabled)
virtual void enable ()
 Enable this widget.
virtual void disable ()
 Disable this widget.
bool isEnabled () const
 Whether it is enabled or not.
virtual void show ()
 Show this surface on the screen.
virtual void hide ()
 Don't display this surface on the screen.
bool isShown () const
void create (int width, int height, SDL_Surface *ref_surface=NULL)
 Create an empty SDL Surface of the given size.
void load (const std::string filename, double zoom=1., double angle=0.)
 Load a image into this surface (.png, .jpg, .bmp, ...).
void free ()
 Release associated resources, and detach from parent.
virtual void update ()
 Method called each frame, to perfom user custom code.
virtual void blit (Surface &to)
virtual void blit (Surface &to, const Rect &to_rect, const Rect &from_rect)

Protected Member Functions

virtual void render ()
 Private method.
virtual Rect getRenderRect () const
 Get the relative zone to render on the screen.
void blitAlpha (SDL_Surface *src_surf, SDL_Surface *dst_surf, SDL_Rect *src_rect, unsigned dst_x, unsigned dst_y)
 Copy the alpha data to dst_surf.

Protected Attributes

SDL_Surface * surf_
bool redraw_all_
VirtualSurfaceparent_

Friends

class VirtualSurface
class ResourceCenter
std::ostream & operator<< (std::ostream &os, const Surface &s)

Detailed Description

Basic encapsulation of SDL_Surface structure.

This is the base class to display something (in rectangular shape) on the screen.

A simple example (assuming you already have a SDLWindow):

  Surface surf("img/lala.png");
  surf.setPos(40, 30);
  win.getScreen.addChild(&surf);

Member Function Documentation

void Surface::blitAlpha ( SDL_Surface *  src_surf,
SDL_Surface *  dst_surf,
SDL_Rect *  src_rect,
unsigned  dst_x,
unsigned  dst_y 
) [protected]

Copy the alpha data to dst_surf.

Note:
Warning, this may slow down things ! work in progress...
void Surface::create ( int  width,
int  height,
SDL_Surface *  ref_surface = NULL 
)

Create an empty SDL Surface of the given size.

Used to do manual rendering with SDL functions and, at the same time, have it in the surface hierarchy.

References VirtualSurface::invalidate().

void Surface::disable (  )  [virtual]

Disable this widget.

Note:
Function update() and render() will not be called for this widget.

Reimplemented in sdlvisu::DialogBox, and sdlvisu::VisuPlayer.

References VirtualSurface::invalidate().

Referenced by sdlvisu::Map::clearBlock(), sdlvisu::Map::clearThrow(), sdlvisu::VisuPlayer::disable(), and sdlvisu::ActionPopup::update().

void Surface::enable (  )  [virtual]
const Rect & Surface::getRect (  )  const
Rect Surface::getRenderRect (  )  const [protected, virtual]

Get the relative zone to render on the screen.

getRect() can be larger than we really want to show, or off-screen. By default, return getRect(), but can be overriden.

Note:
Only used for rendering.
Returns:
Relative Rect to render.

Reimplemented in VirtualScrollableSurface.

Rect Surface::getScreenRect (  )  const [virtual]

Get the absolute surface from the point (0, 0) on the screen.

This is where the surface is render and visible by the user on the screen. This should only be used for events, ie. to compare mouse position (which has absolute position) with this surface position.

Returns:
Absolute surface Rect.

Reimplemented in VirtualScrollableSurface.

References getScreenRect().

Referenced by VirtualScrollableSurface::getScreenRect(), getScreenRect(), sdlvisu::VisuPlayer::update(), sdlvisu::InfoBar::update(), sdlvisu::GameButton::update(), sdlvisu::ActionPopup::update(), and sdlvisu::CmdButton::updateStatus().

void Surface::hide (  )  [virtual]
virtual void Surface::render (  )  [inline, protected, virtual]

Private method.

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

Reimplemented in VirtualSurface.

Referenced by VirtualSurface::render().

void Surface::show (  )  [virtual]
void Surface::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 in InputTextSurface, Sprite, TextSurface, VirtualScrollableSurface, VirtualSurface, sdlvisu::ActionPopup, sdlvisu::DialogBox, sdlvisu::GameButton, sdlvisu::InfoBar, sdlvisu::Map, sdlvisu::Panel, and sdlvisu::VisuPlayer.

References VirtualSurface::invalidate().


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