SDL1 Unicode input support
This commit is contained in:
parent
958087ab86
commit
7959b04573
5 changed files with 29 additions and 29 deletions
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#ifdef USE_SDL1
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <cassert>
|
||||
#endif
|
||||
|
||||
#include "DiabloUI/art_draw.h"
|
||||
#include "DiabloUI/button.h"
|
||||
|
|
@ -223,13 +228,13 @@ void UiFocusPageDown()
|
|||
}
|
||||
}
|
||||
|
||||
void SelheroCatToName(char *inBuf, char *outBuf, int cnt)
|
||||
void SelheroCatToName(const char *inBuf, char *outBuf, int cnt)
|
||||
{
|
||||
strncat(outBuf, inBuf, cnt - strlen(outBuf));
|
||||
}
|
||||
|
||||
#ifdef __vita__
|
||||
void selhero_SetName(char *in_buf, char *out_buf, int cnt)
|
||||
void selhero_SetName(const char *in_buf, char *out_buf, int cnt)
|
||||
{
|
||||
strncpy(out_buf, in_buf, cnt);
|
||||
}
|
||||
|
|
@ -337,12 +342,9 @@ void UiFocusNavigation(SDL_Event *event)
|
|||
#ifdef USE_SDL1
|
||||
if ((event->key.keysym.mod & KMOD_CTRL) == 0) {
|
||||
Uint16 unicode = event->key.keysym.unicode;
|
||||
if (unicode && (unicode & 0xFF80) == 0) {
|
||||
char utf8[SDL_TEXTINPUTEVENT_TEXT_SIZE];
|
||||
utf8[0] = (char)unicode;
|
||||
utf8[1] = '\0';
|
||||
SelheroCatToName(utf8, UiTextInput, UiTextInputLen);
|
||||
}
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> convert;
|
||||
std::string utf8 = convert.to_bytes(unicode);
|
||||
SelheroCatToName(utf8.c_str(), UiTextInput, UiTextInputLen);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1774,7 +1774,7 @@ void control_reset_talk()
|
|||
force_redraw = 255;
|
||||
}
|
||||
|
||||
bool control_talk_last_key(char vkey)
|
||||
bool IsTalkActive()
|
||||
{
|
||||
if (!IsChatAvailable())
|
||||
return false;
|
||||
|
|
@ -1782,28 +1782,11 @@ bool control_talk_last_key(char vkey)
|
|||
if (!talkflag)
|
||||
return false;
|
||||
|
||||
#ifdef USE_SDL1
|
||||
if (vkey >= 0 && vkey < DVL_VK_SPACE)
|
||||
return false;
|
||||
|
||||
std::size_t result = strlen(TalkMessage);
|
||||
if (result < 78) {
|
||||
TalkMessage[result] = vkey;
|
||||
TalkMessage[result + 1] = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void control_new_text(string_view text)
|
||||
{
|
||||
if (!IsChatAvailable())
|
||||
return;
|
||||
|
||||
if (!talkflag)
|
||||
return;
|
||||
|
||||
strncat(TalkMessage, text.data(), sizeof(TalkMessage) - strlen(TalkMessage) - 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ bool control_check_talk_btn();
|
|||
void control_release_talk_btn();
|
||||
void control_type_message();
|
||||
void control_reset_talk();
|
||||
bool control_talk_last_key(char vkey);
|
||||
bool IsTalkActive();
|
||||
void control_new_text(string_view text);
|
||||
bool control_presskeys(int vkey);
|
||||
void DiabloHotkeyMsg(uint32_t dwMsg);
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ void PressKey(int vkey)
|
|||
*/
|
||||
void PressChar(char vkey)
|
||||
{
|
||||
if (gmenu_is_active() || control_talk_last_key(vkey) || sgnTimeoutCurs != CURSOR_NONE || MyPlayerIsDead) {
|
||||
if (gmenu_is_active() || IsTalkActive() || sgnTimeoutCurs != CURSOR_NONE || MyPlayerIsDead) {
|
||||
return;
|
||||
}
|
||||
if (vkey == 'p' || vkey == 'P') {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#ifdef USE_SDL1
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <cassert>
|
||||
#endif
|
||||
|
||||
#include "control.h"
|
||||
#include "controls/controller.h"
|
||||
|
|
@ -474,6 +479,16 @@ bool FetchMessage_Real(tagMSG *lpMsg)
|
|||
break;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
#ifdef USE_SDL1
|
||||
if (gbRunGame && IsTalkActive()) {
|
||||
Uint16 unicode = e.key.keysym.unicode;
|
||||
if (unicode >= ' ') {
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> convert;
|
||||
std::string utf8 = convert.to_bytes(unicode);
|
||||
control_new_text(utf8);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
int key = TranslateSdlKey(e.key.keysym);
|
||||
if (key == -1)
|
||||
return FalseAvail(e.type == SDL_KEYDOWN ? "SDL_KEYDOWN" : "SDL_KEYUP", e.key.keysym.sym);
|
||||
|
|
@ -537,7 +552,7 @@ bool FetchMessage_Real(tagMSG *lpMsg)
|
|||
break;
|
||||
return FalseAvail("SDL_TEXTEDITING", e.edit.length);
|
||||
case SDL_TEXTINPUT:
|
||||
if (gbRunGame) {
|
||||
if (gbRunGame && IsTalkActive()) {
|
||||
control_new_text(e.text.text);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue