Crossfire Client, Trunk
magicmap.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2013 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, see the
9  * 'LICENSE' and 'COPYING' files.
10  *
11  * The authors can be reached via e-mail to crossfire-devel@real-time.com
12  */
13 
19 #include <gtk/gtk.h>
20 
21 #include "client.h"
22 #include "main.h"
23 
25  if (!cpl.magicmap) {
26  // Do nothing if player has no magic map data.
27  return;
28  } else {
29  cpl.showmagic = 1;
30  }
31 
32  /*
33  * Have to set this so that the gtk_widget_show below actually creates the
34  * widget. Switch to this page when person actually casts magic map spell.
35  */
36  gtk_notebook_set_current_page(GTK_NOTEBOOK(map_notebook), MAGIC_MAP_PAGE);
37 
38  GdkWindow *window = gtk_widget_get_window(magic_map);
39  gdk_window_clear(window);
40 
41  cpl.mapxres = gdk_window_get_width(window) / cpl.mmapx;
42  cpl.mapyres = gdk_window_get_height(window) / cpl.mmapy;
43  if (cpl.mapxres < 1 || cpl.mapyres < 1) {
44  LOG(LOG_WARNING, "draw_magic_map",
45  "magic map resolution less than 1, map is %dx%d", cpl.mmapx,
46  cpl.mmapy);
47  return;
48  }
49 
50  /*
51  * In theory, cpl.mapxres and cpl.mapyres do not have to be the same.
52  * However, it probably makes sense to keep them the same value. Need to
53  * take the smaller value.
54  */
55  if (cpl.mapxres > cpl.mapyres) {
57  } else {
59  }
60 
61  cairo_t *cr = gdk_cairo_create(GDK_DRAWABLE(window));
62  for (int y = 0; y < cpl.mmapy; y++) {
63  for (int x = 0; x < cpl.mmapx; x++) {
64  guint8 val = cpl.magicmap[y * cpl.mmapx + x];
65  gdk_cairo_set_source_color(cr, &root_color[val & FACE_COLOR_MASK]);
66  cairo_rectangle(cr, cpl.mapxres * x, cpl.mapyres * y, cpl.mapxres,
67  cpl.mapyres);
68  cairo_fill(cr);
69  }
70  }
71  cairo_destroy(cr);
72 }
73 
78  GdkWindow *window = gtk_widget_get_window(magic_map);
79  cairo_t *cr = gdk_cairo_create(GDK_DRAWABLE(window));
80  gdk_cairo_set_source_color(cr, &root_color[(cpl.showmagic & 2) ? 0 : 1]);
81  cairo_rectangle(cr, cpl.mapxres * cpl.pmapx, cpl.mapyres * cpl.pmapy,
83  cairo_fill(cr);
84  cairo_destroy(cr);
85 }
86 
89  return FALSE;
90 }
LOG_WARNING
@ LOG_WARNING
Warning that something might not work.
Definition: client.h:435
Player_Struct::mapyres
guint16 mapyres
Definition: client.h:364
draw_magic_map
void draw_magic_map()
Definition: magicmap.c:24
map_notebook
GtkWidget * map_notebook
Definition: map.c:37
MAGIC_MAP_PAGE
#define MAGIC_MAP_PAGE
Definition: main.h:42
Player_Struct::mmapx
guint16 mmapx
Definition: client.h:358
Player_Struct::pmapx
guint16 pmapx
Definition: client.h:359
root_color
GdkColor root_color[NUM_COLORS]
Definition: main.c:100
LOG
void LOG(LogLevel level, const char *origin, const char *format,...)
Definition: misc.c:111
Player_Struct::magicmap
guint8 * magicmap
Definition: client.h:361
Player_Struct::showmagic
guint8 showmagic
Definition: client.h:362
Player_Struct::mapxres
guint16 mapxres
Definition: client.h:364
Player_Struct::pmapy
guint16 pmapy
Definition: client.h:359
main.h
cpl
Client_Player cpl
Definition: client.c:69
magic_map
GtkWidget * magic_map
Definition: main.c:103
Player_Struct::mmapy
guint16 mmapy
Definition: client.h:358
on_drawingarea_magic_map_expose_event
gboolean on_drawingarea_magic_map_expose_event()
Definition: magicmap.c:87
FACE_COLOR_MASK
#define FACE_COLOR_MASK
Definition: newclient.h:276
client.h
magic_map_flash_pos
void magic_map_flash_pos()
Definition: magicmap.c:77