2024-02-01 03:12:24 -05:00
|
|
|
#include <libreborn/libreborn.h>
|
|
|
|
|
|
|
|
#include <mods/text-input-box/TextInputScreen.h>
|
|
|
|
|
|
|
|
// VTable
|
|
|
|
void TextInputScreen::setup(Screen_vtable *vtable) {
|
2024-04-03 03:19:12 -04:00
|
|
|
static Screen_keyPressed_t original_keyPressed = vtable->keyPressed;
|
2024-02-01 03:12:24 -05:00
|
|
|
vtable->keyPressed = [](Screen *super2, int key) {
|
2024-04-03 03:19:12 -04:00
|
|
|
original_keyPressed(super2, key);
|
2024-02-01 03:12:24 -05:00
|
|
|
TextInputScreen *self = (TextInputScreen *) super2;
|
2024-02-01 14:56:16 -05:00
|
|
|
for (int i = 0; i < int(self->m_textInputs->size()); i++) {
|
|
|
|
TextInputBox *textInput = (*self->m_textInputs)[i];
|
2024-02-01 03:12:24 -05:00
|
|
|
textInput->keyPressed(key);
|
|
|
|
}
|
|
|
|
};
|
2024-04-03 03:19:12 -04:00
|
|
|
static Screen_keyboardNewChar_t original_keyboardNewChar = vtable->keyboardNewChar;
|
2024-02-01 03:12:24 -05:00
|
|
|
vtable->keyboardNewChar = [](Screen *super2, char key) {
|
2024-04-03 03:19:12 -04:00
|
|
|
original_keyboardNewChar(super2, key);
|
2024-02-01 03:12:24 -05:00
|
|
|
TextInputScreen *self = (TextInputScreen *) super2;
|
2024-02-01 14:56:16 -05:00
|
|
|
for (int i = 0; i < int(self->m_textInputs->size()); i++) {
|
|
|
|
TextInputBox *textInput = (*self->m_textInputs)[i];
|
2024-02-01 03:12:24 -05:00
|
|
|
textInput->charPressed(key);
|
|
|
|
}
|
|
|
|
};
|
2024-04-03 03:19:12 -04:00
|
|
|
static Screen_mouseClicked_t original_mouseClicked = vtable->mouseClicked;
|
2024-02-01 03:12:24 -05:00
|
|
|
vtable->mouseClicked = [](Screen *super2, int x, int y, int param_1) {
|
2024-04-03 03:19:12 -04:00
|
|
|
original_mouseClicked(super2, x, y, param_1);
|
2024-02-01 03:12:24 -05:00
|
|
|
TextInputScreen *self = (TextInputScreen *) super2;
|
2024-02-01 14:56:16 -05:00
|
|
|
for (int i = 0; i < int(self->m_textInputs->size()); i++) {
|
|
|
|
TextInputBox *textInput = (*self->m_textInputs)[i];
|
2024-02-01 03:12:24 -05:00
|
|
|
textInput->onClick(x, y);
|
|
|
|
}
|
|
|
|
};
|
2024-04-03 03:19:12 -04:00
|
|
|
static Screen_render_t original_render = vtable->render;
|
2024-02-01 03:12:24 -05:00
|
|
|
vtable->render = [](Screen *super2, int x, int y, float param_1) {
|
2024-04-03 03:19:12 -04:00
|
|
|
original_render(super2, x, y, param_1);
|
2024-02-01 03:12:24 -05:00
|
|
|
TextInputScreen *self = (TextInputScreen *) super2;
|
2024-02-01 14:56:16 -05:00
|
|
|
for (int i = 0; i < int(self->m_textInputs->size()); i++) {
|
|
|
|
TextInputBox *textInput = (*self->m_textInputs)[i];
|
2024-02-01 03:12:24 -05:00
|
|
|
textInput->tick();
|
|
|
|
textInput->render();
|
|
|
|
}
|
|
|
|
};
|
2024-04-03 03:19:12 -04:00
|
|
|
static Screen_init_t original_init = vtable->init;
|
2024-02-01 14:56:16 -05:00
|
|
|
vtable->init = [](Screen *super2) {
|
2024-04-03 03:19:12 -04:00
|
|
|
original_init(super2);
|
2024-02-01 14:56:16 -05:00
|
|
|
TextInputScreen *self = (TextInputScreen *) super2;
|
|
|
|
self->m_textInputs = new std::vector<TextInputBox *>;
|
|
|
|
};
|
2024-04-03 03:19:12 -04:00
|
|
|
static Screen_removed_t original_removed = vtable->removed;
|
2024-02-01 14:56:16 -05:00
|
|
|
vtable->removed = [](Screen *super2) {
|
2024-04-03 03:19:12 -04:00
|
|
|
original_removed(super2);
|
2024-02-01 14:56:16 -05:00
|
|
|
TextInputScreen *self = (TextInputScreen *) super2;
|
|
|
|
delete self->m_textInputs;
|
|
|
|
};
|
2024-02-01 03:12:24 -05:00
|
|
|
}
|