On-screen keyboard support!

This commit is contained in:
TheBrokenRail
2023-11-02 16:38:22 -04:00
committed by iProgramInCpp
parent 0559f66102
commit f9b07014d2
10 changed files with 78 additions and 13 deletions

View File

@@ -184,3 +184,11 @@ std::string AppPlatform::getAssetPath(const std::string &path) const
return realPath;
}
void AppPlatform::showKeyboard(int x, int y, int w, int h)
{
}
void AppPlatform::hideKeyboard()
{
}

View File

@@ -68,6 +68,9 @@ public:
virtual std::string getPatchData();
virtual void initSoundSystem();
virtual SoundSystem* const getSoundSystem() const;
// On-screen keyboard
virtual void showKeyboard(int x, int y, int w, int h);
virtual void hideKeyboard();
#endif
public:

View File

@@ -249,10 +249,20 @@ void Screen::mouseClicked(int xPos, int yPos, int d) // d = clicked?
}
#ifndef ORIGINAL_CODE
for (int i = 0; i < int(m_textInputs.size()); i++)
// Iterate over focused text inputs first. This is because if changing
// focus, the previous focus must hide the OSK, before the new focus
// shows it.
for (int phase = 0; phase < 2; phase++)
{
TextInputBox* textInput = m_textInputs[i];
textInput->onClick(xPos, yPos);
bool handleFocused = phase == 0;
for (int i = 0; i < int(m_textInputs.size()); i++)
{
TextInputBox* textInput = m_textInputs[i];
if (textInput->m_bFocused == handleFocused)
{
textInput->onClick(m_pMinecraft, xPos, yPos);
}
}
}
// if the keyboard is shown:

View File

@@ -179,11 +179,24 @@ void TextInputBox::tick()
}
}
void TextInputBox::setFocused(bool b)
void TextInputBox::setFocused(Minecraft* minecraft, bool b)
{
if (m_bFocused == b)
return;
if (b)
{
int x = m_xPos / Gui::InvGuiScale;
int y = m_yPos / Gui::InvGuiScale;
int w = m_width / Gui::InvGuiScale;
int h = m_height / Gui::InvGuiScale;
minecraft->platform()->showKeyboard(x, y, w, h);
}
else
{
minecraft->platform()->hideKeyboard();
}
m_bFocused = b;
if (b)
{
@@ -198,9 +211,9 @@ void TextInputBox::setFocused(bool b)
// - we may be undoing the work of another text box
}
void TextInputBox::onClick(int x, int y)
void TextInputBox::onClick(Minecraft* minecraft, int x, int y)
{
setFocused(clicked(x, y));
setFocused(minecraft, clicked(x, y));
}
void TextInputBox::charPressed(int k)

View File

@@ -30,8 +30,8 @@ public:
void charPressed(int chr);
void render();
void tick();
void setFocused(bool b);
void onClick(int x, int y);
void setFocused(Minecraft*, bool b);
void onClick(Minecraft*, int x, int y);
bool clicked(int x, int y);
public:

View File

@@ -35,7 +35,7 @@ void ChatScreen::init()
// set focus directly on the chat text box
m_textChat.init(m_pFont);
m_textChat.setFocused(true);
m_textChat.setFocused(m_pMinecraft, true);
m_buttons.push_back(&m_btnSend);
m_textInputs.push_back(&m_textChat);

View File

@@ -37,7 +37,7 @@ public:
virtual void printf(eLogLevel, const char* const fmt, ...);
};
#if defined(_DEBUG) || !defined(NDEBUG)
#ifndef NDEBUG
#ifdef ANDROID
// TODO: Add a LoggerAndroid