This patch fixes the flickering:
var
MainForm: TMainForm;
CursorBmp : TBGRABitmap;
GridBmp : TBGRABitmap;
SchBmp : TBGRABitmap;
CursorX, CursorY : Integer;
Vxmin, Vxmax : Integer;
Vymin, Vymax : Integer;
Wxmin, Wxmax : Integer;
Wymin, Wymax : Integer;
SchIsDirty : Boolean = True;
CursorFollowMouse : Boolean = True;
Surface:TBGRABitmap; // <<<<<<<<< NEW
implementation
procedure DrawCursor;//Expect the variable to already be created
begin
Surface.PutImage(CursorX-48,CursorY-48,CursorBmp,dmLinearBlend);
end;
procedure DrawGrid;
begin
Surface.PutImage(0,0,GridBmp,dmLinearBlend);
end;
procedure DrawScene;
begin
//Clear the Screen
Surface.Fill(BGRAWhite);
//Draw the Cursor
DrawCursor();
//Draw the Grid
DrawGrid();
//Draw the Schematic
//DrawSchematic();
Surface.Draw(MainForm.Canvas,0,0,true);
end;
procedure TMainForm.FormResize(Sender:TObject);
begin
Surface.SetSize(Width,Height);
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
//Create Cursor
Self.DoubleBuffered := True;
CreateCursor;
CursorX := 150;
CursorY := 150;
CreateGrid;
Surface:= TBGRABitmap.Create(Width,Height);
end;
This fixes your mouse:
procedure TMainForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var CursorXPrev : Integer;
CursorYPrev : Integer;
NearestX,NearestY:integer;
begin
CursorXPrev := CursorX;
CursorYPrev := CursorY;
Label1.Caption := 'Viewport Coordinates:'+IntToStr(X)+','+IntToStr(Y);
if (X mod 16) < 8 then NearestX:= X - (X mod 16) else NearestX:= X + 16 - (X mod 16);
if (Y mod 16) < 8 then NearestY:= Y - (Y mod 16) else NearestY:= Y + 16 - (Y mod 16);
if (NearestX <> CursorX) or (NearestY <> CursorY) then begin
CursorX := NearestX;
CursorY := NearestY;
WriteLn('New CursorY:'+IntToStr(CursorY));
WriteLn('New CursorX:'+IntToStr(CursorX));
end;
If ((CursorXPrev <> CursorX) or (CursorYPrev <> CursorY)) then
begin
DrawScene();
WriteLn();
end;
end;