Alchemy
Loading...
Searching...
No Matches

windows.c

Go to the documentation of this file.
1/// @file
2/// The render output pool, opening and closing windows, starting messages.
3/// Part of window.c, the window object, compiled only through it.
4
6
7/// Takes the first render output from the free list, or returns NULL when every
8/// output is in use.
10 struct UiRenderWork *work = UI_WORK;
11 struct RenderOutput *out = work->freeOutputs.head;
12
13 if (out != NULL) {
14 // Taking the last output leaves the list empty.
15 if (out->next == NULL)
16 work->freeOutputs.tailLink = &work->freeOutputs.head;
17 work->freeOutputs.head = out->next;
18 out->next = NULL;
19 }
20 return out;
21}
22
23/// Returns a render output to the end of the free list. An output from outside
24/// the work block's pool is ignored.
26 struct UiRenderWork *work = UI_WORK;
27
28 if ((u32)out >= (u32)work->outputs &&
29 (u32)out < (u32)&work->freeOutputs.head) {
30 struct RenderOutput **tail = work->freeOutputs.tailLink;
31
32 work->freeOutputs.tailLink = &out->next;
33 *tail = out;
34 out->next = NULL;
35 }
36}
37
38/// Links all 64 render outputs of the pool into the free list.
40 s32 remainingLinks;
41 struct UiRenderWork *work;
42 struct RenderOutput *out;
43 struct RenderOutput *next;
44
45 work = UI_WORK;
46 out = work->outputs;
47 work->freeOutputs.head = out;
48 remainingLinks = UI_OUTPUT_COUNT - 2;
49 do {
50 next = out + 1;
51 remainingLinks--;
52 out->next = next;
53 out = next;
54 } while (remainingLinks >= 0);
55 next->next = NULL;
56 work->freeOutputs.tailLink = &next->next;
57}
58
59/// Sets up the window system for the field (and the other screens outside
60/// battle): allocates and clears the work block, blanks the tilemap, frees
61/// every render output and starts the two per-frame callbacks, the tilemap
62/// upload and the window update.
64 struct UiRenderWork *work;
65#if TBS_PATCH_1
66 volatile u32 fill;
67#endif
68
69 // Clear the work block before linking any of its embedded lists.
71#if TBS_PATCH_1
72 fill = 0;
73 Dma_Set((const void *)&fill, work, DMA_FILL32(RENDER_WORK_SIZE / 4),
74 REG_DMA3);
75#else
77#endif
78 work->dirty = 1;
81#if TBS_PATCH_1
83 Dma_Set((const void *)&fill, work, DMA_FILL32(sizeof(work->tilemap) / 4),
84 REG_DMA3);
85#else
87#endif
88 // Make the output and palette pools available, then start the updates.
93}
94
95/// Sets up the window system for battle, as
96/// UiWork_InitializeWithResourceCounters does for the field, and marks the work
97/// block as in battle (menuState 1). loadGlyphTiles is set only when the Djinn
98/// tutorial flag is set: it loads the glyph tiles the tutorial's messages use.
99void UiWork_Initialize(s32 loadGlyphTiles) {
100 struct UiRenderWork *work;
101#if TBS_PATCH_1
102 volatile u32 fill;
103#endif
104 s32 tileIndex;
105
106 // Copies pixel rows 4 to 6 of UI tile src to rows 0 to 2 of tile dst and
107 // clears the rest of dst.
108 s32 UiWork_CopyTileTail(u32 sourceTile, u32 destinationTile) {
109 sourceTile &= 0x3ff;
110 destinationTile &= 0x3ff;
111 Dma_Set(BG_CHAR_BLOCK(0) + sourceTile * TILE_SIZE_4BPP + 16,
112 BG_CHAR_BLOCK(0) + destinationTile * TILE_SIZE_4BPP, DMA_COPY16(8),
113 REG_DMA3);
114 return Iwram_ClearWords(
115 BG_CHAR_BLOCK(0) + destinationTile * TILE_SIZE_4BPP + 12, 20);
116 }
117
118 // Battle windows share the field's pools but use the canvas tile set.
121#if TBS_PATCH_1
122 fill = 0;
123 Dma_Set((const void *)&fill, work, DMA_FILL32(RENDER_WORK_SIZE / 4),
124 REG_DMA3);
125#else
127#endif
128 work->dirty = 1;
130 work->menuState = 1;
132#if TBS_PATCH_1
134 Dma_Set((const void *)&fill, work, DMA_FILL32(sizeof(work->tilemap) / 4),
135 REG_DMA3);
136#else
137 Iwram_FillWords(work, sizeof(work->tilemap), UI_TILE_PAIR(UI_TILE_BLANK));
138#endif
142 // Tiles 128 to 130 take the lower rows of the bottom frame tiles.
143 UiWork_CopyTileTail(UI_TILE_FRAME_BOTTOM_LEFT, 128);
144 UiWork_CopyTileTail(UI_TILE_FRAME_BOTTOM, 129);
145 UiWork_CopyTileTail(UI_TILE_FRAME_BOTTOM_RIGHT, 130);
146 {
147 u8 mode = 4;
148
149 for (tileIndex = 2; tileIndex >= 0; tileIndex--)
150 work->tileAttributes[tileIndex] = mode;
151 }
152}
153
154/// The per-frame tilemap upload: copies each 256-byte band of the tilemap
155/// (four tile rows) marked in the dirty bits to VRAM. Bit 0 marks the whole
156/// tilemap, bits 1 to 5 one band each. Nothing is copied while menuBusy holds
157/// the upload off.
159 struct UiRenderWork *work = UI_WORK;
160 u32 bands;
161 u8 *src;
162 u8 *dst;
163 if (!work->menuBusy) {
164 bands = work->dirty;
165 if (bands) {
166 dst = UI_TILEMAP_VRAM;
167 src = (u8 *)work->tilemap;
168 if (bands & 1)
169 bands = 63;
170 bands &= 63;
171 bands >>= 1;
172 do {
173 if (bands & 1)
174 Dma_Set(src, dst, DMA_COPY32(64), REG_DMA3);
175 bands >>= 1;
176 src += 256;
177 dst += 256;
178 } while (bands);
179 work->dirty = bands;
180 }
181 }
182}
183
184/// Erases a window's rectangle of the tilemap (x, y, width and height in
185/// tiles), clamped to the screen. In battle the rows below row 16 take tile
186/// 0x7f instead of the blank tile.
187void UiWindow_EraseBorderRect(s32 x, s32 y, u32 width, u32 height) {
188 struct UiRenderWork *canvas = UI_WORK;
189 u16 *cursor = (u16 *)((y * 32 + x) * 2 + (u32)canvas->tilemap);
190 s32 tile;
191 u32 bottom;
192 u32 row;
193 u8 *inBattle;
194
195 tile = 240;
196 bottom = y + height;
197 tile <<= 8;
198 if (bottom > 20)
199 height = 20 - y;
200 if (width <= 1)
201 width = 2;
202 if (width > 30)
203 width = 30;
204 if (height <= 1)
205 height = 2;
206 if (height > 30)
207 height = 30;
208
209 // Clear glyph ownership before replacing the corresponding tile entries.
210 UiWindow_ClearTileAttributesInRect(x, y, width, height);
211
212 row = 0;
213 if (row < height) {
214 inBattle = &canvas->menuState;
215 do {
216 u32 column;
217
218 if (*inBattle != 0) {
219 if ((y + row) > 16)
220 tile = UI_TILE(0x7f);
221 else
222 tile = UI_TILE_BLANK;
223 }
224 column = 0;
225 if (column < width) {
226 do {
227 *cursor++ = tile;
228 column++;
229 } while (column < width);
230 }
231 row++;
232 cursor += 32 - width;
233 } while (row < height);
234 }
235 canvas->dirty = 1;
236}
237
238/// Draws a window at its full size: its frame, and for a text canvas window
239/// the canvas, filled with colour 4 under a frame when the window is framed and
240/// transparent otherwise.
241void UiWindow_DrawOpened(struct UiWindow *window) {
242 u32 flags;
243 u32 value;
244 u32 x;
245 u32 y;
246 u32 width;
247 u32 height;
248 struct UiRenderWork *work;
249
250 work = UI_WORK;
251 value = window->height;
252 flags = window->flags;
253 height = value;
254 value = 0;
255 window->duration = value;
256 x = window->x;
257 y = window->y;
258 width = window->width;
259 // Canvas windows need both pixel storage and their tilemap rectangle.
260 if (UI_WINDOW_TEXT_CANVAS & flags) {
261 if (UI_WINDOW_FRAMED_CANVAS & flags) {
262 UiWindow_DrawFrame(x, y, width, height);
265 } else {
267 }
268 UiWindow_MapTextCanvasTiles(x, y, width, height, 0);
269 } else {
270 UiWindow_DrawFrame(x, y, width, height);
271 }
272 work->dirty = 1;
273}
274
275/// Opens a window at tile (x, y) of width by height tiles in the first free
276/// window slot, and returns it, or NULL when all slots are in use. attrs takes
277/// the UI_WINDOW_ flags. Unless it is UI_WINDOW_INSTANT the window zooms open
278/// over eight frames, and this waits until it is fully open.
280 s32 attrs) {
281 struct UiWindow *slot;
282 struct UiWindow *found;
283 s32 i;
284
285 slot = UI_WORK->windows;
286 found = 0;
287 // A closing slot remains occupied until its animation has finished.
288 for (i = 0; i != WINDOW_COUNT; i++, slot++) {
289 if ((slot->flags & UI_WINDOW_OPEN) == 0 && slot->duration == 0) {
290 found = slot;
291 break;
292 }
293 }
294 if (found != 0) {
295 // Reset the slot before applying the caller's canvas and anchor flags.
296 found->y = y;
297 found->width = width;
298 found->height = height;
299 found->x = x;
300 found->output.head = NULL;
301 found->state = 0;
302 found->output.tailLink = &slot->output.head;
303 found->unk10 = 1;
304 found->flags = UI_WINDOW_OPEN;
306 if (attrs & UI_WINDOW_TEXT_CANVAS) {
308 }
309 if (attrs & UI_WINDOW_FRAMED_CANVAS) {
311 }
312 if (attrs & UI_WINDOW_OUTLINED_TEXT) {
314 }
315 if (attrs & UI_WINDOW_ANCHOR_BOTTOM) {
317 }
318 if (attrs & UI_WINDOW_FIXED_X) {
319 found->flags |= UI_WINDOW_FIXED_X;
320 }
321 if (attrs & UI_WINDOW_INSTANT) {
322 found->flags |= UI_WINDOW_INSTANT;
323 found->frame = 0;
324 found->duration = 1;
325 UiWindow_DrawOpened(found);
326 } else {
327 // Zoom open over eight frames, and wait until it is open.
329 found->frame = UI_WINDOW_OPEN_FRAMES - 1;
330 UiWindow_WaitZoom(found);
331 WaitFrames(1);
332 }
333 }
334 return found;
335}
336
337/// Waits until a zooming window has finished opening or closing.
338void UiWindow_WaitZoom(struct UiWindow *window) {
339 if (!(UI_WINDOW_INSTANT & window->flags) && window->duration != 0) {
340 do {
341 WaitFrames(1);
342 } while (window->duration != 0);
343 }
344}
345
346/// Closes a window: clears its contents and remembers its last rectangle.
347/// With instant set the window is erased and its slot freed at once; otherwise
348/// it zooms closed over four frames first. Does nothing for NULL.
349void UiWork_Finalize(struct UiWindow *window, s32 instant) {
350 u16 zero;
351
352 if (window == 0)
353 return;
354
356 // Keep the old rectangle available while the closing animation shrinks it.
357 window->previousX = window->x;
358 window->previousY = window->y;
359 window->previousWidth = window->width;
360 zero = 0;
361 window->flags = zero;
362 window->previousHeight = window->height;
363
364 if (instant != 0) {
365 UiWindow_EraseBorderRect(window->x, window->y, window->width,
366 window->height);
367 window->output.head = NULL;
368 window->output.tailLink = NULL;
369 window->width = zero;
370 window->height = zero;
371 window->x = zero;
372 window->y = zero;
373 window->unk10 = zero;
374 window->effect = zero;
375 window->state = zero;
376 window->flags = zero;
377 window->frame = zero;
378 window->duration = zero;
379 window->previousX = zero;
380 window->previousY = zero;
381 window->previousWidth = zero;
382 window->previousHeight = zero;
383 } else {
384 // Zoom closed over four frames (UiWork_ProcessDirectWork).
385 window->frame = instant;
387 }
388}
389
390/// Clears a window's contents: redraws its empty frame and releases the render
391/// outputs it carries. A text canvas window is left alone.
393 if (!(UI_WINDOW_TEXT_CANVAS & window->flags)) {
396 }
397}
398
399/// Redraws a window's empty frame at its current rectangle.
401 UiWindow_DrawFrame(window->x, window->y, window->width, window->height);
402}
403
404/// Releases every render output in a list and empties it. outputs is the list,
405/// or a window (whose output list comes first); NULL is ignored.
406void RenderOutput_ClearList(void *outputs) {
407 struct RenderOutputList *list = outputs;
408 struct RenderOutput *node;
409 struct RenderOutput *next;
410
411 next = NULL;
412 if (list != NULL) {
413 node = list->head;
414 // Detach the chain before returning its nodes to the shared free pool.
415 list->tailLink = &list->head;
416 list->head = next;
417 while (node != NULL) {
418 next = node->next;
420 node = next;
421 }
422 }
423}
424
425/// Clears an area of a window's interior to the window fill. left, top, right
426/// and bottom are pixels inside the window, and the area covers every tile
427/// they touch.
428void UiWindow_ClearInteriorTiles(const struct UiWindow *window, u32 left,
429 u32 top, u32 right, u32 bottom) {
430 struct UiRenderWork *work;
431 u32 x;
432 u32 y;
433 u32 width;
434 u32 height;
435 u16 *tiles;
436 u32 row;
437
438 right += 7;
439 bottom += 7;
440 right >>= 3;
441 bottom >>= 3;
442 x = left >> 3;
443 work = UI_WORK;
444 y = top >> 3;
445 x += window->x;
446 y += window->y;
447 right += window->x;
448 bottom += window->y;
449 left = x + 1;
450 top = y + 1;
451 width = right - x;
452 height = bottom - y;
453 UiWindow_ClearTileAttributesInRect(left, top, width, height);
454 tiles = work->tilemap + top * 32 + left;
455 for (row = 0; row < height; row++) {
456 for (left = 0; left < width; left++)
457 *tiles++ = UI_TILE_WINDOW_FILL;
458 tiles += 32 - width;
459 }
460 work->dirty = 1;
461}
462
463/// Points a list's tail link back at its last output, after the list has been
464/// edited by hand.
465/// Nothing calls it.
467 struct RenderOutput *node = list->head;
468 struct RenderOutput **tail = &list->head;
469
470 while (node != NULL) {
471 tail = &node->next;
472 node = node->next;
473 }
474 list->tailLink = tail;
475}
476
477/// Adds a render output to the end of a list; NULL lists are ignored.
479 struct RenderOutput *node) {
480 /* FAKEMATCH: storing the new tail as a RenderOutput * keeps both stores in
481 * one alias set and in order; as list->tailLink = &node->next, 2
482 * instructions differ in tbs-en. */
483 if (list != NULL) {
484 *list->tailLink = node;
485#ifdef UBFIX
486 // Store the address of next through the tail link's actual pointer type.
487 list->tailLink = &node->next;
488#else
489 *(struct RenderOutput **)&list->tailLink = node;
490#endif
491 }
492}
493
494/// Frees a render output: returns it to the free list, releases its resource,
495/// and for a kind-2 output frees its palette slot too.
498 if ((u8)entry->kind != 0) {
500 if ((u8)entry->kind == 2) {
501 // Free its palette slot (999 marks a free slot).
502 u8 *work = gWindowWork[0];
503 s32 offset = entry->oam.palette * 2 + RENDER_PALETTE_TABLE_OFFSET;
504 *(u16 *)(work + offset) = UI_PALETTE_SLOT_FREE;
505 }
506 }
507 entry->active = 0;
508}
509
510/// Starts a free message channel typing the decoded text that begins at entry
511/// into window, with the pen at pixel (x, y). spacing gives each of four lines
512/// an extra gap between characters (or none for NULL); flags is kept with the
513/// channel (nonzero keeps the window's size from page to page). Returns the
514/// channel, or NULL when all three are busy.
516 s32 entry, s32 x, s32 y,
517 u16 *spacing, s32 flags) {
518 struct UiChannelSlot *slot = UI_WORK->channels;
519 struct UiChannelSlot *found = NULL;
520 u32 i;
521
522 for (i = 0; i != UI_MESSAGE_CHANNEL_COUNT; i++, slot++) {
523 if (slot->work == NULL) {
524 found = slot;
525 break;
526 }
527 }
528 if (found != NULL) {
529 // The channel stores pen coordinates in 1/256 pixels.
530 found->work = window;
531 found->startX = x << 8;
532 found->x = x << 8;
533 found->y = y << 8;
534 found->entry = entry;
537 found->countdown = 0;
538 found->outline = 0;
539 found->ended = 0;
540 found->flags = flags;
541 if (spacing != NULL) {
542 for (i = 0; i < UI_MESSAGE_LINE_COUNT; i++)
543 found->spacing[i] = *spacing++;
544 } else {
545 for (i = 0; i < UI_MESSAGE_LINE_COUNT; i++)
546 found->spacing[i] = 0;
547 }
548 found->line = 0;
549 }
550 return found;
551}
552
553/// Starts a channel typing the decoded text at entry into the battle message
554/// window. A channel that already serves a finished window continues below its
555/// last line (scrolling up once both lines are used) unless keepPosition is
556/// set. Returns the channel, or NULL when all three are busy.
558 s32 entry, s32 keepPosition) {
559 struct UiChannelSlot *slot;
560 struct UiChannelSlot *selected;
561 u16 *spacing;
562 u16 zero;
563 u32 index;
564
565 slot = UI_WORK->channels;
566 selected = 0;
567 for (index = 0; index != UI_MESSAGE_CHANNEL_COUNT; slot++, index++) {
568 if (slot->work == 0 || slot->work->state != 0) {
569 selected = slot;
570 break;
571 }
572 }
573
574 if (selected != 0) {
575 // Positions are in 1/256 pixel: the first line is 10 pixels down, the
576 // second 13 pixels below it, and after the second the text scrolls up.
577 if (selected->work == 0) {
578 selected->y = 10 << 8;
579 selected->work = window;
580 selected->x = 3 << 8;
581 } else if (keepPosition == 0) {
582 if (selected->y == 0) {
583 selected->y = 10 << 8;
584 } else if (selected->y < 13 << 8) {
585 selected->y += 13 << 8;
586 } else {
587 UiText_StartCanvasScroll(selected);
588 }
589 selected->x = 3 << 8;
590 }
591
592 zero = 0;
593 selected->startX = 3 << 8;
594 selected->work->state = zero;
595 // Start the next text run without retaining the previous run's style.
596 selected->colour = UI_TEXT_DEFAULT_COLOUR;
598 selected->entry = entry;
599 selected->countdown = zero;
600 selected->outline = zero;
601 selected->line = zero;
602 selected->ended = zero;
603 index = 0;
604 spacing = selected->spacing;
605 do {
606 index++;
607 *spacing++ = zero;
608 } while (index < UI_MESSAGE_LINE_COUNT);
609 }
610 return selected;
611}
612
613/// Clears the text canvas to transparent.
616}
617
618/// Fills the text canvas with the window background colour (4).
622}
623
624/// Resets the pen and text style of the first idle message channel, clearing
625/// the canvas when the channel still has a window.
627 struct UiChannelSlot *slot = UI_WORK->channels;
628 struct UiChannelSlot *selection = 0;
629 s32 i;
630
631 for (i = 0; i != UI_MESSAGE_CHANNEL_COUNT; slot++, i++) {
632 if (slot->work == 0 || slot->work->state != 0) {
633 selection = slot;
634 break;
635 }
636 }
637 if (selection != 0) {
638 if (selection->work != 0) {
640 selection->y = 0;
641 }
642 selection->x = 0;
643 selection->countdown = 0;
644 selection->colour = UI_TEXT_DEFAULT_COLOUR;
645 selection->outline = 0;
647 }
648}
649
650/// Copies the channel's text colour, outline and line spacing into the shared
651/// glyph renderer before that channel draws its next character.
653 struct UiRenderWork *work = UI_WORK;
654
655 work->colour = channel->colour;
656 work->outline = channel->outline;
657 work->lineSpacing = channel->lineSpacing;
658}
659
660/// Starts a channel scrolling its canvas up a line, over two frames.
662 channel->transition = 2;
663}
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
Definition dma.h:62
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
void UiWindow_DrawFrame(s32 x, s32 y, u32 width, u32 height)
Draws an empty window: a frame around a filled interior, at tile (x, y) of width by height tiles.
Definition frames.c:131
void UiWork_ResetCounters(void)
Resets the text style glyphs are drawn with: colour 15, no outline, line spacing 10.
Definition frames.c:236
void UiWork_InitCountersWithResourceAndScheduleRefresh(void)
Loads the glyph tiles, resets the text style and starts the per-frame window update (UiWork_ProcessAl...
Definition frames.c:248
void UiWindow_MapTextCanvasTiles(s32 x, s32 y, u32 width, u32 height, s32 fullWidth)
Maps the text canvas tiles into the interior of a window at tile (x, y).
Definition frames.c:176
void UiWork_InitCountersAndScheduleRefresh(s32 loadGlyphTiles)
Resets the text style and starts the per-frame window update (UiWork_ProcessAll), loading the glyph t...
Definition frames.c:266
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
Definition heap.c:80
@ HEAP_SLOT_WINDOW
Definition heap_state.h:39
#define BG_CHAR_BLOCK(n)
Definition io_reg.h:166
#define TILE_SIZE_4BPP
Definition io_reg.h:168
#define REG_DMA3
Definition io_reg.h:153
static s32 Iwram_FillWords(void *destination, s32 size, u32 value)
Definition iwram_call.h:59
static s32 Iwram_ClearWords(void *destination, s32 size)
Definition iwram_call.h:55
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
Definition scheduler.c:102
#define NULL
Definition bilibin.h:6
u8 gWindowWork[]
A list of render outputs: its first output and the link to append after.
struct RenderOutput ** tailLink
struct RenderOutput * head
A render output: a sprite in a window's output list (a character, an icon or a portrait),...
struct RenderOam oam
s8 active
its UI_SPRITE_ motion; 0 while free
struct RenderOutput * next
the next output in its list
s8 kind
0 for a glyph; otherwise it owns VRAM cache slot index, freed with it, and 2 (a portrait) also its pa...
s8 index
VRAM cache slot, or a glyph's tile after glyphTiles.
A text channel, one of three, which types decoded text into a window a few characters a frame and run...
Definition uiwindow.h:43
u16 outline
outline colour; 0 for none
Definition uiwindow.h:54
u16 colour
text colour; 15 by default
Definition uiwindow.h:53
u16 y
pen, 8.8 fixed-point pixels
Definition uiwindow.h:46
u16 flags
nonzero keeps the window's size from page to page
Definition uiwindow.h:60
u16 x
pen, 8.8 fixed-point pixels
Definition uiwindow.h:45
u16 spacing[4]
Extra advance per line, in 1/256 pixels: after every character in Japanese, after a space in the othe...
Definition uiwindow.h:49
u16 ended
1 once a TEXT_END code is reached
Definition uiwindow.h:58
u16 transition
frames left of the canvas scrolling up a line
Definition uiwindow.h:56
u16 lineSpacing
10 by default
Definition uiwindow.h:55
u16 line
line of the page, indexes spacing; at most 3
Definition uiwindow.h:50
u16 startX
pen x each new line returns to, 8.8 fixed-point pixels
Definition uiwindow.h:57
struct UiWindow * work
the window typed into; NULL when free
Definition uiwindow.h:44
u16 entry
next code in UiRenderWork.entries
Definition uiwindow.h:51
u16 countdown
frames left of a pause, a page wait or a swell
Definition uiwindow.h:52
The window system's work: the windows' tilemap, the windows, the three text channels,...
Definition window.h:19
u8 mode
Set while Mind Read shows thoughts: round frame corners, colour 8 text with no shadow,...
Definition window.h:35
struct RenderOutput outputs[UI_OUTPUT_COUNT]
Definition window.h:23
u16 tilemap[640]
the windows' BG tilemap, 32 by 20 tiles
Definition window.h:20
u8 dirty
The tilemap's 4-row bands to upload: bit 0 for all, bit n + 1 for band n.
Definition window.h:32
u8 level
text tiles' palette; 15 by default, 14 or 5 for low HP
Definition window.h:41
u16 glyphResource
VRAM cache slot of the page arrow; 99 when none.
Definition window.h:50
u16 colour
the current channel's, copied in to draw
Definition window.h:45
u16 outline
the current channel's, copied in to draw
Definition window.h:44
u8 tileAttributes[256]
Per text tile (tiles 0x80 to 0xFF, then 0x200 to 0x27F): bit 0 once allocated, bit 1 while the tilema...
Definition window.h:28
u8 menuState
1 from the work's setup; 2 while a battle message is decoded.
Definition window.h:39
u8 menuBusy
while set, the tilemap is not uploaded
Definition window.h:40
struct RenderOutputList freeOutputs
the outputs not in any window
Definition window.h:24
u16 lineSpacing
the current channel's, copied in to draw
Definition window.h:42
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
Definition uiwindow.h:11
u16 frame
The zoom's step: counts down from 7 to 0 while opening, and up from 0 to duration while closing.
Definition uiwindow.h:28
u16 previousX
tiles
Definition uiwindow.h:30
u16 y
tiles
Definition uiwindow.h:16
u16 effect
The effect a message's TEXT_WINDOW_STATE code sets.
Definition uiwindow.h:21
u16 flags
UI_WINDOW_ flags; 0 once closing or free.
Definition uiwindow.h:25
u16 unk10
1 once opened, 0 once freed; not read by name in TBS
Definition uiwindow.h:17
u16 previousHeight
tiles
Definition uiwindow.h:33
u16 state
0 while a message channel is typing into the window; 1 once its text has ended or closed the window,...
Definition uiwindow.h:24
u16 x
tiles
Definition uiwindow.h:15
u16 height
tiles
Definition uiwindow.h:14
struct RenderOutputList output
the sprites the window carries
Definition uiwindow.h:12
u16 previousY
tiles
Definition uiwindow.h:31
u16 previousWidth
tiles
Definition uiwindow.h:32
u16 width
tiles
Definition uiwindow.h:13
s16 duration
frames of the zoom under way; 0 when none
Definition uiwindow.h:29
#define RENDER_PALETTE_TABLE_OFFSET
Definition tbs_edition.h:73
#define RENDER_WORK_SIZE
Definition tbs_edition.h:72
#define WINDOW_COUNT
Definition tbs_edition.h:69
void UiWindow_ClearTileAttributesInRect(s32 x, s32 y, u32 width, u32 height)
Marks the text tiles under a tilemap rectangle (x, y, width and height in tiles) as no longer shown,...
Definition text_tiles.c:276
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
#define UNUSED
Definition types.h:22
unsigned char u8
Definition types.h:11
#define UI_CANVAS_VRAM
Definition window.h:45
#define UI_TILE_PAIR(entry)
Two copies of a tilemap entry, for filling a run of entries a word at a time.
Definition window.h:57
#define UI_TILEMAP_VRAM
The UI tilemap in VRAM (BG screen block 4), which UiWork_UploadDirtyBlocks copies the work block's ti...
Definition window.h:51
#define UI_WORK
Definition window.h:267
#define UI_TILE(tile)
A tilemap entry of palette 15, the UI palette.
Definition window.h:54
#define DMA_FILL32(count)
The DMA control word that fills count words from one fixed source word.
Definition window.h:109
#define DMA_COPY16(count)
The DMA control word that copies count halfwords.
Definition window.h:114
@ UI_WINDOW_TEXT_CANVAS
text is drawn into a canvas of bitmap tiles (UiWindow_MapTextCanvasTiles)
Definition window.h:31
@ UI_WINDOW_FIXED_X
when a new page resizes the window, its left edge stays put
Definition window.h:39
@ UI_WINDOW_FRAMED_CANVAS
the canvas has a frame and a filled background; without it the canvas is transparent and frameless
Definition window.h:34
@ UI_WINDOW_ANCHOR_BOTTOM
when a new page resizes the window, its bottom edge stays put
Definition window.h:37
@ UI_WINDOW_OUTLINED_TEXT
the canvas text gets an outline
Definition window.h:35
@ UI_WINDOW_OPEN
the window slot is in use
Definition window.h:28
@ UI_WINDOW_INSTANT
opens and closes at once, with no zoom
Definition window.h:29
#define UI_CANVAS_SIZE
Definition window.h:46
#define DMA_COPY32(count)
The DMA control word that copies count words.
Definition window.h:112
@ UI_TILE_WINDOW_FILL
Definition window.h:83
@ UI_TILE_FRAME_BOTTOM
Definition window.h:78
@ UI_TILE_BLANK
Definition window.h:73
@ UI_TILE_FRAME_BOTTOM_LEFT
Definition window.h:77
@ UI_TILE_FRAME_BOTTOM_RIGHT
Definition window.h:79
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106
void UiWork_ClearPortraitSlots(void)
Marks both portrait slots free (999).
Definition messages.c:474
@ UI_OUTPUT_COUNT
Definition window.h:15
What every part of the window object shares: its includes, edition values, macros and the codes of de...
#define UI_MESSAGE_LINE_COUNT
#define UI_MESSAGE_CHANNEL_COUNT
#define UI_TEXT_DEFAULT_LINE_SPACING
#define NO_GLYPH_RESOURCE
A glyph resource id meaning no glyph resource is loaded.
#define UI_TILEMAP_PALETTE
#define UI_WINDOW_CLOSE_FRAMES
#define UI_TEXT_DEFAULT_COLOUR
#define UI_WINDOW_OPEN_FRAMES
#define UI_PALETTE_SLOT_FREE
#define UI_CANVAS_BACKGROUND_WORD
void RenderOutput_AppendToList(struct RenderOutputList *list, struct RenderOutput *node)
Adds a render output to the end of a list; NULL lists are ignored.
Definition windows.c:478
void RenderOutput_InitFreeList(void)
Links all 64 render outputs of the pool into the free list.
Definition windows.c:39
void RenderOutput_PrepareForRedraw(struct UiWindow *window)
Clears a window's contents: redraws its empty frame and releases the render outputs it carries.
Definition windows.c:392
void RenderOutput_Release(struct RenderOutput *entry)
Frees a render output: returns it to the free list, releases its resource, and for a kind-2 output fr...
Definition windows.c:496
void UiWork_ResetFreeChannel(void)
Resets the pen and text style of the first idle message channel, clearing the canvas when the channel...
Definition windows.c:626
s32 Ui_ClearVramBlock(void)
Clears the text canvas to transparent.
Definition windows.c:614
s32 Ui_FillVramBlockPattern(void)
Fills the text canvas with the window background colour (4).
Definition windows.c:619
void UiText_ApplyChannelStyle(struct UiChannelSlot *channel)
Copies the channel's text colour, outline and line spacing into the shared glyph renderer before that...
Definition windows.c:652
void UiWindow_EraseBorderRect(s32 x, s32 y, u32 width, u32 height)
Erases a window's rectangle of the tilemap (x, y, width and height in tiles), clamped to the screen.
Definition windows.c:187
struct UiChannelSlot * UiText_QueueRenderEntries(struct UiWindow *window, s32 entry, s32 x, s32 y, u16 *spacing, s32 flags)
Starts a free message channel typing the decoded text that begins at entry into window,...
Definition windows.c:515
void UiWindow_WaitZoom(struct UiWindow *window)
Waits until a zooming window has finished opening or closing.
Definition windows.c:338
struct UiChannelSlot * UiText_StartBattleMessage(struct UiWindow *window, s32 entry, s32 keepPosition)
Starts a channel typing the decoded text at entry into the battle message window.
Definition windows.c:557
void UiWork_UploadDirtyBlocks(void)
The per-frame tilemap upload: copies each 256-byte band of the tilemap (four tile rows) marked in the...
Definition windows.c:158
void UiWindow_DrawOpened(struct UiWindow *window)
Draws a window at its full size: its frame, and for a text canvas window the canvas,...
Definition windows.c:241
void UiWork_Initialize(s32 loadGlyphTiles)
Sets up the window system for battle, as UiWork_InitializeWithResourceCounters does for the field,...
Definition windows.c:99
void UiWork_Finalize(struct UiWindow *window, s32 instant)
Closes a window: clears its contents and remembers its last rectangle.
Definition windows.c:349
void RenderOutput_ReleaseFree(struct RenderOutput *out)
Returns a render output to the end of the free list.
Definition windows.c:25
void UiText_StartCanvasScroll(struct UiChannelSlot *channel)
Starts a channel scrolling its canvas up a line, over two frames.
Definition windows.c:661
UNUSED void RenderOutputList_UpdateTail(struct RenderOutputList *list)
Points a list's tail link back at its last output, after the list has been edited by hand.
Definition windows.c:466
void RenderOutput_ClearList(void *outputs)
Releases every render output in a list and empties it.
Definition windows.c:406
struct RenderOutput * RenderOutput_AcquireFree(void)
Takes the first render output from the free list, or returns NULL when every output is in use.
Definition windows.c:9
void UiWork_InitializeWithResourceCounters(void)
Sets up the window system for the field (and the other screens outside battle): allocates and clears ...
Definition windows.c:63
void UiWindow_ClearInteriorTiles(const struct UiWindow *window, u32 left, u32 top, u32 right, u32 bottom)
Clears an area of a window's interior to the window fill.
Definition windows.c:428
void RenderOutput_RedrawSavedRect(struct UiWindow *window)
Redraws a window's empty frame at its current rectangle.
Definition windows.c:400
struct UiWindow * UiWindow_Create(s32 x, s32 y, s32 width, s32 height, s32 attrs)
Opens a window at tile (x, y) of width by height tiles in the first free window slot,...
Definition windows.c:279