I worked out how to do it using copyrect.
Code:
// copy a canvas to a given location on another canvas with wrap-round
// canvas' must have equal dimensions
procedure DrawWrap(ACanvas1, ACanvas2 : TCanvas ; W, H, x, y : integer);
Var
V, U : integer;
SRect, DRect : TRect;
begin
V := W - x;
U := H - y;
// Copy rect A into position
SRect := Rect(0, 0, V, U);
DRect := Rect(x, y, W, H);
ACanvas2.CopyRect(DRect, ACanvas1, SRect);
// Copy rect B into position
SRect.Left := V; SRect.Right := W;
DRect.Left := 0; DRect.Right := x;
ACanvas2.CopyRect(DRect, ACanvas1, SRect);
// Copy rect C into position
SRect.Top := U; SRect.Bottom := H;
DRect.Top := 0; DRect.Bottom := y;
ACanvas2.CopyRect(DRect, ACanvas1, SRect);
// Copy rect D into position
SRect.Left := 0; SRect.Right := V;
DRect.Left := x; DRect.Right := W;
ACanvas2.CopyRect(DRect, ACanvas1, SRect);
end;
You can see how it turned out here
http://www.geocities.com/peter_bone_uk/engine3d
and look at the 'world' project
Bookmarks