1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
This commit is contained in:
y5nw 2025-06-23 21:19:34 -07:00 committed by GitHub
commit eaec5ef3a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 63 additions and 3 deletions

View file

@ -37,6 +37,13 @@ enum EEVENT_TYPE
/** This event is created when multiple characters are sent at a time (e.g. using an IME). */ /** This event is created when multiple characters are sent at a time (e.g. using an IME). */
EET_STRING_INPUT_EVENT, EET_STRING_INPUT_EVENT,
//! A string composition event.
/** This event is created when the user "composes" characters (e.g. using an IME) before entering
the complete text.
See https://wiki.libsdl.org/SDL2/SDL_TextEditingExtEvent
*/
EET_STRING_COMPOSITION_EVENT,
//! A touch input event. //! A touch input event.
EET_TOUCH_INPUT_EVENT, EET_TOUCH_INPUT_EVENT,
@ -382,6 +389,19 @@ struct SEvent
core::stringw *Str; core::stringw *Str;
}; };
//! String composition event.
struct SStringComposition
{
//! The string that is composed.
core::stringw *Str;
//! The position within the composition where further text would be inserted.
s32 Start;
//! The number of characters that would be replaced by further typing.
s32 Length;
};
//! Any kind of touch event. //! Any kind of touch event.
struct STouchInput struct STouchInput
{ {
@ -532,6 +552,7 @@ struct SEvent
struct SMouseInput MouseInput; struct SMouseInput MouseInput;
struct SKeyInput KeyInput; struct SKeyInput KeyInput;
struct SStringInput StringInput; struct SStringInput StringInput;
struct SStringComposition StringComposition;
struct STouchInput TouchInput; struct STouchInput TouchInput;
struct SAccelerometerEvent AccelerometerEvent; struct SAccelerometerEvent AccelerometerEvent;
struct SGyroscopeEvent GyroscopeEvent; struct SGyroscopeEvent GyroscopeEvent;

View file

@ -234,6 +234,10 @@ bool CGUIEditBox::OnEvent(const SEvent &event)
inputString(*event.StringInput.Str); inputString(*event.StringInput.Str);
return true; return true;
break; break;
case EET_STRING_COMPOSITION_EVENT:
composeString(*event.StringComposition.Str);
return true;
break;
default: default:
break; break;
} }
@ -1262,10 +1266,10 @@ void CGUIEditBox::inputChar(wchar_t c)
inputString(s); inputString(s);
} }
void CGUIEditBox::inputString(const core::stringw &str) bool CGUIEditBox::insertString(const core::stringw &str)
{ {
if (!isEnabled()) if (!isEnabled())
return; return false;
core::stringw s; core::stringw s;
u32 len = str.size(); u32 len = str.size();
@ -1324,6 +1328,13 @@ void CGUIEditBox::inputString(const core::stringw &str)
} }
BlinkStartTime = os::Timer::getTime(); BlinkStartTime = os::Timer::getTime();
return true;
}
void CGUIEditBox::inputString(const core::stringw &str)
{
if (!insertString(str))
return;
setTextMarkers(0, 0); setTextMarkers(0, 0);
breakText(); breakText();
@ -1331,6 +1342,17 @@ void CGUIEditBox::inputString(const core::stringw &str)
sendGuiEvent(EGET_EDITBOX_CHANGED); sendGuiEvent(EGET_EDITBOX_CHANGED);
} }
void CGUIEditBox::composeString(const core::stringw &str)
{
if (!insertString(str))
return;
setTextMarkers(CursorPos-str.size(), CursorPos);
breakText();
calculateScrollPos();
sendGuiEvent(EGET_EDITBOX_CHANGED);
}
// calculate autoscroll // calculate autoscroll
void CGUIEditBox::calculateScrollPos() void CGUIEditBox::calculateScrollPos()
{ {

View file

@ -144,10 +144,14 @@ protected:
void setTextRect(s32 line); void setTextRect(s32 line);
//! returns the line number that the cursor is on //! returns the line number that the cursor is on
s32 getLineFromPos(s32 pos); s32 getLineFromPos(s32 pos);
//! inserts a string to the edit box; used by inputString and composeString
bool insertString(const core::stringw &str);
//! adds a letter to the edit box //! adds a letter to the edit box
void inputChar(wchar_t c); void inputChar(wchar_t c);
//! adds a string to the edit box //! adds a string to the edit box
void inputString(const core::stringw &str); void inputString(const core::stringw &str);
//! compose a string before it is added
void composeString(const core::stringw &str);
//! calculates the current scroll position //! calculates the current scroll position
void calculateScrollPos(); void calculateScrollPos();
//! calculated the FrameRect //! calculated the FrameRect

View file

@ -552,6 +552,7 @@ bool CGUIEnvironment::postEventFromUser(const SEvent &event)
} }
} }
} break; } break;
case EET_STRING_COMPOSITION_EVENT: [[fallthrough]];
case EET_STRING_INPUT_EVENT: case EET_STRING_INPUT_EVENT:
if (Focus && Focus->OnEvent(event)) if (Focus && Focus->OnEvent(event))
return true; return true;

View file

@ -340,7 +340,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters &param) :
#endif #endif
// Set IME hints // Set IME hints
SDL_SetHint(SDL_HINT_IME_INTERNAL_EDITING, "1"); SDL_SetHint(SDL_HINT_IME_INTERNAL_EDITING, "0");
#if defined(SDL_HINT_IME_SHOW_UI) #if defined(SDL_HINT_IME_SHOW_UI)
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1"); SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
#endif #endif
@ -885,6 +885,18 @@ bool CIrrDeviceSDL::run()
irrevent.StringInput.Str = NULL; irrevent.StringInput.Str = NULL;
} break; } break;
case SDL_TEXTEDITING: {
irrevent.EventType = irr::EET_STRING_COMPOSITION_EVENT;
irrevent.StringComposition.Str = new core::stringw();
irr::core::utf8ToWString(*irrevent.StringInput.Str, SDL_event.edit.text);
irrevent.StringComposition.Start = SDL_event.edit.start;
irrevent.StringComposition.Length = SDL_event.edit.length;
postEventFromUser(irrevent);
delete irrevent.StringInput.Str;
irrevent.StringInput.Str = NULL;
break;
}
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: { case SDL_KEYUP: {
auto keysym = SDL_event.key.keysym.sym; auto keysym = SDL_event.key.keysym.sym;