summaryrefslogtreecommitdiff
path: root/src/JSystem/J2DGraph/J2DPane.cpp
blob: 09f0609118fe5e9a4dec9e6d1bb1e0022fdfa277 (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
//
// Generated by dtk
// Translation Unit: J2DPane.cpp
//

#include "JSystem/J2DGraph/J2DPane.h"
#include "JSystem/JSupport/JSURandomInputStream.h"
#include "dolphin/types.h"

/* 802CF8F4-802CF984       .text __ct__7J2DPaneFv */
J2DPane::J2DPane() : mPaneTree(this) {
    mMagic = 'PAN1';
    mVisible = true;
    mTag = 0;

    mBounds.set(0.f, 0.f, 0.f, 0.f);
    initiate();
}

/* 802CF984-802CFA44       .text __ct__7J2DPaneFP7J2DPanebUlRCQ29JGeometry8TBox2<f> */
J2DPane::J2DPane(J2DPane* pPane, bool visible, u32 tag, const JGeometry::TBox2<f32>& bounds)
    : mPaneTree(this) {
    mMagic = 'PAN1';
    mVisible = visible;
    mTag = tag;
    mBounds.set(bounds);
    if (pPane) {
        pPane->mPaneTree.appendChild(&mPaneTree);
    }
    initiate();
}

/* 802CFA44-802CFAE4       .text __ct__7J2DPaneFUlRCQ29JGeometry8TBox2<f> */
J2DPane::J2DPane(u32 tag, const JGeometry::TBox2<f32>& bounds) : mPaneTree(this) {
    mMagic = 'PAN1';
    mVisible = true;
    mTag = tag;
    mBounds.set(bounds);
    initiate();
}

/* 802CFAE4-802CFB48       .text initiate__7J2DPaneFv */
void J2DPane::initiate() {
    mBasePosition.x = 0.0f;
    mBasePosition.y = 0.0f;
    mRotationAxis = ROTATE_Z;
    mRotation = 0.0f;
    mCullMode = 0;
    mAlpha = 0xFF;
    field_0xae = 1;
    mDrawAlpha = 0xFF;
    field_0xaf = 0;
    calcMtx();
}

/* 802CFB48-802CFC00       .text __ct__7J2DPaneFP7J2DPaneP20JSURandomInputStream */
J2DPane::J2DPane(J2DPane* pParentPane, JSURandomInputStream* pStream) : mPaneTree(this) {
    J2DPaneHeader header;

    int pos = pStream->getPosition();
    pStream->read(&header, sizeof(header));
    mMagic = header.mMagic;
    pos += header.mSize;
    makePaneStream(pParentPane, pStream);
    pStream->seek(pos, JSUStreamSeekFrom_SET);
}

/* 802CFC00-802CFEF8       .text makePaneStream__7J2DPaneFP7J2DPaneP20JSURandomInputStream */
void J2DPane::makePaneStream(J2DPane* pParentPane, JSURandomInputStream* pStream) {
    u8 unk;
    pStream->read(&unk, 1);
    pStream->read(&mVisible, 1);
    pStream->skip(2);
    mTag = pStream->read32b();

    f32 x0 = pStream->readS16();
    f32 y0 = pStream->readS16();
    f32 x1 = x0 + pStream->readS16();
    f32 y1 = y0 + pStream->readS16();
    mBounds.set(x0, y0, x1, y1);

    unk -= 6;
    mRotation = 0;
    if (unk != 0) {
        mRotation = pStream->readU16();
        unk--;
    }

    if (unk != 0) {
        setBasePosition((J2DBasePosition)pStream->readU8());
        unk--;
    } else {
        setBasePosition(J2DBasePosition_0);
    }

    mAlpha = 0xFF;

    if (unk != 0) {
        mAlpha = pStream->readU8();
        unk--;
    }

    field_0xae = 1;
    if (unk != 0) {
        field_0xae = pStream->readU8() != 0;
        unk--;
    }

    pStream->align(4);
    if (pParentPane != NULL) {
        pParentPane->mPaneTree.appendChild(&mPaneTree);
    }

    mCullMode = GX_CULL_NONE;
    mDrawAlpha = 0xFF;
    field_0xaf = 0;
    calcMtx();
}

/* 802CFEF8-802CFFD8       .text __dt__7J2DPaneFv */
J2DPane::~J2DPane() {
    JSUTreeIterator<J2DPane> iterator;
    for (iterator = mPaneTree.getFirstChild(); iterator != mPaneTree.getEndChild();) {
        J2DPane* child = (iterator++).getObject();
        delete child;
    }
}

/* 802CFFD8-802D0078       .text insertChild__7J2DPaneFP7J2DPaneP7J2DPane */
bool J2DPane::insertChild(J2DPane* pPrev, J2DPane* pChild) {
    if (pPrev == NULL || pChild == NULL)
        return false;

    bool result =
        mPaneTree.insertChild(pPrev != NULL ? &pPrev->mPaneTree : NULL, &pChild->mPaneTree);

    if (result) {
        pChild->calcMtx();
    }

    return result;
}

/* 802D0078-802D054C       .text draw__7J2DPaneFffPC14J2DGrafContextb */
void J2DPane::draw(float, float, const J2DGrafContext*, bool) {
    /* Nonmatching */
}

/* 802D054C-802D05C8       .text move__7J2DPaneFff */
void J2DPane::move(float, float) {
    /* Nonmatching */
}

/* 802D05C8-802D0604       .text add__7J2DPaneFff */
void J2DPane::add(f32 px, f32 py) {
    move(mBounds.i.x + px, mBounds.i.y + py);
}

/* 802D0604-802D0680       .text clip__7J2DPaneFRCQ29JGeometry8TBox2<f> */
void J2DPane::clip(const JGeometry::TBox2<f32>& bounds) {
    JGeometry::TBox2<f32> boxA(bounds);
    JGeometry::TBox2<f32> boxB(mScreenPos);
    boxA.addPos(boxB.i);
    mBox.intersect(boxA);
}

/* 802D0680-802D0714       .text search__7J2DPaneFUl */
J2DPane* J2DPane::search(u32 tag) {
    if (tag == mTag) {
        return this;
    }

    JSUTreeIterator<J2DPane> iter;
    for (iter = mPaneTree.getFirstChild(); iter != mPaneTree.getEndChild(); ++iter) {
        if (J2DPane* result = iter.getObject()->search(tag)) {
            return result;
        }
    }
    return NULL;
}

/* 802D0714-802D0800       .text makeMatrix__7J2DPaneFff */
void J2DPane::makeMatrix(float, float) {
    /* Nonmatching */
}

/* 802D0800-802D08D8       .text setBasePosition__7J2DPaneF15J2DBasePosition */
void J2DPane::setBasePosition(J2DBasePosition pos) {
    /* Nonmatching */
    m2DBasePosition = pos;

    if (pos % 3 == 0) {
        mBasePosition.x = 0.0f;
    } else if (pos % 3 == 1) {
        f32 width = mBounds.getWidth();
        mBasePosition.x = 0.5f * width;
    } else {
        mBasePosition.x = mBounds.getWidth();
    }

    if (pos / 3 == 0) {
        mBasePosition.y = 0.0f;
    } else if (pos / 3 == 1) {
        f32 height = mBounds.getHeight();
        mBasePosition.y = height * 0.5f;
    } else {
        mBasePosition.y = mBounds.getHeight();
    }
    mRotationAxis = ROTATE_Z;
    calcMtx();
}

/* 802D08D8-802D08DC       .text drawSelf__7J2DPaneFffPA3_A4_f */
// void J2DPane::drawSelf(float, float, float (*)[3][4]) {
//     /* Nonmatching */
// }

/* 802D08DC-802D08E4       .text getTypeID__7J2DPaneFv */
// u16 J2DPane::getTypeID() {
//     /* Nonmatching */
// }