~ubuntu-branches/ubuntu/hardy/xbill/hardy

« back to all changes in this revision

Viewing changes to x11-athena.cc

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bridgett
  • Date: 2004-09-07 09:52:14 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040907095214-d0m46ojc8f7upuqm
Tags: 2.1-4
maintainer upload of NMU - many thanks Tollef (closes: #268885) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "objects.h"
2
 
#include "x11.h"
3
 
#include "menu.h"
4
 
 
5
 
#include <X11/Xaw/XawInit.h>
6
 
#include <X11/Xaw/Label.h>
7
 
#include <X11/Xaw/Box.h>
8
 
#include <X11/Xaw/MenuButton.h>
9
 
#include <X11/Xaw/SimpleMenu.h>
10
 
#include <X11/Xaw/SmeBSB.h>
11
 
#include <X11/Xaw/SmeLine.h>
12
 
#include <X11/Xaw/AsciiText.h>
13
 
 
14
 
extern Widget scorebox, highscorebox;
15
 
 
16
 
Widget CreateMenuBar(const char *name, Widget parent) {
17
 
        int i,j;
18
 
        Widget menubar, temp;
19
 
        menubar = XtVaCreateManagedWidget(name, boxWidgetClass, parent,
20
 
                XtNborderWidth, 0, XtNorientation, XtEhorizontal, NULL);
21
 
        for (j=0; j<menu.size; j++) {
22
 
                temp = XtCreateManagedWidget(menu.submenu[j].name,
23
 
                        menuButtonWidgetClass, menubar, NULL, 0);
24
 
                menu.submenu[j].pshell = XtCreatePopupShell("menu",
25
 
                        simpleMenuWidgetClass, temp, NULL, 0);
26
 
                for (i=0; i<menu.submenu[j].size; i++) {
27
 
                        if (strlen(menu.submenu[j].button[i].name)) {
28
 
                                temp = XtCreateManagedWidget(
29
 
                                        menu.submenu[j].button[i].name,
30
 
                                        smeBSBObjectClass,
31
 
                                        menu.submenu[j].pshell, NULL, 0);
32
 
                                XtAddCallback(temp, XtNcallback,
33
 
                                        (XtCallbackProc)popup,
34
 
                                        menu.submenu[j].button[i].dialog);
35
 
                        }
36
 
                        else XtCreateManagedWidget("", smeLineObjectClass,
37
 
                                menu.submenu[j].pshell, NULL, 0);
38
 
                }
39
 
        }
40
 
        return menubar;
41
 
}
42
 
 
43
 
void close_window (Widget w, XtPointer client_data, XtPointer call_data) {
44
 
        XtPopdown(XtParent(XtParent(w)));
45
 
}
46
 
 
47
 
Widget CreatePixmapBox(const char *name, Widget parent, Pixmap pixmap,
48
 
        const char *text)
49
 
{
50
 
        Widget base, pshell, button;
51
 
 
52
 
        pshell = XtCreatePopupShell(name, transientShellWidgetClass,
53
 
                parent, NULL, 0);
54
 
 
55
 
        base = CreateRowCol("", pshell);
56
 
 
57
 
        XtVaCreateManagedWidget("", labelWidgetClass, base,
58
 
                XtNbitmap, game.logo.pix, XtNborderWidth, 0, NULL);
59
 
 
60
 
        if (pixmap) XtVaCreateManagedWidget("", labelWidgetClass, base, 
61
 
                XtNbitmap, pixmap, XtNborderWidth, 0, NULL);
62
 
        if (text)
63
 
                XtVaCreateManagedWidget("", labelWidgetClass, base, 
64
 
                        XtNlabel, text, XtNborderWidth, 0, NULL);
65
 
 
66
 
        button = XtVaCreateManagedWidget("OK", commandWidgetClass, base, NULL);
67
 
        XtAddCallback(button, XtNcallback, (XtCallbackProc)close_window, NULL);
68
 
        return base;
69
 
}
70
 
 
71
 
void warp_apply (Widget w, Widget text, XtPointer client_data) {
72
 
        char *str;
73
 
        XtVaGetValues(text, XtNstring, &str, NULL);
74
 
        game.warp_to_level (atoi(str));
75
 
}
76
 
 
77
 
void enter_name (Widget w, Widget text, XtPointer client_data) {
78
 
        char *str, *nl;
79
 
        XtVaGetValues(text, XtNstring, &str, NULL);
80
 
        if (!str[0]) strcpy(str, "Anonymous");
81
 
        else if ((nl = strchr(str,'\n'))) *nl=0;
82
 
        if (strlen(str)>20) str[20] = 0;  /* truncate string if too long */
83
 
        scores.recalc(str);
84
 
}
85
 
 
86
 
Widget CreateEnterText (const char *name, Widget parent, const char *text,
87
 
        XtCallbackProc callback)
88
 
{
89
 
        Widget base, pshell, button, textfield;
90
 
        pshell = XtCreatePopupShell(name, transientShellWidgetClass,
91
 
                parent, NULL, 0);
92
 
        base = CreateRowCol("", pshell);
93
 
        XtVaCreateManagedWidget("", labelWidgetClass, base,
94
 
                XtNlabel, text, XtNborderWidth, 0, NULL);
95
 
 
96
 
        textfield = XtVaCreateManagedWidget("", asciiTextWidgetClass, base,
97
 
                XtNeditType, XawtextEdit, XtNstring, "", XtNwidth, 200, NULL);
98
 
 
99
 
        button = XtVaCreateManagedWidget("OK", commandWidgetClass, base, NULL);
100
 
        XtAddCallback(button, XtNcallback, (XtCallbackProc)callback, textfield);
101
 
        XtAddCallback(button, XtNcallback, (XtCallbackProc)close_window, NULL);
102
 
        button = XtVaCreateManagedWidget("Cancel", commandWidgetClass, base,
103
 
                NULL);
104
 
        XtAddCallback(button, XtNcallback, (XtCallbackProc)close_window, NULL);
105
 
        return base;
106
 
}
107
 
 
108
 
Widget CreateDialog (const char *name, Widget parent, int buttonmask,
109
 
        Pixmap icon, const char *text, const char *buttonlabel,
110
 
        XtCallbackProc callback)
111
 
{
112
 
        Widget base, pshell, button;
113
 
        char *ttext= (char*)malloc(strlen(text)+5);
114
 
        pshell = XtCreatePopupShell(name, transientShellWidgetClass,
115
 
                parent, NULL, 0);
116
 
        base = CreateRowCol("base", pshell);
117
 
        strcpy(ttext, text);
118
 
        if (strlen(ttext)<12) strcat(ttext, "     ");
119
 
        XtVaCreateManagedWidget("label", labelWidgetClass, base,
120
 
                XtNlabel, ttext, XtNborderWidth, 0, NULL);
121
 
        if (icon)
122
 
                XtVaCreateManagedWidget("", labelWidgetClass, base,
123
 
                        XtNbitmap, icon, XtNborderWidth, 0, NULL);
124
 
        if (buttonmask&OK) {
125
 
                if (!buttonlabel) buttonlabel="OK";
126
 
                button = XtVaCreateManagedWidget(buttonlabel,
127
 
                        commandWidgetClass, base, NULL);
128
 
                if (callback)
129
 
                        XtAddCallback(button, XtNcallback,
130
 
                                (XtCallbackProc)callback, NULL);
131
 
                XtAddCallback(button, XtNcallback,
132
 
                        (XtCallbackProc)close_window, NULL);
133
 
        }
134
 
        if (buttonmask&CANCEL) {
135
 
                button = XtVaCreateManagedWidget("Cancel", commandWidgetClass,
136
 
                        base, NULL);
137
 
                XtAddCallback(button, XtNcallback,
138
 
                        (XtCallbackProc)close_window, NULL);
139
 
        }
140
 
        return base;
141
 
}
142
 
 
143
 
Widget CreateDrawingArea(const char *name, Widget parent, int width, int height)
144
 
{
145
 
        return XtVaCreateManagedWidget(name, coreWidgetClass, parent, XtNwidth,
146
 
                width, XtNheight, height, NULL);
147
 
}
148
 
 
149
 
void UI::update_hsbox(char *str) {
150
 
        WidgetList t;
151
 
        XtVaGetValues(highscorebox, XtNchildren, &t, NULL);
152
 
        XtVaSetValues(t[0], XtNlabel, str, NULL);
153
 
}
154
 
 
155
 
void UI::update_scorebox(int level, int score) {
156
 
        WidgetList t;
157
 
        char str[40];
158
 
        sprintf (str, "After Level %d:     \nYour score: %d\n", level, score);
159
 
        XtVaGetValues(scorebox, XtNchildren, &t, NULL);
160
 
        XtVaSetValues(t[0], XtNlabel, str, NULL);
161
 
}
162
 
 
163
 
Widget CreateRowCol(const char *name, Widget parent) {
164
 
        return XtCreateManagedWidget(name, boxWidgetClass, parent, NULL, 0);
165
 
}