summaryrefslogtreecommitdiff
path: root/src/d/pane/d_pane_class_alpha.cpp
blob: 618a563a7ca4111178bc8eefa2d614a6bf2275fd (plain)
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//
// Generated By: dol2asm
// Translation Unit: d/pane/d_pane_class_alpha
//

#include "d/pane/d_pane_class_alpha.h"
#include "JSystem/J2DGraph/J2DScreen.h"
#include "JSystem/JKernel/JKRExpHeap.h"
#include "m_Do/m_Do_ext.h"

/* 802553EC-802553FC 24FD2C 0010+00 0/0 2/2 0/0 .text            __ct__13CPaneMgrAlphaFv */
CPaneMgrAlpha::CPaneMgrAlpha() {}

/* 802553FC-8025546C 24FD3C 0070+00 1/1 9/9 1/1 .text
 * __ct__13CPaneMgrAlphaFP9J2DScreenUxUcP10JKRExpHeap           */
CPaneMgrAlpha::CPaneMgrAlpha(J2DScreen* p_screen, u64 tag, u8 flags, JKRExpHeap* p_heap) {
    J2DPane* pane = p_screen->search(tag);
    mFlags = flags;
    initiateAlpha(pane, p_heap);
}

/* 8025546C-802554E0 24FDAC 0074+00 2/1 1/1 0/0 .text            __dt__13CPaneMgrAlphaFv */
CPaneMgrAlpha::~CPaneMgrAlpha() {
    if (mpFirstStackAlpha != NULL) {
        heap->free(mpFirstStackAlpha);
        mpFirstStackAlpha = NULL;
    }
}

/* 802554E0-802555C8 24FE20 00E8+00 1/1 0/0 0/0 .text
 * initiateAlpha__13CPaneMgrAlphaFP7J2DPaneP10JKRExpHeap        */
void CPaneMgrAlpha::initiateAlpha(J2DPane* p_pane, JKRExpHeap* p_heap) {
    mPane = p_pane;

    if (p_heap != NULL) {
        heap = p_heap;
    } else {
        heap = (JKRExpHeap*)mDoExt_getCurrentHeap();
    }

    mpFirstStackAlpha = NULL;
    field_0x10 = NULL;
    mChildPaneCount = 0;

    if (mFlags != 0) {
        childPaneCount(mPane->getFirstChildPane());

        if (mFlags & 2) {
            mpFirstStackAlpha = heap->alloc(mChildPaneCount, 0x20);
            field_0x10 = (u8*)mpFirstStackAlpha;
            childPaneGetAlpha(mPane->getFirstChildPane());
        }
    }

    if (p_pane->getKind() == 'PAN2') {
        mInitAlpha = 255;
    } else {
        mInitAlpha = p_pane->getAlpha();
    }

    mAlphaTimer = 0;
}

/* 802555C8-80255608 24FF08 0040+00 0/0 40/40 2/2 .text            show__13CPaneMgrAlphaFv */
void CPaneMgrAlpha::show() {
    if (!isVisible()) {
        mPane->show();
    }
}

/* 80255608-8025564C 24FF48 0044+00 0/0 46/46 2/2 .text            hide__13CPaneMgrAlphaFv */
void CPaneMgrAlpha::hide() {
    if (isVisible() == true) {
        mPane->hide();
    }
}

/* 8025564C-80255658 24FF8C 000C+00 2/2 12/12 0/0 .text            isVisible__13CPaneMgrAlphaFv */
bool CPaneMgrAlpha::isVisible() {
    return mPane->isVisible();
}

/* 80255658-80255758 24FF98 0100+00 2/2 2/2 0/0 .text            rateCalc__13CPaneMgrAlphaFssUc */
f32 CPaneMgrAlpha::rateCalc(s16 maxTimer, s16 curTimer, u8 calcType) {
    if (maxTimer <= curTimer) {
        return 1.0f;
    }

    switch (calcType) {
    case 1:
        return (f32)(curTimer * curTimer) / (f32)(maxTimer * maxTimer);
    case 2:
        return (f32)((maxTimer - curTimer) * (maxTimer - curTimer)) / (f32)(maxTimer * maxTimer);
    default:
        return (f32)curTimer / (f32)maxTimer;
    }
}

/* 80255758-802557D0 250098 0078+00 2/0 0/0 0/0 .text            setAlpha__13CPaneMgrAlphaFUc */
void CPaneMgrAlpha::setAlpha(u8 alpha) {
    if (mFlags & 2) {
        field_0x10 = (u8*)mpFirstStackAlpha;
        childPaneSetAlpha(mPane->getFirstChildPane(), alpha);
    }
    mPane->setAlpha(alpha);
}

/* 802557D0-80255828 250110 0058+00 1/1 173/173 5/5 .text            setAlphaRate__13CPaneMgrAlphaFf
 */
void CPaneMgrAlpha::setAlphaRate(f32 rate) {
    setAlpha(mInitAlpha * rate);
}

/* 80255828-80255878 250168 0050+00 0/0 107/107 2/2 .text            getAlphaRate__13CPaneMgrAlphaFv
 */
f32 CPaneMgrAlpha::getAlphaRate() {
    f32 rate = 0.0f;

    if (mInitAlpha != 0) {
        rate = getAlpha() / (f32)mInitAlpha;
    }

    return rate;
}

/* 80255878-80255964 2501B8 00EC+00 0/0 31/31 1/1 .text alphaAnime__13CPaneMgrAlphaFsUcUcUc */
bool CPaneMgrAlpha::alphaAnime(s16 timer, u8 startAlpha, u8 endAlpha, u8 calcType) {
    if (mAlphaTimer < timer - 1) {
        mAlphaTimer++;
        f32 rate = rateCalc(timer, mAlphaTimer, calcType);
        setAlpha(startAlpha + rate * (f32)(endAlpha - startAlpha));
    } else {
        mAlphaTimer = timer;
        setAlpha(endAlpha);
        return true;
    }

    return false;
}

/* 80255964-80255A60 2502A4 00FC+00 0/0 0/0 1/1 .text alphaAnimeLoop__13CPaneMgrAlphaFsUcUcUc */
bool CPaneMgrAlpha::alphaAnimeLoop(s16 param_0, u8 param_1, u8 param_2, u8 param_3) {
    bool ret = false;
    s16 temp_r4 = param_0 / 2;

    mAlphaTimer++;

    if (mAlphaTimer >= param_0) {
        mAlphaTimer = 0;
        ret = true;
    }

    s16 tmp;
    if (mAlphaTimer < temp_r4) {
        tmp = mAlphaTimer;
    } else {
        tmp = param_0 - mAlphaTimer;
    }

    f32 rate = rateCalc(temp_r4, tmp, param_3);
    setAlpha(param_1 + rate * (f32)(param_2 - param_1));

    return ret;
}

/* 80255A60-80255ACC 2503A0 006C+00 1/1 1/1 0/0 .text childPaneCount__13CPaneMgrAlphaFP7J2DPane */
void CPaneMgrAlpha::childPaneCount(J2DPane* p_pane) {
    if (p_pane != NULL) {
        mChildPaneCount++;
        childPaneCount(p_pane->getFirstChildPane());
        childPaneCount(p_pane->getNextChildPane());
    }
}

/* 80255ACC-80255B5C 25040C 0090+00 1/1 1/1 0/0 .text childPaneGetAlpha__13CPaneMgrAlphaFP7J2DPane
 */
void CPaneMgrAlpha::childPaneGetAlpha(J2DPane* p_pane) {
    if (p_pane != NULL) {
        u8 alpha;
        if (p_pane->getKind() == 'PAN2') {
            alpha = 255;
        } else {
            alpha = p_pane->getAlpha();
        }

        *field_0x10 = alpha;
        field_0x10++;
        childPaneGetAlpha(p_pane->getFirstChildPane());
        childPaneGetAlpha(p_pane->getNextChildPane());
    }
}

/* 80255B5C-80255C68 25049C 010C+00 1/1 1/1 0/0 .text
 * childPaneSetAlpha__13CPaneMgrAlphaFP7J2DPaneUc               */
void CPaneMgrAlpha::childPaneSetAlpha(J2DPane* p_pane, u8 alpha) {
    if (p_pane != NULL) {
        if (!p_pane->mIsInfluencedAlpha) {
            f32 tmp;
            if (mInitAlpha == 0) {
                tmp = 0.0f;
            } else {
                tmp = (f32)alpha / (f32)mInitAlpha;
            }

            p_pane->setAlpha(*field_0x10 * tmp);
        }
        
        field_0x10++;
        childPaneSetAlpha(p_pane->getFirstChildPane(), alpha);
        childPaneSetAlpha(p_pane->getNextChildPane(), alpha);
    }
}

/* 80255C68-80255CAC 2505A8 0044+00 0/0 5/5 0/0 .text
 * __ct__17CPaneMgrAlphaMorfFP9J2DScreenUxUcP10JKRExpHeap       */
CPaneMgrAlphaMorf::CPaneMgrAlphaMorf(J2DScreen* p_screen, u64 tag, u8 flags,
                                         JKRExpHeap* p_heap)
    : CPaneMgrAlpha(p_screen, tag, flags, p_heap) {
    initiateAlphaMorf();
}

/* 80255CAC-80255D48 2505EC 009C+00 1/0 0/0 0/0 .text            __dt__17CPaneMgrAlphaMorfFv */
CPaneMgrAlphaMorf::~CPaneMgrAlphaMorf() {
    if (mpFirstSaveAlpha != NULL) {
        heap->free(mpFirstSaveAlpha);
        mpFirstSaveAlpha = NULL;
    }

    if (mpFirstGetAlpha != NULL) {
        heap->free(mpFirstGetAlpha);
        mpFirstGetAlpha = NULL;
    }
}

/* 80255D48-80255DD0 250688 0088+00 1/1 0/0 0/0 .text initiateAlphaMorf__17CPaneMgrAlphaMorfFv */
void CPaneMgrAlphaMorf::initiateAlphaMorf() {
    mpFirstSaveAlpha = NULL;
    field_0x20 = NULL;

    mpFirstGetAlpha = NULL;
    field_0x28 = NULL;

    if (mpFirstStackAlpha != NULL) {
        mpFirstSaveAlpha = heap->alloc(mChildPaneCount, 0x20);
        field_0x20 = (u8*)mpFirstSaveAlpha;

        mpFirstGetAlpha = heap->alloc(mChildPaneCount, 0x20);
        field_0x28 = (u8*)mpFirstGetAlpha;
        setBackupAlpha();
    }
}

/* 80255DD0-80255E28 250710 0058+00 1/1 3/3 0/0 .text setBackupAlpha__17CPaneMgrAlphaMorfFv */
void CPaneMgrAlphaMorf::setBackupAlpha() {
    if (mpFirstStackAlpha != NULL) {
        field_0x20 = (u8*)mpFirstSaveAlpha;
        field_0x28 = (u8*)mpFirstGetAlpha;

        childPaneBackupAlpha(mPane->getFirstChildPane());
    }
}

/* 80255E28-80255E98 250768 0070+00 0/0 3/3 0/0 .text setAlphaMorfRate__17CPaneMgrAlphaMorfFf */
void CPaneMgrAlphaMorf::setAlphaMorfRate(f32 rate) {
    if (mpFirstStackAlpha != NULL) {
        field_0x20 = (u8*)mpFirstSaveAlpha;
        field_0x28 = (u8*)mpFirstGetAlpha;

        childPaneSetAlphaMorf(mPane->getFirstChildPane(), rate);
    } else {
        setAlphaRate(rate);
    }
}

/* 80255E98-80255F28 2507D8 0090+00 1/1 0/0 0/0 .text
 * childPaneBackupAlpha__17CPaneMgrAlphaMorfFP7J2DPane          */
void CPaneMgrAlphaMorf::childPaneBackupAlpha(J2DPane* p_pane) {
    if (p_pane != NULL) {
        *field_0x20 = p_pane->getAlpha();
        field_0x20++;

        *field_0x28 = p_pane->getAlpha();
        field_0x28++;

        childPaneBackupAlpha(p_pane->getFirstChildPane());
        childPaneBackupAlpha(p_pane->getNextChildPane());
    }
}

/* 80255F28-80256018 250868 00F0+00 1/1 0/0 0/0 .text
 * childPaneSetAlphaMorf__17CPaneMgrAlphaMorfFP7J2DPanef        */
void CPaneMgrAlphaMorf::childPaneSetAlphaMorf(J2DPane* p_pane, f32 morf) {
    if (p_pane != NULL) {
        if (*field_0x20 == *field_0x28) {
            p_pane->setAlpha(*field_0x20 * morf);
        } else {
            *field_0x20 = *field_0x28;
        }
        field_0x20++;
        field_0x28++;

        childPaneSetAlphaMorf(p_pane->getFirstChildPane(), morf);
        childPaneSetAlphaMorf(p_pane->getNextChildPane(), morf);
    }
}