~ubuntu-branches/ubuntu/vivid/imaze/vivid

« back to all changes in this revision

Viewing changes to source/Xt_fenster.c

  • Committer: Bazaar Package Importer
  • Author(s): Hans Freitag
  • Date: 2002-11-28 13:24:12 UTC
  • Revision ID: james.westby@ubuntu.com-20021128132412-lw82xl9oq1j36g8b
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** - - -  iMaze  - - -
 
3
**
 
4
** Copyright (c) 1993-2001 by Hans-Ulrich Kiel & Joerg Czeranski
 
5
** All rights reserved.
 
6
**
 
7
** Redistribution and use in source and binary forms, with or without
 
8
** modification, are permitted provided that the following conditions are
 
9
** met:
 
10
**
 
11
** 1. Redistributions of source code must retain the above copyright
 
12
**    notice, this list of conditions and the following disclaimer.
 
13
** 2. Redistributions in binary form must reproduce the above copyright
 
14
**    notice, this list of conditions and the following disclaimer in the
 
15
**    documentation and/or other materials provided with the distribution.
 
16
** 3. The name of the authors may not be used to endorse or promote
 
17
**    products derived from this software without specific prior written
 
18
**    permission.
 
19
** 4. The name ``iMaze'' may not be used for products derived from this
 
20
**    software unless a prefix or a suffix is added to the name.
 
21
**
 
22
** THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 
23
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
24
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
25
** DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT,
 
26
** INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
27
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
28
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
29
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
30
** STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 
31
** IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
32
** POSSIBILITY OF SUCH DAMAGE.
 
33
**
 
34
**
 
35
** Datei: Xt_fenster.c
 
36
**
 
37
** Kommentar:
 
38
**  Fensterverwaltung auf Basis des X Toolkit,
 
39
**  wird fuer Motif und Athena verwendet
 
40
*/
 
41
 
 
42
 
 
43
#include <stdio.h>
 
44
#include <stdlib.h>
 
45
#include <signal.h>
 
46
#include <X11/Intrinsic.h>
 
47
#include <X11/StringDefs.h>
 
48
#include <X11/Shell.h>
 
49
 
 
50
#include "argv.h"
 
51
#include "grafik.h"
 
52
#include "signale.h"
 
53
#include "ereignisse.h"
 
54
#include "client.h"
 
55
#include "fehler.h"
 
56
#include "speicher.h"
 
57
#include "X_grafik.h"
 
58
#include "X_tasten.h"
 
59
#include "X_daten.h"
 
60
#include "X_icon.h"
 
61
#include "Xt_appdefs.h"
 
62
#include "audio.h"
 
63
#include "Xt_fenster.h"
 
64
 
 
65
static char sccsid[] = "@(#)Xt_fenster.c        3.18 12/05/01";
 
66
 
 
67
 
 
68
#define STR_LENGTH 256
 
69
 
 
70
 
 
71
struct arg_option einaus_opts[] =
 
72
{
 
73
        { Arg_Include, NULL, X_eingabe_opts },
 
74
        { Arg_Include, NULL, audio_opts },
 
75
        { Arg_End }
 
76
};
 
77
 
 
78
 
 
79
/* application resources */
 
80
static struct res_data
 
81
{
 
82
        char *audio_directory;
 
83
} res_data;
 
84
static XtResource res_list[] =
 
85
{
 
86
        {
 
87
                XtNsoundDirectory,
 
88
                XtCSoundDirectory,
 
89
                XtRString,
 
90
                sizeof(char *),
 
91
                XtOffsetOf(struct res_data, audio_directory),
 
92
                XtRString,
 
93
                "" /* use DEFAULT_SOUND_DIR in audio.c */
 
94
        }
 
95
};
 
96
 
 
97
static int toplevel_exists = 0;
 
98
 
 
99
static struct blickfelddaten frontview_data;
 
100
static struct blickfelddaten rearview_data;
 
101
static int compass_data;
 
102
static struct punktedaten score_data;
 
103
static struct grundrissdaten map_data;
 
104
 
 
105
static int connected = 0;
 
106
 
 
107
static int network_proc_active = 0;
 
108
static XtInputId network_proc_id;
 
109
 
 
110
static XtInputId audio_select_id;
 
111
 
 
112
static int audio_is_active = 0;
 
113
static int audio_select_pending = 0;
 
114
 
 
115
static void (*audio_signal_handler)(void) = NULL;
 
116
 
 
117
 
 
118
static void audio_select_handler(XtPointer function, int *descriptor,
 
119
        XtInputId *id)
 
120
{
 
121
        ((void (*)(void))function)();
 
122
}
 
123
 
 
124
 
 
125
static void handle_audio_signal(int signal)
 
126
{
 
127
        if (audio_signal_handler != NULL)
 
128
                audio_signal_handler();
 
129
}
 
130
 
 
131
 
 
132
static void popdown_view(struct xt_view *view)
 
133
{
 
134
        if (!view->is_open)
 
135
                return;
 
136
 
 
137
        XtPopdown(view->w);
 
138
        view->is_open = 0;
 
139
}
 
140
 
 
141
 
 
142
static void view_redraw(struct xt_view *view)
 
143
{
 
144
        X_zeichne_sync_anfang(view->window.display);
 
145
        view->redraw(view->X_data, &view->window, view->data);
 
146
        X_zeichne_sync_ende(view->window.display);
 
147
}
 
148
 
 
149
 
 
150
static void set_pause_mode(int in_pause)
 
151
{
 
152
        Arg arglist[1];
 
153
 
 
154
        XtSetArg(arglist[0], XtNsensitive, !in_pause);
 
155
        XtSetValues(xt_pause_button_w, arglist, 1);
 
156
 
 
157
        XtSetArg(arglist[0], XtNsensitive, in_pause);
 
158
        XtSetValues(xt_resume_button_w, arglist, 1);
 
159
}
 
160
 
 
161
 
 
162
static void stop_network_proc(void)
 
163
{
 
164
        if (!network_proc_active)
 
165
                return;
 
166
 
 
167
        network_proc_active = 0;
 
168
        XtRemoveInput(network_proc_id);
 
169
 
 
170
        xt_frontview.was_open = xt_frontview.is_open;
 
171
        xt_rearview.was_open = xt_rearview.is_open;
 
172
        xt_compassview.was_open = xt_compassview.is_open;
 
173
        xt_scoreview.was_open = xt_scoreview.is_open;
 
174
        xt_mapview.was_open = xt_mapview.is_open;
 
175
}
 
176
 
 
177
 
 
178
static void finish_disconnect(void)
 
179
{
 
180
        Arg arglist[1];
 
181
 
 
182
        XtSetArg(arglist[0], XtNsensitive, False);
 
183
        XtSetValues(xt_disconnect_button_w, arglist, 1);
 
184
        XtSetValues(xt_pause_button_w, arglist, 1);
 
185
        XtSetValues(xt_resume_button_w, arglist, 1);
 
186
 
 
187
        stop_network_proc();
 
188
 
 
189
        popdown_view(&xt_rearview);
 
190
        popdown_view(&xt_compassview);
 
191
        popdown_view(&xt_scoreview);
 
192
        popdown_view(&xt_mapview);
 
193
 
 
194
        frontview_data.titelbild = 1;
 
195
        if (xt_frontview.is_open)
 
196
                view_redraw(&xt_frontview);
 
197
 
 
198
        xt_set_status_label("Not connected");
 
199
        xt_set_option_sensitivity(True);
 
200
}
 
201
 
 
202
 
 
203
static void do_disconnect(void)
 
204
{
 
205
        Arg arglist[1];
 
206
        char *server_name;
 
207
        char status_msg[STR_LENGTH];
 
208
 
 
209
        if (!connected)
 
210
                return;
 
211
 
 
212
        connected = 0;
 
213
 
 
214
        XtSetArg(arglist[0], XtNsensitive, False);
 
215
        XtSetValues(xt_disconnect_button_w, arglist, 1);
 
216
        XtSetValues(xt_pause_button_w, arglist, 1);
 
217
        XtSetValues(xt_resume_button_w, arglist, 1);
 
218
 
 
219
        stop_network_proc();
 
220
 
 
221
        popdown_view(&xt_rearview);
 
222
        popdown_view(&xt_compassview);
 
223
        popdown_view(&xt_scoreview);
 
224
        popdown_view(&xt_mapview);
 
225
 
 
226
        frontview_data.titelbild = 1;
 
227
        if (xt_frontview.is_open)
 
228
                view_redraw(&xt_frontview);
 
229
 
 
230
        server_name = xt_get_string_value(xt_server_field_w);
 
231
 
 
232
        strcpy(status_msg, "Disconnecting from ");
 
233
        strncat(status_msg, server_name,
 
234
                sizeof status_msg - strlen(status_msg));
 
235
 
 
236
        xt_set_status_label(status_msg);
 
237
 
 
238
        XFlush(XtDisplay(xt_toplevel));
 
239
 
 
240
        client_spiel_beenden();
 
241
 
 
242
        xt_set_status_label("Not connected");
 
243
        xt_set_option_sensitivity(True);
 
244
}
 
245
 
 
246
 
 
247
static void network_ready_handler(XtPointer data, int *source, XtInputId *id)
 
248
{
 
249
        if (bewegung(0, 1))
 
250
        {
 
251
                char **error_message;
 
252
                char *button_label;
 
253
 
 
254
                milden_fehler_abfragen(&error_message, &button_label);
 
255
                ueblen_fehler_anzeigen(error_message, button_label);
 
256
 
 
257
                if (connected)
 
258
                        do_disconnect();
 
259
                else
 
260
                        finish_disconnect();
 
261
        }
 
262
}
 
263
 
 
264
 
 
265
static Boolean connect_work_proc(XtPointer closure)
 
266
{
 
267
        Arg arglist[1];
 
268
        char server_name[STR_LENGTH], message_name[STR_LENGTH];
 
269
        char status_msg[STR_LENGTH];
 
270
        Boolean camera_mode;
 
271
        int *descriptor;
 
272
 
 
273
        if (connected)
 
274
                return True;
 
275
 
 
276
        strncpy(server_name, xt_get_string_value(xt_server_field_w),
 
277
                sizeof server_name);
 
278
        server_name[sizeof server_name - 1] = 0;
 
279
 
 
280
        strncpy(message_name, xt_get_string_value(xt_message_field_w),
 
281
                sizeof message_name);
 
282
        message_name[sizeof message_name - 1] = 0;
 
283
 
 
284
        camera_mode = xt_get_toggle_value(xt_camera_toggle_w);
 
285
 
 
286
        if (client_spiel_starten(server_name, message_name, camera_mode))
 
287
        {
 
288
                char **error_message;
 
289
                char *button_label;
 
290
 
 
291
                milden_fehler_abfragen(&error_message, &button_label);
 
292
                ueblen_fehler_anzeigen(error_message, button_label);
 
293
 
 
294
                finish_disconnect();
 
295
                return True;
 
296
        }
 
297
 
 
298
        if ((descriptor = bewegung_deskriptor()) != NULL)
 
299
        {
 
300
                network_proc_id = XtAppAddInput(xt_app_context, *descriptor,
 
301
                        (XtPointer)XtInputReadMask, network_ready_handler,
 
302
                        NULL);
 
303
                network_proc_active = 1;
 
304
        }
 
305
 
 
306
        connected = 1;
 
307
        frontview_data.titelbild = 0;
 
308
 
 
309
        if (xt_frontview.was_open)
 
310
                xt_popup_view(&xt_frontview);
 
311
 
 
312
        if (xt_rearview.was_open)
 
313
                xt_popup_view(&xt_rearview);
 
314
 
 
315
        if (xt_compassview.was_open)
 
316
                xt_popup_view(&xt_compassview);
 
317
 
 
318
        if (xt_scoreview.was_open)
 
319
                xt_popup_view(&xt_scoreview);
 
320
 
 
321
        if (xt_mapview.was_open)
 
322
                xt_popup_view(&xt_mapview);
 
323
 
 
324
        strcpy(status_msg, "Connected to ");
 
325
        strncat(status_msg, server_name,
 
326
                sizeof status_msg - strlen(status_msg));
 
327
 
 
328
        xt_set_status_label(status_msg);
 
329
 
 
330
        XtSetArg(arglist[0], XtNsensitive, True);
 
331
        XtSetValues(xt_disconnect_button_w, arglist, 1);
 
332
 
 
333
        set_pause_mode(0);
 
334
        return True;
 
335
}
 
336
 
 
337
 
 
338
static void destroy_handler(Widget widget, XtPointer client_data,
 
339
        XtPointer call_data)
 
340
{
 
341
        toplevel_exists = 0;
 
342
 
 
343
        exit(0);
 
344
}
 
345
 
 
346
 
 
347
/* bis hier lokaler Teil                       */
 
348
/***********************************************/
 
349
/* ab hier globaler Teil                       */
 
350
 
 
351
 
 
352
void xt_view_init(struct xt_view *view)
 
353
{
 
354
        Arg arglist[3];
 
355
        Dimension width, height;
 
356
        unsigned int depth;
 
357
 
 
358
        XtSetArg(arglist[0], XtNwidth, &width);
 
359
        XtSetArg(arglist[1], XtNheight, &height);
 
360
        XtSetArg(arglist[2], XtNdepth, &depth);
 
361
 
 
362
        XtGetValues(view->w, arglist, 3);
 
363
 
 
364
        view->window.breite = width;
 
365
        view->window.hoehe = height;
 
366
        view->window.farbtiefe = depth;
 
367
 
 
368
        view->init(&view->X_data, &view->window);
 
369
}
 
370
 
 
371
 
 
372
void xt_view_resize(Widget widget, XtPointer client_data, XtPointer call_data)
 
373
{
 
374
        struct xt_view *view;
 
375
 
 
376
        view = (struct xt_view *)client_data;
 
377
        X_zeichne_sync_anfang(view->window.display);
 
378
        X_fenster_freigeben(&view->X_data, &view->window);
 
379
        xt_view_init(view);
 
380
        X_zeichne_sync_ende(view->window.display);
 
381
}
 
382
 
 
383
 
 
384
void xt_view_redraw(Widget widget, XtPointer client_data, XtPointer call_data)
 
385
{
 
386
        struct xt_view *view;
 
387
 
 
388
        view = (struct xt_view *)client_data;
 
389
        X_zeichne_sync_anfang(view->window.display);
 
390
        view->redraw(view->X_data, &view->window, view->data);
 
391
        X_zeichne_sync_ende(view->window.display);
 
392
}
 
393
 
 
394
 
 
395
void xt_view_destroy(Widget widget, XtPointer client_data, XtPointer call_data)
 
396
{
 
397
        struct xt_view *view;
 
398
 
 
399
        view = (struct xt_view *)client_data;
 
400
 
 
401
        view->is_open = 0;
 
402
        view->is_initialized = 0;
 
403
}
 
404
 
 
405
 
 
406
void xt_view_toggle(Widget widget, XtPointer client_data, XtPointer call_data)
 
407
{
 
408
        struct xt_view *view;
 
409
 
 
410
        view = (struct xt_view *)client_data;
 
411
 
 
412
        if (view->is_open)
 
413
                popdown_view(view);
 
414
        else
 
415
                xt_popup_view(view);
 
416
}
 
417
 
 
418
 
 
419
void xt_disconnect_handler(Widget widget, XtPointer client_data,
 
420
        XtPointer call_data)
 
421
{
 
422
        do_disconnect();
 
423
}
 
424
 
 
425
 
 
426
void xt_connect_handler(Widget widget, XtPointer client_data,
 
427
        XtPointer call_data)
 
428
{
 
429
        char *server_name;
 
430
        char status_msg[STR_LENGTH];
 
431
 
 
432
        if (connected)
 
433
                return;
 
434
 
 
435
        xt_set_option_sensitivity(False);
 
436
 
 
437
        server_name = xt_get_string_value(xt_server_field_w);
 
438
 
 
439
        strcpy(status_msg, "Connecting to ");
 
440
        strncat(status_msg, server_name,
 
441
                sizeof status_msg - strlen(status_msg));
 
442
 
 
443
        xt_set_status_label(status_msg);
 
444
 
 
445
        XtAppAddWorkProc(xt_app_context, connect_work_proc, NULL);
 
446
        XSync(XtDisplay(xt_toplevel), False);
 
447
}
 
448
 
 
449
 
 
450
void xt_pause_handler(Widget widget, XtPointer client_data,
 
451
        XtPointer call_data)
 
452
{
 
453
        eingabe_simulieren(STOPSIGNAL);
 
454
}
 
455
 
 
456
 
 
457
void xt_resume_handler(Widget widget, XtPointer client_data,
 
458
        XtPointer call_data)
 
459
{
 
460
        eingabe_simulieren(WEITERSIGNAL);
 
461
}
 
462
 
 
463
 
 
464
void xt_exit_handler(Widget widget, XtPointer client_data, XtPointer call_data)
 
465
{
 
466
        do_disconnect();
 
467
 
 
468
        XtDestroyWidget(xt_toplevel);
 
469
}
 
470
 
 
471
 
 
472
void zeichne_sync_anfang(void)
 
473
{
 
474
        X_zeichne_sync_anfang(XtDisplay(xt_toplevel));
 
475
}
 
476
 
 
477
 
 
478
void zeichne_sync_ende(void)
 
479
{
 
480
        X_zeichne_sync_ende(XtDisplay(xt_toplevel));
 
481
}
 
482
 
 
483
 
 
484
void zeichne_blickfeld(struct objektdaten *objekte_neu)
 
485
{
 
486
        objekte_kopieren(&frontview_data.objekte, objekte_neu);
 
487
 
 
488
        if (xt_frontview.is_open)
 
489
                X_zeichne_blickfeld(xt_frontview.X_data, &xt_frontview.window,
 
490
                        &frontview_data);
 
491
}
 
492
 
 
493
 
 
494
void zeichne_rueckspiegel(struct objektdaten *objekte_rueck_neu)
 
495
{
 
496
        objekte_kopieren(&rearview_data.objekte, objekte_rueck_neu);
 
497
 
 
498
        if (xt_rearview.is_open)
 
499
                X_zeichne_blickfeld(xt_rearview.X_data, &xt_rearview.window,
 
500
                        &rearview_data);
 
501
}
 
502
 
 
503
 
 
504
void zeichne_karte(int spieler_index, int anzkreise_neu,
 
505
        struct kartenkreis *kreise_neu)
 
506
{
 
507
        map_data.anzkreise_alt = map_data.anzkreise;
 
508
        map_data.kreise_alt = map_data.kreise;
 
509
        liste_kopieren(&map_data.anzkreise, (void **)&map_data.kreise,
 
510
                &anzkreise_neu, (void **)&kreise_neu,
 
511
                sizeof(struct kartenkreis));
 
512
 
 
513
        if (xt_mapview.is_open)
 
514
                X_zeichne_karte(xt_mapview.X_data, &xt_mapview.window,
 
515
                        &map_data);
 
516
 
 
517
        liste_freigeben(&map_data.anzkreise_alt,
 
518
                (void **)&map_data.kreise_alt);
 
519
        map_data.anzkreise_alt = 0;
 
520
        map_data.kreise_alt = NULL;
 
521
}
 
522
 
 
523
 
 
524
void zeichne_grundriss(int anzlinien_neu, struct kartenlinie *linien_neu)
 
525
{
 
526
        liste_freigeben(&map_data.anzlinien, (void **)&map_data.linien);
 
527
        liste_kopieren(&map_data.anzlinien, (void **)&map_data.linien,
 
528
                &anzlinien_neu, (void **)&linien_neu,
 
529
                sizeof(struct kartenlinie));
 
530
 
 
531
        if (xt_mapview.is_open)
 
532
                X_zeichne_grundriss(xt_mapview.X_data, &xt_mapview.window,
 
533
                        &map_data);
 
534
}
 
535
 
 
536
 
 
537
void zeichne_kompass(int blickrichtung_neu)
 
538
{
 
539
        compass_data = blickrichtung_neu;
 
540
 
 
541
        if (xt_compassview.is_open)
 
542
                X_zeichne_kompass(xt_compassview.X_data,
 
543
                        &xt_compassview.window, &compass_data);
 
544
}
 
545
 
 
546
 
 
547
void zeichne_punkte(struct punktedaten *punkte_neu)
 
548
{
 
549
        liste_freigeben(&score_data.anzpunkte, (void **)&score_data.punkte);
 
550
        liste_kopieren(&score_data.anzpunkte, (void **)&score_data.punkte,
 
551
                &punkte_neu->anzpunkte, (void **)&punkte_neu->punkte,
 
552
                sizeof(struct punktestand));
 
553
 
 
554
        if (xt_scoreview.is_open)
 
555
                X_zeichne_punkte(xt_scoreview.X_data, &xt_scoreview.window,
 
556
                        &score_data);
 
557
}
 
558
 
 
559
 
 
560
void grafik_schleife(void)
 
561
{
 
562
        connected = 0;
 
563
 
 
564
        XtAppMainLoop(xt_app_context);
 
565
}
 
566
 
 
567
 
 
568
int grafik_init(int *argc, char **argv)
 
569
{
 
570
        Colormap colormap;
 
571
        Arg arglist[1];
 
572
 
 
573
        audio_is_active = 0;
 
574
 
 
575
        xt_toplevel = XtAppInitialize(&xt_app_context, "IMaze",
 
576
                NULL, 0, argc, argv, fallback_app_resources, NULL, 0);
 
577
        XtAddCallback(xt_toplevel, XtNdestroyCallback, destroy_handler, NULL);
 
578
 
 
579
        toplevel_exists = 1;
 
580
 
 
581
        XtGetApplicationResources(xt_toplevel, (XtPointer)&res_data,
 
582
                res_list, XtNumber(res_list), NULL, 0);
 
583
 
 
584
        xt_fill_main(xt_toplevel);
 
585
        XtRealizeWidget(xt_toplevel);
 
586
 
 
587
        XtSetArg(xt_icon_arglist[0], XtNiconPixmap,
 
588
                X_create_icon_pixmap(XtDisplay(xt_toplevel),
 
589
                XScreenNumberOfScreen(XtScreen(xt_toplevel))));
 
590
 
 
591
        XtSetValues(xt_toplevel, xt_icon_arglist, 1);
 
592
 
 
593
        if (X_farben_init(XtDisplay(xt_toplevel),
 
594
                XScreenNumberOfScreen(XtScreen(xt_toplevel)), &colormap))
 
595
        {
 
596
                XtRemoveCallback(xt_toplevel, XtNdestroyCallback,
 
597
                        destroy_handler, NULL);
 
598
                XtDestroyWidget(xt_toplevel);
 
599
 
 
600
                toplevel_exists = 0;
 
601
 
 
602
                return 1;
 
603
        }
 
604
 
 
605
        XtSetArg(arglist[0], XtNcolormap, colormap);
 
606
        XtSetValues(xt_toplevel, arglist, 1);
 
607
 
 
608
        xt_frontview.name = "frontView";
 
609
        xt_frontview.data = &frontview_data;
 
610
        xt_frontview.is_open = 0;
 
611
        xt_frontview.is_initialized = 0;
 
612
        xt_frontview.was_open = 1;
 
613
        xt_frontview.init = X_fenster_init;
 
614
        xt_frontview.redraw = X_zeichne_blickfeld;
 
615
        objekt_listen_init(&frontview_data.objekte);
 
616
        frontview_data.fadenkreuz = 1;
 
617
        frontview_data.titelbild = 1;
 
618
 
 
619
        xt_scoreview.name = "score";
 
620
        xt_scoreview.data = &score_data;
 
621
        xt_scoreview.is_open = 0;
 
622
        xt_scoreview.is_initialized = 0;
 
623
        xt_scoreview.was_open = 1;
 
624
        xt_scoreview.init = X_fenster_init;
 
625
        xt_scoreview.redraw = X_zeichne_punkte;
 
626
        liste_initialisieren(&score_data.anzpunkte,
 
627
                (void **)&score_data.punkte);
 
628
 
 
629
        xt_compassview.name = "compass";
 
630
        xt_compassview.data = &compass_data;
 
631
        xt_compassview.is_open = 0;
 
632
        xt_compassview.is_initialized = 0;
 
633
        xt_compassview.was_open = 0;
 
634
        xt_compassview.init = X_fenster_init;
 
635
        xt_compassview.redraw = X_zeichne_kompass;
 
636
        compass_data = -1;
 
637
 
 
638
        xt_rearview.name = "rearView";
 
639
        xt_rearview.data = &rearview_data;
 
640
        xt_rearview.is_open = 0;
 
641
        xt_rearview.is_initialized = 0;
 
642
        xt_rearview.was_open = 0;
 
643
        xt_rearview.init = X_fenster_init;
 
644
        xt_rearview.redraw = X_zeichne_blickfeld;
 
645
        objekt_listen_init(&rearview_data.objekte);
 
646
        rearview_data.fadenkreuz = 0;
 
647
        rearview_data.titelbild = 0;
 
648
 
 
649
        xt_mapview.name = "map";
 
650
        xt_mapview.data = &map_data;
 
651
        xt_mapview.is_open = 0;
 
652
        xt_mapview.is_initialized = 0;
 
653
        xt_mapview.was_open = 0;
 
654
        xt_mapview.init = X_karte_init;
 
655
        xt_mapview.redraw = X_zeichne_grundriss;
 
656
        liste_initialisieren(&map_data.anzlinien, (void **)&map_data.linien);
 
657
        liste_initialisieren(&map_data.anzkreise, (void **)&map_data.kreise);
 
658
        map_data.anzkreise_alt = 0;
 
659
        map_data.kreise_alt = NULL;
 
660
 
 
661
        if (X_eingabe_init())
 
662
                return 1;
 
663
 
 
664
        xt_popup_view(&xt_frontview);
 
665
 
 
666
        switch (audio_start(res_data.audio_directory))
 
667
        {
 
668
        case Audio_Started:
 
669
                audio_is_active = 1;
 
670
                return 0;
 
671
 
 
672
        case Audio_Failed:
 
673
                return 0;
 
674
 
 
675
        case Audio_Abort:
 
676
        default:
 
677
                return 1;
 
678
        }
 
679
}
 
680
 
 
681
 
 
682
void grafik_ende(void)
 
683
{
 
684
        if (toplevel_exists)
 
685
                XtDestroyWidget(xt_toplevel);
 
686
 
 
687
        X_eingabe_ende();
 
688
 
 
689
        if (!audio_is_active)
 
690
                return;
 
691
 
 
692
        audio_close();
 
693
        audio_is_active = 0;
 
694
}
 
695
 
 
696
 
 
697
void ueblen_fehler_anzeigen(char **meldung, char *knopf)
 
698
{
 
699
        if (!toplevel_exists)
 
700
        {
 
701
                while (*meldung != NULL)
 
702
                        fprintf(stderr, "iMaze: %s\n", *meldung++);
 
703
 
 
704
                return;
 
705
        }
 
706
 
 
707
        if (connected)
 
708
        {
 
709
                connected = 0;
 
710
                stop_network_proc();
 
711
        }
 
712
 
 
713
        xt_request_window(meldung, knopf, NULL, 0, "error");
 
714
}
 
715
 
 
716
 
 
717
void ereignisse_darstellen(char ereignisse[ERG_ANZ])
 
718
{
 
719
        if (ereignisse[PAUSE_ERG])
 
720
                set_pause_mode(1);
 
721
        else if (ereignisse[ERWACHT_ERG])
 
722
                set_pause_mode(0);
 
723
 
 
724
        if (audio_is_active)
 
725
        {
 
726
                audio_play(ereignisse);
 
727
                return;
 
728
        }
 
729
 
 
730
        if (ereignisse[ABGESCHOSSEN_ERG] || ereignisse[GETROFFEN_ERG] ||
 
731
                ereignisse[AKTION_FEHLER_ERG] || ereignisse[SUSPENDIERT_ERG])
 
732
                XBell(XtDisplay(xt_toplevel), 0);
 
733
}
 
734
 
 
735
 
 
736
int rueckfrage(char **meldung, char *weiter_knopf, char *abbruch_knopf)
 
737
{
 
738
        if (!toplevel_exists)
 
739
        {
 
740
                static char *message[] = { "iMaze - Fatal Error", "",
 
741
                        "Couldn't open notice window.", NULL };
 
742
 
 
743
                uebler_fehler(message, NULL);
 
744
        }
 
745
 
 
746
        return xt_request_window(meldung, weiter_knopf,
 
747
                abbruch_knopf, 1, "question") == 1;
 
748
}
 
749
 
 
750
 
 
751
void disconnect_abfrage(void)
 
752
{
 
753
        static char *message[] = { "Do you really want do disconnect?", NULL };
 
754
 
 
755
        if (!rueckfrage(message, "Sure", "Play on"))
 
756
                return;
 
757
 
 
758
        do_disconnect();
 
759
}
 
760
 
 
761
 
 
762
void audio_select_descriptor(int descriptor, void (*function)(void),
 
763
        int for_output)
 
764
{
 
765
        if (audio_select_pending)
 
766
        {
 
767
                XtRemoveInput(audio_select_id);
 
768
                audio_select_pending = 0;
 
769
        }
 
770
 
 
771
        if (function != NULL)
 
772
        {
 
773
                audio_select_id = XtAppAddInput(xt_app_context, descriptor,
 
774
                        for_output ? (XtPointer)XtInputWriteMask :
 
775
                                (XtPointer)XtInputReadMask,
 
776
                        audio_select_handler, (XtPointer)function);
 
777
                audio_select_pending = 1;
 
778
        }
 
779
}
 
780
 
 
781
 
 
782
void audio_handle_signal(int signal, void (*function)(void))
 
783
{
 
784
        audio_signal_handler = function;
 
785
 
 
786
        if (audio_signal_handler == NULL)
 
787
                handle_signal(signal, SIG_DFL);
 
788
        else
 
789
                handle_signal(signal, handle_audio_signal);
 
790
}