34 |
34 |
35 implementation |
35 implementation |
36 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; |
37 |
37 |
38 const MaxStrIndex = 27; |
38 const MaxStrIndex = 27; |
|
39 MaxInputStrLen = 240; |
39 |
40 |
40 type TChatLine = record |
41 type TChatLine = record |
41 Tex: PTexture; |
42 Tex: PTexture; |
42 Time: Longword; |
43 Time: Longword; |
43 Width: LongInt; |
44 Width: LongInt; |
681 end; |
683 end; |
682 end; |
684 end; |
683 |
685 |
684 // TODO: honor utf8, don't break utf8 chars when shifting chars beyond limit |
686 // TODO: honor utf8, don't break utf8 chars when shifting chars beyond limit |
685 procedure InsertIntoInputStr(var s: shortstring); |
687 procedure InsertIntoInputStr(var s: shortstring); |
686 var i, l, lastc: integer; |
688 var i, l, il, lastc: integer; |
687 begin |
689 begin |
688 l:= Length(s); |
690 // safe length for string |
|
691 l:= min(MaxInputStrLen-cursorPos, Length(s)); |
689 |
692 |
690 // if we insert rather than append, shift info in InputStrL accordingly |
693 // if we insert rather than append, shift info in InputStrL accordingly |
691 if cursorPos < Length(InputStr.s) then |
694 if cursorPos < Length(InputStr.s) then |
692 begin |
695 begin |
693 for i:= Length(InputStr.s) downto cursorPos + 1 do |
696 for i:= Length(InputStr.s) downto cursorPos + 1 do |
694 begin |
697 begin |
695 if InputStrL[i] <> InputStrLNoPred then |
698 if InputStrL[i] <> InputStrLNoPred then |
696 begin |
699 begin |
697 InputStrL[i+l]:= InputStrL[i] + l; |
700 il:= i + l; |
|
701 // only shift if not overflowing |
|
702 if il <= MaxInputStrLen then |
|
703 InputStrL[il]:= InputStrL[i] + l; |
698 InputStrL[i]:= InputStrLNoPred; |
704 InputStrL[i]:= InputStrLNoPred; |
699 end; |
705 end; |
700 end; |
706 end; |
701 end; |
707 end; |
702 |
708 |
703 InputStrL[cursorPos + l]:= cursorPos; |
709 InputStrL[cursorPos + l]:= cursorPos; |
704 Insert(s, InputStr.s, cursorPos + 1); |
710 // insert string truncated to safe length |
|
711 Insert(copy(s,1,l), InputStr.s, cursorPos + 1); |
|
712 if Length(InputStr.s) > MaxInputStrLen then |
|
713 InputStr.s[0]:= char(MaxInputStrLen); |
|
714 |
705 SetLine(InputStr, InputStr.s, true); |
715 SetLine(InputStr, InputStr.s, true); |
706 |
716 |
707 // move cursor to end of inserted string |
717 // move cursor to end of inserted string |
708 lastc:= 255; |
718 lastc:= MaxInputStrLen; |
709 cursorPos:= min(lastc, cursorPos + l); |
719 cursorPos:= min(lastc, cursorPos + l); |
710 UpdateCursorCoords(); |
720 UpdateCursorCoords(); |
711 end; |
721 end; |
712 |
722 |
713 procedure PasteFromClipboard(); |
723 procedure PasteFromClipboard(); |
714 begin |
724 begin |
715 SendIPC(_S'P'); |
725 SendIPC(_S'Y'); |
716 end; |
726 end; |
717 |
727 |
718 procedure CheckPasteBuffer(); |
728 procedure CheckPasteBuffer(); |
719 begin |
729 begin |
720 if Length(ChatPasteBuffer) > 0 then |
730 if Length(ChatPasteBuffer) > 0 then |