sdl_utils.cpp File Reference

Support-routines for the SDL-graphics-library. More...

#include "global.hpp"
#include "config.hpp"
#include "log.hpp"
#include "sdl_utils.hpp"
#include "util.hpp"
#include "video.hpp"
#include <algorithm>
#include <string.h>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>

Include dependency graph for sdl_utils.cpp:

Go to the source code of this file.

Functions

SDL_Color int_to_color (const Uint32 rgb)
Uint32 color_to_int (const SDL_Color &color)
SDLKey sdl_keysym_from_name (std::string const &keyname)
bool point_in_rect (int x, int y, const SDL_Rect &rect)
bool rects_overlap (const SDL_Rect &rect1, const SDL_Rect &rect2)
SDL_Rect intersect_rects (SDL_Rect const &rect1, SDL_Rect const &rect2)
SDL_Rect create_rect (const int x, const int y, const int w, const int h)
 Creates an empty SDL_Rect.
bool operator< (const surface &a, const surface &b)
static SDL_PixelFormat & get_neutral_pixel_format ()
surface make_neutral_surface (surface const &surf)
surface create_optimized_surface (surface const &surf)
surface stretch_surface_horizontal (const surface &surf, const unsigned w, const bool optimize)
 Streches a surface in the horizontal direction.
surface stretch_surface_vertical (const surface &surf, const unsigned h, const bool optimize)
 Streches a surface in the vertical direction.
surface scale_surface (surface const &surf, int w, int h, bool optimize)
surface scale_surface_blended (surface const &surf, int w, int h, bool optimize)
surface adjust_surface_colour (surface const &surf, int red, int green, int blue, bool optimize)
surface greyscale_image (surface const &surf, bool optimize)
surface darken_image (surface const &surf, bool optimize)
surface recolor_image (surface surf, const std::map< Uint32, Uint32 > &map_rgb, bool optimize)
surface brighten_image (surface const &surf, fixed_t amount, bool optimize)
surface adjust_surface_alpha (surface const &surf, fixed_t amount, bool optimize)
surface adjust_surface_alpha_add (surface const &surf, int amount, bool optimize)
surface mask_surface (surface const &surf, surface const &mask)
 Applies a mask on a surface.
surface blur_surface (surface const &surf, int depth, bool optimize)
 Cross-fades a surface.
surface blur_alpha_surface (surface const &surf, int depth, bool optimize)
 Cross-fades a surface with alpha channel.
surface cut_surface (surface const &surf, SDL_Rect const &r)
 Cuts a rectangle from a surface.
surface blend_surface (surface const &surf, double amount, Uint32 colour, bool optimize)
surface flip_surface (surface const &surf, bool optimize)
surface flop_surface (surface const &surf, bool optimize)
surface create_compatible_surface (surface const &surf, int width, int height)
void blit_surface (const surface &src, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
 Replacement for SDL_BlitSurface.
void fill_rect_alpha (SDL_Rect &rect, Uint32 colour, Uint8 alpha, surface const &target)
surface get_surface_portion (surface const &src, SDL_Rect &area)
SDL_Rect get_non_transparent_portion (surface const &surf)
bool operator== (const SDL_Rect &a, const SDL_Rect &b)
bool operator!= (const SDL_Rect &a, const SDL_Rect &b)
bool operator== (const SDL_Color &a, const SDL_Color &b)
bool operator!= (const SDL_Color &a, const SDL_Color &b)
SDL_Color inverse (const SDL_Color &colour)
void draw_rectangle (int x, int y, int w, int h, Uint32 colour, surface target)
void draw_solid_tinted_rectangle (int x, int y, int w, int h, int r, int g, int b, double alpha, surface target)
void draw_centered_on_background (surface surf, const SDL_Rect &rect, const SDL_Color &color, surface target)


Detailed Description

Support-routines for the SDL-graphics-library.

Definition in file sdl_utils.cpp.


Function Documentation

surface adjust_surface_alpha ( surface const &  surf,
fixed_t  amount,
bool  optimize 
)

surface adjust_surface_alpha_add ( surface const &  surf,
int  amount,
bool  optimize 
)

surface adjust_surface_colour ( surface const &  surf,
int  red,
int  green,
int  blue,
bool  optimize 
)

surface blend_surface ( surface const &  surf,
double  amount,
Uint32  colour,
bool  optimize 
)

void blit_surface ( const surface src,
const SDL_Rect *  srcrect,
surface dst,
const SDL_Rect *  dstrect 
)

Replacement for SDL_BlitSurface.

SDL_BlitSurface has problems with blitting partly transparent surfaces so this is a replacement. It ignores the SDL_SRCALPHA and SDL_SRCCOLORKEY flags. src and dst will have the SDL_RLEACCEL flag removed. The return value of SDL_BlistSurface is normally ignored so no return value. The rectangles are const and will not be modified.

Parameters:
src The surface to blit.
srcrect The region of the surface to blit
dst The surface to blit on.
dstrect The offset to blit the surface on, only x and y are used.

Definition at line 1291 of file sdl_utils.cpp.

References minimum(), and surface_lock::pixels().

Referenced by gui2::twindow::draw(), gui2::tpanel::draw(), gui2::tlistbox::draw(), gui2::tcontrol::draw(), gui2::ttext::draw(), gui2::timage::draw(), and image::getMinimap().

surface blur_alpha_surface ( surface const &  surf,
int  depth,
bool  optimize 
)

Cross-fades a surface with alpha channel.

Todo:
FIXME: This is just an adapted copy-paste of the normal blur but with blur alpha channel too

Definition at line 984 of file sdl_utils.cpp.

References create_optimized_surface(), make_neutral_surface(), minimum(), and surface_lock::pixels().

surface blur_surface ( surface const &  surf,
int  depth,
bool  optimize 
)

surface brighten_image ( surface const &  surf,
fixed_t  amount,
bool  optimize 
)

Uint32 color_to_int ( const SDL_Color &  color  ) 

Definition at line 42 of file sdl_utils.cpp.

surface create_compatible_surface ( surface const &  surf,
int  width,
int  height 
)

surface create_optimized_surface ( surface const &  surf  ) 

SDL_Rect create_rect ( const int  x,
const int  y,
const int  w,
const int  h 
)

Creates an empty SDL_Rect.

Since SDL_Rect can't be created as temp variable in one step create this wrapper.

Definition at line 95 of file sdl_utils.cpp.

References rect.

Referenced by gui2::create_rect(), and gui2::twidget::get_rect().

surface cut_surface ( surface const &  surf,
SDL_Rect const &  r 
)

Cuts a rectangle from a surface.

Definition at line 1107 of file sdl_utils.cpp.

References create_compatible_surface(), surface_lock::pixels(), and size.

Referenced by image::locator::load_image_sub_file().

surface darken_image ( surface const &  surf,
bool  optimize 
)

void draw_centered_on_background ( surface  surf,
const SDL_Rect &  rect,
const SDL_Color &  color,
surface  target 
)

Definition at line 1698 of file sdl_utils.cpp.

References r, and update_rect().

Referenced by display::draw_minimap(), mp::create::hide_children(), and mp::create::process_event().

void draw_rectangle ( int  x,
int  y,
int  w,
int  h,
Uint32  colour,
surface  target 
)

void draw_solid_tinted_rectangle ( int  x,
int  y,
int  w,
int  h,
int  r,
int  g,
int  b,
double  alpha,
surface  target 
)

void fill_rect_alpha ( SDL_Rect &  rect,
Uint32  colour,
Uint8  alpha,
surface const &  target 
)

surface flip_surface ( surface const &  surf,
bool  optimize 
)

surface flop_surface ( surface const &  surf,
bool  optimize 
)

static SDL_PixelFormat& get_neutral_pixel_format (  )  [static]

Definition at line 106 of file sdl_utils.cpp.

Referenced by make_neutral_surface().

SDL_Rect get_non_transparent_portion ( surface const &  surf  ) 

Definition at line 1507 of file sdl_utils.cpp.

References make_neutral_surface(), and surface_lock::pixels().

Referenced by display::draw_image_for_report().

surface get_surface_portion ( surface const &  src,
SDL_Rect &  area 
)

surface greyscale_image ( surface const &  surf,
bool  optimize 
)

SDL_Color int_to_color ( const Uint32  rgb  ) 

SDL_Rect intersect_rects ( SDL_Rect const &  rect1,
SDL_Rect const &  rect2 
)

Definition at line 82 of file sdl_utils.cpp.

Referenced by surface_restorer::restore(), and display::scroll().

SDL_Color inverse ( const SDL_Color &  colour  ) 

Definition at line 1594 of file sdl_utils.cpp.

References inverse().

Referenced by inverse().

surface make_neutral_surface ( surface const &  surf  ) 

surface mask_surface ( surface const &  surf,
surface const &  mask 
)

bool operator!= ( const SDL_Color &  a,
const SDL_Color &  b 
)

Definition at line 1590 of file sdl_utils.cpp.

References operator==().

bool operator!= ( const SDL_Rect &  a,
const SDL_Rect &  b 
)

Definition at line 1581 of file sdl_utils.cpp.

References operator==().

bool operator< ( const surface a,
const surface b 
)

Definition at line 101 of file sdl_utils.cpp.

References surface::get().

bool operator== ( const SDL_Color &  a,
const SDL_Color &  b 
)

Definition at line 1586 of file sdl_utils.cpp.

bool operator== ( const SDL_Rect &  a,
const SDL_Rect &  b 
)

Definition at line 1576 of file sdl_utils.cpp.

bool point_in_rect ( int  x,
int  y,
const SDL_Rect &  rect 
)

surface recolor_image ( surface  surf,
const std::map< Uint32, Uint32 > &  map_rgb,
bool  optimize 
)

bool rects_overlap ( const SDL_Rect &  rect1,
const SDL_Rect &  rect2 
)

surface scale_surface ( surface const &  surf,
int  w,
int  h,
bool  optimize 
)

surface scale_surface_blended ( surface const &  surf,
int  w,
int  h,
bool  optimize 
)

SDLKey sdl_keysym_from_name ( std::string const &  keyname  ) 

Definition at line 49 of file sdl_utils.cpp.

References name.

Referenced by hotkey::hotkey_item::load_from_config().

surface stretch_surface_horizontal ( const surface surf,
const unsigned  w,
const bool  optimize 
)

Streches a surface in the horizontal direction.

The stretches a surface it uses the first pixel in the horizontal direction of the original surface and copies that to the destination. This means only the first column of the original is used for the destination.

Parameters:
surf The source surface.
w The width of the resulting surface.
optimize Should the return surface be RLE optimized.
Returns:
An optimized surface. returned.
Return values:
0 Returned upon error.
surf Returned if w == surf->w, note this ignores the optimize flag.

Definition at line 168 of file sdl_utils.cpp.

References create_optimized_surface(), make_neutral_surface(), and surface_lock::pixels().

Referenced by gui2::timage::draw().

surface stretch_surface_vertical ( const surface surf,
const unsigned  h,
const bool  optimize 
)

Streches a surface in the vertical direction.

The stretches a surface it uses the first pixel in the vertical direction of the original surface and copies that to the destination. This means only the first row of the original is used for the destination.

Parameters:
surf The source surface.
h The height of the resulting surface.
optimize Should the return surface be RLE optimized.
Returns:
An optimized surface. returned.
Return values:
0 Returned upon error.
surf Returned if h == surf->h, note this ignores the optimize flag.

Definition at line 228 of file sdl_utils.cpp.

References create_optimized_surface(), make_neutral_surface(), and surface_lock::pixels().

Referenced by gui2::timage::draw().


Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs