📄 buf2d.inc
字号:
inc(p);
end;
inc(y0,iy); inc(p,ry);
until false;
end; {TBuf2d.line}
Procedure TBuf2d.turnRight;
var
_l,_r,_d:pointer;
i,_w,_h:dword;
begin
if empty then exit;
getmem(_d,contentSize);
_r:=_d;
_w:=w; _h:=h;
for i:=0 to pred(w) do begin
_l:=at(i,pred(h));
asm
mov esi,_l
mov edi,_r
mov ecx,_h
@1:
mov al,[edi]
mov ah,[esi]
mov [esi],al
mov [edi],ah
inc edi
sub esi,_w
dec ecx
jnz @1
end;
inc(_r,h);
end;
freemem(d,contentSize);
d:=_d;
w:=_h; h:=_w;
end; {TBuf2d.turnRight}
Procedure TBuf2d.flipH;
var i,j:longint;
begin
if empty then exit;
for j:=pred(h) downto 0 do
for i:=pred(w shr 1) downto 0 do
xchg(byte(at(i,j)^),byte(at(w-1-i,j)^),1);
end; {TBuf2d.flipH}
Procedure TBuf2d.flipV;
var i,j:longint;
begin
if empty then exit;
for j:=pred(h shr 1) downto 0 do
xchg(byte(atline(j)^),byte(atline(h-1-j)^),w);
end; {TBuf2d.flipV}
Procedure TBuf2d.pasteInMe(_x,_y:TCoordinate;host:PBuf2d);
var
c:TRect;
_d,_s:pointer;
begin
if (host=nil) then exit;
if empty or host^.empty or (_x>=w) or (_y>=h) or (_x+host^.w<=0) or (_y+host^.h<=0) or (host^.method=mtNone) or (host^.method=0) then exit;
c.init(0,0,host^.w,host^.h);
{$IFDEF clip}
if clipping then c.intersect(clip);
{$ENDIF}
if _x<0 then begin inc(c.w,_x); c.x:=-_x; _x:=0; end;
if _y<0 then begin inc(c.h,_y); c.y:=-_y; _y:=0; end;
if c.empty then exit;
if _x+c.w>w then c.w:=w-_x;
if _y+c.h>h then c.h:=h-_y;
_s:=host^.at(c.x,c.y);
_d:=at(_x,_y);
while c.h>0 do begin
pasteLine(_s,_d,c.w,host^.method);
inc(_s,host^.w);
inc(_d,w);
dec(c.h);
end;
end; {TBuf2d.pasteInMe}
Procedure TBuf2d.pasteMeTo(dest:PBuf2d;_x,_y:TCoordinate);
var
c:TRect;
_d,_s:pointer;
begin
if (dest=nil) or (method=mtNone) or (method=0) then exit;
if empty or dest^.empty or (_x+w<=0) or (_y+h<=0) or (_x>=dest^.w) or (_y>=dest^.h) then exit;
c.init(0,0,w,h);
{$IFDEF clip}
if clipping then c.intersect(clip);
{$ENDIF}
if _x<0 then begin inc(c.w,_x); c.x:=-_x; _x:=0; end;
if _y<0 then begin inc(c.h,_y); c.y:=-_y; _y:=0; end;
if _x+w>dest^.w then c.w:=dest^.w-_x;
if _y+h>dest^.h then c.h:=dest^.h-_y;
_s:=at(c.x,c.y);
_d:=dest^.at(_x,_y);
while c.h>0 do begin
pasteLine(_s,_d,c.w,method);
inc(_s,w);
inc(_d,dest^.w);
dec(c.h);
end;
end; {TBuf2d.pasteMeTo}
Procedure TBuf2d.paste;
begin
RunError(errAbstractMethod);
end; {TBuf2d.paste}
Procedure TBuf2d.cycleH(rel:longint);
const CYCLEMAXWIDTH=1024;
var
j,w_rel:longint;
backup:array[0..CYCLEMAXWIDTH-1] of byte;
begin
if (w<=1) or empty then exit;
if abs(rel)>=w then rel:=rel mod w;
if rel>0 then rel:=w-rel else rel:=-rel;
if rel>=CYCLEMAXWIDTH then die(errCycleH);
if rel=0 then exit;
w_rel:=w-rel;
for j:=pred(h) downto 0 do begin
move(atline(j)^,backup,rel);
move(at(rel,j)^,atline(j)^,w_rel);
move(backup,at(w_rel,j)^,rel);
end;
end; {TBuf2d.cycleH}
Procedure TBuf2d.cycleV(rel:longint);
var backup:pointer;
begin
if (h<=1) or empty then exit;
if abs(rel)>=h then rel:=rel mod h;
if rel>0 then rel:=h-rel else rel:=-rel;
if rel=0 then exit;
getmem(backup,rel*w);
move(d^,backup^,rel*w);
move(atline(rel)^,d^,(h-rel)*w);
move(backup^,atline(h-rel)^,rel*w);
freemem(backup,rel*w);
end; {TBuf2d.cycleV}
Procedure TBuf2d.shiftH(rel:longint);
var j:longint;
begin
if empty or (rel=0) then exit;
if abs(rel)>=w then paint(0)
else if rel<0 then begin
rel:=-rel;
for j:=pred(h) downto 0 do begin
move(at(rel,j)^,atline(j)^,w-rel);
fillchar(at(w-rel,j)^,rel,0);
end;
end else
for j:=pred(h) downto 0 do begin
move(atline(j)^,at(rel,j)^,w-rel);
fillchar(atline(j)^,rel,0);
end;
end; {TBuf2d.shiftH}
Procedure TBuf2d.shiftV(rel:longint);
begin
if empty or (rel=0) then exit;
if abs(rel)>=w then paint(0)
else if rel<0 then begin
rel:=-rel;
move(atline(rel)^,d^,(h-rel)*w);
fillchar(atline(h-rel)^,rel*w,0);
end else begin
rotmove(d^,atline(rel)^,(h-rel)*w);
fillchar(d^,rel*w,0);
end;
end; {TBuf2d.shiftV}
Procedure TBuf2d.replace(old,new:byte;swap:boolean);
var i,j:integer;
begin
if empty then exit;
for j:=h-1 downto 0 do
for i:=w-1 downto 0 do
if getpoint(i,j)=old then
setpoint(i,j,new)
else if swap and (getpoint(i,j)=new) then
setpoint(i,j,old);
end; {TBuf2d.replace}
Procedure TBuf2d.neg(n:byte);
var i,j:integer;
begin
if empty then exit;
for j:=0 to h-1 do
for i:=0 to w-1 do
setpoint(i,j,n-getpoint(i,j));
end; {TBuf2d.neg}
Procedure TBuf2d.zoom2x; {does not work for the last odd line and row}
var
j,_w:longint;
_s,_d:pointer;
begin
if empty then exit;
_w:=w div 2;
for j:=pred(h div 2) downto 0 do begin
_s:=d; inc(_s,j*w+w div 2);
_d:=d; inc(_d,2*j*w+w-w and 1);
asm
mov esi,_s
mov edi,_d
mov ecx,_w
@1:
dec esi
mov eax,[esi]
mov ah,al
dec edi
dec edi
mov [edi],ax
dec ecx
jnz @1
end;
pasteLine(atline(j*2),atline(j*2+1),w,mtMovsd);
end;
end; {TBuf2d.zoom2x}
Procedure TBuf2d.flood2(_x,_y:TCoordinate; c1:byte);
const
RUNNING_UP =$80;
RUNNING_LEFT =$40;
SEARCH_UP =1;
SEARCH_DOWN =2;
var
i,j:TCoordinate;
c0,flags:byte;
procedure floodPush(x_,y_:TCoordinate);
begin
if floodfillSP<FLOODFILLSTACKSIZE then begin
floodfillstack[floodfillSP].x:=x_;
floodfillstack[floodfillSP].y:=y_;
inc(floodfillSP);
end;
end; {floodPush}
begin {TBuf2d.flood2}
if not contains(_x,_y) then exit;
c0:=getPoint(_x,_y); if c0=c1 then exit;
j:=_y; flags:=0;
repeat
if (getPoint(_x,j)<>c0) or (j<0) or (j>=h) then begin
if flags and RUNNING_UP=0 then begin
j:=pred(_y);
flags:=flags or RUNNING_UP;
end else break;
end;
if (getPoint(_x,j)<>c0) and (flags and RUNNING_UP<>0) then break;
flags:=flags and not($43);
i:=_x;
repeat
if (getPoint(i,j)<>c0) or (i<0) or (i>=w) then begin
if flags and RUNNING_LEFT=0 then begin
i:=pred(_x);
flags:=flags or RUNNING_LEFT;
end else break;
end;
if (getPoint(i,j)<>c0) and (flags and RUNNING_LEFT<>0) then break;
setPoint(i,j,c1);
if getPoint(i,j-1)<>c0 then
flags:=flags or SEARCH_UP
else if flags and SEARCH_UP<>0 then begin
floodPush(i,j-1);
flags:=flags and not(SEARCH_UP);
end;
if getPoint(i,j+1)<>c0 then
flags:=flags or SEARCH_DOWN
else if flags and SEARCH_DOWN<>0 then begin
floodPush(i,j+1);
flags:=flags and not(SEARCH_DOWN);
end;
if flags and RUNNING_LEFT=0 then inc(i) else dec(i);
until false;
if flags and RUNNING_UP=0 then inc(j) else dec(j);
until j<0;
end; {TBuf2d.flood2}
procedure TBuf2d.flood(_x,_y:TCoordinate; c1:byte);
begin
floodfillSP:=0;
flood2(_x,_y,c1);
while floodfillSP>0 do begin
dec(floodfillSP);
flood2(floodfillstack[floodfillSP].x,floodfillstack[floodfillSP].y,c1);
end;
end;
Procedure TBuf2d.flashline;
begin
RunError(errAbstractMethod);
end; {TBuf2d.flashline}
{$IFDEF fw}
procedure TBuf2d.fw(_x,_y:TCoordinate;s:string;color,f:byte);
var i,j,k:longint;
begin
if f and $80<>0 then quad(_x,_y,length(s) shl either(f=0,3,2),7,0);
f:=f and 1;
for k:=1 to length(s) do
for j:=0 to 7 do
for i:=0 to either(f=0,7,3) do
if font8[f][ord(s[k]) shl 3+j] and ($80 shr i)<>0 then setpoint(_x+pred(k) shl (2+byte(f=0))+i,_y+j,color);
end; {TBuf2d.fw}
{$ENDIF}
Destructor TBuf2d.done;
begin
free;
end; {TBuf2d.done}
{note: TBuf2d has virtual methods and thus must be instantiated properly}
{$ENDIF}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -