home *** CD-ROM | disk | FTP | other *** search
- unit Shapes;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs;
-
- type
- TSampleShapeType = (sstRectangle, sstSquare, sstRoundRect, sstRoundSquare,
- sstEllipse, sstCircle);
- TSampleShape = class(TGraphicControl)
- private
- { Private declarations }
- FShape: TSampleShapeType;
- FPen: TPen;
- FBrush: TBrush;
- procedure SetShape(Value: TSampleShapeType);
- procedure SetBrush(Value: TBrush);
- procedure SetPen(Value: TPen);
- protected
- { Protected declarations }
- procedure Paint; override;
- public
- { Public declarations }
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- { Published declarations }
- procedure StyleChanged(Sender: TObject);
- property Brush: TBrush read FBrush write SetBrush;
- property DragCursor;
- property DragMode;
- property Height default 65;
- property OnDragDrop;
- property OnDragOver;
- property OnEndDrag;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property Pen: TPen read FPen write SetPen;
- property Shape: TSampleShapeType read FShape write SetShape;
- property Width default 65;
- end;
-
- procedure Register;
-
- implementation
-
- procedure Register;
- begin
- RegisterComponents('Samples', [TSampleShape]);
- end;
-
- constructor TSampleShape.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Width := 65;
- Height := 65;
- FPen := TPen.Create;
- FPen.OnChange := StyleChanged;
- FBrush := TBrush.Create;
- FBrush.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;
-
- end.
-