Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
draw_box.c
Go to the documentation of this file.
1#include "common.h"
2#include "nu/nusys.h"
3#include "include_asset.h"
4
5#define INTEGER_LOG2(x) ((x) <= 1 ? 0 : (x) <= 2 ? 1 : (x) <= 4 ? 2 : (x) <= 8 ? 3 : (x) <= 16 ? 4 : (x) <= 32 ? 5 : (x) <= 64 ? 6 : (x) <= 128 ? 7 : (x) <= 256 ? 8 : (x) <= 512 ? 9 : 10)
6
7typedef struct DefaultWindowStyle {
8 /* 0x00 */ u8 bgIndex;
9 /* 0x01 */ u8 cornersIndex;
10 /* 0x02 */ u8 combineModeIndex;
11 /* 0x03 */ Color_RGBA8 color1;
12 /* 0x07 */ Color_RGBA8 color2;
13} DefaultWindowStyle; // size = 0x0B
14
15#define BOX_QUAD_BUFFER_NUM 21
17
19 {
20 .bgIndex = 1,
21 .cornersIndex = 0,
22 .combineModeIndex = 0,
23 .color1 = { .r = 200, .g = 191, .b = 164, .a = 255 },
24 .color2 = { .r = 128, .g = 128, .b = 128, .a = 255 }
25 },
26 {
27 .bgIndex = 1,
28 .cornersIndex = 1,
29 .combineModeIndex = 1,
30 .color1 = { .r = 255, .g = 200, .b = 128, .a = 255 },
31 .color2 = { .r = 128, .g = 128, .b = 128, .a = 255 }
32 },
33 {
34 .bgIndex = 1,
35 .cornersIndex = 2,
36 .combineModeIndex = 1,
37 .color1 = { .r = 232, .g = 196, .b = 77, .a = 255 },
38 .color2 = { .r = 163, .g = 123, .b = 0, .a = 255 }
39 },
40 {
41 .bgIndex = 0,
42 .cornersIndex = 3,
43 .combineModeIndex = 1,
44 .color1 = { .r = 226, .g = 225, .b = 216, .a = 255 },
45 .color2 = { .r = 217, .g = 208, .b = 201, .a = 255 }
46 },
47 {
48 .bgIndex = 1,
49 .cornersIndex = 4,
50 .combineModeIndex = 1,
51 .color1 = { .r = 61, .g = 74, .b = 188, .a = 255 },
52 .color2 = { .r = 0, .g = 25, .b = 28, .a = 255 }
53 },
54 {
55 .bgIndex = 1,
56 .cornersIndex = 5,
57 .combineModeIndex = 1,
58 .color1 = { .r = 235, .g = 230, .b = 119, .a = 255 },
59 .color2 = { .r = 142, .g = 90, .b = 37, .a = 255 }
60 },
61 {
62 .bgIndex = 1,
63 .cornersIndex = 6,
64 .combineModeIndex = 1,
65 .color1 = { .r = 235, .g = 230, .b = 119, .a = 255 },
66 .color2 = { .r = 142, .g = 99, .b = 37, .a = 255 }
67 },
68 {
69 .bgIndex = 1,
70 .cornersIndex = 4,
71 .combineModeIndex = 1,
72 .color1 = { .r = 215, .g = 191, .b = 116, .a = 255 },
73 .color2 = { .r = 132, .g = 70, .b = 50, .a = 255 }
74 },
75 {
76 .bgIndex = 1,
77 .cornersIndex = 4,
78 .combineModeIndex = 1,
79 .color1 = { .r = 215, .g = 191, .b = 116, .a = 255 },
80 .color2 = { .r = 132, .g = 70, .b = 50, .a = 255 }
81 },
82 {
83 .bgIndex = 1,
84 .cornersIndex = 4,
85 .combineModeIndex = 1,
86 .color1 = { .r = 141, .g = 143, .b = 255, .a = 255 },
87 .color2 = { .r = 43, .g = 69, .b = 102, .a = 255 }
88 },
89 {
90 .bgIndex = 1,
91 .cornersIndex = 8,
92 .combineModeIndex = 1,
93 .color1 = { .r = 141, .g = 143, .b = 255, .a = 255 },
94 .color2 = { .r = 43, .g = 69, .b = 102, .a = 255 }
95 },
96 {
97 .bgIndex = 1,
98 .cornersIndex = 4,
99 .combineModeIndex = 1,
100 .color1 = { .r = 170, .g = 208, .b = 128, .a = 255 },
101 .color2 = { .r = 71, .g = 123, .b = 83, .a = 255 }
102 },
103 {
104 .bgIndex = 1,
105 .cornersIndex = 8,
106 .combineModeIndex = 1,
107 .color1 = { .r = 170, .g = 208, .b = 128, .a = 255 },
108 .color2 = { .r = 71, .g = 123, .b = 83, .a = 255 }
109 },
110 {
111 .bgIndex = 1,
112 .cornersIndex = 4,
113 .combineModeIndex = 1,
114 .color1 = { .r = 200, .g = 200, .b = 90, .a = 255 },
115 .color2 = { .r = 140, .g = 140, .b = 0, .a = 255 }
116 },
117 {
118 .bgIndex = 1,
119 .cornersIndex = 8,
120 .combineModeIndex = 1,
121 .color1 = { .r = 200, .g = 200, .b = 90, .a = 255 },
122 .color2 = { .r = 140, .g = 140, .b = 0, .a = 255 }
123 },
124 {
125 .bgIndex = 1,
126 .cornersIndex = 4,
127 .combineModeIndex = 1,
128 .color1 = { .r = 235, .g = 230, .b = 119, .a = 255 },
129 .color2 = { .r = 142, .g = 90, .b = 37, .a = 255 }
130 },
131 {
132 .bgIndex = 1,
133 .cornersIndex = 4,
134 .combineModeIndex = 1,
135 .color1 = { .r = 142, .g = 212, .b = 236, .a = 255 },
136 .color2 = { .r = 67, .g = 98, .b = 69, .a = 255 }
137 },
138 {
139 .bgIndex = 1,
140 .cornersIndex = 4,
141 .combineModeIndex = 1,
142 .color1 = { .r = 167, .g = 151, .b = 119, .a = 255 },
143 .color2 = { .r = 98, .g = 55, .b = 154, .a = 255 }
144 },
145 {
146 .bgIndex = 1,
147 .cornersIndex = 7,
148 .combineModeIndex = 1,
149 .color1 = { .r = 17, .g = 151, .b = 29, .a = 255 },
150 .color2 = { .r = 8, .g = 55, .b = 14, .a = 255 }
151 },
152 {
153 .bgIndex = 1,
154 .cornersIndex = 7,
155 .combineModeIndex = 1,
156 .color1 = { .r = 110, .g = 110, .b = 200, .a = 255 },
157 .color2 = { .r = 10, .g = 10, .b = 100, .a = 255 }
158 },
159 {
160 .bgIndex = 1,
161 .cornersIndex = 4,
162 .combineModeIndex = 1,
163 .color1 = { .r = 181, .g = 60, .b = 60, .a = 255 },
164 .color2 = { .r = 76, .g = 10, .b = 0, .a = 255 }
165 },
166 {
167 .bgIndex = 1,
168 .cornersIndex = 4,
169 .combineModeIndex = 1,
170 .color1 = { .r = 174, .g = 227, .b = 235, .a = 255 },
171 .color2 = { .r = 76, .g = 110, .b = 60, .a = 255 }
172 },
173 {
174 .bgIndex = 0,
175 .cornersIndex = 3,
176 .combineModeIndex = 1,
177 .color1 = { .r = 126, .g = 125, .b = 216, .a = 255 },
178 .color2 = { .r = 217, .g = 108, .b = 201, .a = 255 }
179 }
180};
181
182INCLUDE_IMG("ui/box/corners9.png", ui_box_corners9_png);
183INCLUDE_IMG("ui/box/corners8.png", ui_box_corners8_png);
184INCLUDE_IMG("ui/box/corners6.png", ui_box_corners6_png);
185INCLUDE_IMG("ui/box/corners7.png", ui_box_corners7_png);
186INCLUDE_IMG("ui/box/corners3.png", ui_box_corners3_png);
187INCLUDE_IMG("ui/box/corners5.png", ui_box_corners5_png);
188INCLUDE_IMG("ui/box/corners4.png", ui_box_corners4_png);
189INCLUDE_IMG("ui/box/bg_tile.png", ui_box_bg_tile_png);
190INCLUDE_IMG("ui/box/corners1.png", ui_box_corners1_png);
191INCLUDE_IMG("ui/box/corners2.png", ui_box_corners2_png);
192INCLUDE_IMG("ui/box/bg_flat.png", ui_box_bg_flat_png);
193
195 {
197 .fmt = G_IM_FMT_I,
198 .bitDepth = G_IM_SIZ_4b,
199 .width = 16,
200 .height = 16,
201 .unk_07 = { 0, 0, 0, 0},
202 .size = 128
203 },
204 {
205 .imgData = ui_box_bg_flat_png,
206 .fmt = G_IM_FMT_I,
207 .bitDepth = G_IM_SIZ_4b,
208 .width = 16,
209 .height = 1,
210 .unk_07 = { 0, 0, 0, 0},
211 .size = 8
212 }
213};
214
216 {
217 .imgData = ui_box_corners1_png,
218 .fmt = G_IM_FMT_IA,
219 .bitDepth = G_IM_SIZ_8b,
220 .size1 = { 16, 16},
221 .size2 = { 16, 16},
222 .size3 = { 16, 16},
223 .size4 = { 16, 16},
224 .unk_0D = { 0, 0, 0}
225 },
226 {
227 .imgData = ui_box_corners2_png,
228 .fmt = G_IM_FMT_I,
229 .bitDepth = G_IM_SIZ_4b,
230 .size1 = { 16, 16},
231 .size2 = { 16, 16},
232 .size3 = { 16, 16},
233 .size4 = { 16, 16},
234 .unk_0D = { 0, 0, 0}
235 },
236 {
237 .imgData = ui_box_corners3_png,
238 .fmt = G_IM_FMT_IA,
239 .bitDepth = G_IM_SIZ_8b,
240 .size1 = { 16, 32},
241 .size2 = { 16, 32},
242 .size3 = { 16, 16},
243 .size4 = { 16, 16},
244 .unk_0D = { 0, 0, 0}
245 },
246 {
247 .imgData = ui_box_corners4_png,
248 .fmt = G_IM_FMT_IA,
249 .bitDepth = G_IM_SIZ_8b,
250 .size1 = { 8, 8},
251 .size2 = { 8, 8},
252 .size3 = { 8, 8},
253 .size4 = { 8, 8},
254 .unk_0D = { 0, 0, 0}
255 },
256 {
257 .imgData = ui_box_corners5_png,
258 .fmt = G_IM_FMT_IA,
259 .bitDepth = G_IM_SIZ_8b,
260 .size1 = { 16, 8},
261 .size2 = { 16, 8},
262 .size3 = { 16, 8},
263 .size4 = { 16, 8},
264 .unk_0D = { 0, 0, 0}
265 },
266 {
267 .imgData = ui_box_corners6_png,
268 .fmt = G_IM_FMT_IA,
269 .bitDepth = G_IM_SIZ_8b,
270 .size1 = { 16, 8},
271 .size2 = { 16, 8},
272 .size3 = { 16, 8},
273 .size4 = { 16, 16},
274 .unk_0D = { 0, 0, 0}
275 },
276 {
277 .imgData = ui_box_corners7_png,
278 .fmt = G_IM_FMT_IA,
279 .bitDepth = G_IM_SIZ_8b,
280 .size1 = { 16, 8},
281 .size2 = { 16, 8},
282 .size3 = { 16, 8},
283 .size4 = { 16, 8},
284 .unk_0D = { 0, 0, 0}
285 },
286 {
287 .imgData = ui_box_corners8_png,
288 .fmt = G_IM_FMT_IA,
289 .bitDepth = G_IM_SIZ_8b,
290 .size1 = { 24, 24},
291 .size2 = { 24, 24},
292 .size3 = { 24, 24},
293 .size4 = { 24, 24},
294 .unk_0D = { 0, 0, 0}
295 },
296 {
297 .imgData = ui_box_corners9_png,
298 .fmt = G_IM_FMT_IA,
299 .bitDepth = G_IM_SIZ_8b,
300 .size1 = { 16, 16},
301 .size2 = { 16, 16},
302 .size3 = { 16, 16},
303 .size4 = { 16, 16},
304 .unk_0D = { 0, 0, 0}
305 }
306};
307
309 gsDPSetCombineMode(PM_CC_BOX1_OPAQUE, PM_CC_BOX1_CYC2),
310 gsDPSetCombineMode(PM_CC_BOX2_OPAQUE, PM_CC_BOX2_CYC2),
311 gsDPSetCombineMode(PM_CC_BOX1_TRANSPARENT, PM_CC_BOX1_CYC2),
312 gsDPSetCombineMode(PM_CC_BOX2_TRANSPARENT, PM_CC_BOX2_CYC2)
313};
314
316
318 .vp = {
319 .vscale = { 640, 480, 511, 0 },
320 .vtrans = { 640, 480, 511, 0 }
321 }
322};
323
324#include "vtx/drawbox1.vtx.inc.c"
325
327 0.000000, 0.000000, 0.000000, -6.000000,
328 0.000000, 0.000000, 0.000000, 0.000000,
329 0.000000, 0.000000, 0.000000, 0.000000,
330 0.000000, 0.000000, 0.000000, 0.000000
331);
332
333// @bug there's an issue with the way the "quads" temp below is used, sometimes going out of bounds.
334// In vanilla, this results in some data being written to an unused struct field inside gPartnerStatus, which doesn't
335// cause any issues. In shiftable builds, there's no telling where quads might be, so we make some adjustments to
336// prevent the overflow
337s32 draw_box(s32 flags, WindowStyle windowStyle, s32 posX, s32 posY, s32 posZ, s32 width, s32 height, u8 opacity,
338 u8 darkening, f32 scaleX, f32 scaleY, f32 rotX, f32 rotY, f32 rotZ,
339 void (*fpDrawContents)(s32, s32, s32, s32, s32, s32, s32), void* drawContentsArg0, Matrix4f rotScaleMtx,
340 s32 translateX, s32 translateY, Matrix4f outMtx)
341{
342 Matrix4f mtx1, mtx2, mtx3;
343 u8 primR, primG, primB, primA, envR, envG, envB, envA;
344 DefaultWindowStyle* defaultStyle = NULL;
345 WindowStyleCustom* customStyle = NULL;
346 WindowCorners* corners;
347 WindowBackground* background;
348 u32 bgWidth, bgHeight;
349 u32 cornerWidth, cornerHeight;
350 s32 masks, maskt;
351 Vtx* quads;
352 s32 idx;
353 s32 i, j;
354 s32 tmem = 0x100;
355 u32 bgScrollOffsetX, bgScrollOffsetY;
356
357 s32 foo;
358 s32 alpha = foo * opacity / 255;
359
360 if (windowStyle.defaultStyleID <= WINDOW_STYLE_MAX && windowStyle.defaultStyleID >= 0) {
361 defaultStyle = &gBoxDefaultStyles[windowStyle.defaultStyleID];
362
363 primR = defaultStyle->color1.r;
364 primG = defaultStyle->color1.g;
365 primB = defaultStyle->color1.b;
366 primA = defaultStyle->color1.a * opacity / 255;
367 envR = defaultStyle->color2.r;
368 envG = defaultStyle->color2.g;
369 envB = defaultStyle->color2.b;
370 envA = defaultStyle->color2.a;
371
372 background = &gBoxBackground[defaultStyle->bgIndex];
373 corners = &gBoxCorners[defaultStyle->cornersIndex];
374 } else {
375 primR = windowStyle.customStyle->color1.r;
376 primG = windowStyle.customStyle->color1.g;
377 primB = windowStyle.customStyle->color1.b;
378 primA = windowStyle.customStyle->color1.a * opacity / 255;
379 envR = windowStyle.customStyle->color2.r;
380 envG = windowStyle.customStyle->color2.g;
381 envB = windowStyle.customStyle->color2.b;
382 envA = windowStyle.customStyle->color2.a;
383
384 customStyle = windowStyle.customStyle;
385 background = &windowStyle.customStyle->background;
386 corners = &windowStyle.customStyle->corners;
387 }
388 {
389 u8* bgImage;
390 u8* cornersImage;
391 s32 bgFmt;
392 s32 bgMasks;
393 s32 bgMaskt;
394 Vec2bu* cornersSizes;
395 u32 cornersFmt;
396 u32 cornersBitDepth;
397 Mtx* sp154;
398
399 bgFmt = background->fmt;
400 cornersImage = corners->imgData;
401
402 bgWidth = background->width;
403 bgImage = background->imgData;
404 bgHeight = background->height;
405
406 bgMasks = INTEGER_LOG2(bgWidth);
407 bgMaskt = INTEGER_LOG2(bgHeight);
408
409 quads = NULL;
410 sp154 = NULL;
411 cornersSizes = (Vec2bu*)&corners->size1;
412 cornersFmt = corners->fmt;
413 cornersBitDepth = corners->bitDepth;
414
415 if (width <= 0 || height <= 0 || opacity == 0 || posX <= -768 || posY <= -768) {
416 return TRUE;
417 }
418
419 if (posX >= SCREEN_WIDTH || posY >= SCREEN_HEIGHT) {
420 return TRUE;
421 }
422
423 if (posX + width >= 768 || posY + height >= 768 || posX + width <= 0 || posY + height <= 0) {
424 return TRUE;
425 }
426
428 quads = gBoxQuadBuffer[gBoxQuadIndex++];
430 gBoxQuadIndex = 0;
431 }
432 }
433
434 gDPPipeSync(gMainGfxPos++);
435 gDPSetCycleType(gMainGfxPos++, G_CYC_2CYCLE);
436 gDPSetBlendColor(gMainGfxPos++, 0, 0, 0, 0);
437 gDPSetFogColor(gMainGfxPos++, 0, 0, 0, darkening);
438 gDPSetRenderMode(gMainGfxPos++, PM_RM_SHROUD, G_RM_XLU_SURF2);
439 if (!(flags & DRAW_FLAG_NO_CLIP)) {
440 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
441 }
442
443 if (defaultStyle != NULL) {
444 Gfx* gfxPos = gMainGfxPos;
445 *gfxPos = gBoxCombineModes[defaultStyle->combineModeIndex + (primA != 255 ? 2 : 0)];
446 } else {
447 Gfx* gfxPos = gMainGfxPos;
448 if (primA != 255) {
449 *gfxPos = customStyle->transparentCombineMode;
450 } else {
451 *gfxPos = customStyle->opaqueCombineMode;
452 }
453 }
454
455 gMainGfxPos++;
456 gDPSetTextureFilter(gMainGfxPos++, G_TF_POINT);
457
458 if (quads != NULL) {
459 gSPViewport(gMainGfxPos++, &gBoxViewport);
460 guFrustumF(mtx1, -80.0f, 80.0f, 60.0f, -60.0f, 160.0f, 480.0f, 1.0f);
463 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
464 guPositionF(mtx1, rotX, rotY, rotZ, 1.0f, posX + width / 2, posY + height / 2, posZ);
465 if (scaleX != 1.0f || scaleY != 1.0f) {
466 guScaleF(mtx2, scaleX, scaleY, 1.0f);
467 guMtxCatF(mtx2, mtx1, mtx1);
468 }
469 if (rotScaleMtx != 0) {
470 guTranslateF(mtx2, -translateX / 2, -translateY / 2, 0.0f);
471 guMtxCatF(mtx1, mtx2, mtx2);
472 guMtxCatF(mtx2, rotScaleMtx, mtx1);
473 }
474 if (outMtx) {
475 for (i = 0; i < 4; i++) {
476 for (j = 0; j < 4; j++) {
477 outMtx[i][j] = mtx1[i][j];
478 }
479 }
480 }
481 guTranslateF(mtx2, -160.0f, -120.0f, -320.0f);
482 guMtxCatF(mtx1, mtx2, mtx1);
483 gSPClearGeometryMode(gMainGfxPos++, G_CULL_BOTH | G_LIGHTING);
485 gSPSetGeometryMode(gMainGfxPos++, G_CULL_BACK);
486 }
488 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
489 gDPSetTexturePersp(gMainGfxPos++, G_TP_PERSP);
490 gSPPerspNormalize(gMainGfxPos++, 20);
491 } else {
492 gDPSetTexturePersp(gMainGfxPos++, G_TP_NONE);
493 }
494
495 gSPTexture(gMainGfxPos++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
496 gDPSetTextureLUT(gMainGfxPos++, G_TT_NONE);
497 gDPSetTextureDetail(gMainGfxPos++, G_TD_CLAMP);
498 gDPSetTextureLOD(gMainGfxPos++, G_TL_TILE);
499 gDPSetPrimColor(gMainGfxPos++, 0, 0, primR, primG, primB, primA);
500 gDPSetEnvColor(gMainGfxPos++, envR, envG, envB, envA);
501 if (bgImage != NULL) {
502 switch (background->bitDepth) {
503 case G_IM_SIZ_4b:
504 gDPLoadTextureTile_4b(gMainGfxPos++, bgImage, bgFmt, bgWidth, bgHeight, 0, 0, bgWidth - 1, bgHeight - 1, 0, G_TX_WRAP, G_TX_WRAP, bgMasks, bgMaskt, G_TX_NOLOD, G_TX_NOLOD);
505 break;
506 case G_IM_SIZ_8b:
507 gDPLoadTextureTile(gMainGfxPos++, bgImage, bgFmt, G_IM_SIZ_8b, bgWidth, bgHeight, 0, 0, bgWidth - 1, bgHeight - 1, 0, G_TX_WRAP, G_TX_WRAP, bgMasks, bgMaskt, G_TX_NOLOD, G_TX_NOLOD);
508 break;
509 case G_IM_SIZ_16b:
510 gDPLoadTextureTile(gMainGfxPos++, bgImage, bgFmt, G_IM_SIZ_16b, bgWidth, bgHeight, 0, 0, bgWidth - 1, bgHeight - 1, 0, G_TX_WRAP, G_TX_WRAP, bgMasks, bgMaskt, G_TX_NOLOD, G_TX_NOLOD);
511 break;
512 case G_IM_SIZ_32b:
513 gDPLoadTextureTile(gMainGfxPos++, bgImage, bgFmt, G_IM_SIZ_32b, bgWidth, bgHeight, 0, 0, bgWidth - 1, bgHeight - 1, 0, G_TX_WRAP, G_TX_WRAP, bgMasks, bgMaskt, G_TX_NOLOD, G_TX_NOLOD);
514 break;
515 }
516
518 bgScrollOffsetY = (gGameStatusPtr->frameCounter * 4) & 0x1FF;
519 bgScrollOffsetX = 511 - bgScrollOffsetY;
520 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE,
521 width / 2 * 4 + bgScrollOffsetX,
522 height / 2 * 4 + bgScrollOffsetY,
523 (width / 2 + bgWidth - 1) * 4 + bgScrollOffsetX,
524 (height / 2 + bgHeight - 1) * 4 + bgScrollOffsetY);
525 } else {
526 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE, width / 2 * 4, height / 2 * 4,
527 (width / 2 + bgWidth - 1) * 4, (height / 2 + bgHeight - 1)* 4);
528 }
529 }
530
531 if (cornersImage != NULL) {
532 for (idx = 0; idx < 4; idx++) {
533 cornerWidth = cornersSizes[idx].x;
534 cornerHeight = cornersSizes[idx].y;
535 masks = INTEGER_LOG2(cornerWidth);
536 maskt = INTEGER_LOG2(cornerHeight);
537
538
539 switch (cornersBitDepth) {
540 case G_IM_SIZ_4b:
541 gDPLoadMultiTile_4b(gMainGfxPos++, cornersImage, tmem, 1, cornersFmt, cornerWidth, cornerHeight, 0, 0, cornerWidth - 1, cornerHeight - 1, 0, G_TX_CLAMP, G_TX_CLAMP, masks, maskt, G_TX_NOLOD, G_TX_NOLOD);
542 cornersImage += cornerWidth * cornerHeight / 2;
543 break;
544 case G_IM_SIZ_8b:
545 gDPLoadMultiTile(gMainGfxPos++, cornersImage, tmem, 1, cornersFmt, G_IM_SIZ_8b, cornerWidth, cornerHeight, 0, 0, cornerWidth - 1, cornerHeight - 1, 0, G_TX_CLAMP, G_TX_CLAMP, masks, maskt, G_TX_NOLOD, G_TX_NOLOD);
546 cornersImage += cornerWidth * cornerHeight;
547 break;
548 case G_IM_SIZ_16b:
549 gDPLoadMultiTile(gMainGfxPos++, cornersImage, tmem, 1, cornersFmt, G_IM_SIZ_16b, cornerWidth, cornerHeight, 0, 0, cornerWidth - 1, cornerHeight - 1, 0, G_TX_CLAMP, G_TX_CLAMP, masks, maskt, G_TX_NOLOD, G_TX_NOLOD);
550 cornersImage += cornerWidth * cornerHeight * 2;
551 break;
552 case G_IM_SIZ_32b:
553 gDPLoadMultiTile(gMainGfxPos++, cornersImage, tmem, 1, cornersFmt, G_IM_SIZ_32b, cornerWidth, cornerHeight, 0, 0, cornerWidth - 1, cornerHeight - 1, 0, G_TX_CLAMP, G_TX_CLAMP, masks, maskt, G_TX_NOLOD, G_TX_NOLOD);
554 cornersImage += cornerWidth * cornerHeight * 4;
555 break;
556 }
557
558 switch(idx) {
559 case 1:
560 gDPSetTileSize(gMainGfxPos++, 1, (width - cornerWidth) * 4, 0, (width - 1) * 4, (cornerHeight - 1) * 4);
561 break;
562 case 2:
563 gDPSetTileSize(gMainGfxPos++, 1, 0, (height - cornerHeight) * 4, (cornerWidth - 1) * 4, (height - 1) * 4);
564 break;
565 case 3:
566 gDPSetTileSize(gMainGfxPos++, 1, (width - cornerWidth) * 4, (height - cornerHeight) * 4, (width - 1) * 4, (height - 1) * 4);
567 break;
568 }
569
570 if (quads != NULL) {
571 switch(idx) {
572 case 0:
573 quads[0].v.ob[0] = -width / 2;
574 quads[0].v.ob[1] = -height / 2;
575 quads[0].v.ob[2] = 0;
576
577 quads[1].v.ob[0] = 0;
578 quads[1].v.ob[1] = -height / 2;
579 quads[1].v.ob[2] = 0;
580
581 quads[2].v.ob[0] = -width / 2;
582 quads[2].v.ob[1] = 0;
583 quads[2].v.ob[2] = 0;
584
585 quads[3].v.ob[0] = 0;
586 quads[3].v.ob[1] = 0;
587 quads[3].v.ob[2] = 0;
588
589 quads[0].v.tc[0] = 0;
590 quads[0].v.tc[1] = 0;
591
592 quads[1].v.tc[0] = (width / 2) * 32;
593 quads[1].v.tc[1] = 0;
594
595 quads[2].v.tc[0] = 0;
596 quads[2].v.tc[1] = (height / 2) * 32;
597
598 quads[3].v.tc[0] = (width / 2) * 32;
599 quads[3].v.tc[1] = (height / 2) * 32;
600 break;
601 case 1:
602 quads[4].v.ob[0] = 0;
603 quads[4].v.ob[1] = -height / 2;
604 quads[4].v.ob[2] = 0;
605
606 quads[5].v.ob[0] = (-width / 2) + width;
607 quads[5].v.ob[1] = -height / 2;
608 quads[5].v.ob[2] = 0;
609
610 quads[6].v.ob[0] = 0;
611 quads[6].v.ob[1] = 0;
612 quads[6].v.ob[2] = 0;
613
614 quads[7].v.ob[0] = (-width / 2) + width;
615 quads[7].v.ob[1] = 0;
616 quads[7].v.ob[2] = 0;
617
618 quads[4].v.tc[0] = (width / 2) * 32;
619 quads[4].v.tc[1] = 0;
620
621 quads[5].v.tc[0] = width * 32;
622 quads[5].v.tc[1] = 0;
623
624 quads[6].v.tc[0] = (width / 2) * 32;
625 quads[6].v.tc[1] = (height / 2) * 32;
626
627 quads[7].v.tc[0] = width * 32;
628 quads[7].v.tc[1] = (height / 2) * 32;
629
630#ifndef SHIFT
631 quads += 4;
632#endif
633 break;
634 case 2:
635 quads[8].v.ob[0] = -width / 2;
636 quads[8].v.ob[1] = 0;
637 quads[8].v.ob[2] = 0;
638
639 quads[9].v.ob[0] = 0;
640 quads[9].v.ob[1] = 0;
641 quads[9].v.ob[2] = 0;
642
643 quads[10].v.ob[0] = -width / 2;
644 quads[10].v.ob[1] = height / 2;
645 quads[10].v.ob[2] = 0;
646
647 quads[11].v.ob[0] = 0;
648 quads[11].v.ob[1] = height / 2;
649 quads[11].v.ob[2] = 0;
650
651 quads[8].v.tc[0] = 0;
652 quads[8].v.tc[1] = (height / 2) * 32;
653
654 quads[9].v.tc[0] = (width / 2) * 32;
655 quads[9].v.tc[1] = (height / 2) * 32;
656
657 quads[10].v.tc[0] = 0;
658 quads[10].v.tc[1] = height * 32;
659
660 quads[11].v.tc[0] = (width / 2) * 32;
661 quads[11].v.tc[1] = height * 32;
662
663#ifndef SHIFT
664 quads += 8;
665#endif
666 break;
667 case 3:
668 quads[12].v.ob[0] = 0;
669 quads[12].v.ob[1] = 0;
670 quads[12].v.ob[2] = 0;
671
672 quads[13].v.ob[0] = (-width / 2) + width;
673 quads[13].v.ob[1] = 0;
674 quads[13].v.ob[2] = 0;
675
676 quads[14].v.ob[0] = 0;
677 quads[14].v.ob[1] = height / 2;
678 quads[14].v.ob[2] = 0;
679
680 quads[15].v.ob[0] = (-width / 2) + width;
681 quads[15].v.ob[1] = height / 2;
682 quads[15].v.ob[2] = 0;
683
684 quads[12].v.tc[0] = (width / 2) * 32;
685 quads[12].v.tc[1] = (height / 2) * 32;
686
687 quads[13].v.tc[0] = width * 32;
688 quads[13].v.tc[1] = (height / 2) * 32;
689
690 quads[14].v.tc[0] = (width / 2) * 32;
691 quads[14].v.tc[1] = height * 32;
692
693 quads[15].v.tc[0] = width * 32;
694 quads[15].v.tc[1] = height * 32;
695
696#ifndef SHIFT
697 quads += 12;
698#endif
699 break;
700 }
701#ifdef SHIFT
702 gSPVertex(gMainGfxPos++, &quads[idx*4], 4, 0);
703#else
704 gSPVertex(gMainGfxPos++, quads, 4, 0);
705#endif
706 gSP2Triangles(gMainGfxPos++, 0, 3, 1, 0, 0, 2, 3, 0);
707 } else {
708 switch (idx) {
709 case 0:
710 gSPScisTextureRectangle(gMainGfxPos++, posX * 4, posY * 4, (posX + width / 2) * 4, (posY + height / 2) * 4, G_TX_RENDERTILE, 0, 0, 0x400, 0x400);
711 break;
712 case 1:
713 gSPScisTextureRectangle(gMainGfxPos++, (posX + width / 2) * 4, posY * 4, (posX + width) * 4, (posY + height / 2) * 4, G_TX_RENDERTILE, (width / 2) * 32, 0, 0x400, 0x400);
714 break;
715 case 2:
716 gSPScisTextureRectangle(gMainGfxPos++, posX * 4, (posY + height / 2) * 4, (posX + width / 2) * 4, (posY + height) * 4, G_TX_RENDERTILE, 0, (height / 2) * 32, 0x400, 0x400);
717 break;
718 case 3:
719 gSPScisTextureRectangle(gMainGfxPos++, (posX + width / 2) * 4, (posY + height / 2) * 4, (posX + width) * 4, (posY + height) * 4, G_TX_RENDERTILE, (width / 2) * 32, (height / 2) * 32, 0x400, 0x400);
720 break;
721 }
722
723 }
724 gDPPipeSync(gMainGfxPos++);
725 }
726 } else if (bgImage != NULL) {
727 if (quads != NULL) {
728 quads[0].v.ob[0] = -width / 2;
729 quads[0].v.ob[1] = -height / 2;
730 quads[0].v.ob[2] = 0;
731
732 quads[1].v.ob[0] = (-width / 2) + width;
733 quads[1].v.ob[1] = -height / 2;
734 quads[1].v.ob[2] = 0;
735
736 quads[2].v.ob[0] = -width / 2;
737 quads[2].v.ob[1] = height / 2;
738 quads[2].v.ob[2] = 0;
739
740 quads[3].v.ob[0] = (-width / 2) + width;
741 quads[3].v.ob[1] = height / 2;
742 quads[3].v.ob[2] = 0;
743
744
745 quads[0].v.tc[0] = 0;
746 quads[0].v.tc[1] = 0;
747
748 quads[1].v.tc[1] = 0;
749 quads[1].v.tc[0] = width * 32;
750
751 quads[2].v.tc[0] = 0;
752 quads[2].v.tc[1] = height * 32;
753
754 quads[3].v.tc[0] = width * 32;
755 quads[3].v.tc[1] = height * 32;
756
757 gSPVertex(gMainGfxPos++, &quads[0], 4, 0);
758 gSP2Triangles(gMainGfxPos++, 0, 3, 1, 0, 0, 2, 3, 0);
759 } else {
760 gSPScisTextureRectangle(gMainGfxPos++, posX * 4, posY * 4, (posX + width) * 4, (posY + height) * 4, G_TX_RENDERTILE, 0, 0, 0x0400, 0x0400);
761 }
762 gDPPipeSync(gMainGfxPos++);
763 }
764
765 gDPSetTexturePersp(gMainGfxPos++, G_TP_NONE);
766 gDPSetCycleType(gMainGfxPos++, G_CYC_1CYCLE);
767 if(fpDrawContents != NULL) {
768 if (quads != NULL) {
769 void* mdl_address = mdl_get_next_texture_address(width * height * 2);
770 if(mdl_address != 0) {
771 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, OS_K0_TO_PHYSICAL(mdl_address));
772 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, width, height);
773 gDPSetCycleType(gMainGfxPos++, G_CYC_FILL);
774 gDPSetFillColor(gMainGfxPos++, PACK_FILL_COLOR(primR, primG, primB, 0));
775 gDPSetRenderMode(gMainGfxPos++, G_RM_NOOP, G_RM_NOOP2);
776 gDPFillRectangle(gMainGfxPos++, 0, 0, width - 1, height - 1);
777 gDPPipeSync(gMainGfxPos++);
778 gDPSetScissorFrac(gMainGfxPos++, G_SC_NON_INTERLACE, 4, 4, (width - 1) * 4.0f, (height - 1) * 4.0f);
779 gDPSetCycleType(gMainGfxPos++, G_CYC_1CYCLE);
780
781 fpDrawContents((s32)drawContentsArg0, 0, 0, width, height, opacity, darkening);
782
783 gDPPipeSync(gMainGfxPos++);
784 gDPSetColorImage(gMainGfxPos++, G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, OS_K0_TO_PHYSICAL(nuGfxCfb_ptr));
785 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, 320, 240);
786 gSPViewport(gMainGfxPos++, &gBoxViewport);
787 gSPMatrix(gMainGfxPos++, sp154, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
788 gSPTexture(gMainGfxPos++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
789 gDPSetCycleType(gMainGfxPos++, G_CYC_1CYCLE);
790 gDPSetTextureLUT(gMainGfxPos++, G_TT_NONE);
791 gDPSetCombineMode(gMainGfxPos++, G_CC_DECALRGBA, G_CC_DECALRGBA);
792 gDPSetRenderMode(gMainGfxPos++, G_RM_CLD_SURF, G_RM_NOOP2);
793 gDPSetTexturePersp(gMainGfxPos++, G_TP_PERSP);
794 gDPSetTextureFilter(gMainGfxPos++, G_TF_BILERP);
795 guTranslateF(mtx3, 0.0f, 6.0f, 0.0f);
796 guMtxF2L(mtx3, &gBoxMatrix);
797 guTranslateF(mtx3, 0.0f, -height / 2, 0.0f);
799 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
800 for (idx = 0; idx < height / 6; idx++) {
801 s32 extraHeight, lineHeight;
802 if (idx == height / 6 - 1) {
803 extraHeight = 0;
804 if (height % 6 != 0) {
805 extraHeight = 1;
806 }
807 } else {
808 extraHeight = 1;
809 }
810 lineHeight = extraHeight + 5;
811 gDPLoadTextureTile(gMainGfxPos++, OS_K0_TO_PHYSICAL(mdl_address), G_IM_FMT_RGBA, G_IM_SIZ_16b, width, 0,
812 0, idx * 6, width - 1, idx * 6 + lineHeight, 0,
813 G_TX_CLAMP, G_TX_CLAMP, 9, 3, G_TX_NOLOD, G_TX_NOLOD);
814 gDPSetTileSize(gMainGfxPos++, G_TX_RENDERTILE, (160 - width / 2) * 4, 0, ((160 - width / 2) + width - 1) * 4, lineHeight * 4);
815 gSPVertex(gMainGfxPos++, &vtx_drawbox1, 4, 0);
816 gSP2Triangles(gMainGfxPos++, 0, 3, 1, 0, 0, 2, 3, 0);
817 gDPPipeSync(gMainGfxPos++);
818 gSPMatrix(gMainGfxPos++, &gBoxMatrix, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
819 }
820 }
821 } else {
822 fpDrawContents((s32)drawContentsArg0, posX, posY, width, height, opacity, darkening);
823 }
824 }
825 if (quads != NULL) {
826 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
827 gDPSetTexturePersp(gMainGfxPos++, G_TP_NONE);
828 gDPPipeSync(gMainGfxPos++);
829 }
830 return FALSE;
831 }
832}
u16 * nuGfxCfb_ptr
Definition cam_main.c:14
WindowCorners corners
WindowBackground background
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
WindowStyleCustom * customStyle
s8 flags
Definition demo_api.c:15
DefaultWindowStyle gBoxDefaultStyles[]
Definition draw_box.c:18
Mtx gBoxMatrix
Definition draw_box.c:326
BSS Vtx gBoxQuadBuffer[21][16]
Definition draw_box.c:16
WindowCorners gBoxCorners[]
Definition draw_box.c:215
#define BOX_QUAD_BUFFER_NUM
Definition draw_box.c:15
#define INTEGER_LOG2(x)
Definition draw_box.c:5
Vp gBoxViewport
Definition draw_box.c:317
s32 gBoxQuadIndex
Definition draw_box.c:315
Color_RGBA8 color1
Definition draw_box.c:11
WindowBackground gBoxBackground[]
Definition draw_box.c:194
Gfx gBoxCombineModes[]
Definition draw_box.c:308
Color_RGBA8 color2
Definition draw_box.c:12
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define guFrustumF
#define guPositionF
#define draw_box
#define guScaleF
@ WINDOW_STYLE_MAX
Definition enums.h:6393
@ DRAW_FLAG_NO_CLIP
Definition enums.h:5005
@ DRAW_FLAG_ROTSCALE
Definition enums.h:5003
@ DRAW_FLAG_CULL_BACK
Definition enums.h:5006
@ DRAW_FLAG_ANIMATED_BACKGROUND
Definition enums.h:5004
void * mdl_get_next_texture_address(s32)
Definition model.c:4509
#define INCLUDE_IMG(FILENAME, SYMBOLNAME)
s8 ui_box_corners4_png[]
s8 ui_box_bg_tile_png[]
#define RDP_MATRIX( Ax, Bx, Cx, Dx, Ay, By, Cy, Dy, Az, Bz, Cz, Dz, Aw, Bw, Cw, Dw)
Definition macros.h:233
#define PM_RM_SHROUD
Definition macros.h:274
#define SCREEN_WIDTH
Definition macros.h:105
#define BSS
Definition macros.h:7
#define SCREEN_HEIGHT
Definition macros.h:106
#define PM_CC_BOX1_TRANSPARENT
Definition macros.h:458
#define PM_CC_BOX2_TRANSPARENT
Definition macros.h:459
#define PM_CC_BOX1_CYC2
Definition macros.h:461
#define PACK_FILL_COLOR(r, g, b, a)
Definition macros.h:163
#define PM_CC_BOX2_OPAQUE
Definition macros.h:457
#define PM_CC_BOX2_CYC2
Definition macros.h:462
#define PM_CC_BOX1_OPAQUE
Definition macros.h:456
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16