Browse Source

SDL1 Unicode input support

pull/2933/head
Anders Jenbo 5 years ago
parent
commit
7959b04573
  1. 18
      Source/DiabloUI/diabloui.cpp
  2. 19
      Source/control.cpp
  3. 2
      Source/control.h
  4. 2
      Source/diablo.cpp
  5. 17
      Source/miniwin/misc_msg.cpp

18
Source/DiabloUI/diabloui.cpp

@ -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;

19
Source/control.cpp

@ -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);
}

2
Source/control.h

@ -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);

2
Source/diablo.cpp

@ -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') {

17
Source/miniwin/misc_msg.cpp

@ -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…
Cancel
Save