UIutils.c
5.2 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
#include <ultra64.h>
#include <ultralog.h>
#include <assert.h>
#include "UI.h"
#include "font_ext.h"
#include "music.h" /* for PRINTF */
#define kBevel_w 0
static char sIsMouseDown;
static void __DPFrameRectangle(Gfx **ppGfx, int l, int t, int r, int b);
void
SetMouseDown (char isDown)
{
sIsMouseDown = isDown;
}
char
IsMouseDown (void)
{
return sIsMouseDown;
}
void
SetRect (Rect *pR, int l, int t, int r, int b)
{
pR->left = l;
pR->top = t;
pR->right = r;
pR->bottom = b;
}
void
OffsetRect (Rect *pR, int x, int y)
{
pR->left += x;
pR->top += y;
pR->right += x;
pR->bottom += y;
}
void
InsetRect (Rect *pR, int x, int y)
{
pR->left += x;
pR->top += y;
pR->right -= x;
pR->bottom -= y;
}
char
PointInRect (Rect *pR, Point *pPt)
{
if (pPt->x < pR->left || pPt->x > pR->right || pPt->y < pR->top || pPt->y > pR->bottom)
return FALSE;
return TRUE;
}
/*
Draws a beveled rectangle.
The rectangle coordinates are defined by 'pR' and if 'isSunken'
is true the rectangle is draw to look like a well, otherwise
it is drawn to look like a raised surface. The rectangle is
filled with gray. The display list commands for rendering the
beveled rectangle are written to 'ppGfx'.
*/
void
DrawBeveledRect (Rect *pR, char isSunken, char isHilited, Gfx **ppGfx)
{
u16 shortcolor;
/*assert(ppGfx != NULL);
assert(pR != NULL);*/
/* Set up the display list commands. */
gDPPipeSync((*ppGfx)++);
gDPSetCycleType ((*ppGfx)++, G_CYC_FILL);
gDPSetRenderMode ((*ppGfx)++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
/* Fill in the rectangle with gray. */
if (isHilited)
shortcolor = GPACK_RGBA5551(255, 170, 99, 1);
else
shortcolor = GPACK_RGBA5551(176, 176, 176, 1);
gDPSetFillColor((*ppGfx)++, shortcolor << 16 | shortcolor);
gDPFillRectangle((*ppGfx)++, pR->left+1, pR->top+1, pR->right-1, pR->bottom-1);
/* Draw the left and top edges. */
if (isSunken)
shortcolor = GPACK_RGBA5551(139, 102, 139, 1);
else
shortcolor = GPACK_RGBA5551(255, 236, 139, 1);
gDPPipeSync((*ppGfx)++);
gDPSetFillColor((*ppGfx)++, shortcolor << 16 | shortcolor);
gDPFillRectangle((*ppGfx)++, pR->left, pR->top, pR->right, pR->top+kBevel_w);
gDPFillRectangle((*ppGfx)++, pR->left, pR->top, pR->left+kBevel_w, pR->bottom);
/* Draw the right and bottom edges. */
if (isSunken)
shortcolor = GPACK_RGBA5551(255, 236, 139, 1);
else
shortcolor = GPACK_RGBA5551(139, 139, 139, 1);
gDPPipeSync((*ppGfx)++);
gDPSetFillColor((*ppGfx)++, shortcolor << 16 | shortcolor);
gDPFillRectangle((*ppGfx)++, pR->left, pR->bottom, pR->right, pR->bottom+kBevel_w);
gDPFillRectangle((*ppGfx)++, pR->right, pR->top, pR->right+kBevel_w, pR->bottom);
gDPPipeSync((*ppGfx)++);
}
/*
Draws an icon defined by a sprite image centered
in the given rectangle.
*/
void
DrawSpriteIcon (Rect *pR, Sprite *pIcon, Gfx **ppGfx)
{
Gfx * dl;
int xIcon, yIcon;
/* Calculate the x and y coordinates for centering the icon. */
xIcon = pR->left + ((pR->right - pR->left)>>1) - (pIcon->width>>1);
yIcon = pR->top + ((pR->bottom - pR->top)>>1) - (pIcon->height>>1);
spSetAttribute (pIcon, SP_TRANSPARENT | SP_CUTOUT);
/* Center the icon. */
spMove (pIcon, xIcon, yIcon);
pIcon->rsp_dl_next = pIcon->rsp_dl;
dl = spDraw (pIcon);
gSPDisplayList ((*ppGfx)++, dl);
if((pIcon->rsp_dl_next -dl) >= pIcon->ndisplist)
PRINTF("Display List overrun by %d\n", (pIcon->rsp_dl_next -dl) - pIcon->ndisplist);
}
/*
Draws a gray rectangle.
The rectangle coordinates are defined by 'pR' and
the gray color is defined by 'grayIndex'. Display
list commands for rendering the rectangle are
written into 'ppGfx'.
*/
void
DrawGrayRect (Rect *pR, char grayIndex, Gfx **ppGfx)
{
u16 shortcolor;
gDPPipeSync((*ppGfx)++);
gDPSetCycleType ((*ppGfx)++, G_CYC_FILL);
gDPSetRenderMode ((*ppGfx)++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
shortcolor = GPACK_RGBA5551(grayIndex, grayIndex, grayIndex, 1);
gDPSetFillColor((*ppGfx)++, shortcolor << 16 | shortcolor);
__DPFrameRectangle(ppGfx, pR->left, pR->top, pR->right, pR->bottom);
gDPPipeSync((*ppGfx)++);
}
/*
Draws a sunken box with a number string.
The 'str' must contain only numeric characters and/or decimals, commas,
pluses, or minues. No other characters currently exist in kDigit6Font.
*/
void
DrawValueStrBox (Rect *pR, char *valueStr, char isHilited, Sprite *pStrSprite, Gfx **ppGfx)
{
Gfx *gp;
DrawBeveledRect (pR, TRUE, isHilited, ppGfx);
gp = *ppGfx;
font_init (&gp);
font_set_pos (pR->left + 2, pR->top + 2); /* Inset from the box's frame. */
font_set_color (0, 0, 0, 255);
font_set_scale (1.0, 1.0);
font_set_win (8, 1);
font_show_string (&gp, valueStr, pStrSprite);
font_finish (&gp);
*ppGfx = gp;
}
static void
__DPFrameRectangle(Gfx **ppGfx, int l, int t, int r, int b)
{
gDPFillRectangle((*ppGfx)++, l, t, r, t);
gDPFillRectangle((*ppGfx)++, r, t, r, b);
gDPFillRectangle((*ppGfx)++, l, b, r, b);
gDPFillRectangle((*ppGfx)++, l, t, l, b);
}