Crossfire Client, Branch  R11627
magicmap.c
Go to the documentation of this file.
00001 const char * const rcsid_gtk2_magicmap_c =
00002     "$Id: magicmap.c 9193 2008-06-01 14:26:32Z anmaster $";
00003 /*
00004     Crossfire client, a client program for the crossfire program.
00005 
00006     Copyright (C) 2005 Mark Wedel & Crossfire Development Team
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 
00022     The author can be reached via e-mail to crossfire@metalforge.org
00023 */
00024 
00030 #ifdef HAVE_CONFIG_H
00031 #  include <config.h>
00032 #endif
00033 
00034 #include <gtk/gtk.h>
00035 #include <glade/glade.h>
00036 
00037 #include "client.h"
00038 
00039 #include "main.h"
00040 
00041 extern GtkWidget *magic_map;    
00042 extern GtkWidget *map_notebook; 
00043 extern GdkColor root_color[NUM_COLORS];
00044 
00045 static GdkGC *magic_map_gc=NULL;
00046 
00051 void draw_magic_map(void)
00052 {
00053     int x=0, y=0;
00054 
00055     /*
00056      * This can happen if a person selects the magic map pane before actually
00057      * getting any magic map data
00058      */
00059     if (!cpl.magicmap) return;
00060 
00061     /*
00062      * Have to set this so that the gtk_widget_show below actually creates the
00063      * widget.  Switch to this page when person actually casts magic map spell.
00064      */
00065     gtk_notebook_set_current_page(GTK_NOTEBOOK(map_notebook), MAGIC_MAP_PAGE);
00066 
00067     gtk_widget_show(magic_map);
00068 
00069     if (!magic_map_gc) magic_map_gc = gdk_gc_new (magic_map->window);
00070 
00071     gdk_gc_set_foreground (magic_map_gc, &root_color[0]);
00072     gdk_draw_rectangle (magic_map->window, magic_map_gc,
00073                        TRUE,
00074                        0,
00075                        0,
00076                        magic_map->allocation.width,
00077                        magic_map->allocation.height);
00078 
00079     cpl.mapxres = magic_map->allocation.width/cpl.mmapx;
00080     cpl.mapyres = magic_map->allocation.height/cpl.mmapy;
00081 
00082     if (cpl.mapxres < 1 || cpl.mapyres<1) {
00083         LOG(LOG_WARNING,"gtk::draw_magic_map","magic map resolution less than 1, map is %dx%d",
00084               cpl.mmapx, cpl.mmapy);
00085         return;
00086     }
00087 
00088     /*
00089      * In theory, cpl.mapxres and cpl.mapyres do not have to be the same.
00090      * However, it probably makes sense to keep them the same value.  Need to
00091      * take the smaller value.
00092      */
00093     if (cpl.mapxres>cpl.mapyres) cpl.mapxres=cpl.mapyres;
00094     else cpl.mapyres=cpl.mapxres;
00095 
00096     /*
00097      * This is keeping the same unpacking scheme that the server uses to pack
00098      * it up.
00099      */
00100     for (y = 0; y < cpl.mmapy; y++) {
00101         for (x = 0; x < cpl.mmapx; x++) {
00102             uint8 val = cpl.magicmap[y*cpl.mmapx + x];
00103 
00104             gdk_gc_set_foreground(
00105                 magic_map_gc, &root_color[val&FACE_COLOR_MASK]);
00106 
00107             gdk_draw_rectangle(magic_map->window, magic_map_gc,
00108                                TRUE,
00109                                cpl.mapxres*x,
00110                                cpl.mapyres*y,
00111                                cpl.mapxres,
00112                                cpl.mapyres);
00113         }
00114     }
00115 }
00116 
00120 void magic_map_flash_pos(void)
00121 {
00122     /*
00123      * Don't want to keep doing this if the user switches back to the map
00124      * window.
00125      */
00126     if (gtk_notebook_get_current_page(GTK_NOTEBOOK(map_notebook))!=MAGIC_MAP_PAGE) {
00127         cpl.showmagic=0;
00128     }
00129 
00130     if (!cpl.showmagic) return;
00131 
00132     cpl.showmagic ^=2;
00133     if (cpl.showmagic & 2) {
00134         gdk_gc_set_foreground (magic_map_gc, &root_color[0]);
00135     } else {
00136         gdk_gc_set_foreground (magic_map_gc, &root_color[1]);
00137     }
00138     gdk_draw_rectangle (magic_map->window, magic_map_gc,
00139                       TRUE,
00140                       cpl.mapxres*cpl.pmapx,
00141                       cpl.mapyres*cpl.pmapy,
00142                       cpl.mapxres,
00143                       cpl.mapyres);
00144 }
00145 
00153 gboolean
00154 on_drawingarea_magic_map_expose_event  (GtkWidget       *widget,
00155                                         GdkEventExpose  *event,
00156                                         gpointer         user_data)
00157 {
00158     draw_magic_map();
00159     return FALSE;
00160 }