Listing 9


//das Bsp. verwendet die Bitmap Card.bmp die Maske CardMask.bmp
//die Karte kann ruckfrei mit der Maus bewegt werden

unit MouseMoveBmp;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormPaint(Sender: TObject);
  private
    function Max(a, b: Integer): Integer;
    function Min(a, b: Integer): Integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Symbol, Mask, BackBmp: TBitmap;
  BmpPos: TPoint;
  xdiff, ydiff: Integer;
  mouse: Boolean;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
Symbol:=TBitmap.Create;
Symbol.LoadFromFile('Card.bmp'); //Ecken der Karte schwarz füllen
Hintergrund
Mask:=TBitmap.Create;
Mask.LoadFromFile('CardMask.bmp'); //schwarzes Kartenblatt, weiße Ecken
Hintergrund

BackBmp:=TBitmap.Create;
BackBmp.width:=Symbol.width;
BackBmp.height:=Symbol.height;

BmpPos.x:=0;
BmpPos.y:=0;
mouse:=False;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin

if (Button=mbLeft) and (x>=BmpPos.x) and (x<BmpPos.x+Symbol.width) and
(y>=BmpPos.y) and (y<BmpPos.y+Symbol.height) then
begin
mouse:=True; xdiff:=x-BmpPos.x; ydiff:=y-BmpPos.y;
end;

end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var CopyBmp: TBitmap;
      oldBmpPosx, oldBmpPosy: Integer;

begin

if mouse then
begin
CopyBmp:=TBitmap.Create;

oldBmpPosx:=BmpPos.x; oldBmpPosy:=BmpPos.y;
BmpPos.x:=x-xdiff; BmpPos.y:=y-ydiff;

CopyBmp.width:=(Max(oldBmpPosx, BmpPos.x)+Symbol.width)-Min(oldBmpPosx,
BmpPos.x);
CopyBmp.height:=(Max(oldBmpPosy,
BmpPos.y)+Symbol.height)-Min(oldBmpPosy, BmpPos.y);

BitBlt(CopyBmp.canvas.handle, 0, 0, CopyBmp.width, CopyBmp.height,
canvas.handle, Min(oldBmpPosx, BmpPos.x), Min(oldBmpPosy, BmpPos.y),
SRCCOPY);
BitBlt(CopyBmp.canvas.handle, oldBmpPosx-Min(oldBmpPosx, BmpPos.x),
oldBmpPosy-Min(oldBmpPosy, BmpPos.y), Symbol.width, Symbol.height,
BackBmp.canvas.handle, 0, 0, SRCCOPY);

BitBlt(BackBmp.canvas.handle, 0, 0, Symbol.width, Symbol.height,
CopyBmp.canvas.handle, BmpPos.x-Min(oldBmpPosx, BmpPos.x),
BmpPos.y-Min(oldBmpPosy, BmpPos.y), SRCCOPY);

BitBlt(CopyBmp.canvas.handle, BmpPos.x-Min(oldBmpPosx, BmpPos.x),
BmpPos.y-Min(oldBmpPosy, BmpPos.y), Symbol.width, Symbol.height,
Mask.canvas.handle, 0, 0, SRCAND);
BitBlt(CopyBmp.canvas.handle, BmpPos.x-Min(oldBmpPosx, BmpPos.x),
BmpPos.y-Min(oldBmpPosy, BmpPos.y), Symbol.width, Symbol.height,
Symbol.canvas.handle, 0, 0, SRCINVERT);

BitBlt(canvas.handle, Min(oldBmpPosx, BmpPos.x), Min(oldBmpPosy,
BmpPos.y), CopyBmp.width, CopyBmp.height, CopyBmp.canvas.handle, 0, 0,
SRCCOPY);

CopyBmp.Free;
end;

end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
mouse:=False;
end;

procedure TForm1.FormPaint(Sender: TObject);
var cv: Integer;

begin
for cv:=0 to 50 do
    canvas.textout(0, cv*canvas.TextHeight('Wg'),
'jhfiwreitrewiturielgijrjegrerehzrejiretiuettiutiurtiuuitruitrtiuzoieuztoezetozoizewizetzewtzewzteowiietiuezw');

BitBlt(BackBmp.canvas.handle, BmpPos.x, BmpPos.y, Symbol.width,
Symbol.height, canvas.handle, 0, 0, SRCCOPY);

BitBlt(canvas.handle, BmpPos.x, BmpPos.y, Symbol.width, Symbol.height,
Mask.canvas.handle, 0, 0, SRCAND);
BitBlt(canvas.handle, BmpPos.x, BmpPos.y, Symbol.width, Symbol.height,
Symbol.canvas.handle, 0, 0, SRCINVERT);
end;

//

function TForm1.Max(a, b: Integer): Integer;
begin
if a>=b then result:=a else result:=b;
end;

function TForm1.Min(a, b: Integer): Integer;
begin
if a<=b then result:=a else result:=b;
end;

end.

Zurück zur Hauptseite