musicUI.c
3.83 KB
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
#include <assert.h>
#include "gfx.h"
#include "musicUI.h"
#include "UIpane.h"
#include "UI.h"
#include "transport.h"
#include "sndplayUI.h"
#include "cursor.h"
#include "performance.h"
#include "channelUI.h"
static UIPane * sPaneList[kNumPanes];
static UIGlobals sUIGlobals;
static void __UIPaneInit (int id, UIPane **ppPane);
static void __UIInitGlobals (void);
static void __UIDrawGlobals (Gfx **ppGfx);
static void __UIProcessGlobals (UIEvent *pEvent);
static void __UIHandleGlobals (UIPane *pPane, UIEvent *pEvent);
static void __PopPaneToTop (UIPane *pPane);
void
UIInit (void)
{
int i;
__UIInitGlobals ();
for (i=0; i<kNumPanes; i++)
__UIPaneInit (i, &sPaneList[i]);
}
static void
__UIPaneInit (int id, UIPane **ppPane)
{
/* Initialize the pane according to its id so we can easily */
/* debug specific windows by simply altering the ids. */
/* From here on out pane ids are not used. */
switch (id)
{
case kXptPaneID:
Xpt_Init (ppPane);
break;
case kPerfPaneID:
Perf_Init (ppPane);
break;
case kChlPaneID:
Chl_Init (ppPane);
break;
case kSndPlayID:
SndP_Init (ppPane);
break;
}
}
void
UIDraw (Gfx **ppGfx)
{
UIPane * pPane;
int i;
/* Draw panes in reverse order so that panes at the top of the list */
/* appear on top of the other panes. */
for (i=kNumPanes; --i>=0; )
{
pPane = sPaneList[i];
assert(pPane != NULL);
pPane->DrawProc (pPane, ppGfx);
}
/* Draw global UI objects last since they are usually modal. */
__UIDrawGlobals (ppGfx);
}
void
UIProcessEvent (UIEvent *pEvent)
{
UIPane * pPane;
Point pt;
int i;
/* Handle all global UI events. */
__UIProcessGlobals (pEvent);
Crsr_GetCoords (&pt.x, &pt.y);
/* Send events to panes in forward order so that panes that */
/* appear on top get to handle events first. */
for (i=0; i<kNumPanes; i++)
{
pPane = sPaneList[i];
assert(pPane != NULL);
if (PointInRect (&pPane->bounds, &pt))
{
if (!pPane->HandleEventProc (pPane, pEvent))
__UIHandleGlobals (pPane, pEvent);
__PopPaneToTop (pPane);
break;
}
}
}
void
__UIDrawGlobals (Gfx **ppGfx)
{
Rect moveRect;
int dx, dy;
if (sUIGlobals.fMovePane)
{
Crsr_GetCoords (&dx, &dy);
moveRect = sUIGlobals.fMovePane->bounds;
OffsetRect (&moveRect, dx - sUIGlobals.fMoveOrigin.x, dy - sUIGlobals.fMoveOrigin.y);
DrawGrayRect (&moveRect, 32, ppGfx);
}
}
void
__UIInitGlobals (void)
{
int i;
for (i=0; i<kNumPanes; i++)
sPaneList[i] = NULL;
sUIGlobals.fMovePane = NULL;
}
void
__UIProcessGlobals (UIEvent *pEvent)
{
int dx, dy;
if (sUIGlobals.fMovePane && pEvent->type == kMouseUp)
{
Crsr_GetCoords (&dx, &dy);
OffsetRect (&sUIGlobals.fMovePane->bounds, dx - sUIGlobals.fMoveOrigin.x, dy - sUIGlobals.fMoveOrigin.y);
sUIGlobals.fMovePane = NULL;
}
}
void
__UIHandleGlobals (UIPane *pPane, UIEvent *pEvent)
{
if (pEvent->type == kMouseDown)
{
assert(sUIGlobals.fMovePane == NULL);
sUIGlobals.fMovePane = pPane;
Crsr_GetCoords (&sUIGlobals.fMoveOrigin.x, &sUIGlobals.fMoveOrigin.y);
}
}
void
__PopPaneToTop (UIPane *pPane)
{
int i;
/* Locate 'pPane' in the list. */
for (i=kNumPanes; --i >= 0; )
{
if (sPaneList[i] == pPane)
break;
}
/* If we didn't find it in the list, then there's a bug somewhere. */
assert(i>=0);
/* Shift all panes above 'pPane' down. */
/* This will do nothing if 'pPane' is already at the top. */
for (; i > 0; --i)
{
sPaneList[i] = sPaneList[i-1];
}
/* Place 'pPane' at the top of the list. */
sPaneList[0] = pPane;
}