summaryrefslogtreecommitdiff
path: root/include/nw4r/lyt/lyt_layout.h
blob: 543065fb0d6469a085b1bddb2a30a28a7f17d94a (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
#ifndef NW4R_LYT_LAYOUT_H
#define NW4R_LYT_LAYOUT_H

#include "common.h"
#include "nw4r/lyt/lyt_animation.h"
#include "nw4r/lyt/lyt_types.h"
#include "rvl/MEM/mem_allocator.h"

#include <new>

namespace nw4r {
namespace lyt {

namespace res {
struct Layout {
    DataBlockHeader blockheader; // at 0x00
    u8 originType;               // at 0x08
    u8 padding[3];               // at 0x09
    Size layoutSize;             // at 0x0C
};

} // namespace res

class Layout {
public:
    ut::Rect GetLayoutRect() const;
    static Pane *BuildPaneObj(s32 kind, const void *dataPtr, const ResBlockSet &ResBlockSet);

    Layout();
    virtual ~Layout();                                                                                   // at 0x08
    virtual bool Build(const void *lytResBuf, ResourceAccessor *pResAcsr);                               // at 0x0C
    virtual AnimTransform *CreateAnimTransform();                                                        // at 0x10
    virtual AnimTransform *CreateAnimTransform(const void *animResBuf, ResourceAccessor *pResAcsr);      // at 0x14
    virtual AnimTransform *CreateAnimTransform(const AnimResource &animRes, ResourceAccessor *pResAcsr); // at 0x18
    virtual void BindAnimation(AnimTransform *pAnimTrans);                                               // at 0x1C
    virtual void UnbindAnimation(AnimTransform *pAnimTrans);                                             // at 0x20
    virtual void UnbindAllAnimation();                                                                   // at 0x24
    virtual bool BindAnimationAuto(const AnimResource &animRes, ResourceAccessor *pResAcsr);             // at 0x28
    virtual void SetAnimationEnable(AnimTransform *pAnimTrans, bool bEnable);                            // at 0x2C
    virtual void CalculateMtx(const DrawInfo &drawInfo);                                                 // at 0x30
    virtual void Draw(const DrawInfo &drawInfo);                                                         // at 0x34
    virtual void Animate(u32 option);                                                                    // at 0x38
    virtual void SetTagProcessor(ut::TagProcessorBase<wchar_t> *pTagProcessor);                          // at 0x3C

    ut::LinkList<AnimTransform, 4> &GetAnimTransformList() {
        return mAnimTransList;
    }

    Pane *GetRootPane() const {
        return mpRootPane;
    }

    GroupContainer *GetGroupContainer() const {
        return mpGroupContainer;
    }

protected:
    ut::LinkList<AnimTransform, 4> mAnimTransList; // at 0x04
    Pane *mpRootPane;                              // at 0x10
    GroupContainer *mpGroupContainer;              // at 0x14
    Size mLayoutSize;                              // at 0x18

public:
    // STATICS
    static void FreeMemory(void *p) {
        MEMFreeToAllocator(mspAllocator, p);
    }

    static void *AllocMemory(size_t n) {
        return MEMAllocFromAllocator(mspAllocator, n);
    }

    template <typename T>
    static void DeleteArray(T *p, size_t n);

    template <typename T>
    static T *NewArray(size_t n);

    template <typename T>
    static void DeleteObj(T *t);

    template <typename T>
    static void DeletePrimArray(T *objAry);

    template <typename T>
    static T *NewObj();

    template <typename T, typename P1>
    static T *NewObj(P1 param1);

    template <typename T, typename P1, typename P2>
    static T *NewObj(P1 param1, P2 param2);

    static MEMAllocator *mspAllocator;
};

template <typename T>
void Layout::DeleteArray(T *p, size_t n) {
    if (p) {
        for (size_t i = 0; i < n; i++) {
            p[i].~T();
        }

        FreeMemory(p);
    }
}

template <typename T>
T *Layout::NewArray(size_t n) {
    T *array = (T *)AllocMemory(n * sizeof(T));
    if (!array) {
        return nullptr;
    }

    for (size_t i = 0; i < n; i++) {
        new (&array[i]) T();
    }

    return array;
}

template <typename T>
void Layout::DeleteObj(T *t) {
    if (t) {
        t->~T();
        FreeMemory(t);
    }
}

template <typename T>
void Layout::DeletePrimArray(T *objAry) {
    if (objAry) {
        FreeMemory(objAry);
    }
}

template <typename T>
T *Layout::NewObj() {
    T *pMem = (T *)AllocMemory(sizeof(T));
    if (pMem) {
        return new (pMem) T();
    } else {
        return nullptr;
    }
}

template <typename T, typename P1>
T *Layout::NewObj(P1 param1) {
    T *pMem = (T *)AllocMemory(sizeof(T));
    if (pMem) {
        return new (pMem) T(param1);
    } else {
        return nullptr;
    }
}

template <typename T, typename P1, typename P2>
T *Layout::NewObj(P1 param1, P2 param2) {
    T *pMem = (T *)AllocMemory(sizeof(T));
    if (pMem) {
        return new (pMem) T(param1, param2);
    } else {
        return nullptr;
    }
}

} // namespace lyt
} // namespace nw4r

#endif