hedgewars/uChat.pas
branchsdl2transition
changeset 11372 208bc571f949
parent 11365 b8b208501475
child 11476 c4e1d39acc56
equal deleted inserted replaced
11371:59db509c20c6 11372:208bc571f949
   795             end;
   795             end;
   796         end;
   796         end;
   797 end;
   797 end;
   798 
   798 
   799 procedure KeyPressChat(keysym: TSDL_Keysym);
   799 procedure KeyPressChat(keysym: TSDL_Keysym);
   800 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0);
   800 const nonStateMask = (not (KMOD_NUM or KMOD_CAPS));
   801       nonStateMask = (not (KMOD_NUM or KMOD_CAPS));
   801 var i, index: integer;
   802 var i, btw, index: integer;
   802     selMode, ctrl, ctrlonly: boolean;
   803     utf8: shortstring;
       
   804     action, selMode, ctrl, ctrlonly: boolean;
       
   805     skip: TCharSkip;
   803     skip: TCharSkip;
   806     Scancode: TSDL_Scancode;
   804     Scancode: TSDL_Scancode;
   807     Sym: TSDL_Keycode;
       
   808     Modifier: Word;
   805     Modifier: Word;
   809 begin
   806 begin
   810     Scancode:= keysym.scancode;
   807     Scancode:= keysym.scancode;
   811     Sym:= keysym.sym;
       
   812     Modifier:= keysym.modifier;
   808     Modifier:= keysym.modifier;
   813 
   809 
   814     LastKeyPressTick:= RealTicks;
   810     LastKeyPressTick:= RealTicks;
   815     action:= true;
       
   816 
   811 
   817     selMode:= (modifier and (KMOD_LSHIFT or KMOD_RSHIFT)) <> 0;
   812     selMode:= (modifier and (KMOD_LSHIFT or KMOD_RSHIFT)) <> 0;
   818     ctrl:= (modifier and (KMOD_LCTRL or KMOD_RCTRL)) <> 0;
   813     ctrl:= (modifier and (KMOD_LCTRL or KMOD_RCTRL)) <> 0;
   819     ctrlonly:= ctrl and ((modifier and nonStateMask and (not (KMOD_LCTRL or KMOD_RCTRL))) = 0);
   814     ctrlonly:= ctrl and ((modifier and nonStateMask and (not (KMOD_LCTRL or KMOD_RCTRL))) = 0);
   820     skip:= none;
   815     skip:= none;
   983                 cursorPos:= 0;
   978                 cursorPos:= 0;
   984                 HandleSelection(true);
   979                 HandleSelection(true);
   985                 cursorPos:= Length(InputStr.s);
   980                 cursorPos:= Length(InputStr.s);
   986                 UpdateCursorCoords();
   981                 UpdateCursorCoords();
   987                 end
   982                 end
   988             else
       
   989                 action:= false;
       
   990             end;
   983             end;
   991         SDL_SCANCODE_c:
   984         SDL_SCANCODE_c:
   992             begin
   985             begin
   993             // copy
   986             // copy
   994             if ctrlonly then
   987             if ctrlonly then
   995                 CopySelectionToClipboard()
   988                 CopySelectionToClipboard()
   996             else
       
   997                 action:= false;
       
   998             end;
   989             end;
   999         SDL_SCANCODE_v:
   990         SDL_SCANCODE_v:
  1000             begin
   991             begin
  1001             // paste
   992             // paste
  1002             if ctrlonly then
   993             if ctrlonly then
  1003                 begin
   994                 begin
  1004                 DeleteSelected();
   995                 DeleteSelected();
  1005                 PasteFromClipboard();
   996                 PasteFromClipboard();
  1006                 end
   997                 end
  1007             else
       
  1008                 action:= false;
       
  1009             end;
   998             end;
  1010         SDL_SCANCODE_x:
   999         SDL_SCANCODE_x:
  1011             begin
  1000             begin
  1012             // cut
  1001             // cut
  1013             if ctrlonly then
  1002             if ctrlonly then
  1014                 begin
  1003                 begin
  1015                 CopySelectionToClipboard();
  1004                 CopySelectionToClipboard();
  1016                 DeleteSelected();
  1005                 DeleteSelected();
  1017                 end
  1006                 end
  1018             else
  1007             end;
  1019                 action:= false;
  1008         end;
  1020             end;
       
  1021         else
       
  1022             action:= false;
       
  1023         end;
       
  1024     (*
       
  1025     if (not action) and (Sym <> SDLK_UNKNOWN) and ((Sym and SDLK_SCANCODE_MASK) = 0) then
       
  1026         begin
       
  1027         DeleteSelected();
       
  1028 
       
  1029         if (Sym < $80) then
       
  1030             btw:= 1
       
  1031         else if (Sym < $800) then
       
  1032             btw:= 2
       
  1033         else if (Sym < $10000) then
       
  1034             btw:= 3
       
  1035         else
       
  1036             btw:= 4;
       
  1037 
       
  1038         utf8:= '';
       
  1039 
       
  1040         for i:= btw downto 2 do
       
  1041             begin
       
  1042             utf8:= char((Sym or $80) and $BF) + utf8;
       
  1043             Sym:= Sym shr 6
       
  1044             end;
       
  1045 
       
  1046         utf8:= char(Sym or firstByteMark[Pred(btw)]) + utf8;
       
  1047 
       
  1048         if Length(InputStr.s) + btw > MaxInputStrLen then
       
  1049             exit;
       
  1050 
       
  1051         // if speech bubble quotes are used as first input, add the closing quote and place cursor inbetween
       
  1052         if (Length(InputStr.s) = 0) and (Length(utf8) = 1) and (charIsForHogSpeech(utf8[1])) then
       
  1053             begin
       
  1054             InsertIntoInputStr(utf8);
       
  1055             InsertIntoInputStr(utf8);
       
  1056             cursorPos:= 1;
       
  1057             UpdateCursorCoords();
       
  1058             end
       
  1059         else
       
  1060             InsertIntoInputStr(utf8);
       
  1061         end
       
  1062         *)
       
  1063 end;
  1009 end;
  1064 
  1010 
  1065 procedure TextInput(var event: TSDL_TextInputEvent);
  1011 procedure TextInput(var event: TSDL_TextInputEvent);
  1066 var s: shortstring;
  1012 var s: shortstring;
  1067     l: byte;
  1013     l: byte;