28 procedure CleanupInput; |
28 procedure CleanupInput; |
29 procedure AddChatString(s: shortstring); |
29 procedure AddChatString(s: shortstring); |
30 procedure DrawChat; |
30 procedure DrawChat; |
31 procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); |
31 procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); |
32 procedure SendHogSpeech(s: shortstring); |
32 procedure SendHogSpeech(s: shortstring); |
|
33 procedure CopyToClipboard(var newContent: shortstring); |
33 |
34 |
34 implementation |
35 implementation |
35 uses SDLh, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils; |
36 uses SDLh, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uRenderUtils; |
36 |
37 |
37 const MaxStrIndex = 27; |
38 const MaxStrIndex = 27; |
563 begin |
564 begin |
564 DelBytesFromInputStrBack(max(cursorPos, selectedPos), abs(selectedPos-cursorPos)); |
565 DelBytesFromInputStrBack(max(cursorPos, selectedPos), abs(selectedPos-cursorPos)); |
565 cursorPos:= min(cursorPos, selectedPos); |
566 cursorPos:= min(cursorPos, selectedPos); |
566 ResetSelection(); |
567 ResetSelection(); |
567 end; |
568 end; |
|
569 UpdateCursorCoords(); |
568 end; |
570 end; |
569 |
571 |
570 procedure HandleSelection(enabled: boolean); |
572 procedure HandleSelection(enabled: boolean); |
571 begin |
573 begin |
572 if enabled then |
574 if enabled then |
656 cursorPos:= InputStrL[cursorPos]; |
658 cursorPos:= InputStrL[cursorPos]; |
657 break; |
659 break; |
658 end; |
660 end; |
659 end; |
661 end; |
660 end; |
662 end; |
|
663 end; |
|
664 |
|
665 var clipboardBuffer: shortstring; |
|
666 |
|
667 procedure CopyToClipboard(var newContent: shortstring); |
|
668 begin |
|
669 clipboardBuffer:= newContent; |
|
670 end; |
|
671 |
|
672 procedure CopySelectionToClipboard(); |
|
673 var selection: shortstring; |
|
674 begin |
|
675 if selectedPos >= 0 then |
|
676 begin |
|
677 selection:= copy(InputStr.s, min(CursorPos, selectedPos) + 1, abs(CursorPos - selectedPos)); |
|
678 CopyToClipboard(selection); |
|
679 end; |
|
680 end; |
|
681 |
|
682 // TODO: honor utf8, don't break utf8 chars when shifting chars beyond limit |
|
683 procedure InsertIntoInputStr(var s: shortstring); |
|
684 var i, l, lastc: integer; |
|
685 begin |
|
686 l:= Length(s); |
|
687 |
|
688 // if we insert rather than append, shift info in InputStrL accordingly |
|
689 if cursorPos < Length(InputStr.s) then |
|
690 begin |
|
691 for i:= Length(InputStr.s) downto cursorPos + 1 do |
|
692 begin |
|
693 if InputStrL[i] <> InputStrLNoPred then |
|
694 begin |
|
695 InputStrL[i+l]:= InputStrL[i] + l; |
|
696 InputStrL[i]:= InputStrLNoPred; |
|
697 end; |
|
698 end; |
|
699 end; |
|
700 |
|
701 InputStrL[cursorPos + l]:= cursorPos; |
|
702 Insert(s, InputStr.s, cursorPos + 1); |
|
703 SetLine(InputStr, InputStr.s, true); |
|
704 |
|
705 // move cursor to end of inserted string |
|
706 lastc:= 255; |
|
707 cursorPos:= min(lastc, cursorPos + l); |
|
708 UpdateCursorCoords(); |
|
709 end; |
|
710 |
|
711 procedure PasteFromClipboard(); |
|
712 begin |
|
713 DeleteSelected(); |
|
714 InsertIntoInputStr(clipboardBuffer); |
661 end; |
715 end; |
662 |
716 |
663 procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); |
717 procedure KeyPressChat(Key, Sym: Longword; Modifier: Word); |
664 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
718 const firstByteMark: array[0..3] of byte = (0, $C0, $E0, $F0); |
665 var i, btw, index: integer; |
719 var i, btw, index: integer; |
689 if ctrl and (selectedPos < 0) then |
743 if ctrl and (selectedPos < 0) then |
690 begin |
744 begin |
691 HandleSelection(true); |
745 HandleSelection(true); |
692 SkipInputChars(skip, true); |
746 SkipInputChars(skip, true); |
693 DeleteSelected(); |
747 DeleteSelected(); |
694 end; |
748 end |
|
749 else |
|
750 UpdateCursorCoords(); |
|
751 |
695 end |
752 end |
696 else |
753 else |
697 DeleteSelected(); |
754 DeleteSelected(); |
698 UpdateCursorCoords(); |
|
699 end; |
755 end; |
700 SDLK_DELETE: |
756 SDLK_DELETE: |
701 begin |
757 begin |
702 if selectedPos < 0 then |
758 if selectedPos < 0 then |
703 begin |
759 begin |
889 utf8:= char(Key or firstByteMark[Pred(btw)]) + utf8; |
972 utf8:= char(Key or firstByteMark[Pred(btw)]) + utf8; |
890 |
973 |
891 if Length(InputStr.s) + btw > 240 then |
974 if Length(InputStr.s) + btw > 240 then |
892 exit; |
975 exit; |
893 |
976 |
894 // if we insert rather than append, shift info in InputStrL accordingly |
977 InsertIntoInputStr(utf8); |
895 if cursorPos < Length(InputStr.s) then |
|
896 begin |
|
897 for i:= Length(InputStr.s) downto cursorPos + 1 do |
|
898 begin |
|
899 if InputStrL[i] <> InputStrLNoPred then |
|
900 begin |
|
901 InputStrL[i+btw]:= InputStrL[i] + btw; |
|
902 InputStrL[i]:= InputStrLNoPred; |
|
903 end; |
|
904 end; |
|
905 end; |
|
906 |
|
907 InputStrL[cursorPos + btw]:= cursorPos; |
|
908 Insert(utf8, InputStr.s, cursorPos + 1); |
|
909 SetLine(InputStr, InputStr.s, true); |
|
910 |
|
911 cursorPos:= cursorPos + btw; |
|
912 UpdateCursorCoords(); |
|
913 end |
978 end |
914 end; |
979 end; |
915 |
980 |
916 procedure chChatMessage(var s: shortstring); |
981 procedure chChatMessage(var s: shortstring); |
917 begin |
982 begin |