Crossfire Client, Branches  R11627
magicmap.c
Go to the documentation of this file.
1 const char * const rcsid_gtk2_magicmap_c =
2  "$Id: magicmap.c 9193 2008-06-01 14:26:32Z anmaster $";
3 /*
4  Crossfire client, a client program for the crossfire program.
5 
6  Copyright (C) 2005 Mark Wedel & Crossfire Development Team
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 
22  The author can be reached via e-mail to crossfire@metalforge.org
23 */
24 
30 #ifdef HAVE_CONFIG_H
31 # include <config.h>
32 #endif
33 
34 #include <gtk/gtk.h>
35 #include <glade/glade.h>
36 
37 #include "client.h"
38 
39 #include "main.h"
40 
41 extern GtkWidget *magic_map;
42 extern GtkWidget *map_notebook;
43 extern GdkColor root_color[NUM_COLORS];
44 
45 static GdkGC *magic_map_gc=NULL;
46 
51 void draw_magic_map(void)
52 {
53  int x=0, y=0;
54 
55  /*
56  * This can happen if a person selects the magic map pane before actually
57  * getting any magic map data
58  */
59  if (!cpl.magicmap) return;
60 
61  /*
62  * Have to set this so that the gtk_widget_show below actually creates the
63  * widget. Switch to this page when person actually casts magic map spell.
64  */
65  gtk_notebook_set_current_page(GTK_NOTEBOOK(map_notebook), MAGIC_MAP_PAGE);
66 
67  gtk_widget_show(magic_map);
68 
69  if (!magic_map_gc) magic_map_gc = gdk_gc_new (magic_map->window);
70 
71  gdk_gc_set_foreground (magic_map_gc, &root_color[0]);
72  gdk_draw_rectangle (magic_map->window, magic_map_gc,
73  TRUE,
74  0,
75  0,
76  magic_map->allocation.width,
77  magic_map->allocation.height);
78 
79  cpl.mapxres = magic_map->allocation.width/cpl.mmapx;
80  cpl.mapyres = magic_map->allocation.height/cpl.mmapy;
81 
82  if (cpl.mapxres < 1 || cpl.mapyres<1) {
83  LOG(LOG_WARNING,"gtk::draw_magic_map","magic map resolution less than 1, map is %dx%d",
84  cpl.mmapx, cpl.mmapy);
85  return;
86  }
87 
88  /*
89  * In theory, cpl.mapxres and cpl.mapyres do not have to be the same.
90  * However, it probably makes sense to keep them the same value. Need to
91  * take the smaller value.
92  */
94  else cpl.mapyres=cpl.mapxres;
95 
96  /*
97  * This is keeping the same unpacking scheme that the server uses to pack
98  * it up.
99  */
100  for (y = 0; y < cpl.mmapy; y++) {
101  for (x = 0; x < cpl.mmapx; x++) {
102  uint8 val = cpl.magicmap[y*cpl.mmapx + x];
103 
104  gdk_gc_set_foreground(
106 
107  gdk_draw_rectangle(magic_map->window, magic_map_gc,
108  TRUE,
109  cpl.mapxres*x,
110  cpl.mapyres*y,
111  cpl.mapxres,
112  cpl.mapyres);
113  }
114  }
115 }
116 
121 {
122  /*
123  * Don't want to keep doing this if the user switches back to the map
124  * window.
125  */
126  if (gtk_notebook_get_current_page(GTK_NOTEBOOK(map_notebook))!=MAGIC_MAP_PAGE) {
127  cpl.showmagic=0;
128  }
129 
130  if (!cpl.showmagic) return;
131 
132  cpl.showmagic ^=2;
133  if (cpl.showmagic & 2) {
134  gdk_gc_set_foreground (magic_map_gc, &root_color[0]);
135  } else {
136  gdk_gc_set_foreground (magic_map_gc, &root_color[1]);
137  }
138  gdk_draw_rectangle (magic_map->window, magic_map_gc,
139  TRUE,
142  cpl.mapxres,
143  cpl.mapyres);
144 }
145 
153 gboolean
155  GdkEventExpose *event,
156  gpointer user_data)
157 {
158  draw_magic_map();
159  return FALSE;
160 }
uint16 pmapx
Definition: client.h:297
GtkWidget * magic_map
Definition: main.c:56
GtkWidget * map_notebook
Definition: map.c:68
static XEvent event
Definition: x11.c:193
#define FACE_COLOR_MASK
Definition: newclient.h:251
uint8 * magicmap
Definition: client.h:299
uint16 pmapy
Definition: client.h:297
gboolean on_drawingarea_magic_map_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
Definition: magicmap.c:154
void LOG(LogLevel level, const char *origin, const char *format,...)
Definition: misc.c:178
#define TRUE
Definition: client-types.h:71
static GdkGC * magic_map_gc
Definition: magicmap.c:45
Client_Player cpl
Definition: client.c:77
uint16 mapxres
Definition: client.h:302
uint16 mmapy
Definition: client.h:296
#define NUM_COLORS
Definition: main.h:32
GdkColor root_color[NUM_COLORS]
Definition: gx11.c:244
#define MAGIC_MAP_PAGE
Definition: main.h:45
uint8 showmagic
Definition: client.h:300
const char *const rcsid_gtk2_magicmap_c
Definition: magicmap.c:1
uint16 mapyres
Definition: client.h:302
void magic_map_flash_pos(void)
Definition: magicmap.c:120
unsigned char uint8
Definition: client-types.h:81
uint16 mmapx
Definition: client.h:296
#define FALSE
Definition: client-types.h:68
void draw_magic_map(void)
Definition: magicmap.c:51