Crossfire Client, Trunk
map.c File Reference
#include "client.h"
#include <math.h>
#include <gtk/gtk.h>
#include "image.h"
#include "main.h"
#include "mapdata.h"
#include "gtk2proto.h"
+ Include dependency graph for map.c:

Go to the source code of this file.

Functions

static void coord_to_tile (int x, int y, int *dx, int *dy)
 
void display_map_doneupdate (int redraw, int notice)
 
int display_mapscroll (int dx, int dy)
 
static void draw_darkness (cairo_t *cr, int nx, int ny, int mx_start, int my_start)
 
void draw_map ()
 
static void draw_pixmap (cairo_t *cr, PixmapInfo *pixmap, int ax, int ay, int off_x, int off_y)
 
static void draw_smooth_pixmap (cairo_t *cr, PixmapInfo *pixmap, const int sx, const int sy, const int dx, const int dy)
 
static void drawsmooth (cairo_t *cr, int mx, int my, int layer, int picx, int picy)
 
static void gtk_map_redraw ()
 
static gboolean map_button_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
 
void map_check_resize ()
 
static void map_draw_layer (cairo_t *cr, int layer, int pass, int mx_start, int nx, int my_start, int ny, int off_x, int off_y)
 
static gboolean map_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
 
void map_init (GtkWidget *window_root)
 
static double mapcell_darkness (int mx, int my)
 
int relative_direction (int dx, int dy)
 
void resize_map_window (int x, int y)
 
static void update_global_offset ()
 

Variables

static GtkWidget * map_drawing_area
 
int map_image_size = DEFAULT_IMAGE_SIZE
 
GtkWidget * map_notebook
 
static gboolean map_updated = FALSE
 
int predict_alpha
 
bool time_map_redraw
 

Detailed Description

Initializes and renders the map drawing area. Handles map drawing area events, notably the "click to look at" mouse event.

Definition in file map.c.

Function Documentation

◆ coord_to_tile()

static void coord_to_tile ( int  x,
int  y,
int *  dx,
int *  dy 
)
static

Given x, y coordinates on the map drawing area, determine the tile that the coordinates are on with respect to the player. Clicking on the tile with the player returns (0, 0).

Definition at line 540 of file map.c.

References CONFIG_MAPHEIGHT, CONFIG_MAPSCALE, CONFIG_MAPWIDTH, map_drawing_area, map_image_size, and use_config.

Referenced by map_button_event().

+ Here is the caller graph for this function:

◆ display_map_doneupdate()

void display_map_doneupdate ( int  redraw,
int  notice 
)

This is called after the map has been all digested. this should perhaps be removed, and left to being done from from the main event loop.

Parameters
redrawIf set, force redraw of all tiles.
noticeIf set, another call will follow soon.

Definition at line 622 of file map.c.

References map_updated, and redraw().

Referenced by Map2Cmd(), map_scrollCmd(), and MapExtendedCmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ display_mapscroll()

int display_mapscroll ( int  dx,
int  dy 
)

Definition at line 156 of file map.c.

Referenced by mapdata_scroll().

+ Here is the caller graph for this function:

◆ draw_darkness()

static void draw_darkness ( cairo_t *  cr,
int  nx,
int  ny,
int  mx_start,
int  my_start 
)
static

Create light map nx wide, ny tall. Add a border 1px around to get rid of edge effects.

Definition at line 317 of file map.c.

References CFG_LT_PIXEL, CFG_LT_PIXEL_BEST, CFG_LT_TILE, CONFIG_LIGHTING, global_offset_x, global_offset_y, map_image_size, mapcell_darkness(), MIN, and use_config.

Referenced by gtk_map_redraw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_map()

void draw_map ( )

Draw the map window using the appropriate backend.

Definition at line 477 of file map.c.

References CONFIG_MAPSCALE, gtk_map_redraw(), LOG(), LOG_DEBUG, map_check_resize(), time_map_redraw, update_global_offset(), and use_config.

Referenced by map_expose_event(), and redraw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_pixmap()

static void draw_pixmap ( cairo_t *  cr,
PixmapInfo pixmap,
int  ax,
int  ay,
int  off_x,
int  off_y 
)
static

Draw a pixmap to the given map tile on screen.

Parameters
axMap cell on-screen x-coordinate
ayMap cell on-screen y-coordinate

Definition at line 138 of file map.c.

References global_offset_x, global_offset_y, PixmapInfo::map_image, and map_image_size.

Referenced by map_draw_layer().

+ Here is the caller graph for this function:

◆ draw_smooth_pixmap()

static void draw_smooth_pixmap ( cairo_t *  cr,
PixmapInfo pixmap,
const int  sx,
const int  sy,
const int  dx,
const int  dy 
)
static

Definition at line 145 of file map.c.

References global_offset_x, global_offset_y, PixmapInfo::map_image, and map_image_size.

Referenced by drawsmooth().

+ Here is the caller graph for this function:

◆ drawsmooth()

static void drawsmooth ( cairo_t *  cr,
int  mx,
int  my,
int  layer,
int  picx,
int  picy 
)
static

Draw anything in adjacent squares that could smooth on given square

Parameters
mx
mySquare to smooth on. You should not call this function to smooth on a 'completely black' square.
layerLayer to examine (we smooth only one layer at a time)
picx
picyPlace on the map_drawing_area->window to draw

Definition at line 170 of file map.c.

References draw_smooth_pixmap(), MapCellLayer::face, MapCell::heads, mapdata_can_smooth(), mapdata_cell(), mapdata_contains(), pixmaps, MapCell::smooth, and PixmapInfo::smooth_face.

Referenced by map_draw_layer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gtk_map_redraw()

static void gtk_map_redraw ( )
static

◆ map_button_event()

static gboolean map_button_event ( GtkWidget *  widget,
GdkEventButton *  event,
gpointer  user_data 
)
static

Handle a mouse event in the drawing area.

Definition at line 585 of file map.c.

References clear_fire(), coord_to_tile(), fire_dir(), look_at(), relative_direction(), run_move_to(), and set_move_to().

Referenced by map_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ map_draw_layer()

static void map_draw_layer ( cairo_t *  cr,
int  layer,
int  pass,
int  mx_start,
int  nx,
int  my_start,
int  ny,
int  off_x,
int  off_y 
)
static

Draw a single map layer to the given cairo context.

Definition at line 283 of file map.c.

References CONFIG_FOGWAR, CONFIG_SMOOTH, draw_pixmap(), drawsmooth(), mapdata_cell(), mapdata_face_info(), pixmaps, and use_config.

Referenced by gtk_map_redraw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ map_expose_event()

static gboolean map_expose_event ( GtkWidget *  widget,
GdkEventExpose *  event,
gpointer  user_data 
)
static

Definition at line 499 of file map.c.

References draw_map().

Referenced by map_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ map_init()

void map_init ( GtkWidget *  window_root)

This initializes the stuff we need for the map.

Parameters
window_rootThe client's main playing window.

Definition at line 86 of file map.c.

References CONFIG_MAPSCALE, DEFAULT_IMAGE_SIZE, do_new_image(), face_info, Face_Information_struct::faceset, Face_Information_struct::facesets, PixmapInfo::full_icon_height, PixmapInfo::full_icon_width, PixmapInfo::icon_height, PixmapInfo::icon_width, image_size, LOG(), LOG_ERROR, map_button_event(), map_check_resize(), map_drawing_area, map_expose_event(), map_image_size, map_notebook, pixmaps, rescale_rgba_data(), FaceSets_struct::size, use_config, and window_xml.

Referenced by show_main_client().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapcell_darkness()

static double mapcell_darkness ( int  mx,
int  my 
)
static

Definition at line 309 of file map.c.

References CONFIG_FOGWAR, MapCell::darkness, mapdata_cell(), and use_config.

Referenced by draw_darkness().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ relative_direction()

int relative_direction ( int  dx,
int  dy 
)

Given a relative tile coordinate, determine its compass direction.

Parameters
dxRelative 'x' coordinate
dyRelative 'y' coordinate
Returns
0 if x and y are both zero, 1-8 for each compass direction

Definition at line 511 of file map.c.

Referenced by map_button_event(), and run_move_to().

+ Here is the caller graph for this function:

◆ resize_map_window()

void resize_map_window ( int  x,
int  y 
)

Resize_map_window is a NOOP for the time being - not sure if it will in fact need to do something, since there are scrollbars for the map window now. Note - this is note a window resize request, but rather process the size (in spaces) of the map - is received from server.

Definition at line 463 of file map.c.

Referenced by SetupCmd().

+ Here is the caller graph for this function:

◆ update_global_offset()

static void update_global_offset ( )
static

Definition at line 466 of file map.c.

References global_offset_x, global_offset_y, map_image_size, predict_alpha, want_offset_x, and want_offset_y.

Referenced by draw_map().

+ Here is the caller graph for this function:

Variable Documentation

◆ map_drawing_area

GtkWidget* map_drawing_area
static

Definition at line 38 of file map.c.

Referenced by coord_to_tile(), gtk_map_redraw(), map_check_resize(), and map_init().

◆ map_image_size

◆ map_notebook

GtkWidget* map_notebook

Definition at line 37 of file map.c.

Referenced by client_tick(), draw_magic_map(), and map_init().

◆ map_updated

gboolean map_updated = FALSE
static

Definition at line 35 of file map.c.

Referenced by display_map_doneupdate(), and gtk_map_redraw().

◆ predict_alpha

int predict_alpha

Speed of local map prediction scrolling, 0-100 (0 to disable).

Definition at line 54 of file config.c.

Referenced by config_load(), save_defaults(), and update_global_offset().

◆ time_map_redraw

bool time_map_redraw

Definition at line 51 of file config.c.

Referenced by draw_map().