home *** CD-ROM | disk | FTP | other *** search
- unit sTranspControl;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, udcUtil;
-
- type
- TsTranspControl = class(TGraphicControl)
- private
- { Private declarations }
- FTransparency : integer;
- tb : TTransparentBitmap;
- FOptimize : boolean;
- procedure SetTransparency(const Value: integer);
- procedure SetOptimize(const Value: boolean);
- protected
- { Protected declarations }
- public
- { Public declarations }
- FStoredBmp : TBitmap;
- constructor Create(AOwner:TComponent); override;
- destructor Destroy; override;
- procedure Paint; override;
- published
- { Published declarations }
- property Transparency: integer read FTransparency write SetTransparency;
- property Optimize : boolean read FOptimize write SetOptimize;
- property Align;
- property Anchors;
- property AutoSize;
- property BiDiMode;
- property Caption;
- property Color;
- property Constraints;
- property DragCursor;
- property DragKind;
- property DragMode;
- property Enabled;
- property Font;
- property ParentBiDiMode;
- property ParentColor;
- property ParentFont;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property Visible;
- property OnClick;
- property OnContextPopup;
- property OnDblClick;
- property OnDragDrop;
- property OnDragOver;
- property OnEndDock;
- property OnEndDrag;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnStartDock;
- property OnStartDrag;
- end;
-
- implementation
-
- uses
- sPanel;
-
- { TsTranspControl }
-
- constructor TsTranspControl.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle + [csOpaque];
- tb := TTransparentBitmap.Create;
- FStoredBmp := TBitMap.Create;
- FOptimize := True;
- ParentFont := True;
- AutoSize := True;
- end;
-
- destructor TsTranspControl.Destroy;
- begin
- inherited;
- tb.Free;
- end;
-
- procedure TsTranspControl.Paint;
- var
- R: TRect;
- DC: HDC;
- P: TPoint;
- begin
- R := ClientRect;
- FStoredBmp.Height := R.Bottom - R.Top;
- FStoredBmp.Width := R.Right - R.Left;
- if FTransparency = 0 then begin
- FStoredBmp.Canvas.Brush.Color := Color;
- FStoredBmp.Canvas.FillRect(R);
- end
- else begin
- DC := GetWindowDC(Canvas.Handle);
- tb.NewBitmap;
- tb.Bitmap.Height := R.Bottom - R.Top;
- tb.Bitmap.Width := R.Right - R.Left;
- if (Parent is TsPanel) and Assigned(TsPanel(Parent).FStoredBmp) and Optimize then begin
- bitBlt(tb.Bitmap.Canvas.Handle, 0, 0, tb.Bitmap.Width, tb.Bitmap.Height, TsPanel(Parent).FStoredBmp.Canvas.Handle, Left, Top, SrcCopy);
- end
- else begin
- P.x := 0; P.y := 0;
- P := ClientToScreen(P);
- OffsetRect(R, P.x , P.y);
-
- tb.GetScreenBitmap(R);
- end;
- tb.ApplyTransparency(Rect(0, 0, R.Right - R.Left, R.Bottom - R.Top), Color, Transparency);
- BitBlt(FStoredBmp.Canvas.Handle, 0, 0, TB.TransBitmap.Width, TB.TransBitmap.Height, TB.TransBitmap.Canvas.Handle, 0, 0, SRCCOPY);
- ReleaseDC(Canvas.Handle, DC);
- end;
- Self.
- Canvas.CopyRect(ClientRect, FStoredBmp.Canvas, ClientRect);
- end;
-
- procedure TsTranspControl.SetOptimize(const Value: boolean);
- begin
- FOptimize := Value;
- Invalidate;
- end;
-
- procedure TsTranspControl.SetTransparency(const Value: integer);
- begin
- if FTransparency <> Value then begin
- if Value < 0 then FTransparency := 0
- else if Value > 100 then FTransparency := 100
- else FTransparency := Value;
- Invalidate;
- end;
- end;
-
- end.
-