The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Macros | Enumerations | Functions
utils.hpp File Reference
#include "scoped_resource.hpp"
#include "util.hpp"
#include "sdl/compat.hpp"
#include <SDL.h>
#include <cstdlib>
#include <iosfwd>
#include <map>
#include <string>
Include dependency graph for utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  surface
 
struct  surface::free_sdl_surface
 
struct  surface_lock
 Helper class for pinning SDL surfaces into memory. More...
 
struct  const_surface_lock
 
struct  surface_restorer
 
struct  clip_rect_setter
 

Macros

#define SDL_BUTTON_WHEELUP   4
 
#define SDL_BUTTON_WHEELDOWN   5
 
#define SDL_BUTTON_WHEELLEFT   6
 
#define SDL_BUTTON_WHEELRIGHT   7
 

Enumerations

enum  channel { RED, GREEN, BLUE, ALPHA }
 

Functions

SDLKey sdl_keysym_from_name (std::string const &keyname)
 
bool operator< (const surface &a, const surface &b)
 
void sdl_blit (const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
 
void sdl_copy_portion (const surface &screen, SDL_Rect *screen_rect, surface &dst, SDL_Rect *dst_rect)
 
Uint32 blend_rgba (const surface &surf, unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned char drop)
 This method blends a RGBA color. More...
 
bool is_neutral (const surface &surf)
 Check that the surface is neutral bpp 32. More...
 
surface make_neutral_surface (const surface &surf)
 
surface create_neutral_surface (int w, int h)
 
surface create_optimized_surface (const surface &surf)
 
surface stretch_surface_horizontal (const surface &surf, const unsigned w, const bool optimize=true)
 Stretches a surface in the horizontal direction. More...
 
surface stretch_surface_vertical (const surface &surf, const unsigned h, const bool optimize=true)
 Stretches a surface in the vertical direction. More...
 
surface scale_surface_xbrz (const surface &surf, size_t z)
 Scale a surface using xBRZ algorithm. More...
 
surface scale_surface_nn (const surface &surf, int w, int h)
 Scale a surface using the nearest neighbor algorithm (provided by xBRZ lib) More...
 
surface scale_surface (const surface &surf, int w, int h, bool optimize)
 Scale a surface. More...
 
surface scale_surface (const surface &surf, int w, int h)
 
surface scale_surface_sharp (const surface &surf, int w, int h, bool optimize=true)
 Scale a surface using modified nearest neighbour algorithm. More...
 
surface tile_surface (const surface &surf, int w, int h, bool optimize=true)
 Tile a surface. More...
 
surface adjust_surface_color (const surface &surf, int r, int g, int b, bool optimize=true)
 
surface greyscale_image (const surface &surf, bool optimize=true)
 
surface monochrome_image (const surface &surf, const int threshold, bool optimize=true)
 
surface sepia_image (const surface &surf, bool optimize=true)
 
surface negative_image (const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB, bool optimize=true)
 
surface alpha_to_greyscale (const surface &surf, bool optimize=true)
 
surface wipe_alpha (const surface &surf, bool optimize=true)
 
surface shadow_image (const surface &surf, bool optimize=true)
 create an heavy shadow of the image, by blurring, increasing alpha and darkening More...
 
surface swap_channels_image (const surface &surf, channel r, channel g, channel b, channel a, bool optimize=true)
 
surface recolor_image (surface surf, const std::map< Uint32, Uint32 > &map_rgb, bool optimize=true)
 Recolors a surface using a map with source and converted palette values. More...
 
surface brighten_image (const surface &surf, fixed_t amount, bool optimize=true)
 
surface get_surface_portion (const surface &surf, SDL_Rect &rect)
 Get a portion of the screen. More...
 
surface adjust_surface_alpha (const surface &surf, fixed_t amount, bool optimize=true)
 
surface adjust_surface_alpha_add (const surface &surf, int amount, bool optimize=true)
 
surface mask_surface (const surface &surf, const surface &mask, bool *empty_result=nullptr, const std::string &filename=std::string())
 Applies a mask on a surface. More...
 
bool in_mask_surface (const surface &surf, const surface &mask)
 Check if a surface fit into a mask. More...
 
surface submerge_alpha (const surface &surf, int depth, float alpha_base, float alpha_delta, bool optimize=true)
 Progressively reduce alpha of bottom part of the surface. More...
 
surface light_surface (const surface &surf, const surface &lightmap, bool optimize=true)
 Light surf using lightmap. More...
 
surface blur_surface (const surface &surf, int depth=1, bool optimize=true)
 Cross-fades a surface. More...
 
void blur_surface (surface &surf, SDL_Rect rect, int depth=1)
 Cross-fades a surface in place. More...
 
surface blur_alpha_surface (const surface &surf, int depth=1, bool optimize=true)
 Cross-fades a surface with alpha channel. More...
 
surface cut_surface (const surface &surf, SDL_Rect const &r)
 Cuts a rectangle from a surface. More...
 
surface blend_surface (const surface &surf, const double amount, const Uint32 color, const bool optimize=true)
 Blends a surface with a color. More...
 
surface rotate_any_surface (const surface &surf, float angle, int zoom, int offset, bool optimize=true)
 Rotates a surface by any degrees. More...
 
surface rotate_180_surface (const surface &surf, bool optimize=true)
 Rotates a surface 180 degrees. More...
 
surface rotate_90_surface (const surface &surf, bool clockwise, bool optimize=true)
 Rotates a surface 90 degrees. More...
 
surface flip_surface (const surface &surf, bool optimize=true)
 
surface flop_surface (const surface &surf, bool optimize=true)
 
surface create_compatible_surface (const surface &surf, int width=-1, int height=-1)
 
void blit_surface (const surface &src, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
 Replacement for sdl_blit. More...
 
SDL_Rect get_non_transparent_portion (const surface &surf)
 
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 &color)
 
SDL_Color int_to_color (const Uint32 rgb)
 
SDL_Color string_to_color (const std::string &color_string)
 Return the color the string represents. More...
 
SDL_Color create_color (const unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=SDL_ALPHA_OPAQUE)
 
void put_pixel (const surface &surf, surface_lock &surf_lock, int x, int y, Uint32 pixel)
 Helper methods for setting/getting a single pixel in an image. More...
 
Uint32 get_pixel (const surface &surf, const const_surface_lock &surf_lock, int x, int y)
 
void draw_centered_on_background (surface surf, const SDL_Rect &rect, const SDL_Color &color, surface target)
 
std::ostream & operator<< (std::ostream &s, const SDL_Rect &rect)
 

Macro Definition Documentation

#define SDL_BUTTON_WHEELDOWN   5

Definition at line 39 of file utils.hpp.

Referenced by gui2::event::thandler::mouse_button_down().

#define SDL_BUTTON_WHEELLEFT   6

Definition at line 43 of file utils.hpp.

Referenced by gui2::event::thandler::mouse_button_down().

#define SDL_BUTTON_WHEELRIGHT   7

Definition at line 47 of file utils.hpp.

Referenced by gui2::event::thandler::mouse_button_down().

#define SDL_BUTTON_WHEELUP   4

Definition at line 35 of file utils.hpp.

Referenced by gui2::event::thandler::mouse_button_down().

Enumeration Type Documentation

enum channel
Enumerator
RED 
GREEN 
BLUE 
ALPHA 

Definition at line 250 of file utils.hpp.

Function Documentation

surface adjust_surface_alpha ( const surface surf,
fixed_t  amount,
bool  optimize = true 
)
surface adjust_surface_alpha_add ( const surface surf,
int  amount,
bool  optimize = true 
)
surface adjust_surface_color ( const surface surf,
int  r,
int  g,
int  b,
bool  optimize = true 
)
surface alpha_to_greyscale ( const surface surf,
bool  optimize = true 
)
Uint32 blend_rgba ( const surface surf,
unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a,
unsigned char  drop 
)

This method blends a RGBA color.

The method takes as input a surface, the RGB color to blend and a value specifying how much blending to apply. The blended color is returned. Caution: if you use a transparent color, make sure the resulting color is not equal to the transparent color.

Definition at line 356 of file utils.cpp.

Referenced by battle_prediction_pane::get_hp_distrib_surface().

surface blend_surface ( const surface surf,
const double  amount,
const Uint32  color,
const bool  optimize = true 
)

Blends a surface with a color.

Every pixel in the surface will be blended with the color given. The final color of a pixel is amount * color + (1 - amount) * original.

Parameters
surfThe surface to blend.
amountThe amount of the new color is determined by color. Must be a number in the range [0, 1].
colorThe color to blend width, note its alpha channel is ignored.
optimizeShould the return surface be RLE optimized.
Returns
The blended surface.

Definition at line 1840 of file utils.cpp.

References create_optimized_surface(), i, make_neutral_surface(), surface_lock::pixels(), vaddq_u16(), tmatrix< T, S, D >::val, vdup_n_u8(), vdupq_n_u16(), vld4_u8(), vmull_u8(), vshrn_n_u16(), and vst4_u8().

Referenced by blend_image(), image::blend_modification::operator()(), and display::render_image().

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

Replacement for sdl_blit.

sdl_blit 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.

Precondition
src contains a valid canvas.
dst contains a valid neutral canvas.
The caller must make sure the src fits on the dst.
Parameters
srcThe surface to blit.
srcrectThe region of the surface to blit
dstThe surface to blit on.
dstrectThe offset to blit the surface on, only x and y are used.

Definition at line 2185 of file utils.cpp.

References sdl::create_rect(), is_neutral(), make_neutral_surface(), surface_lock::pixels(), and const_surface_lock::pixels().

Referenced by image::apply_light(), font::floating_label::create_surface(), gui::button::draw_contents(), gui::tristate_button::draw_contents(), draw_panel(), gui::multimenu::draw_row(), image::getMinimap(), image::blit_modification::operator()(), image::mask_modification::operator()(), image::brighten_modification::operator()(), image::darken_modification::operator()(), image::background_modification::operator()(), storyscreen::part_ui::prepare_background(), editor::mouse_action_map_label::set_mouse_overlay(), editor::mouse_action_village::set_mouse_overlay(), editor::mouse_action_paste::set_mouse_overlay(), editor::mouse_action_starting_position::set_mouse_overlay(), and editor::mouse_action::set_terrain_mouse_overlay().

surface blur_alpha_surface ( const surface surf,
int  depth = 1,
bool  optimize = true 
)

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 1659 of file utils.cpp.

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

Referenced by image::bl_modification::operator()(), and shadow_image().

surface blur_surface ( const surface surf,
int  depth = 1,
bool  optimize = true 
)
void blur_surface ( surface surf,
SDL_Rect  rect,
int  depth = 1 
)

Cross-fades a surface in place.

Parameters
surfThe surface to blur, must be not optimized and have 32 bits per pixel.
rectThe part of the surface to blur.
depthThe depth of the blurring.

Definition at line 1543 of file utils.cpp.

References surface_lock::pixels().

surface brighten_image ( const surface surf,
fixed_t  amount,
bool  optimize = true 
)
SDL_Color create_color ( const unsigned char  red,
unsigned char  green,
unsigned char  blue,
unsigned char  alpha = SDL_ALPHA_OPAQUE 
)

Definition at line 89 of file utils.cpp.

Referenced by image::getMinimap(), game_lua_kernel::intf_print(), the_end(), and unit_moves().

surface create_compatible_surface ( const surface surf,
int  width = -1,
int  height = -1 
)
surface create_neutral_surface ( int  w,
int  h 
)
surface create_optimized_surface ( const surface surf)
surface cut_surface ( const surface surf,
SDL_Rect const &  r 
)

Cuts a rectangle from a surface.

Definition at line 1782 of file utils.cpp.

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

Referenced by image::load_image_sub_file(), and image::crop_modification::operator()().

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

Definition at line 2518 of file utils.cpp.

References sdl::fill_rect(), sdl_blit(), and update_rect().

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

surface flip_surface ( const surface surf,
bool  optimize = true 
)
surface flop_surface ( const surface surf,
bool  optimize = true 
)
SDL_Rect get_non_transparent_portion ( const surface surf)

Definition at line 2381 of file utils.cpp.

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

Referenced by display::draw_image_for_report().

Uint32 get_pixel ( const surface surf,
const const_surface_lock surf_lock,
int  x,
int  y 
)

Definition at line 2006 of file utils.cpp.

References const_surface_lock::pixels().

Referenced by rotate_any_surface().

surface get_surface_portion ( const surface surf,
SDL_Rect &  rect 
)

Get a portion of the screen.

Send nullptr if the portion is outside of the screen.

Parameters
surfThe source surface.
rectThe portion of the source surface to copy.
Returns
A surface containing the portion of the source. No RLE or Alpha bits are set.
Return values
0if error or the portion is outside of the surface.

Definition at line 2335 of file utils.cpp.

References create_compatible_surface(), and sdl_copy_portion().

Referenced by gui2::tcanvas::blit(), gui2::twindow::draw(), gui::dialog_frame::draw_background(), display::draw_image_for_report(), display::refresh_report(), halo::halo_impl::effect::render(), and surface_restorer::update().

surface greyscale_image ( const surface surf,
bool  optimize = true 
)
bool in_mask_surface ( const surface surf,
const surface mask 
)

Check if a surface fit into a mask.

Definition at line 1349 of file utils.cpp.

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

Referenced by image::is_in_hex().

SDL_Color int_to_color ( const Uint32  rgb)
SDL_Color inverse ( const SDL_Color &  color)

Definition at line 2458 of file utils.cpp.

References inverse().

Referenced by inverse().

bool is_neutral ( const surface surf)

Check that the surface is neutral bpp 32.

The surface may have an empty alpha channel.

Parameters
surfThe surface to test.
Returns
The status true if neutral, false if not.

Definition at line 113 of file utils.cpp.

Referenced by gui2::tcanvas::blit(), and blit_surface().

surface light_surface ( const surface surf,
const surface lightmap,
bool  optimize = true 
)

Light surf using lightmap.

Parameters
surfThe source surface.
lightmapadd/subtract this color to surf but RGB values are converted to (X-128)*2 to cover the full (-256,256) spectrum. Should already be neutral
optimizeWhether the new surface should be RLE encoded.

Definition at line 1458 of file utils.cpp.

References create_optimized_surface(), g, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.

Referenced by image::apply_light(), and image::light_modification::operator()().

surface make_neutral_surface ( const surface surf)
surface mask_surface ( const surface surf,
const surface mask,
bool *  empty_result = nullptr,
const std::string filename = std::string() 
)
surface monochrome_image ( const surface surf,
const int  threshold,
bool  optimize = true 
)
surface negative_image ( const surface surf,
const int  thresholdR,
const int  thresholdG,
const int  thresholdB,
bool  optimize = true 
)
bool operator!= ( const SDL_Color &  a,
const SDL_Color &  b 
)

Definition at line 2454 of file utils.cpp.

References operator==().

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

Definition at line 108 of file utils.cpp.

References surface::get().

std::ostream& operator<< ( std::ostream &  s,
const SDL_Rect &  rect 
)

Definition at line 2535 of file utils.cpp.

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

Definition at line 2450 of file utils.cpp.

Referenced by operator!=().

void put_pixel ( const surface surf,
surface_lock surf_lock,
int  x,
int  y,
Uint32  pixel 
)

Helper methods for setting/getting a single pixel in an image.

Lifted from http://sdl.beuc.net/sdl.wiki/Pixel_Access

Parameters
surfThe image to get or receive the pixel from.
surf_lockThe locked surface to make sure the pointers are valid.
xThe position in the row of the pixel.
yThe row of the pixel.

Definition at line 1975 of file utils.cpp.

References surface_lock::pixels().

Referenced by rotate_any_surface().

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

Recolors a surface using a map with source and converted palette values.

This is most often used for team-coloring.

Parameters
surfThe source surface.
map_rgbMap of color values, with the keys corresponding to the source palette, and the values to the recolored palette.
optimizeWhether the new surface should be RLE encoded. Only useful when the source is not the screen and it is going to be used multiple times.
Returns
A recolored surface, or a null surface if there are problems with the source.

Definition at line 1126 of file utils.cpp.

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

Referenced by image::rc_modification::operator()().

surface rotate_180_surface ( const surface surf,
bool  optimize = true 
)

Rotates a surface 180 degrees.

Parameters
surfThe surface to rotate.
optimizeShould the return surface be RLE optimized.
Returns
The rotated surface.

Definition at line 2029 of file utils.cpp.

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

Referenced by image::fl_modification::operator()(), and image::rotate_modification::operator()().

surface rotate_90_surface ( const surface surf,
bool  clockwise,
bool  optimize = true 
)

Rotates a surface 90 degrees.

Parameters
surfThe surface to rotate.
clockwiseWhether the rotation should be clockwise (true) or counter-clockwise (false).
optimizeShould the return surface be RLE optimized.
Returns
The rotated surface.

Definition at line 2071 of file utils.cpp.

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

Referenced by image::rotate_modification::operator()().

surface rotate_any_surface ( const surface surf,
float  angle,
int  zoom,
int  offset,
bool  optimize = true 
)

Rotates a surface by any degrees.

Precondition
zoom >= offset Otherwise
Returns
will have empty pixels.
Precondition
offset > 0 Otherwise the procedure will not return.
Parameters
surfThe surface to rotate.
angleThe angle of rotation.
zoomWhich zoom level to use for calculating the result.
offsetPixel offset when scanning the zoomed source.
optimizeShould the return surface be RLE optimized.
Returns
The rotated surface.

Definition at line 1920 of file utils.cpp.

References create_neutral_surface(), create_optimized_surface(), get_pixel(), put_pixel(), and scale_surface().

Referenced by image::rotate_modification::operator()().

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

Scale a surface.

Parameters
surfThe source surface.
wThe width of the resulting surface.
hThe height of the resulting surface.
optimizeShould the return surface be RLE optimized.
Returns
A surface containing the scaled version of the source.
Return values
0Returned upon error.
surfReturned if w == surf->w and h == surf->h note this ignores the optimize flag.

Definition at line 447 of file utils.cpp.

References create_neutral_surface(), create_optimized_surface(), e, ftofxp, fxpdiv, fxptoi, h, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.

surface scale_surface ( const surface surf,
int  w,
int  h 
)
surface scale_surface_nn ( const surface surf,
int  w,
int  h 
)

Scale a surface using the nearest neighbor algorithm (provided by xBRZ lib)

Parameters
surfThe sources surface
wThe width of the resulting surface.
hThe height of the resulting surface.
Returns
The rescaled surface.

Definition at line 404 of file utils.cpp.

References create_neutral_surface(), create_optimized_surface(), h, make_neutral_surface(), xbrz::nearestNeighborScale(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.

Referenced by image::select_algorithm().

surface scale_surface_sharp ( const surface surf,
int  w,
int  h,
bool  optimize = true 
)

Scale a surface using modified nearest neighbour algorithm.

Use only if preserving sharp edges is a priority (e.g. minimap).

Parameters
surfThe source surface.
wThe width of the resulting surface.
hThe height of the resulting surface.
optimizeShould the return surface be RLE optimized.
Returns
A surface containing the scaled version of the source.
Return values
0Returned upon error.
surfReturned if w == surf->w and h == surf->h note this ignores the optimize flag.

Definition at line 577 of file utils.cpp.

References create_neutral_surface(), create_optimized_surface(), floating_point_emulation::floor(), g, h, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), surf, and floating_point_emulation::tfloat< T, S >::to_int().

Referenced by image::getMinimap(), and image::scale_modification::operator()().

surface scale_surface_xbrz ( const surface surf,
size_t  z 
)

Scale a surface using xBRZ algorithm.

Parameters
surfThe source surface
zThe scaling factor. Should be an integer 2-5 (1 is tolerated).
Returns
The scaled (optimized) surface

Definition at line 366 of file utils.cpp.

References create_neutral_surface(), create_optimized_surface(), make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and xbrz::scale().

Referenced by image::xbrz_modification::operator()(), and image::scale_xbrz_helper().

void sdl_blit ( const surface src,
SDL_Rect *  src_rect,
surface dst,
SDL_Rect *  dst_rect 
)
inline
void sdl_copy_portion ( const surface screen,
SDL_Rect *  screen_rect,
surface dst,
SDL_Rect *  dst_rect 
)
inline
SDLKey sdl_keysym_from_name ( std::string const &  keyname)

Definition at line 103 of file utils.cpp.

surface sepia_image ( const surface surf,
bool  optimize = true 
)
surface shadow_image ( const surface surf,
bool  optimize = true 
)

create an heavy shadow of the image, by blurring, increasing alpha and darkening

Definition at line 987 of file utils.cpp.

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

Referenced by font::floating_label::create_surface().

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

Stretches 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
surfThe source surface.
wThe width of the resulting surface.
optimizeShould the return surface be RLE optimized.
Returns
An optimized surface. returned.
Return values
0Returned upon error.
surfReturned if w == surf->w, note this ignores the optimize flag.

Definition at line 178 of file utils.cpp.

References create_neutral_surface(), create_optimized_surface(), make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.

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

Stretches 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
surfThe source surface.
hThe height of the resulting surface.
optimizeShould the return surface be RLE optimized.
Returns
An optimized surface. returned.
Return values
surfReturned if h == surf->h, note this ignores the optimize flag.

Definition at line 223 of file utils.cpp.

References create_neutral_surface(), create_optimized_surface(), h, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.

SDL_Color string_to_color ( const std::string color_string)

Return the color the string represents.

Return font::NORMAL_COLOR if the string is empty or can't be matched against any other color.

Definition at line 1206 of file help_impl.cpp.

References font::BAD_COLOR, font::BIGMAP_COLOR, font::BLACK_COLOR, font::GOOD_COLOR, int_to_color(), font::NORMAL_COLOR, string2rgb(), and font::YELLOW_COLOR.

Referenced by help::help_text_area::handle_format_cfg(), game_lua_kernel::intf_float_label(), game_lua_kernel::intf_print(), and terrain_label::read().

surface submerge_alpha ( const surface surf,
int  depth,
float  alpha_base,
float  alpha_delta,
bool  optimize = true 
)

Progressively reduce alpha of bottom part of the surface.

Parameters
surfThe source surface.
depthThe height of the bottom part in pixels
alpha_baseThe alpha adjustment at the interface
alpha_deltaThe alpha adjustment reduction rate by pixel depth
optimizeOptimize by converting to result to display

Definition at line 1395 of file utils.cpp.

References amount, create_optimized_surface(), d, ftofxp, fxpmult, g, make_neutral_surface(), and surface_lock::pixels().

Referenced by display::render_image().

surface swap_channels_image ( const surface surf,
channel  r,
channel  g,
channel  b,
channel  a,
bool  optimize = true 
)
surface tile_surface ( const surface surf,
int  w,
int  h,
bool  optimize = true 
)

Tile a surface.

Parameters
surfThe source surface.
wThe width of the resulting surface.
hThe height of the resulting surface.
optimizeShould the return surface be RLE optimized
Returns
A surface containing the tiled version of the source.
Return values
0Returned upon error
surfReturned if w == surf->w and h == surf->h note this ignores the optimize flag.

Definition at line 674 of file utils.cpp.

References create_neutral_surface(), create_optimized_surface(), h, i, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), surf, and sw.

Referenced by draw_panel(), and storyscreen::part_ui::prepare_background().

surface wipe_alpha ( const surface surf,
bool  optimize = true 
)