mirror of
https://github.com/celisej567/mcpe.git
synced 2026-01-05 18:10:09 +03:00
On-screen keyboard support!
This commit is contained in:
committed by
iProgramInCpp
parent
0559f66102
commit
f9b07014d2
@@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user