Crossfire Client, Trunk  R20996
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 }
Warning that something might not work.
Definition: client.h:443
guint16 mmapy
Definition: client.h:360
guint16 pmapx
Definition: client.h:361
guint8 * magicmap
Definition: client.h:363
guint16 mapyres
Definition: client.h:366
void LOG(LogLevel level, const char *origin, const char *format,...)
Definition: misc.c:111
GtkWidget * magic_map
Definition: main.c:97
guint16 mmapx
Definition: client.h:360
Client_Player cpl
Definition: client.c:66
GtkWidget * map_notebook
Definition: map.c:44
GdkColor root_color[NUM_COLORS]
Definition: main.c:94
guint16 pmapy
Definition: client.h:361
guint8 showmagic
Definition: client.h:364
#define MAGIC_MAP_PAGE
Definition: main.h:39
gboolean on_drawingarea_magic_map_expose_event()
Definition: magicmap.c:87
#define FACE_COLOR_MASK
Definition: newclient.h:281
guint16 mapxres
Definition: client.h:366
void magic_map_flash_pos()
Definition: magicmap.c:77
void draw_magic_map()
Definition: magicmap.c:24