hedgewars/uChat.pas
changeset 11697 446ce60700dd
parent 11696 fa4bc078e509
child 11776 f2031643fe98
equal deleted inserted replaced
11696:fa4bc078e509 11697:446ce60700dd
  1009 end;
  1009 end;
  1010 
  1010 
  1011 procedure TextInput(var event: TSDL_TextInputEvent);
  1011 procedure TextInput(var event: TSDL_TextInputEvent);
  1012 var s: shortstring;
  1012 var s: shortstring;
  1013     l: byte;
  1013     l: byte;
       
  1014     isl: integer;
  1014 begin
  1015 begin
  1015     DeleteSelected();
  1016     DeleteSelected();
  1016 
  1017 
  1017     l:= 0;
  1018     l:= 0;
       
  1019     // fetch all bytes of character/input
  1018     while event.text[l] <> #0 do
  1020     while event.text[l] <> #0 do
  1019         begin
  1021         begin
  1020         s[l + 1]:= event.text[l];
  1022         s[l + 1]:= event.text[l];
  1021         inc(l)
  1023         inc(l)
  1022         end;
  1024         end;
  1023 
  1025 
  1024     if l > 0 then
  1026     if l > 0 then
  1025         begin
  1027         begin
  1026         if byte(InputStr.s[0]) + l > 240 then exit;
  1028         isl:= Length(InputStr.s);
  1027         s[0]:= char(l);
  1029         // check if user is typing a redundant closing hog-speech quotation mark
  1028         InsertIntoInputStr(s);
  1030         if (l = 1) and (isl >= 2) and (cursorPos = isl - 1) and charIsForHogSpeech(s[1])
  1029 
  1031           and (s[1] = InputStr.s[1]) and (s[1] = InputStr.s[isl]) then
  1030         // add closing hog speech quotation marks automatically
  1032             begin
  1031         if (l = 1) and (Length(InputStr.s) = 1) and charIsForHogSpeech(s[1]) then
  1033             MoveCursorToNextChar();
  1032             begin
  1034             UpdateCursorCoords();
       
  1035             end
       
  1036         else
       
  1037             begin
       
  1038             // don't add input that doesn't fit
       
  1039             if isl + l > MaxInputStrLen then exit;
       
  1040             s[0]:= char(l);
  1033             InsertIntoInputStr(s);
  1041             InsertIntoInputStr(s);
  1034             MoveCursorToPreviousChar();
  1042 
  1035             UpdateCursorCoords();
  1043             // add closing hog speech quotation marks automagically
       
  1044             if (l = 1) and (Length(InputStr.s) = 1) and charIsForHogSpeech(s[1]) then
       
  1045                 begin
       
  1046                 InsertIntoInputStr(s);
       
  1047                 MoveCursorToPreviousChar();
       
  1048                 UpdateCursorCoords();
       
  1049                 end;
  1036             end;
  1050             end;
  1037 
  1051 
  1038         end
  1052         end
  1039 end;
  1053 end;
  1040 
  1054