channelUI.c
6.4 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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
/*====================================================================
* channelUI.c
*
* Copyright 1995, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
/*========================*/
#include <ultra64.h>
#include <ultralog.h>
#include <os.h>
#include <assert.h>
#include "audio.h"
#include "channelUI.h"
#include "sequence.h"
#include "UIpane.h"
#include "font_ext.h"
static Channel sChannel;
static void __ChlItemInit (UIItem *pItem, int id);
static void __ChlPaneDrawProc (UIPane *pPane, Gfx **ppGfx);
static void __ChlDrawValueBox (UIItem *pItem, Gfx **ppGfx);
static char __ChlHandleEventProc (UIPane *pPane, UIEvent *pEvent);
static char __ChlHandleMouseDown (UIPane *pPane, Point *pPt);
static char __ChlHandleMouseUp (UIPane *pPane, Point *pPt);
static char __ChlHandleButtonDown (UIPane *pPane, int button);
#define kNumValueBoxStr_bms 9
static Bitmap sValueBoxStrBM[kNumValueBoxStr_bms];
static Gfx sValueBoxStrDL[kNumValueBox][NUM_DL(kNumValueBoxStr_bms)];
static Sprite sValueBoxStrSprite =
{
0,0, /* Position: x,y */
0,0, /* Sprite size in texels (x,y) */
1.0,1.0, /* Sprite Scale: x,y */
0,0, /* Explosion (x,y) */
SP_TRANSPARENT, /* Sprite Attributes */
0x1234, /* Sprite Depth: Z */
255,255,255,255, /* Sprite Coloration: RGBA */
0,0,NULL, /* Color LookUp Table: start_index, length, address */
0,1, /* Sprite Bitmap index: start index, step increment */
kNumValueBoxStr_bms, /* Number of bitmaps */
NUM_DL(kNumValueBoxStr_bms), /* Number of display list locations allocated */
15, 128, /* Sprite Bitmap Height: Used_height, physical height */
G_IM_FMT_I, /* Sprite Bitmap Format */
G_IM_SIZ_4b, /* Sprite Bitmap Texel Size */
sValueBoxStrBM, /* Pointer to bitmaps */
&sValueBoxStrDL[0][0], /* Display list memory */
&sValueBoxStrDL[0][0], /* HACK: dynamic_dl pointer */
};
void
Chl_Init (UIPane **ppPane)
{
UIItem *pItem;
int i;
/* Initialize the Channel object's pane. */
sChannel.fPane.numItems = kNumChlItems;
sChannel.fPane.itemList = sChannel.fItemList;
sChannel.fPane.pData = &sChannel;
sChannel.fPane.DrawProc = __ChlPaneDrawProc;
sChannel.fPane.HandleEventProc = __ChlHandleEventProc;
SetRect (&sChannel.fPane.bounds, kChl_l, kChl_t, kChl_l + kChl_w, kChl_t + kChl_h);
/* Initialize each of the channel's pane's items. */
for (i=0; i<sChannel.fPane.numItems; i++)
{
pItem = &sChannel.fPane.itemList[i];
__ChlItemInit (pItem, i);
}
/* Return the pane's address to the caller. */
*ppPane = &sChannel.fPane;
}
static void
__ChlItemInit (UIItem *pItem, int id)
{
Item_Init (pItem, id);
pItem->pPane = &sChannel.fPane;
switch (id)
{
case kMasterVolItemID:
pItem->DrawProc = __ChlDrawValueBox;
SetRect (&pItem->bounds,
kMasterVolItem_l,
kMasterVolItem_t,
kMasterVolItem_l + kMasterVolItem_w,
kMasterVolItem_t + kMasterVolItem_h);
break;
}
}
/*
Channel UI Procs
*/
static void
__ChlPaneDrawProc (UIPane *pPane, Gfx **ppGfx)
{
UIItem * pItem;
int i;
/* Draw the Channel window. */
DrawBeveledRect (&pPane->bounds, FALSE, FALSE, ppGfx);
/* Draw the Channel pane's UI items. */
for (i=0; i<pPane->numItems; i++)
{
pItem = &pPane->itemList[i];
pItem->DrawProc (pItem, ppGfx);
}
}
static void
__ChlDrawValueBox (UIItem *pItem, Gfx **ppGfx)
{
Rect boundsRect;
s32 value;
char str[10];
if (pItem->id == kMasterVolItemID)
{
value = Seq_GetVolume ();
value >>= 8;
}
sprintf (str, "%d", value);
/* Get the bounds for the value box. */
Item_GetScreenBounds (pItem, &boundsRect);
/* Assign unique storage for this item's sprite display list. */
sValueBoxStrSprite.rsp_dl_next = &sValueBoxStrDL[pItem->id - kMasterVolItemID][0];
/* Draw the value box. */
font_set_font (kDigit6Font); /* Use small digits to save space. */
DrawValueStrBox (&boundsRect, str, Item_IsSelected (pItem), &sValueBoxStrSprite, ppGfx);
}
static char
__ChlHandleEventProc (UIPane *pPane, UIEvent *pEvent)
{
char isHandled = FALSE;
switch (pEvent->type)
{
case kMouseDown:
isHandled = __ChlHandleMouseDown (pPane, &pEvent->where);
break;
case kMouseUp:
isHandled = __ChlHandleMouseUp (pPane, &pEvent->where);
break;
case kButtonDown:
isHandled = __ChlHandleButtonDown (pPane, pEvent->what);
break;
}
}
static char
__ChlHandleMouseDown (UIPane *pPane, Point *pPt)
{
UIItem * pItem;
char isHandled = FALSE;
Pane_DeselectAllItems (pPane);
if (Pane_ItemClicked (pPane, pPt, &pItem))
{
assert(pItem != NULL);
Item_SetSelected (pItem, TRUE);
isHandled = TRUE;
}
isHandled = FALSE;
}
static char
__ChlHandleMouseUp (UIPane *pPane, Point *pPt)
{
UIItem * pItem;
char isHandled = FALSE;
if (Pane_ItemClicked (pPane, pPt, &pItem))
{
assert(pItem != NULL);
isHandled = TRUE;
}
return isHandled;
}
static char
__ChlHandleButtonDown (UIPane *pPane, int button)
{
UIItem * pItem;
if ((button & CONT_UP) || (button & CONT_DOWN))
{
if (Pane_GetSelectedItem (pPane, &pItem))
{
switch (pItem->id)
{
case kMasterVolItemID:
Seq_AdjustVolume (button & CONT_UP);
break;
}
}
}
return TRUE;
}