summaryrefslogtreecommitdiff
path: root/libs/JSystem/src/JAWExtSystem/JAWExtSystem.cpp
blob: 9495148ece9b83c325a003478dcc50d748d0c55d (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
#include "JSystem/JSystem.h" // IWYU pragma: keep

#include "JSystem/JAWExtSystem/JAWExtSystem.h"
#include "JSystem/J2DGraph/J2DOrthoGraph.h"
#include "JSystem/JAWExtSystem/JAWGraphContext.h"
#include "JSystem/JAWExtSystem/JAWWindow.h"
#include "JSystem/JUtility/JUTGamePad.h"
#include <algorithm>

JGadget::TList<JAWWindow*> JAWExtSystem::sPage[128];
JAWExtSystem::TSystemInterface JAWExtSystem::sInterface;
s32 JAWExtSystem::sCurrentPage = ARRAY_SIZE(sPage) - 1;
u8 JAWExtSystem::lbl_80748E44;

BOOL JAWExtSystem::registWindow(u32 param_1, JAWWindow* param_2, int param_3, int param_4) {
    TCurrentHeap heap(sInterface);
    if (param_1 >= ARRAY_SIZE(sPage)) {
        return FALSE;
    }
    param_2->move(param_3, param_4);
    sPage[param_1].push_back(param_2);
    if (sCurrentPage > param_1) {
        sCurrentPage = param_1;
    }
    return TRUE;
}

BOOL JAWExtSystem::destroyWindow(u32 param_1, JAWWindow* param_2) {
    TCurrentHeap heap(sInterface);
    if (param_1 >= ARRAY_SIZE(sPage)) {
        return FALSE;
    }
    JGadget::TList<JAWWindow*>* page = &sPage[param_1];
    JGadget::TList<JAWWindow*>::iterator it = std::find(page->begin(), page->end(), param_2);
    if (it == page->end()) {
        return FALSE;
    }
    page->erase(it);
    return TRUE;
}

void JAWExtSystem::nextPage() {
    int page = sCurrentPage;
    do {
        sCurrentPage++;
        if (sCurrentPage >= ARRAY_SIZE(sPage)) {
            sCurrentPage = 0;
        }
        if (page == sCurrentPage) {
            break;
        }
    } while (sPage[sCurrentPage].empty());
}

void JAWExtSystem::prevPage() {
    int page = sCurrentPage;
    do {
        sCurrentPage--;
        if (sCurrentPage < 0) {
            sCurrentPage = ARRAY_SIZE(sPage) - 1;
        }
        if (page == sCurrentPage) {
            break;
        }
    } while (sPage[sCurrentPage].empty());
}

void JAWExtSystem::nextWindow() {
    JGadget::TList<JAWWindow*>* page = &sPage[sCurrentPage];
    JGadget::TList<JAWWindow*>::iterator begin = page->begin();
    if (begin == page->end()) {
        return;
    }
    JAWWindow* window = *begin;
    page->erase(begin);
    page->push_back(window);
}

void JAWExtSystem::prevWindow() {
    JGadget::TList<JAWWindow*>* page = &sPage[sCurrentPage];
    JGadget::TList<JAWWindow*>::iterator end = page->end();
    end--;
    if (end == page->end()) {
        return;
    }
    JAWWindow* window = *end;
    page->erase(end);
    page->push_front(window);
}

void JAWExtSystem::draw() {
    TCurrentHeap heap(sInterface);
    if (!JAWGraphContext::lbl_8074CD30) {
        return;
    }
    J2DOrthoGraph ortho(0.0f, 0.0f, 640.0f, 480.0f, -1.0f, 1.0f);
    ortho.setOrtho(0.0f, -20.0f, 640.0f, 520.0f, -1.0, 1.0f);
    ortho.setPort();
    JGadget::TList<JAWWindow*>* page = &sPage[sCurrentPage];
    JGadget::TIterator_reverse<JGadget::TList<JAWWindow*>::iterator> it;
    for (it = page->rbegin(); it != page->rend(); it++) {
        JAWWindow** window = &*it;
        (*window)->initIf();
        (*window)->setAlpha(lbl_80748E44);
        (*window)->draw(0, 0, &ortho);
    }
    for (int i = 0; i < ARRAY_SIZE(sPage); i++) {
        JGadget::TList<JAWWindow*>* page = &sPage[i];
        JGadget::TIterator_reverse<JGadget::TList<JAWWindow*>::iterator> it;
        for (it = page->rbegin(); it != page->rend(); it++) {
            JAWWindow** window = &*it;
            (*window)->frameWork();
        }
    }
    GXSetScissor(0, 0, 640, 480);
}

void JAWExtSystem::padProc(const JUTGamePad& pad) {
    TCurrentHeap heap(sInterface);
    if (pad.getAnalogR() && pad.testTrigger(PAD_BUTTON_MENU)) {
        JAWGraphContext::lbl_8074CD30 ^= true;
    }
    if (!JAWGraphContext::lbl_8074CD30) {
        return;
    }
    JGadget::TList<JAWWindow*>* page = &sPage[sCurrentPage];
    JGadget::TList<JAWWindow*>::iterator begin = page->begin();
    if (begin == page->end()) {
        return;
    }
    JAWWindow* window = *begin;
    if (pad.getAnalogR()) {
        f32 f31 = pad.getAnalogL() * 0.1f + 8.0f;
        int r25 = f31 * pad.getMainStickX();
        int r28 = -int(f31 * pad.getMainStickY());
        if (pad.testButton(PAD_BUTTON_X)) {
            window->addSize(r25, r28);
        } else if (pad.testButton(PAD_BUTTON_B)) {
            int r29 = lbl_80748E44;
            r29 += (r28 > 0 ? -2 : r28 < 0 ? 2 : 0) * (pad.getAnalogL() ? 2 : 1);
            if (r29 < 0) {
                r29 = 0;
            }
            if (r29 >= 256) {
                r29 = 255;
            }
            lbl_80748E44 = r29;
        } else {
            window->addPosition(r25, r28);
        }
        if (pad.testTrigger(PAD_BUTTON_RIGHT)) {
            nextPage();
        }
        if (pad.testTrigger(PAD_BUTTON_LEFT)) {
            prevPage();
        }
        if (pad.testTrigger(PAD_BUTTON_UP)) {
            prevWindow();
        }
        if (pad.testTrigger(PAD_BUTTON_DOWN)) {
            nextWindow();
        }
    } else {
        window->padProc(pad);
    }
}