# HG changeset patch # User unc0rr # Date 1170366131 0 # Node ID d9b88dbdf5a95b2d22763073ba1b66da8a6cb8a0 # Parent b5175878dc118eeada0bc2272c65c34020a95ffa Support unicode input for chat diff -r b5175878dc11 -r d9b88dbdf5a9 hedgewars/CCHandlers.inc --- a/hedgewars/CCHandlers.inc Sun Jan 28 21:03:58 2007 +0000 +++ b/hedgewars/CCHandlers.inc Thu Feb 01 21:42:11 2007 +0000 @@ -100,8 +100,7 @@ var c: LongInt; begin if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/color"', true); -//val(id, CurrentTeam^.Color, c); -CurrentTeam^.Color:= random($FFFFFF); +val(id, CurrentTeam^.Color, c); CurrentTeam^.AdjColor:= CurrentTeam^.Color; AdjustColor(CurrentTeam^.AdjColor) end; diff -r b5175878dc11 -r d9b88dbdf5a9 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Sun Jan 28 21:03:58 2007 +0000 +++ b/hedgewars/SDLh.pas Thu Feb 01 21:42:11 2007 +0000 @@ -194,6 +194,7 @@ function SDL_Init(flags: Longword): integer; cdecl; external SDLLibName; procedure SDL_Quit; cdecl; external SDLLibName; function SDL_VideoDriverName(var namebuf; maxlen: integer): PChar; cdecl; external SDLLibName; +procedure SDL_EnableUNICODE(enable: integer); cdecl; external SDLLibName; procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName; function SDL_GetTicks: Longword; cdecl; external SDLLibName; diff -r b5175878dc11 -r d9b88dbdf5a9 hedgewars/hwengine.dpr --- a/hedgewars/hwengine.dpr Sun Jan 28 21:03:58 2007 +0000 +++ b/hedgewars/hwengine.dpr Thu Feb 01 21:42:11 2007 +0000 @@ -140,7 +140,7 @@ cConsoleYAdd:= cConsoleHeight; GameState:= gsConsole end; - gsConsole: KeyPressConsole(event.key.keysym.sym); + gsConsole: KeyPressConsole(event.key.keysym.unicode); end; SDL_ACTIVEEVENT: if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then cHasFocus:= event.active.gain = 1; @@ -212,6 +212,7 @@ WriteToConsole('Init SDL... '); SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); WriteLnToConsole(msgOK); +SDL_EnableUNICODE(1); WriteToConsole('Init SDL_ttf... '); SDLTry(TTF_Init <> -1, true); diff -r b5175878dc11 -r d9b88dbdf5a9 hedgewars/uConsole.pas --- a/hedgewars/uConsole.pas Sun Jan 28 21:03:58 2007 +0000 +++ b/hedgewars/uConsole.pas Thu Feb 01 21:42:11 2007 +0000 @@ -234,8 +234,12 @@ end; procedure KeyPressConsole(Key: Longword); +const firstByteMark: array[1..4] of byte = (0, $C0, $E0, $F0); +var i, btw: integer; + utf8: shortstring; begin -case Key of +if Key <> 0 then + case Key of 8: if Length(InputStr)>0 then dec(InputStr[0]); 9: AutoComplete; 13,271: begin @@ -250,7 +254,19 @@ cConsoleYAdd:= 0; ResetKbd end; - else InputStr:= InputStr + char(Key) + else + if (Key < $80) then btw:= 1 + else if (Key < $800) then btw:= 2 + else if (Key < $10000) then btw:= 3 + else btw:= 4; + utf8:= ''; + for i:= btw downto 2 do + begin + utf8:= char((Key or $80) and $BF) + utf8; + Key:= Key shr 6 + end; + utf8:= char(Key or firstByteMark[btw]) + utf8; + InputStr:= InputStr + utf8 end end;