home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 August
/
VPR9608A.BIN
/
del20try
/
install
/
data.z
/
SHAPES.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-05-08
|
3KB
|
129 lines
unit Shapes;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TSampleShapeType = (sstRectangle, sstSquare, sstRoundRect, sstRoundSquare,
sstEllipse, sstCircle);
TSampleShape = class(TGraphicControl)
private
FShape: TSampleShapeType;
FPen: TPen;
FBrush: TBrush;
procedure SetBrush(Value: TBrush);
procedure SetPen(Value: TPen);
procedure SetShape(Value: TSampleShapeType);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Brush: TBrush read FBrush write SetBrush;
property DragCursor;
property DragMode;
property Height default 65;
property Pen: TPen read FPen write SetPen;
property Shape: TSampleShapeType read FShape write SetShape;
property Width default 65;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
procedure StyleChanged(Sender: TObject);
end;
procedure Register;
implementation
constructor TSampleShape.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 65;
Height := 65;
FBrush := TBrush.Create;
FBrush.OnChange := StyleChanged;
FPen := TPen.Create;
FPen.OnChange := StyleChanged;
end;
destructor TSampleShape.Destroy;
begin
FPen.Free;
FBrush.Free;
inherited Destroy;
end;
procedure TSampleShape.Paint;
var
X, Y, W, H, S: Integer;
begin
with Canvas do
begin
Pen := FPen;
Brush := FBrush;
W := Width;
H := Height;
if W < H then S := W else S := H;
case FShape of
sstRectangle, sstRoundRect, sstEllipse:
begin
X := 0;
Y := 0;
end;
sstSquare, sstRoundSquare, sstCircle:
begin
X := (W - S) div 2;
Y := (H - S) div 2;
W := S;
H := S;
end;
end;
case FShape of
sstRectangle, sstSquare:
Rectangle(X, Y, X + W, Y + H);
sstRoundRect, sstRoundSquare:
RoundRect(X, Y, X + W, Y + H, S div 4, S div 4);
sstCircle, sstEllipse:
Ellipse(X, Y, X + W, Y + H);
end;
end;
end;
procedure TSampleShape.SetBrush(Value: TBrush);
begin
FBrush.Assign(Value);
end;
procedure TSampleShape.SetPen(Value: TPen);
begin
FPen.Assign(Value);
end;
procedure TSampleShape.SetShape(Value: TSampleShapeType);
begin
if FShape <> Value then
begin
FShape := Value;
Invalidate;
end;
end;
procedure TSampleShape.StyleChanged(Sender: TObject);
begin
Invalidate;
end;
procedure Register;
begin
RegisterComponents('Samples', [TSampleShape]);
end;
end.