File: lln_window.c

package info (click to toggle)
lletters 0.1.95-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,152 kB
  • ctags: 502
  • sloc: sh: 9,985; ansic: 3,225; makefile: 230; sed: 93; perl: 50
file content (250 lines) | stat: -rw-r--r-- 6,825 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* 
 *  Linux Letters and Numbers
 *  By Kirk Ismay, <captain@netidea.com> 
 * 
 *  Based on my daughters once favorite game, Larry's Letters and Numbers.
 *  This is a Linux replacement, as the original was written for Windows. 
 *  I have made several improvements too.*/

#include <string.h>
#include "lletters.h"

extern int ll_sound;

/* Set the font of a widget */
void
lln_set_widget_font (GtkWidget * widget)
{
  /*GtkStyle *style;

    gtk_widget_ensure_style (widget);
  style = gtk_style_copy (widget->style);

  style->font = gdk_font_load ("-*-utopia-*-r-*-*-60-400-*-*-*-*-*-*");

  gtk_widget_set_style (widget, style);*/
  gtk_widget_set_name  (widget, "main_label");

}

void
close_my_window (GtkWidget * widget, GtkWidget * window)
{
  gtk_widget_destroy (window);
}

int
close_window (GtkWidget * widget, GdkEvent * event, GtkWidget * window)
{
  gtk_widget_destroy (window);
  return TRUE;
}

void
lln_pack_image_in_box (GtkWidget * parent, GtkWidget * box, gchar * filename)
{/* Largely based upon contributions from Paul Keinzle. 01-Mar-99 */

  GtkWidget *pixmapwid;
  GdkPixmap *pixmap;
  GdkBitmap *mask;
  GtkStyle *style;
  GdkImlibImage *image;

  style = gtk_widget_get_style (parent);

  image = gdk_imlib_load_image(g_strconcat(lln_image_dir, filename, NULL));

  gdk_imlib_render(image, image->rgb_width, image->rgb_height);

  pixmap = gdk_imlib_move_image(image);
  mask = gdk_imlib_move_mask(image);

  pixmapwid = gtk_pixmap_new (pixmap, mask);

  gtk_box_pack_start (GTK_BOX (box), pixmapwid, FALSE, FALSE, 0);

  /* KI: This gets the image out of the imlib cache. Prevents a
   * problem where pictures took a long time to load */

  gdk_imlib_kill_image(image);
  gdk_imlib_free_pixmap(pixmap);

}

/* Play the sound file corresponding to the image file name */
/* Adapted from contributions by Paul Keinzle. */
gint
lln_sound_play(gpointer *filename)
{
#ifdef SOUND
  gchar *soundfile, *ext;
  if (ll_sound == TRUE) {
  if (filename) { 

    /* Remove the image file name extension. Paul Keinzle.*/
    ext = strrchr(filename, '.');
    if (ext == NULL)
      soundfile = g_strconcat(lln_sound_dir, filename, ".wav", NULL);
    else {
      *ext = '\0';
      soundfile = g_strconcat(lln_sound_dir, filename, ".wav", NULL);
      *ext = '.';
    }
    /* End change. PK */

    /* Added check to see if file is really there. KI */ 
    if (lln_check_file (soundfile)==TRUE) {
      play_file (soundfile);
      g_free (soundfile);
    }

    else {
      g_warning (_("No sound file matching \'%s\'\n"), soundfile);
      g_free(soundfile);
    }
  }
  }
#endif

  lln_ignore = FALSE;

  return (FALSE);
}

GtkWidget*
lln_image_popup_new (char filename[], char title[], char label[])
{/* Largely based upon contributions from Paul Keinzle. 01-Mar-99 */

  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *caption, *info ; 
  GtkWidget *main_box, *button_box, *img_box, *box_label;

  /* Create the popup window */
  window = gtk_window_new (GTK_WINDOW_POPUP);
  gtk_widget_set_name  (window, "lln_popup");
  
  gtk_grab_add(window);

  gtk_window_set_title (GTK_WINDOW (window), title);
  gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_container_border_width (GTK_CONTAINER (window), 5);

  gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
		      GTK_SIGNAL_FUNC (get_keystroke), (gpointer) 1);
  gtk_signal_connect (GTK_OBJECT (window), "key_release_event",
		      GTK_SIGNAL_FUNC (get_keystroke), (gpointer) 1);
  gtk_signal_connect (GTK_OBJECT (window), "delete_event",
                      GTK_SIGNAL_FUNC (close_window), window);
  
  gtk_widget_realize (GTK_WIDGET (window));

  /* put a vertical container inside the window */
  main_box = gtk_vbox_new (FALSE, 0);
  button_box = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), button_box);

  /* add a button (centered and clickable) */
  button = gtk_button_new ();
  gtk_widget_set_name  (button, "lln_popup_button");

  gtk_signal_connect (GTK_OBJECT (button), "button_press_event",
  	      GTK_SIGNAL_FUNC (retransmit_press), window);
  gtk_signal_connect (GTK_OBJECT (button), "button_release_event",
  	      GTK_SIGNAL_FUNC (retransmit_release), window);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (close_my_window), window);

  gtk_box_pack_start (GTK_BOX (button_box), button, TRUE, TRUE, 0);
  
  /* get our image */  
  if (filename) {
    img_box = gtk_hbox_new (TRUE, 0);
    lln_pack_image_in_box (window, img_box, filename);
    gtk_box_pack_start (GTK_BOX (main_box), img_box, TRUE, TRUE, 0);
  } 

  /* finally add some text */
  if (label) {
    caption = gtk_label_new (label);
    lln_set_widget_font (caption);
    gtk_box_pack_start (GTK_BOX (main_box), caption, TRUE, TRUE, 0);
  }
   gtk_container_add (GTK_CONTAINER (button), main_box);   
  /* Brief Instructions */
  info = gtk_label_new (_("Press any key or click on the image\nto  go back to the main window.")); 
  gtk_box_pack_start (GTK_BOX (main_box), info, TRUE, TRUE, 0);

  /* Display it all */
  gtk_widget_show_all (window);

  return window;

}

void
lln_show_letter (GtkWidget * widget, gpointer * data)
{
  GtkWidget *window;
  char title[255], caption[255], *filename, *word;
  char letter = (char) ( (int) data);  /* Odd cast to prevent bogus warning */

  /* Ignore events until window is closed. Paul Keinzle */ 
  if (lln_ignore == TRUE) return;

  lln_ignore = TRUE;
/* Begin change JPV - 1999/03/06 */
  sprintf (title, _("The Letter %c"), letter);
/* End change JPV - 1999/03/06 */

  filename = lln_get_file (letter);
  if (filename) {
      sprintf (caption, "%c, %s", 
	     lln_get_1st_letter ((char *) filename),
	     lln_get_word ((char *) filename));
  } 
  else{

/* Begin change JPV - 1999/03/06 */
    sprintf(caption, _("No matching image\nfiles for %c!"), letter);
/* End change JPV - 1999/03/06 */

  }
  
  window = lln_image_popup_new (filename, title, caption);
  gtk_timeout_add(500, (gpointer) lln_sound_play, filename);

}

void
lln_show_number (GtkWidget * widget, gpointer * data)
{
  GtkWidget *window;
  char title[255], *caption, *filename;
  int number = (int) data;

  /* Ignore events until window is closed. Paul Keinzle */ 
  if (lln_ignore == TRUE) return;

  lln_ignore = TRUE;
  
/* Begin change JPV - 1999/03/06 */
  sprintf (title, _("The Number %i"), number);
/* End change JPV - 1999/03/06 */

  filename = lln_get_file ((char) number + 48);
  if (filename) {
    caption = lln_get_number ((char *) filename);
  }
  else{

/* Begin change JPV - 1999/03/06 */
    sprintf(caption, _("No Matching image\nfiles for %i!"), number);
/* End change JPV - 1999/03/06 */

  }
  
  window = lln_image_popup_new (filename, title, caption);
  gtk_timeout_add(500, (gpointer) lln_sound_play, filename);
}