GetFloaterHandle example for Delphi

This example uses the GetFloaterHandle and SetRgnHandle methods to specify the mask for the paste. It also shows how to use the HasRgn, FloaterWidth, and FloaterHeight properties.

//Note that ZoomFactorX, ZoomFactorY must be declared as a global variables, and //have a correct data when you use this code.
var
   nRet: integer;
   sRet: Smallint;
   //Declare the variable for the Combine operation.
   MyOp :Longint;
   //Declare the variable for the saved region.
   SavedRgn :Longint;
   //Declare the variables for the client area coordinates.
   LCRgnX, LCRgnY, LCRgnWidth, LCRgnHeight: Single;
   //Declare the variables for the bitmap coordinates.
   LBRgnX, LBRgnY, LBRgnWidth, LBRgnHeight: Single;
   //Declare the RasterProcess object
   RasterProc: LEADRasterProcess;
begin
   RasterProc:= CreateComObject (CLASS_LEADRasterProcess ) as LEADRasterProcess;
   //Exit this routine if there is no region.
   if (LEADRasterView1.Raster.HasRgn = False) then
      Exit;
   //Save the region that is in the floater.
   SavedRgn := LEADRasterView1.GetFloaterHandle (nRet);
   //Get the floater into another bitmap
   LEADRasterView2.ScaleMode := LEADRasterView1.ScaleMode;
   LEADRasterView2.Raster.RefBitmap := False;
   LEADRasterView2.Raster.Bitmap := LEADRasterView1.Floater;
   //Get the floater//s client coordinates into local variables.
   LCRgnX := LEADRasterView1.FloaterDstLeft;
   LCRgnY := LEADRasterView1.FloaterDstTop;
   LCRgnWidth := LEADRasterView1.FloaterDstWidth;
   LCRgnHeight := LEADRasterView1.FloaterDstHeight;
   //Translate the client coordinates to bitmap coordinates.
   LBRgnX := ((LCRgnX - LEADRasterView1.DstLeft) / ZoomFactorX) + LEADRasterView1.SrcLeft;
   LBRgnY := ((LCRgnY - LEADRasterView1.DstTop) / ZoomFactorY) + LEADRasterView1.SrcTop;
   LBRgnWidth := LEADRasterView1.FloaterWidth;
   LBRgnHeight := LEADRasterView1.FloaterHeight;
   //Delete the floater.
   LEADRasterView1.FloaterVisible := False;
   LEADRasterView1.Floater:= 0;
   //Set the saved region to use as a mask for the Combine method.
   LEADRasterView1.Raster.SetRgnHandle (SavedRgn, LBRgnX, LBRgnY, L_RGN_SET);
   //Use the Combine method to paste the LEADRasterView2 bitmap into the LEADRasterView1 bitmap.
   MyOp := CB_OP_ADD + CB_DST_0; //Operation flags for a simple paste.
   RasterProc.Combine (LEADRasterView1.Raster,
                  LBRgnX, LBRgnY, LBRgnWidth, LBRgnHeight,
                  LEADRasterView2.Raster,
                  0, 0, MyOp);
   //Repaint the part of the client area that has changed.
   LEADRasterView1.RepaintRect (LCRgnX, LCRgnY, LCRgnWidth, LCRgnHeight, False, sRet);
   //Free the region.
   LEADRasterView1.Raster.FreeRgn ();
   //Delete the region handle.
   LEADRasterView1.Raster.DeleteRgnHandle (SavedRgn);
end;