📄 gfxedit.inc
字号:
{$IFNDEF gfxedit}
{$DEFINE gfxedit}
{$I PALS.INC}
{$I CONSOLE.INC}
{$I EVENTS.INC}
type
TGFXEdit=object(TConsole)
private
ofsx:longint;
public
flags:dword;
text,lasttext:string;
bgcolor,blcolor:byte;
Constructor init(_x,_y:longint; _w,_h:dword; _font:PBMFont; _fontmethod:dword);
procedure drawcursor(_x,_w:integer);
procedure drawblock(_x,_w:integer);
function input(_text:string; cur,maxlength:integer):string;
end; {TGFXEdit}
{$IFDEF settings}
const
romasciinoshift:array[0..12] of char=(#27,'`','1','2','3','4','5','6','7','8','9','0','-');
romasciishift:array[0..12] of char=(#27,'~','!','@','#','$','%','^','&','*','(',')','_');
{$ENDIF}
Constructor TGFXEdit.init(_x,_y:longint; _w,_h:dword; _font:PBMFont; _fontmethod:dword);
begin
inherited init(_x,_y,_w,_h,_font,_fontmethod,0,1);
font:=_font;
flags:=0;
bgcolor:=0;
blcolor:=0;
ofsx:=0;
text:='';
lasttext:='';
end; {TGFXEdit.init}
procedure TGFXEdit.drawcursor(_x,_w:integer);
var
i,j:integer;
c:byte;
begin
if font=nil then exit;
for i:=_x to _x+_w-1 do
for j:=0 to font^.lineheight-1 do begin
c:=getpoint(i,j)*3;
setpoint(i,j,nearestcolor(63-pal[c],63-pal[c+1],63-pal[c+2],ofs(pal)));
end;
end; {TGFXEdit.drawcursor}
procedure TGFXEdit.drawblock(_x,_w:integer);
var
i,j:integer;
c:byte;
begin
if font=nil then exit;
quad(_x,0,_w,font^.lineheight,blcolor);
end; {TGFXEdit.drawblock}
Function TGFXEdit.input(_text:string; cur,maxlength:integer):string;
var
e:TEvent;
finish:boolean;
i,j:longint;
begin
text:=_text; result:=text; finish:=false;
if (font=nil) or (maxlength<=0) then exit;
if maxlength>255 then maxlength:=255;
font^.setup(@self,fontmethod,delay);
ofsx:=0;
repeat
if cur<1 then cur:=1 else if cur>length(text)+1 then cur:=length(text)+1;
paint(bgcolor);
j:=font^.textwidth(system.copy(text,1,cur-1),true);
i:=font^.textwidth(system.copy(text,cur,1),true); if i<1 then i:=2;
if j+i>w then ofsx:=w-i-j; if ofsx+j<0 then ofsx:=-j;
font^.writexy(ofsx,0,text);
if mem[ROM_KEYFLAGS] and kfINSERT=0 then i:=1;
drawcursor(j+ofsx,i);
pasteMeTo(@screen,x,y);
if finish then break;
repeat until GetEvent(e) and (e.typ=evKEYBOARD);
case e.key of
#5: text:=lasttext; {CTRL-E}
#8: if (cur>1) and (text<>'') then begin
dec(cur);
delete(text,cur,1);
end;
#9: finish:=true;
#13: begin
result:=text;
finish:=true;
end;
#25: text:=''; {CTRL-Y}
#27: begin
text:='';
finish:=true;
end;
#0: case e.keyext of
';': begin
e.typ:=evMESSAGE;
e.msgcode:=msgHelp;
end;
'K': if cur>1 then dec(cur);
'M': inc(cur);
'S': delete(text,cur,1);
'G': cur:=1;
'O': cur:=length(text)+1;
end;
else begin
{$IFDEF settings}
if settings.y2z then if e.key in ['Y','Z','y','z'] then e.key:=char(ord(e.key) xor 3);
if settings.romascii then if (e.keyscan in [2..11]) then e.key:=char(either(e.keyflags and kfANYSHIFT=0,ord(romasciinoshift[e.keyscan]),ord(romasciishift[e.keyscan])));
{$ENDIF}
if mem[ROM_KEYFLAGS] and kfINSERT=0 then
if length(text)<maxlength then begin
insert(e.key,text,cur);
inc(cur);
end else
else
if cur<maxlength+1 then begin
if cur=length(text)+1 then text:=text+e.key else text[cur]:=e.key;
inc(cur);
end;
end;
end;
until false;
result:=text;
lasttext:=result;
end; {TGFXEdit.input}
{$ENDIF}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -