Hi All!
I need to runtime modify cursor image. Drawing by cursor Canvas do not work correctly: any painting make image transparent.
On the FPC-forum helped me with this code:
procedure TToolFill.UpdateImage;
var
Cur : TCursorImage;
Bitmap : PBitmapInfo;
FillColor : TRGBQuad;
procedure Square(x, y, w : integer);
var
I, J : Integer;
begin
// квадратик
with FillColor do begin
rgbRed := Red(fColor);
rgbGreen := Green(fColor);
rgbBlue := Blue(fColor);
rgbReserved := $FF;
end;
for I := y to y+w do begin
for J := x to x+w do begin
Bitmap^.bmiColors[I * Cur.Width + J] := FillColor;
end;
end;
end;
begin
Cur := TCursorImage.Create;
Cur.LoadFromResourceID(HINSTANCE, CurId);
GetMem(Bitmap, SizeOf(TBitmapInfoHeader) + Cur.Width * Cur.Height * SizeOf(TColor));
with Bitmap^.bmiHeader do begin
biSize := SizeOf(TBitmapInfoHeader);
biWidth := Cur.Width;
biHeight := Cur.Height;
biPlanes := 1;
biBitCount := 32;
biCompression := BI_RGB;
biSizeImage := biWidth * biHeight * SizeOf(TColor);
end;
GetDIBits(Cur.Canvas.Handle, Cur.BitmapHandle, 0, Cur.Height, @(Bitmap^.bmiColors), Bitmap, DIB_RGB_COLORS);
Square(Cur.Width - 9, Cur.Height - 9, 8);
SetDIBits(Cur.Canvas.Handle, Cur.BitmapHandle, 0, Cur.Height, @(Bitmap^.bmiColors), Bitmap, DIB_RGB_COLORS);
FreeMem(Bitmap);
Screen.Cursors[CurId] := Cur.ReleaseHandle;
Cur.Free;
//
WorkScreen.PB.Cursor := CurId;
end;
But this code not flexible becouse drawind curves, ellipses and angled lines need more work.
My question to the connoisseurs is this: is there any way to do the same thing on the principle of drawing on canvas?
For example, instead of the above procedure
Square(..) use something like
SomeObj.Canvas.FillRect (...)?