27 procedure freeModule; |
27 procedure freeModule; |
28 procedure ReloadLines; |
28 procedure ReloadLines; |
29 procedure CleanupInput; |
29 procedure CleanupInput; |
30 procedure AddChatString(s: shortstring); |
30 procedure AddChatString(s: shortstring); |
31 procedure DrawChat; |
31 procedure DrawChat; |
32 procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); |
32 procedure KeyPressChat(keysym: TSDL_Keysym); |
33 procedure SendHogSpeech(s: shortstring); |
33 procedure SendHogSpeech(s: shortstring); |
34 procedure CopyToClipboard(var newContent: shortstring); |
34 procedure CopyToClipboard(var newContent: shortstring); |
35 |
|
36 procedure TextInput(var event: TSDL_TextInputEvent); |
35 procedure TextInput(var event: TSDL_TextInputEvent); |
37 |
36 |
38 implementation |
37 implementation |
39 uses uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils; |
38 uses uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils; |
40 |
39 |
778 inc(cursorPos, Length(s)); |
778 inc(cursorPos, Length(s)); |
779 UpdateCursorCoords(); |
779 UpdateCursorCoords(); |
780 end; |
780 end; |
781 end; |
781 end; |
782 |
782 |
783 procedure TextInput(var event: TSDL_TextInputEvent); |
|
784 var s: shortstring; |
|
785 l: byte; |
|
786 begin |
|
787 DeleteSelected(); |
|
788 |
|
789 l:= 0; |
|
790 while event.text[l] <> #0 do |
|
791 begin |
|
792 s[l + 1]:= event.text[l]; |
|
793 inc(l) |
|
794 end; |
|
795 s[0]:= char(l); |
|
796 |
|
797 if byte(InputStr.s[0]) + l > 240 then exit; |
|
798 |
|
799 InsertIntoInputStr(s); |
|
800 end; |
|
801 |
|
802 procedure PasteFromClipboard(); |
783 procedure PasteFromClipboard(); |
803 var clip: PChar; |
784 var clip: PChar; |
804 begin |
785 begin |
805 // use SDL2 clipboard functions |
786 // use SDL2 clipboard functions |
806 if SDL_HasClipboardText() then |
787 if SDL_HasClipboardText() then |
813 SDL_free(Pointer(clip)); |
794 SDL_free(Pointer(clip)); |
814 end; |
795 end; |
815 end; |
796 end; |
816 end; |
797 end; |
817 |
798 |
818 procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); |
799 procedure KeyPressChat(keysym: TSDL_Keysym); |
819 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
800 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
820 nonStateMask = (not (KMOD_NUM or KMOD_CAPS)); |
801 nonStateMask = (not (KMOD_NUM or KMOD_CAPS)); |
821 var i, btw, index: integer; |
802 var i, btw, index: integer; |
822 utf8: shortstring; |
803 utf8: shortstring; |
823 action, selMode, ctrl, ctrlonly: boolean; |
804 action, selMode, ctrl, ctrlonly: boolean; |
824 skip: TCharSkip; |
805 skip: TCharSkip; |
825 begin |
806 Scancode: TSDL_Scancode; |
|
807 Sym: TSDL_Keycode; |
|
808 Modifier: Word; |
|
809 begin |
|
810 Scancode:= keysym.scancode; |
|
811 Sym:= keysym.sym; |
|
812 Modifier:= keysym.modifier; |
|
813 |
826 LastKeyPressTick:= RealTicks; |
814 LastKeyPressTick:= RealTicks; |
827 action:= true; |
815 action:= true; |
828 |
816 |
829 selMode:= (modifier and (KMOD_LSHIFT or KMOD_RSHIFT)) <> 0; |
817 selMode:= (modifier and (KMOD_LSHIFT or KMOD_RSHIFT)) <> 0; |
830 ctrl:= (modifier and (KMOD_LCTRL or KMOD_RCTRL)) <> 0; |
818 ctrl:= (modifier and (KMOD_LCTRL or KMOD_RCTRL)) <> 0; |
831 ctrlonly:= ctrl and ((modifier and nonStateMask and (not (KMOD_LCTRL or KMOD_RCTRL))) = 0); |
819 ctrlonly:= ctrl and ((modifier and nonStateMask and (not (KMOD_LCTRL or KMOD_RCTRL))) = 0); |
832 skip:= none; |
820 skip:= none; |
833 |
821 |
834 case Sym of |
822 case Scancode of |
835 SDLK_BACKSPACE: |
823 SDL_SCANCODE_BACKSPACE: |
836 begin |
824 begin |
837 if selectedPos < 0 then |
825 if selectedPos < 0 then |
838 begin |
826 begin |
839 HandleSelection(true); |
827 HandleSelection(true); |
840 |
828 |
864 end; |
852 end; |
865 |
853 |
866 DeleteSelected(); |
854 DeleteSelected(); |
867 UpdateCursorCoords(); |
855 UpdateCursorCoords(); |
868 end; |
856 end; |
869 SDLK_ESCAPE: |
857 SDL_SCANCODE_ESCAPE: |
870 begin |
858 begin |
871 if Length(InputStr.s) > 0 then |
859 if Length(InputStr.s) > 0 then |
872 begin |
860 begin |
873 SetLine(InputStr, '', true); |
861 SetLine(InputStr, '', true); |
874 ResetCursor(); |
862 ResetCursor(); |
875 end |
863 end |
876 else CleanupInput |
864 else CleanupInput |
877 end; |
865 end; |
878 SDLK_RETURN, SDLK_KP_ENTER: |
866 SDL_SCANCODE_RETURN, SDL_SCANCODE_KP_ENTER: |
879 begin |
867 begin |
880 if Length(InputStr.s) > 0 then |
868 if Length(InputStr.s) > 0 then |
881 begin |
869 begin |
882 AcceptChatString(InputStr.s); |
870 AcceptChatString(InputStr.s); |
883 SetLine(InputStr, '', false); |
871 SetLine(InputStr, '', false); |
884 ResetCursor(); |
872 ResetCursor(); |
885 end; |
873 end; |
886 CleanupInput |
874 CleanupInput |
887 end; |
875 end; |
888 SDLK_UP, SDLK_DOWN: |
876 SDL_SCANCODE_UP, SDL_SCANCODE_DOWN: |
889 begin |
877 begin |
890 if (Sym = SDLK_UP) and (history < localLastStr) then inc(history); |
878 if (Scancode = SDL_SCANCODE_UP) and (history < localLastStr) then inc(history); |
891 if (Sym = SDLK_DOWN) and (history > 0) then dec(history); |
879 if (Scancode = SDL_SCANCODE_DOWN) and (history > 0) then dec(history); |
892 index:= localLastStr - history + 1; |
880 index:= localLastStr - history + 1; |
893 if (index > localLastStr) then |
881 if (index > localLastStr) then |
894 begin |
882 begin |
895 SetLine(InputStr, '', true); |
883 SetLine(InputStr, '', true); |
896 end |
884 end |
1030 action:= false; |
1019 action:= false; |
1031 end; |
1020 end; |
1032 else |
1021 else |
1033 action:= false; |
1022 action:= false; |
1034 end; |
1023 end; |
1035 |
1024 (* |
1036 // TODO: ctrl+c etc. probably won't work anymore while in text input mode |
1025 if (not action) and (Sym <> SDLK_UNKNOWN) and ((Sym and SDLK_SCANCODE_MASK) = 0) then |
1037 end; |
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; |
|
1064 |
|
1065 procedure TextInput(var event: TSDL_TextInputEvent); |
|
1066 var s: shortstring; |
|
1067 l: byte; |
|
1068 begin |
|
1069 DeleteSelected(); |
|
1070 |
|
1071 l:= 0; |
|
1072 while event.text[l] <> #0 do |
|
1073 begin |
|
1074 s[l + 1]:= event.text[l]; |
|
1075 inc(l) |
|
1076 end; |
|
1077 |
|
1078 if l > 0 then |
|
1079 begin |
|
1080 if byte(InputStr.s[0]) + l > 240 then exit; |
|
1081 s[0]:= char(l); |
|
1082 InsertIntoInputStr(s); |
|
1083 end |
|
1084 end; |
|
1085 |
1038 |
1086 |
1039 procedure chChatMessage(var s: shortstring); |
1087 procedure chChatMessage(var s: shortstring); |
1040 begin |
1088 begin |
1041 AddChatString(s) |
1089 AddChatString(s) |
1042 end; |
1090 end; |
1079 |
1127 |
1080 procedure chChat(var s: shortstring); |
1128 procedure chChat(var s: shortstring); |
1081 begin |
1129 begin |
1082 s:= s; // avoid compiler hint |
1130 s:= s; // avoid compiler hint |
1083 GameState:= gsChat; |
1131 GameState:= gsChat; |
|
1132 SDL_StopTextInput(); |
1084 SDL_StartTextInput(); |
1133 SDL_StartTextInput(); |
|
1134 //SDL_EnableKeyRepeat(200,45); |
1085 if length(s) = 0 then |
1135 if length(s) = 0 then |
1086 SetLine(InputStr, '', true) |
1136 SetLine(InputStr, '', true) |
1087 else |
1137 else |
1088 begin |
1138 begin |
1089 SetLine(InputStr, '/team ', true); |
1139 SetLine(InputStr, '/team ', true); |