Fixes and enhancements from my MCPE repository. (https://github.com/mschiller890/mcpe64)

This commit is contained in:
2026-03-10 19:31:40 +01:00
parent 0c97ceb340
commit 2fc323639a
69 changed files with 2509 additions and 639 deletions

View File

@@ -1,90 +1,100 @@
#include "TextBox.h"
#include "../Gui.h"
#include "../../Minecraft.h"
#include "../../../AppPlatform.h"
#include "platform/input/Mouse.h"
#include "../../../platform/input/Mouse.h"
TextBox::TextBox( int id, const std::string& msg )
: TextBox(id, 0, 0, msg) {}
// delegate constructors
TextBox::TextBox(int id, const std::string& msg)
: TextBox(id, 0, 0, msg)
{
}
TextBox::TextBox( int id, int x, int y, const std::string& msg )
: TextBox(id, x, y, 24, msg) {}
TextBox::TextBox(int id, int x, int y, const std::string& msg)
: TextBox(id, x, y, 24, Font::DefaultLineHeight + 4, msg)
{
}
TextBox::TextBox( int id, int x, int y, int w, const std::string& msg )
: GuiElement(true, true, x, y, w, Font::DefaultLineHeight + 4),
id(id), hint(msg), focused(false), blink(false) {}
TextBox::TextBox(int id, int x, int y, int w, int h, const std::string& msg)
: GuiElement(true, true, x, y, w, h),
id(id), hint(msg), focused(false), blink(false), blinkTicks(0)
{
}
void TextBox::setFocus(Minecraft* minecraft) {
if(!focused) {
minecraft->platform()->showKeyboard();
focused = true;
blinkTicks = 0;
blink = false;
}
if (!focused) {
minecraft->platform()->showKeyboard();
focused = true;
blinkTicks = 0;
blink = false;
}
}
bool TextBox::loseFocus(Minecraft* minecraft) {
if(focused) {
minecraft->platform()->showKeyboard();
focused = false;
return true;
}
return false;
if (focused) {
minecraft->platform()->hideKeyboard();
focused = false;
return true;
}
return false;
}
void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
if (buttonNum == MouseAction::ACTION_LEFT) {
if (pointInside(x, y)) {
setFocus(minecraft);
} else {
loseFocus(minecraft);
}
}
if (buttonNum == MouseAction::ACTION_LEFT) {
if (pointInside(x, y)) {
setFocus(minecraft);
} else {
loseFocus(minecraft);
}
}
}
void TextBox::handleChar(char c) {
if (focused) {
text.push_back(c);
}
if (focused && c >= 32 && c < 127 && (int)text.size() < 256) {
text.push_back(c);
}
}
void TextBox::handleKey(int key) {
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
text.pop_back();
}
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
text.pop_back();
}
}
void TextBox::tick(Minecraft* minecraft) {
blinkTicks++;
if (blinkTicks >= 5) {
blink = !blink;
blinkTicks = 0;
}
blinkTicks++;
if (blinkTicks >= 5) {
blink = !blink;
blinkTicks = 0;
}
}
void TextBox::render( Minecraft* minecraft, int xm, int ym ) {
// textbox like in beta 1.7.3
fill(x, y, x + width, y + height, 0xffa0a0a0);
fill(x + 1, y + 1, x + width - 1, y + height - 1, 0xff000000);
void TextBox::render(Minecraft* minecraft, int xm, int ym) {
// textbox like in beta 1.7.3
// change appearance when focused so the user can tell it's active
// active background darker gray with a subtle border
uint32_t bgColor = focused ? 0xffa0a0a0 : 0xffa0a0a0;
uint32_t borderColor = focused ? 0xff000000 : 0xff000000;
fill(x, y, x + width, y + height, bgColor);
fill(x + 1, y + 1, x + width - 1, y + height - 1, borderColor);
glEnable2(GL_SCISSOR_TEST);
glScissor(
Gui::GuiScale * (x + 2),
minecraft->height - Gui::GuiScale * (y + height - 2),
Gui::GuiScale * (width - 2),
Gui::GuiScale * (height - 2)
);
glEnable2(GL_SCISSOR_TEST);
glScissor(
Gui::GuiScale * (x + 2),
minecraft->height - Gui::GuiScale * (y + height - 2),
Gui::GuiScale * (width - 2),
Gui::GuiScale * (height - 2)
);
if (text.empty() && !focused) {
drawString(minecraft->font, hint, x + 2, y + 2, 0xff5e5e5e);
}
if (text.empty() && !focused) {
drawString(minecraft->font, hint, x + 2, y + 2, 0xff5e5e5e);
}
if (focused && blink) text.push_back('_');
if (focused && blink) text.push_back('_');
drawString(minecraft->font, text, x + 2, y + 2, 0xffffffff);
drawString(minecraft->font, text, x + 2, y + 2, 0xffffffff);
if (focused && blink) text.pop_back();
if (focused && blink) text.pop_back();
glDisable2(GL_SCISSOR_TEST);
glDisable2(GL_SCISSOR_TEST);
}