Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
cursor.c
Go to the documentation of this file.
1#include "engine/game.h"
2
3/* Cursor method: shows it (from its first frame) or hides it */
4void cursorSetVisible(Cursor *task, s32 visible) {
5 task->visible = visible;
6 if (visible == 0) {
7 task->substate = 0;
8 task->time = 0;
9 }
10 task->dirty = 1;
11}
12
13/* Cursor method: moves it */
14void cursorSetPos(Cursor *task, s32 x, s32 y) {
15 task->x = x;
16 task->y = y;
17 task->dirty = 1;
18}
19
20/* Cursor method: the CLUT row of its glyph */
21void cursorSetPalette(Cursor *task, s32 palette) {
22 task->palette = palette;
23 task->dirty = 1;
24}
25
26/* Cursor method: the vsyncs it rests between two swings */
27void cursorSetIdleDelay(Cursor *task, s32 delay) {
28 task->idleDelay = delay;
29}
30
31/* Cursor method: the vsyncs of each frame of a swing */
32void cursorSetFrameDelay(Cursor *task, s32 delay) {
33 task->frameDelay = delay;
34}
35
36/* Cursor method: keeps it on its first frame */
37void cursorSetStill(Cursor *task, s32 still) {
38 task->still = still;
39}
40
41/* The cursor task: creates its text window, then swings it every idleDelay vsyncs */
42void updateCursor(Cursor *task, TextWindow **win) {
43 switch (task->state) {
44 case 0:
45 default:
46 if (*win == NULL) {
47 *win = createTextWindow(task->layerId, 1, task->x, task->y);
48 }
49 (*win)->setText(*win, CURSOR_FRAMES[task->frame]);
50 (*win)->setVisible(*win, task->visible);
51 (*win)->setDepth(*win, task->depth);
52 task->time = GFX.funcs.getTime();
53 task->nextState(task);
54 break;
55 case 1:
56 if (task->dirty != 0) {
57 (*win)->setVisible(*win, task->visible);
58 (*win)->setPos(*win, task->x, task->y);
59 (*win)->setPalette(*win, task->palette);
60 task->dirty = 0;
61 }
62 if (task->visible != 0) {
63 if (task->still != 0) {
64 if (task->frame != 0) {
65 task->frame = 0;
66 (*win)->setText(*win, CURSOR_FRAMES[0]);
67 }
68 } else if (task->substate == 0) {
69 if ((GFX.funcs.getTime() - task->time) / task->idleDelay != 0) {
70 task->time = GFX.funcs.getTime();
71 task->frame = 1;
72 (*win)->setText(*win, CURSOR_FRAMES[1]);
73 task->substate = 1;
74 }
75 } else if ((GFX.funcs.getTime() - task->time) / task->frameDelay != 0) {
76 task->time = GFX.funcs.getTime();
77 if (++task->frame >= 5) {
78 task->frame = 0;
79 task->substate = 0;
80 }
81 (*win)->setText(*win, CURSOR_FRAMES[task->frame]);
82 }
83 }
84 break;
85 case 2:
86 case 3:
87 break;
88 }
89}
90
91/* A menu cursor on a layer at (x, y) */
92Cursor *createCursor(s16 layerId, s32 depth, s16 x, s16 y) {
93 Cursor *task = createTask(updateCursor, sizeof(Cursor), 4);
94
95 task->layerId = layerId;
96 task->depth = depth;
97 task->x = x;
98 task->y = y;
99 task->visible = 1;
100 task->idleDelay = 0x20;
101 task->frameDelay = 6;
103 task->setPos = cursorSetPos;
107 task->setStill = cursorSetStill;
108 return task;
109}
110
111/* The cursor's frames as text, each the code of one of its glyphs in the font. -G8
112 unit: they are small, so they go to the small data (.sdata) */
113static char CURSOR_TEXT_3[4] = "\x81\x88";
114static char CURSOR_TEXT_2[4] = "\x81\x87";
115static char CURSOR_TEXT_1[4] = "\x81\x86";
116static char CURSOR_TEXT_0[4] = "\x81\x85";
117
118/* The cursor's frames, the last one repeated as it swings back */
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
char * CURSOR_FRAMES[5]
The cursor's frames, the last one repeated as it swings back.
Definition cursor.c:119
void cursorSetVisible(Cursor *task, s32 visible)
Cursor method: shows it (from its first frame) or hides it.
Definition cursor.c:4
static char CURSOR_TEXT_0[4]
Definition cursor.c:116
void cursorSetPos(Cursor *task, s32 x, s32 y)
Cursor method: moves it.
Definition cursor.c:14
Cursor * createCursor(s16 layerId, s32 depth, s16 x, s16 y)
A menu cursor on a layer at (x, y)
Definition cursor.c:92
void updateCursor(Cursor *task, TextWindow **win)
The cursor task: creates its text window, then swings it every idleDelay vsyncs.
Definition cursor.c:42
static char CURSOR_TEXT_3[4]
The cursor's frames as text, each the code of one of its glyphs in the font.
Definition cursor.c:113
void cursorSetFrameDelay(Cursor *task, s32 delay)
Cursor method: the vsyncs of each frame of a swing.
Definition cursor.c:32
void cursorSetPalette(Cursor *task, s32 palette)
Cursor method: the CLUT row of its glyph.
Definition cursor.c:21
void cursorSetStill(Cursor *task, s32 still)
Cursor method: keeps it on its first frame.
Definition cursor.c:37
static char CURSOR_TEXT_2[4]
Definition cursor.c:114
void cursorSetIdleDelay(Cursor *task, s32 delay)
Cursor method: the vsyncs it rests between two swings.
Definition cursor.c:27
static char CURSOR_TEXT_1[4]
Definition cursor.c:115
A menu cursor: a text window showing one of the CURSOR_FRAMES glyphs.
Definition text.h:19
s32 idleDelay
Definition text.h:30
void(* setIdleDelay)()
Definition text.h:36
s32 substate
Definition text.h:20
s32 state
Definition text.h:20
void(* nextState)(struct Cursor *task)
Definition text.h:20
s32 frame
Definition text.h:28
s32 visible
Definition text.h:26
s32 dirty
Definition text.h:27
void(* setPalette)()
Definition text.h:35
void(* setPos)()
(cursor, x, y)
Definition text.h:34
void(* setFrameDelay)()
Definition text.h:37
void(* setStill)()
Definition text.h:38
s32 frameDelay
Definition text.h:31
s32 y
Definition text.h:24
void(* setVisible)()
(cursor, visible)
Definition text.h:33
s32 depth
Definition text.h:22
s32 palette
PALETTE_*, its text window's.
Definition text.h:25
s32 x
Definition text.h:23
s32 time
Definition text.h:29
s32 still
stay on frame 0
Definition text.h:32
s32 layerId
Definition text.h:21
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
A text window (createTextWindow): up to six text buffers (0 is shown, 1-5 are "work" buffers that con...
Definition text.h:131
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
TextWindow * createTextWindow(s16 layerId, s16 style, s16 x, s16 y)
A text window on a layer, in a font style, at (x, y)