From 6fc3ad181843ea8ee8c1be9060fda475b8d906b4 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 7 Oct 2019 01:03:09 +0300 Subject: [PATCH] improve text input --- src/game/sdl/g_system.pas | 7 ++----- src/shared/utils.pas | 6 ++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index 81b1ca3..25e95ec 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -263,11 +263,8 @@ implementation begin KeyPress(key) end; - if down and (ev.keysym.unicode <= $44F) then - begin - if IsPrintable1251(ch) then - CharPress(ch) - end + if down and IsValid1251(ev.keysym.unicode) and IsPrintable1251(ch) then + CharPress(ch) end; function sys_HandleInput (): Boolean; diff --git a/src/shared/utils.pas b/src/shared/utils.pas index 4c4db7b..20706c6 100644 --- a/src/shared/utils.pas +++ b/src/shared/utils.pas @@ -87,6 +87,7 @@ function int64ToStrComma (i: Int64): AnsiString; function upcase1251 (ch: AnsiChar): AnsiChar; inline; function locase1251 (ch: AnsiChar): AnsiChar; inline; +function IsValid1251 (ch: Word): Boolean; function IsPrintable1251 (ch: AnsiChar): Boolean; function toLowerCase1251 (const s: AnsiString): AnsiString; @@ -962,6 +963,11 @@ begin result := ch; end; +function IsValid1251 (ch: Word): Boolean; +begin + result := (ch = Ord('?')) or (wc2shitmap[ch] <> '?') +end; + function IsPrintable1251 (ch: AnsiChar): Boolean; begin result := (ch >= #32) and (ch <> #127) -- 2.29.2