OSDN Git Service

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