Adonthell  0.4
surface Class Reference

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

#include <surface.h>

Inheritance diagram for surface:
Collaboration diagram for surface:

Public Member Functions

 surface (const u_int8 &scale=1)
 Default constructor. More...
 
virtual ~surface ()
 Destructor. More...
 
surfaceoperator= (const surface &src)
 Surface copy (similar to copy ()). More...
 
void copy (const surface &src)
 Synonym of operator = to guarantee its access from Python. More...
 
Settings.

These methods sets the parameters of the surface.

bool is_masked () const
 Returns whether a surface is masked or not. More...
 
void set_mask (bool m)
 Sets the mask parameter of the surface. More...
 
u_int8 alpha () const
 Returns the alpha value of the surface. More...
 
void set_alpha (u_int8 a, const bool &alpha_channel=false)
 Sets the alpha value of the surface. More...
 
bool has_alpha_channel () const
 Returns whether the surface has an alpha channel. More...
 
u_int8 scale () const
 Get the surfaces current scaling factor. More...
 
void set_scale (const u_int8 &scale)
 Change the scale of the surface to the given value, resizing the internal texture appropriately. More...
 
Drawing Methods.
void draw (s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Draw the surface. More...
 
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. More...
 
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. More...
 
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. More...
 
Pixel manipulation Methods.

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

u_int32 map_color (const u_int8 &r, const u_int8 &g, const u_int8 &b, const u_int8 &a=255) const
 
void unmap_color (u_int32 col, u_int8 &r, u_int8 &g, u_int8 &b, u_int8 &a) const
 
void lock () const
 Locks the surface. More...
 
void unlock () const
 Unlock the surface after you've worked on it's pixels with the get_pix () and put_pix () methods. More...
 
void put_pix (u_int16 x, u_int16 y, u_int32 col)
 Puts a pixel of a given color. More...
 
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. More...
 
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. More...
 
u_int32 get_pix (u_int16 x, u_int16 y) const
 Gets a pixel from the surface. More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from drawable
 drawable ()
 Default constructor. More...
 
virtual ~drawable ()
 Destructor. More...
 
u_int16 length () const
 Returns the length of the drawable. More...
 
u_int16 height () const
 Returns the height of the drawable. More...
 
virtual bool update ()
 Virtual update function, provided for objects which doesn't need one. More...
 
virtual bool input_update ()
 Virtual input update function, provided for objects which doesn't need one. More...
 

Protected Member Functions

void resize (u_int16 l, u_int16 h)
 Resize this surface. More...
 
void clear ()
 Resets the surface to it's initial state, that is totally empty. More...
 
void set_data (void *data, u_int16 l, u_int16 h, u_int8 bytes_per_pixel=BYTES_PER_PIXEL, u_int32 red_mask=R_MASK, u_int32 green_mask=G_MASK, u_int32 blue_mask=B_MASK, u_int32 alpha_mask=0)
 
void * get_data (u_int8 bytes_per_pixel, u_int32 red_mask, u_int32 green_mask, u_int32 blue_mask, u_int32 alpha_mask) const
 
SDL_Surface * to_sw_surface (SDL_Rect *rect=NULL) const
 Create a software surface backed by the (streaming) texture data. More...
 
void lock (SDL_Rect *rect) const
 lock part of the surface specified by rect More...
 
- Protected Member Functions inherited from drawable
void set_length (u_int16 l)
 Sets the length of the drawable. More...
 
void set_height (u_int16 h)
 Sets the height of the drawable. More...
 

Protected Attributes

SDL_Texture * Surface
 the surface More...
 
u_int8 scale_
 current scale More...
 
s_int16 offset_x_
 sub-pixel offset More...
 

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:

  • a mask parameter, indicating whether the transparent color (which hex triplet is 0xFF00FF, and you can get with screen::trans_col ()) should be drawn or not.
  • an alpha parameter, indicating the level of translucency of the surface. it's range go from 0 to 255, 0 being totally invisible and 255 totally opaque.

Definition at line 85 of file surface.h.

Constructor & Destructor Documentation

surface::surface ( const u_int8 scale = 1)

Default constructor.

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

Definition at line 41 of file surface.cc.

surface::~surface ( )
virtual

Destructor.

Definition at line 53 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 118 of file surface.h.

void surface::set_mask ( bool  m)

Sets the mask parameter of the surface.

Parameters
mtrue if the surface should be masked, false otherwise.

Definition at line 59 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 136 of file surface.h.

void surface::set_alpha ( u_int8  a,
const bool &  alpha_channel = false 
)

Sets the alpha value of the surface.

If alpha_channel is set to true, then the surface_alpha value will be silently ignored. Needs to be called before surface::resize to take effect.

Parameters
surface_alphaThe new alpha value for this surface.
alpha_channelWhether to enable per-pixel alpha for the surface.

Definition at line 106 of file surface.cc.

bool surface::has_alpha_channel ( ) const
inline

Returns whether the surface has an alpha channel.

Returns
true if it has an alpha channel, false otherwise.

Definition at line 155 of file surface.h.

u_int8 surface::scale ( ) const
inline

Get the surfaces current scaling factor.

Definition at line 163 of file surface.h.

void surface::set_scale ( const u_int8 scale)

Change the scale of the surface to the given value, resizing the internal texture appropriately.

Parameters
scalethe new scale to set.

Definition at line 515 of file surface.cc.

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

Draw the surface.

Parameters
xX position where to draw.
yY position where to draw.
da_optoptional drawing_area to use during the drawing operation.
targetpointer to the surface where to draw the drawable. If NULL, draw on the screen.

Implements drawable.

Definition at line 191 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
xX position where to draw.
yY position where to draw.
sxX position where to start drawing from this image.
syY position where to start drawing from this image.
sllength of the part of this image to draw.
shheight of the part of this image to draw.
da_optoptional drawing_area to use during the drawing operation.
targetpointer 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 158 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 225 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
xX position where to fill.
yY position where to fill.
llength of the area to fill.
hheight of the area to fill.
colcolor to fill the surface with.
da_optoptionnal drawing_area to use during the fill operation.

Definition at line 239 of file surface.cc.

void surface::lock ( ) const
inline

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 271 of file surface.h.

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 336 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
xX position of the pixel to change.
yY position of the pixel to change.
colcolor to put.

Definition at line 347 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
xX position of the pixel to change.
yY position of the pixel to change.
rred value of the color to put.
ggreen value of the color to put.
bblue 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 313 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 328 of file surface.h.

u_int32 surface::get_pix ( u_int16  x,
u_int16  y 
) 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
xX position of the pixel to change.
yY position of the pixel to change. returned color.

Definition at line 441 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
xX position of the pixel to change.
yY position of the pixel to change.
rred value of the color.
ggreen value of the color.
bblue value of the color.
Attention
Not accessible from Python. Use get_pix_rgb from Python instead.
See also
get_pix_rgb ()

Definition at line 360 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 378 of file surface.h.

surface & surface::operator= ( const surface src)

Surface copy (similar to copy ()).

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

Definition at line 587 of file surface.cc.

void surface::copy ( const surface src)
inline

Synonym of operator = to guarantee its access from Python.

See also
operator =

Definition at line 401 of file surface.h.

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

Resize this surface.

All the content will be lost.

Parameters
lnew length.
hnew height.

Definition at line 631 of file surface.cc.

void surface::clear ( )
protected

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

Definition at line 665 of file surface.cc.

SDL_Surface * surface::to_sw_surface ( SDL_Rect *  rect = NULL) const
protected

Create a software surface backed by the (streaming) texture data.

Definition at line 123 of file surface.cc.

void surface::lock ( SDL_Rect *  rect) const
protected

lock part of the surface specified by rect

Definition at line 325 of file surface.cc.

Member Data Documentation

SDL_Texture* surface::Surface
protected

the surface

Definition at line 440 of file surface.h.

u_int8 surface::scale_
protected

current scale

Definition at line 443 of file surface.h.

s_int16 surface::offset_x_
protected

sub-pixel offset

Definition at line 446 of file surface.h.


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