Freeciv-3.2
Loading...
Searching...
No Matches
Functions | Variables
graphics.c File Reference
#include <SDL3_image/SDL_image.h>
#include <SDL3_ttf/SDL_ttf.h>
#include "fcintl.h"
#include "log.h"
#include "tilespec.h"
#include "colors.h"
#include "gui_tilespec.h"
#include "mapview.h"
#include "themebackgrounds.h"
#include "themespec.h"
#include "graphics.h"

Go to the source code of this file.

Functions

struct gui_layergui_layer_new (int x, int y, SDL_Surface *surface)
 
void gui_layer_destroy (struct gui_layer **gui_layer)
 
struct gui_layerget_gui_layer (SDL_Surface *surface)
 
struct gui_layeradd_gui_layer (int width, int height)
 
void remove_gui_layer (struct gui_layer *gui_layer)
 
void screen_rect_to_layer_rect (struct gui_layer *gui_layer, SDL_Rect *dest_rect)
 
void layer_rect_to_screen_rect (struct gui_layer *gui_layer, SDL_Rect *dest_rect)
 
int alphablit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
 
int screen_blit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *dstrect, unsigned char alpha_mod)
 
SDL_Surfacecrop_rect_from_surface (SDL_Surface *psource, SDL_Rect *prect)
 
SDL_Surfacemask_surface (SDL_Surface *src, SDL_Surface *mask, int mask_offset_x, int mask_offset_y)
 
SDL_Surfaceload_surf (const char *fname)
 
SDL_Surfacecreate_surf_with_format (SDL_PixelFormat pf, int width, int height)
 
SDL_Surfacecreate_surf (int width, int height)
 
SDL_Surfaceconvert_surf (SDL_Surface *surf_in)
 
SDL_Surfacecreate_filled_surface (Uint16 w, Uint16 h, SDL_Color *pcolor)
 
int clear_surface (SDL_Surface *surf, SDL_Rect *dstrect)
 
int blit_entire_src (SDL_Surface *psrc, SDL_Surface *pdest, Sint16 dest_x, Sint16 dest_y)
 
Uint32 get_pixel (SDL_Surface *surf, Sint16 x, Sint16 y)
 
Uint32 get_first_pixel (SDL_Surface *surf)
 
void init_sdl (int flags)
 
static void free_surfaces (void)
 
bool create_surfaces (int width, int height)
 
void quit_sdl (void)
 
bool set_video_mode (unsigned width, unsigned height, unsigned flags_in)
 
void update_main_screen (void)
 
int main_window_width (void)
 
int main_window_height (void)
 
int fill_rect_alpha (SDL_Surface *surf, SDL_Rect *prect, SDL_Color *pcolor)
 
bool correct_rect_region (SDL_Rect *prect)
 
bool is_in_rect_area (int x, int y, const SDL_Rect *rect)
 
void get_smaller_surface_rect (SDL_Surface *surf, SDL_Rect *rect)
 
SDL_Surfacecrop_visible_part_from_surface (SDL_Surface *psrc)
 
SDL_Surfaceresize_surface (const SDL_Surface *psrc, Uint16 new_width, Uint16 new_height, int smooth)
 
SDL_Surfaceresize_surface_box (const SDL_Surface *psrc, Uint16 new_width, Uint16 new_height, int smooth, bool scale_up, bool absolute_dimensions)
 
SDL_Surfacecopy_surface (SDL_Surface *src)
 
bool is_view_supported (enum ts_type type)
 
void tileset_type_set (enum ts_type type)
 
void create_frame (SDL_Surface *dest, Sint16 left, Sint16 top, Sint16 width, Sint16 height, SDL_Color *pcolor)
 
void create_line (SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
 

Variables

struct sdl3_data main_data
 
static SDL_Surfacemain_surface = NULL
 
static bool render_dirty = TRUE
 

Function Documentation

◆ add_gui_layer()

struct gui_layer * add_gui_layer ( int  width,
int  height 
)

Buffer allocation function. This function is call by "create_window(...)" function and allocate buffer layer for this function.

Pointer for this buffer is put in buffer array on last position that flush functions will draw this layer last.

Definition at line 105 of file graphics.c.

◆ alphablit()

int alphablit ( SDL_Surface src,
SDL_Rect srcrect,
SDL_Surface dst,
SDL_Rect dstrect,
unsigned char  alpha_mod 
)

Execute alphablit.

Definition at line 192 of file graphics.c.

◆ blit_entire_src()

int blit_entire_src ( SDL_Surface psrc,
SDL_Surface pdest,
Sint16  dest_x,
Sint16  dest_y 
)

Blit entire src [SOURCE] surface to destination [DEST] surface on position : [dest_x],[dest_y] using it's actual alpha and color key settings.

Definition at line 417 of file graphics.c.

◆ clear_surface()

int clear_surface ( SDL_Surface surf,
SDL_Rect dstrect 
)

Fill surface with (0, 0, 0, 0), so the next blitting operation can set the per pixel alpha

Definition at line 396 of file graphics.c.

◆ convert_surf()

SDL_Surface * convert_surf ( SDL_Surface surf_in)

Convert surface to the main window format.

Definition at line 354 of file graphics.c.

◆ copy_surface()

SDL_Surface * copy_surface ( SDL_Surface src)

Return copy of the surface

Definition at line 1132 of file graphics.c.

◆ correct_rect_region()

bool correct_rect_region ( SDL_Rect prect)

Make rectangle region sane. Return TRUE if result is sane.

Definition at line 709 of file graphics.c.

◆ create_filled_surface()

SDL_Surface * create_filled_surface ( Uint16  w,
Uint16  h,
SDL_Color pcolor 
)

Create an surface with screen format and fill with color. If pcolor == NULL surface is filled with transparent white A = 128

Definition at line 363 of file graphics.c.

◆ create_frame()

void create_frame ( SDL_Surface dest,
Sint16  left,
Sint16  top,
Sint16  width,
Sint16  height,
SDL_Color pcolor 
)

Create colored frame

Definition at line 1167 of file graphics.c.

◆ create_line()

void create_line ( SDL_Surface dest,
Sint16  x0,
Sint16  y0,
Sint16  x1,
Sint16  y1,
SDL_Color pcolor 
)

Create single colored line

Definition at line 1198 of file graphics.c.

◆ create_surf()

SDL_Surface * create_surf ( int  width,
int  height 
)

Create surface with the same format as main window

Definition at line 346 of file graphics.c.

◆ create_surf_with_format()

SDL_Surface * create_surf_with_format ( SDL_PixelFormat  pf,
int  width,
int  height 
)

Create an surface with format

Definition at line 328 of file graphics.c.

◆ create_surfaces()

bool create_surfaces ( int  width,
int  height 
)

Create new main window surfaces.

Definition at line 556 of file graphics.c.

◆ crop_rect_from_surface()

SDL_Surface * crop_rect_from_surface ( SDL_Surface psource,
SDL_Rect prect 
)

Create new surface (prect->w x prect->h size) and copy prect area of psource. if prect == NULL then create copy of entire psource.

Definition at line 231 of file graphics.c.

◆ crop_visible_part_from_surface()

SDL_Surface * crop_visible_part_from_surface ( SDL_Surface psrc)

Create new surface that is just visible part of source surface.

Definition at line 1048 of file graphics.c.

◆ fill_rect_alpha()

int fill_rect_alpha ( SDL_Surface surf,
SDL_Rect prect,
SDL_Color pcolor 
)

Fill rectangle with color with alpha channel.

Definition at line 675 of file graphics.c.

◆ free_surfaces()

static void free_surfaces ( void  )
static

Free existing surfaces

Definition at line 543 of file graphics.c.

◆ get_first_pixel()

Uint32 get_first_pixel ( SDL_Surface surf)

Get first pixel Return the pixel value at (0, 0) NOTE: The surface must be locked before calling this!

Definition at line 468 of file graphics.c.

◆ get_gui_layer()

struct gui_layer * get_gui_layer ( SDL_Surface surface)

Get surface gui_layer.

Definition at line 83 of file graphics.c.

◆ get_pixel()

Uint32 get_pixel ( SDL_Surface surf,
Sint16  x,
Sint16  y 
)

Get pixel Return the pixel value at (x, y) NOTE: The surface must be locked before calling this!

Definition at line 430 of file graphics.c.

Referenced by convert_iconlabel_to_themeiconlabel2(), create_themelabel2(), and SurfaceToCursor().

◆ get_smaller_surface_rect()

void get_smaller_surface_rect ( SDL_Surface surf,
SDL_Rect rect 
)

Get visible rectangle from surface.

Definition at line 757 of file graphics.c.

◆ gui_layer_destroy()

void gui_layer_destroy ( struct gui_layer **  gui_layer)

Free resources associated with gui_layer.

Definition at line 74 of file graphics.c.

◆ gui_layer_new()

struct gui_layer * gui_layer_new ( int  x,
int  y,
SDL_Surface surface 
)

Allocate new gui_layer.

Definition at line 59 of file graphics.c.

◆ init_sdl()

void init_sdl ( int  flags)

Initialize sdl with Flags

Definition at line 506 of file graphics.c.

◆ is_in_rect_area()

bool is_in_rect_area ( int  x,
int  y,
const SDL_Rect rect 
)

Return whether coordinates are in rectangle.

Definition at line 746 of file graphics.c.

◆ is_view_supported()

bool is_view_supported ( enum ts_type  type)

Return whether the client supports given view type

Definition at line 1146 of file graphics.c.

◆ layer_rect_to_screen_rect()

void layer_rect_to_screen_rect ( struct gui_layer gui_layer,
SDL_Rect dest_rect 
)

Translate dest_rect from gui_layer's to global screen coordinates.

Definition at line 178 of file graphics.c.

◆ load_surf()

SDL_Surface * load_surf ( const char fname)

Load a surface from file putting it in software mem.

Definition at line 308 of file graphics.c.

◆ main_window_height()

int main_window_height ( void  )

Return height of the main window

Definition at line 667 of file graphics.c.

◆ main_window_width()

int main_window_width ( void  )

Return width of the main window

Definition at line 659 of file graphics.c.

◆ mask_surface()

SDL_Surface * mask_surface ( SDL_Surface src,
SDL_Surface mask,
int  mask_offset_x,
int  mask_offset_y 
)

Reduce the alpha of the final surface proportional to the alpha of the mask. Thus if the mask has 50% alpha the final image will be reduced by 50% alpha.

mask_offset_x, mask_offset_y is the offset of the mask relative to the origin of the source image. The pixel at (mask_offset_x, mask_offset_y) in the mask image will be used to clip pixel (0, 0) in the source image which is pixel (-x, -y) in the new image.

Definition at line 256 of file graphics.c.

◆ quit_sdl()

void quit_sdl ( void  )

Free screen buffers

Definition at line 600 of file graphics.c.

◆ remove_gui_layer()

void remove_gui_layer ( struct gui_layer gui_layer)

Free buffer layer ( call by popdown_window_group_dialog(...) func ) Func. Free buffer layer and clear buffer array entry.

Definition at line 141 of file graphics.c.

◆ resize_surface()

SDL_Surface * resize_surface ( const SDL_Surface psrc,
Uint16  new_width,
Uint16  new_height,
int  smooth 
)

Scale surface.

Definition at line 1060 of file graphics.c.

◆ resize_surface_box()

SDL_Surface * resize_surface_box ( const SDL_Surface psrc,
Uint16  new_width,
Uint16  new_height,
int  smooth,
bool  scale_up,
bool  absolute_dimensions 
)

Resize a surface to fit into a box with the dimensions 'new_width' and a 'new_height'. If 'scale_up' is FALSE, a surface that already fits into the box will not be scaled up to the boundaries of the box. If 'absolute_dimensions' is TRUE, the function returns a surface with the dimensions of the box and the scaled/original surface centered in it.

Definition at line 1080 of file graphics.c.

◆ screen_blit()

int screen_blit ( SDL_Surface src,
SDL_Rect srcrect,
SDL_Rect dstrect,
unsigned char  alpha_mod 
)

Execute alphablit to the main surface

Definition at line 218 of file graphics.c.

◆ screen_rect_to_layer_rect()

void screen_rect_to_layer_rect ( struct gui_layer gui_layer,
SDL_Rect dest_rect 
)

Translate dest_rect from global screen to gui_layer's coordinates.

Definition at line 166 of file graphics.c.

◆ set_video_mode()

bool set_video_mode ( unsigned  width,
unsigned  height,
unsigned  flags_in 
)

Switch to given video mode.

Definition at line 614 of file graphics.c.

◆ tileset_type_set()

void tileset_type_set ( enum ts_type  type)

Loading tileset of the specified type

Definition at line 1160 of file graphics.c.

◆ update_main_screen()

void update_main_screen ( void  )

Render from main surface with screen renderer.

Definition at line 643 of file graphics.c.

Variable Documentation

◆ main_data

struct sdl3_data main_data

Definition at line 50 of file graphics.c.

◆ main_surface

SDL_Surface* main_surface = NULL
static

Definition at line 52 of file graphics.c.

◆ render_dirty

bool render_dirty = TRUE
static

Definition at line 54 of file graphics.c.