aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/EditBox.cpp
diff options
context:
space:
mode:
authordaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
committerdaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
commitb691c43c44ff180d10e7d4a9afc83b98551ff586 (patch)
tree3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.Client/EditBox.cpp
parentdef8cb415354ac390b7e89052a50605285f1aca9 (diff)
Initial commit
Diffstat (limited to 'Minecraft.Client/EditBox.cpp')
-rw-r--r--Minecraft.Client/EditBox.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/Minecraft.Client/EditBox.cpp b/Minecraft.Client/EditBox.cpp
new file mode 100644
index 00000000..54ee62ef
--- /dev/null
+++ b/Minecraft.Client/EditBox.cpp
@@ -0,0 +1,110 @@
+#include "stdafx.h"
+#include "EditBox.h"
+#include "..\Minecraft.World\SharedConstants.h"
+
+EditBox::EditBox(Screen *screen, Font *font, int x, int y, int width, int height, const wstring& value)
+{
+ // 4J - added initialisers
+ maxLength = 0;
+ frame = 0;
+
+ this->screen = screen;
+ this->font = font;
+ this->x = x;
+ this->y = y;
+ this->width = width;
+ this->height = height;
+ this->setValue(value);
+}
+
+void EditBox::setValue(const wstring& value)
+{
+ this->value = value;
+}
+
+wstring EditBox::getValue()
+{
+ return value;
+}
+
+void EditBox::tick()
+{
+ frame++;
+}
+
+void EditBox::keyPressed(wchar_t ch, int eventKey)
+{
+ if (!active || !inFocus) {
+ return;
+ }
+
+
+ if (ch == 9)
+ {
+ screen->tabPressed();
+ }
+/* 4J removed
+ if (ch == 22)
+ {
+ String msg = Screen.getClipboard();
+ if (msg == null) msg = "";
+ int toAdd = 32 - value.length();
+ if (toAdd > msg.length()) toAdd = msg.length();
+ if (toAdd > 0) {
+ value += msg.substring(0, toAdd);
+ }
+ }
+ */
+
+ if (eventKey == Keyboard::KEY_BACK && value.length() > 0)
+ {
+ value = value.substr(0, value.length() - 1);
+ }
+ if (SharedConstants::acceptableLetters.find(ch) != wstring::npos && (value.length() < maxLength || maxLength == 0))
+ {
+ value += ch;
+ }
+
+}
+
+void EditBox::mouseClicked(int mouseX, int mouseY, int buttonNum)
+{
+ bool newFocus = active && (mouseX >= x && mouseX < (x + width) && mouseY >= y && mouseY < (y + height));
+ focus(newFocus);
+}
+
+void EditBox::focus(bool newFocus)
+{
+ if (newFocus && !inFocus)
+ {
+ // reset the underscore counter to give quicker selection feedback
+ frame = 0;
+ }
+ inFocus = newFocus;
+}
+
+void EditBox::render()
+{
+ fill(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);
+ fill(x, y, x + width, y + height, 0xff000000);
+
+ if (active)
+ {
+ bool renderUnderscore = inFocus && (frame / 6 % 2 == 0);
+ drawString(font, value + (renderUnderscore ? L"_" : L""), x + 4, y + (height - 8) / 2, 0xe0e0e0);
+ }
+ else
+ {
+ drawString(font, value, x + 4, y + (height - 8) / 2, 0x707070);
+ }
+}
+
+void EditBox::setMaxLength(int maxLength)
+{
+ this->maxLength = maxLength;
+}
+
+int EditBox::getMaxLength()
+{
+ return maxLength;
+} \ No newline at end of file