surface Class Reference

Class where drawables can actually be drawn to. More...

#include <surface.h>

Inheritance diagram for surface:
Inheritance graph
[legend]
Collaboration diagram for surface:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 surface (bool mode=true)
 Default constructor.
virtual ~surface ()
 Destructor.
surfaceoperator= (surface &src)
 Surface copy (similar to copy ()).
void copy (surface &src)
 Synonym of operator = to guarantee its access from Python.
Settings.

These methods sets the parameters of the surface.



bool is_masked () const
 Returns whether a surface is masked or not.
void set_mask (bool m)
 Sets the mask parameter of the surface.
u_int8 alpha () const
 Returns the alpha value of the surface.
void set_alpha (u_int8 a)
 Sets the alpha value of the surface.
bool is_dbl_mode () const
void set_dbl_mode (bool mode)
Drawing Methods.



void draw (s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Draw the surface.
void draw (s_int16 x, s_int16 y, s_int16 sx, s_int16 sy, u_int16 sl, u_int16 sh, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Draw a part of the surface.
void draw_part (s_int16 x, s_int16 y, s_int16 sx, s_int16 sy, u_int16 sl, u_int16 sh, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Synonym of draw () to guarantee its access from Python.
void fillrect (s_int16 x, s_int16 y, u_int16 l, u_int16 h, u_int32 col, drawing_area *da_opt=NULL)
 Fills an area of the surface with a given color.
void fillrect (s_int16 x, s_int16 y, u_int16 l, u_int16 h, u_int8 r, u_int8 g, u_int8 b, drawing_area *da_opt=NULL)
 Fills an area of the surface with a given color.
void fillrect_rgb (s_int16 x, s_int16 y, u_int16 l, u_int16 h, u_int8 r, u_int8 g, u_int8 b, drawing_area *da_opt=NULL)
 Synonym of fillrect () to guarantee its access from Python.
Pixel manipulation Methods.

Use these methods to directly and quickly manipulate pixels from a surface.



void lock () const
 Locks the surface.
void unlock () const
 Unlock the surface after you've worked on it's pixels with the get_pix () and put_pix () methods.
void put_pix (u_int16 x, u_int16 y, u_int32 col)
 Puts a pixel of a given color.
void put_pix (u_int16 x, u_int16 y, u_int8 r, u_int8 g, u_int8 b)
 Puts a pixel of a given color.
void put_pix_rgb (u_int16 x, u_int16 y, u_int8 r, u_int8 g, u_int8 b)
 Synonym of put_pix () to guarantee its access from Python.
void get_pix (u_int16 x, u_int16 y, u_int32 &col) const
 Gets a pixel from the surface.
void get_pix (u_int16 x, u_int16 y, u_int8 &r, u_int8 &g, u_int8 &b) const
 Gets a pixel from a surface.
void get_pix_rgb (u_int16 x, u_int16 y, u_int8 r, u_int8 g, u_int8 b) const
 Synonym of get_pix () to guarantee its access from Python.

Public Attributes

SDL_Surface * vis
 The actual surface.

Protected Member Functions

void resize (u_int16 l, u_int16 h)
 Resize this surface.
void clear ()
 Resets the surface to it's initial state, that is totally empty.
void resize_aux (u_int16 l, u_int16 h)
void double_size (const surface &src)
void half_size (const surface &src)
void get_pix_aux (u_int16 x, u_int16 y, u_int32 &col) const
void put_pix_aux (u_int16 x, u_int16 y, u_int32 col)

Protected Attributes

bool changed
 Must be set to true when you change the surface by something else than class surface operations.
bool dbl_mode
 double mode

Friends

class screen

Detailed Description

Class where drawables can actually be drawn to.

Another name for a surface could eventually be "pixmap". A surface is nothing more than an array of pixels where drawables can put their image to. This class has only two purposes: to group methods shared by image and screen, and to ensure that every drawing operation can be performed on the screen or on an image.

Every surface has two special parameters:

Definition at line 51 of file surface.h.


Constructor & Destructor Documentation

surface::surface ( bool  mode = true  ) 

Default constructor.

The surface will be totally empty, that is (0, 0) sized, no mask, alpha value of 255 (opaque).

Definition at line 183 of file surface.cc.

surface::~surface (  )  [virtual]

Destructor.

Definition at line 193 of file surface.cc.


Member Function Documentation

bool surface::is_masked (  )  const [inline]

Returns whether a surface is masked or not.

Returns:
true if the surface is masked, false if it isn't.

Definition at line 84 of file surface.h.

void surface::set_mask ( bool  m  ) 

Sets the mask parameter of the surface.

Parameters:
m true if the surface should be masked, false otherwise.

Definition at line 198 of file surface.cc.

u_int8 surface::alpha (  )  const [inline]

Returns the alpha value of the surface.

Returns:
the alpha value of the surface.

Definition at line 102 of file surface.h.

void surface::set_alpha ( u_int8  a  ) 

Sets the alpha value of the surface.

Parameters:
a The new alpha value for this surface.

Definition at line 208 of file surface.cc.

void surface::draw ( s_int16  x,
s_int16  y,
const drawing_area da_opt = NULL,
surface target = NULL 
) const [inline]

Draw the surface.

Parameters:
x X position where to draw.
y Y position where to draw.
da_opt optional drawing_area to use during the drawing operation.
target pointer to the surface where to draw the drawable. If NULL, draw on the screen.

Definition at line 138 of file surface.h.

void surface::draw ( s_int16  x,
s_int16  y,
s_int16  sx,
s_int16  sy,
u_int16  sl,
u_int16  sh,
const drawing_area da_opt = NULL,
surface target = NULL 
) const

Draw a part of the surface.

Parameters:
x X position where to draw.
y Y position where to draw.
sx X position where to start drawing from this image.
sy Y position where to start drawing from this image.
sl length of the part of this image to draw.
sh height of the part of this image to draw.
da_opt optional drawing_area to use during the drawing operation.
target pointer to the surface where to draw the drawable. If NULL, draw on the screen.
Attention:
Not accessible from Python. Use draw_part () from Python instead.
See also:
draw_part ()

Definition at line 215 of file surface.cc.

void surface::draw_part ( s_int16  x,
s_int16  y,
s_int16  sx,
s_int16  sy,
u_int16  sl,
u_int16  sh,
const drawing_area da_opt = NULL,
surface target = NULL 
) const [inline]

Synonym of draw () to guarantee its access from Python.

See also:
draw ()

Definition at line 172 of file surface.h.

void surface::fillrect ( s_int16  x,
s_int16  y,
u_int16  l,
u_int16  h,
u_int32  col,
drawing_area da_opt = NULL 
)

Fills an area of the surface with a given color.

The color you pass to this function MUST come from a game's function (like surface::get_pix () or screen::trans_col ()), because of the screen depth dependant value of the col argument.

Parameters:
x X position where to fill.
y Y position where to fill.
l length of the area to fill.
h height of the area to fill.
col color to fill the surface with.
da_opt optionnal drawing_area to use during the fill operation.

Definition at line 260 of file surface.cc.

void surface::fillrect ( s_int16  x,
s_int16  y,
u_int16  l,
u_int16  h,
u_int8  r,
u_int8  g,
u_int8  b,
drawing_area da_opt = NULL 
) [inline]

Fills an area of the surface with a given color.

This function is independant of the screen depth. You just give the red, green and blue triplets of the color you want to fill with.

Parameters:
x X position where to fill.
y Y position where to fill.
l length of the area to fill.
h height of the area to fill.
r red value of the color to fill with.
g green value of the color to fill with.
b blue value of the color to fill with.
da_opt optionnal drawing_area to use during the fill operation.
Attention:
Not accessible from Python. Use fillrect_rgb from Python instead.
See also:
fillrect_rgb ()

Definition at line 216 of file surface.h.

void surface::fillrect_rgb ( s_int16  x,
s_int16  y,
u_int16  l,
u_int16  h,
u_int8  r,
u_int8  g,
u_int8  b,
drawing_area da_opt = NULL 
) [inline]

Synonym of fillrect () to guarantee its access from Python.

See also:
fillrect ()

Definition at line 228 of file surface.h.

void surface::lock (  )  const

Locks the surface.

Sometimes you may want to access directly the pixels of a surface. This can be done with the get_pix () and put_pix () methods, thus you must ABSOLUTELY lock the surface before doing so. This function is made for that. Note that using get_pix () or put_pix () without locking the surface may result in unpredictable behavior, crashes included.

Definition at line 287 of file surface.cc.

void surface::unlock (  )  const

Unlock the surface after you've worked on it's pixels with the get_pix () and put_pix () methods.

Definition at line 294 of file surface.cc.

void surface::put_pix ( u_int16  x,
u_int16  y,
u_int32  col 
)

Puts a pixel of a given color.

The col parameter is specific to the current screen depth, and must come from a game's function like get_pix or screen::trans_col ().

Parameters:
x X position of the pixel to change.
y Y position of the pixel to change.
col color to put.

Definition at line 301 of file surface.cc.

void surface::put_pix ( u_int16  x,
u_int16  y,
u_int8  r,
u_int8  g,
u_int8  b 
) [inline]

Puts a pixel of a given color.

The r, g and b parameters are the hex triplets of the color to put.

Parameters:
x X position of the pixel to change.
y Y position of the pixel to change.
r red value of the color to put.
g green value of the color to put.
b blue value of the color to put.
Attention:
Not accessible from Python. Use put_pix_rgb from Python instead.
See also:
put_pix_rgb ()

Definition at line 294 of file surface.h.

void surface::put_pix_rgb ( u_int16  x,
u_int16  y,
u_int8  r,
u_int8  g,
u_int8  b 
) [inline]

Synonym of put_pix () to guarantee its access from Python.

See also:
put_pix ()

Definition at line 305 of file surface.h.

void surface::get_pix ( u_int16  x,
u_int16  y,
u_int32 &  col 
) const

Gets a pixel from the surface.

The col parameter is specific to the current screen depth, and can be used with functions like put_pix ().

Parameters:
x X position of the pixel to change.
y Y position of the pixel to change.
col returned color.

Definition at line 360 of file surface.cc.

void surface::get_pix ( u_int16  x,
u_int16  y,
u_int8 &  r,
u_int8 &  g,
u_int8 &  b 
) const [inline]

Gets a pixel from a surface.

The returned r, g and b values are the hex triplets of the color.

Parameters:
x X position of the pixel to change.
y Y position of the pixel to change.
r red value of the color.
g green value of the color.
b blue value of the color.
Attention:
Not accessible from Python. Use get_pix_rgb from Python instead.
See also:
get_pix_rgb ()

Definition at line 337 of file surface.h.

void surface::get_pix_rgb ( u_int16  x,
u_int16  y,
u_int8  r,
u_int8  g,
u_int8  b 
) const [inline]

Synonym of get_pix () to guarantee its access from Python.

See also:
get_pix ()

Definition at line 350 of file surface.h.

surface & surface::operator= ( surface src  ) 

Surface copy (similar to copy ()).

Attention:
Not available from Python. Use copy () from Python instead.
See also:
copy ()

Definition at line 400 of file surface.cc.

void surface::copy ( surface src  )  [inline]

Synonym of operator = to guarantee its access from Python.

See also:
operator =

Definition at line 373 of file surface.h.

void surface::resize ( u_int16  l,
u_int16  h 
) [protected]

Resize this surface.

All the content will be lost.

Parameters:
l new length.
h new height.

Reimplemented in image, and label.

Definition at line 422 of file surface.cc.

void surface::clear (  )  [protected]

Resets the surface to it's initial state, that is totally empty.

Reimplemented in image.

Definition at line 447 of file surface.cc.


Member Data Documentation

SDL_Surface* surface::vis

The actual surface.

Definition at line 382 of file surface.h.

bool surface::changed [mutable, protected]

Must be set to true when you change the surface by something else than class surface operations.

Definition at line 405 of file surface.h.

bool surface::dbl_mode [protected]

double mode

Definition at line 416 of file surface.h.


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

Generated on 19 Feb 2010 for Adonthell by  doxygen 1.6.1