mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-17 20:10:23 +03:00
On-screen keyboard support!
This commit is contained in:
committed by
iProgramInCpp
parent
0559f66102
commit
f9b07014d2
@@ -221,3 +221,26 @@ Keyboard::KeyState AppPlatform_sdl_base::GetKeyState(SDL_Event event)
|
||||
return Keyboard::DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void AppPlatform_sdl_base::showKeyboard(int x, int y, int w, int h)
|
||||
{
|
||||
if (SDL_IsTextInputActive())
|
||||
{
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
SDL_Rect rect;
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
rect.w = w;
|
||||
rect.h = h;
|
||||
SDL_SetTextInputRect(&rect);
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
|
||||
void AppPlatform_sdl_base::hideKeyboard()
|
||||
{
|
||||
if (SDL_IsTextInputActive())
|
||||
{
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ public:
|
||||
static MouseButtonType GetMouseButtonType(SDL_Event event);
|
||||
static bool GetMouseButtonState(SDL_Event event);
|
||||
static Keyboard::KeyState GetKeyState(SDL_Event event);
|
||||
|
||||
// On-screen keyboard
|
||||
void showKeyboard(int x, int y, int w, int h) override;
|
||||
void hideKeyboard() override;
|
||||
private:
|
||||
SDL_Window *_window;
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@ static void teardown()
|
||||
|
||||
static int TranslateSDLKeyCodeToVirtual(int sdlCode)
|
||||
{
|
||||
if (sdlCode == SDLK_AC_BACK) {
|
||||
// Android Back Button
|
||||
sdlCode = SDLK_ESCAPE;
|
||||
}
|
||||
switch (sdlCode) {
|
||||
#define CODE(x) case SDLK_ ## x: return SDLVK_ ## x;
|
||||
#include "compat/SDLKeyCodes.h"
|
||||
@@ -330,6 +334,9 @@ int main(int argc, char *argv[])
|
||||
Minecraft::height = std::stoi(argv[2]);
|
||||
#endif
|
||||
|
||||
// Lock To Landscape
|
||||
SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight");
|
||||
|
||||
// Create Window
|
||||
int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
window = SDL_CreateWindow("ReMinecraftPE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Minecraft::width, Minecraft::height, flags);
|
||||
@@ -339,9 +346,6 @@ int main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Enable Text Input
|
||||
SDL_StartTextInput();
|
||||
|
||||
// Create OpenGL ES Context
|
||||
context = SDL_GL_CreateContext(window);
|
||||
if (!context)
|
||||
|
||||
@@ -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