File: callbacks.C

package info (click to toggle)
xshisen 1:1.51-4.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,124 kB
  • sloc: cpp: 4,007; sh: 152; perl: 146; makefile: 114
file content (182 lines) | stat: -rw-r--r-- 4,030 bytes parent folder | download | duplicates (8)
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
#include "body.h"

void
PopDownTO(XtPointer data, XtIntervalId *id)
{
    Widget w = (Widget)data;
    XtUnmanageChild(w);
    bd->Shuffle();
    tm->ResetTimer();
    bd->DrawAll();
}

void
ScoreRegisterCB(Widget w, int index)
{
#if DEBUG
    fprintf(stderr, "ScoreRegisterCB\n");
#endif
    sc->Register();
#if USE_MOTIF
    XtRemoveCallback(w, XmNokCallback, (XtCallbackProc)ScoreRegisterCB, NULL);
#else /* USE_MOTIF */
    XtRemoveCallback(w, XtNcallback, (XtCallbackProc)ScoreRegisterCB, NULL);
#endif /* USE_MOTIF */
}

void
ResizeCB(void)
{
    int wid, hei;

    if (bd->GetGeometry(wid, hei))
        bd->SetSize(wid, hei);
#if DEBUG
    fprintf(stderr, "ResizeCB: (%d,%d)\n", wid, hei);
#endif
}

void
ExposeCB(Widget w, XtPointer tag, XtPointer p)
{
#if USE_MOTIF
    XExposeEvent *e = &(((XmDrawingAreaCallbackStruct *)p)->event->xexpose);
#else /* USE_MOTIF */
    XExposeEvent *e = &(((XEvent *)p)->xexpose);
#endif /* USE_MOTIF */
#if DEBUG
    fprintf(stderr, "ExposeCB: (%d,%d) -> (%d,%d)\n", e->x, e->y, e->width, e->height);
#endif
    bd->DrawRegion(e->x, e->y, e->width, e->height);
}

void
GameCB(Widget w, int index)
{
    static long pausedTime;
    int pauseStatus;
#if DEBUG
    fprintf(stderr, "GameCB: %d\n", index);
#endif
    switch(index) {
    case 0: /* Start */
        bd->LogGiveUp();
        bd->Shuffle();
        bd->DrawAll();
        mb->Sensitive();
        tm->ResetTimer();
        break;
    case 1: /* Restart */
        bd->LogGiveUp();
        bd->Restart();
        bd->DrawAll();
        mb->Sensitive();
        tm->ResetTimer();
        break;
    case 2: /* Pause */
        pauseStatus = bd->TogglePause();
        if (pauseStatus == 1) { // Paused
            mb->PauseOn();
            pausedTime = tm->GetTimer();
        } else if (pauseStatus == 0) {  // Pause cancelled
            mb->PauseOff();
            tm->SetTimer(pausedTime);
        }
        break;
    case 3: /* Score */
        sc->DisplayScore(bd->game);
        break;
    case 4: /* Personal Score */
        sc->PersonalStat(bd->game);
        break;
    case 5: /* About */
        Message(MESSAGE_SYMBOL, globRes.aboutString);
        break;
    case 6: /* Exit */
        exit(0);
    }
}

void
SuppCB(Widget w, int index)
{
#if DEBUG
    fprintf(stderr, "SuppCB: %d\n", index);
#endif
    switch(index) {
    case 0: /* Hint */
        bd->Hint();
        break;
    case 1: /* Back */
        bd->Back();
        break;
    }
}

void
ChangeGameCB(Widget w, int index, XtPointer p)
{
    int xsize, ysize;
    int trial;

#if DEBUG
    fprintf(stderr, "ChangeGameCB: %d\n", index);
#endif
    if (index >= NUM_GAME) {
        if (index == NUM_GAME) {
            bd->ToggleClickTrial();
        } else {
            bd->ToggleGravity();
        }
        SetGameStart();
        bd->DrawAll();
    } else {
        mb->CheckGame(index);
        trial = bd->game / NUM_GAME;
        if (index == bd->game % NUM_GAME)
            return;
        index += trial * NUM_GAME;
        GetGameSize(index, xsize, ysize);
        bd->ChangeGame(index, xsize, ysize);
        GetBoardSizeFromGameSize(xsize, ysize, globRes.Width, globRes.Height);
        bd->SetGeometry(globRes.Width, globRes.Height);
        SetGameStart();
    }
    bd->WriteRcFile();
}

void
ChangePixmapCB(Widget w, int index, XtPointer p)
{
    char subdir[16];
extern Widget toplevel;

#if DEBUG
    fprintf(stderr, "ChangePixmapCB: %d\n", index);
#endif
    mb->CheckPixmap(index);
    if (globRes.imageSet != index + 1) {
        int xsize, ysize;
	globRes.imageSet = index + 1;
        InitPicture();
        GetGameSize(bd->game%NUM_GAME, xsize, ysize);
        GetBoardSizeFromGameSize(xsize, ysize, globRes.Width, globRes.Height);
        bd->SetGeometry(globRes.Width, globRes.Height);
        bd->WriteRcFile();
        SetGameStart();
    }
}

void
AutoDemoCB(void)
{
    bd->Robot();
    XtAppAddTimeOut(app_context, 2000,
                    (XtTimerCallbackProc)AutoDemoCB, NULL);
}

void
ExitCB(void)
{
    exit(0);
}