OSDN Git Service

guarantee an alter on oracle
[nethackexpress/trunk.git] / win / gnome / gnworn.c
1 /*      SCCS Id: @(#)gnbind.c   3.4     2002/04/15      */
2 /* Copyright (C) 2002, Dylan Alex Simon                 */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 #include "gnworn.h"
6 #include "gnglyph.h"
7 #include "gnsignal.h"
8 #include "gnomeprv.h"
9
10 #define WORN_WIDTH      3
11 #define WORN_HEIGHT     6
12
13 #ifdef TOURIST
14 #define WORN_OBJECT_LIST /* struct obj *[WORN_HEIGHT][WORN_WIDTH] = */ { \
15     { uquiver,  uarmh,      u.twoweap ? NULL : uswapwep }, \
16     { u.twoweap ? uswapwep : NULL,  ublindf,    uwep        }, \
17     { uleft,    uamul,      uright      }, \
18     { uarms,    uarmc,      uarmg       }, \
19     { uarmu,    uarm,       uskin       }, \
20     { uball,    uarmf,      uchain      } \
21 }
22 #else
23 #define WORN_OBJECT_LIST /* struct obj *[WORN_HEIGHT][WORN_WIDTH] = */ { \
24     { uquiver,  uarmh,      u.twoweap ? NULL : uswapwep }, \
25     { u.twoweap ? uswapwep : NULL,      ublindf,    uwep    }, \
26     { uleft,    uamul,      uright      }, \
27     { uarms,    uarmc,      uarmg       }, \
28     { NULL,     uarm,       uskin       }, \
29     { uball,    uarmf,      uchain      } \
30 }
31 #endif
32
33 static GtkWidget *worn_contents[WORN_HEIGHT][WORN_WIDTH];
34 static struct obj *last_worn_objects[WORN_HEIGHT][WORN_WIDTH];
35
36 GdkImlibImage *image_of_worn_object(struct obj *o);
37 void ghack_worn_display(GtkWidget *win, boolean block, gpointer data);
38
39 GtkWidget*
40 ghack_init_worn_window()
41 {
42     GtkWidget *top;
43     GtkWidget *table;
44     GtkWidget *tablealign;
45     GtkWidget *label;
46     int i,j;
47
48     top = gtk_vbox_new(FALSE, 2);
49
50     table = gtk_table_new(WORN_HEIGHT, WORN_WIDTH, TRUE);
51     for (i = 0; i < WORN_HEIGHT; i++) {
52         for (j = 0; j < WORN_WIDTH; j++) {
53             worn_contents[i][j] =
54                 gnome_pixmap_new_from_imlib(image_of_worn_object(NULL));
55             last_worn_objects[i][j] = NULL; /* a pointer that will never be */
56             gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(worn_contents[i][j]),
57                              j, j+1, i, i+1, 0, 0, 0, 0);
58         }
59     }
60     tablealign = gtk_alignment_new(0.5, 0.0, 0.0, 1.0);
61     gtk_box_pack_start(GTK_BOX(top), tablealign, FALSE, FALSE, 0);
62     gtk_container_add(GTK_CONTAINER(tablealign), table);
63
64     label = gtk_label_new("Equipment");
65     gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
66     gtk_box_pack_start(GTK_BOX(top), label, FALSE, FALSE, 0);
67
68     gtk_signal_connect(GTK_OBJECT(top), "ghack_display",
69                        GTK_SIGNAL_FUNC(ghack_worn_display), NULL);
70
71     return top;
72 }
73
74 GdkImlibImage*
75 image_of_worn_object(struct obj *o)
76 {
77     int glyph;
78     GdkImlibImage *im;
79
80     if (o)
81         glyph = obj_to_glyph(o);
82     else
83         glyph = cmap_to_glyph(S_stone);
84
85     im = ghack_image_from_glyph(glyph, FALSE);
86
87     return im;
88 }
89
90 void
91 ghack_worn_display(GtkWidget *win, boolean block, gpointer data)
92 {
93     int i, j;
94     struct obj *worn_objects[WORN_HEIGHT][WORN_WIDTH] = WORN_OBJECT_LIST;
95
96     for (i = 0; i < WORN_HEIGHT; i++) {
97         for (j = 0; j < WORN_WIDTH; j++) {
98             if (worn_objects[i][j] != last_worn_objects[i][j]) {
99                 last_worn_objects[i][j] = worn_objects[i][j];
100                 gnome_pixmap_load_imlib(GNOME_PIXMAP(worn_contents[i][j]),
101                                 image_of_worn_object(worn_objects[i][j]));
102             }
103         }
104     }
105 }