以下是我做的一个256色调色板抖动动画的控件,你拉回去看看吧,或许能给你带来灵感,改动一下可以实现
多种颜色的渐进抖动动画,跟98启动时底下的蓝白色滚动条一样。
{
256色调色板抖动动画 BY zhuancha
email:zhuancha@inhe.net
date :2001-04-20
}
unit CoolTitleBar;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ExtCtrls;
type
TCoolTitleBar = class;
TRegionType = class(TPersistent)
public
FRegion:hRgn;
Owner:TCoolTitleBar;
end;
TCoolTitleBar = class(TPanel)
private
Fregion : TRegionType;
FOrgRgn : PRgnData;
FOrgSize : Integer;
Dummy:TRegionType;
FDraggable:boolean;
CycleTimer: TTimer;
FCycleInterval: Cardinal;
FBackMove:Boolean;
{---------------------------调色板变量定义--------------------------------}
LogicalPalette:tagLogPalette;
pNum:Integer;
iRed,iGreen,iBlue:Integer;
pe:tagPALETTEENTRY;
hEntryNum:Integer;
FPALENTRIES:Integer;
hNum:Integer;
pbAnm:TPaintBox;
{-------------------------------------------------------------------------}
procedure SetBackMove(Value: Boolean);
procedure TimerCycle(Sender: TObject);
procedure SetCycleInterval(Value: Cardinal);
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
//procedure AnimateDemoPalette;//建立动画调色板
procedure MakeSpectrumSegments;//在指定区域内画方格
procedure SegmentColor(Entry:integer);//对所划的方格根据建立的调色板进行着色
protected
procedure pbAnmMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);override;
procedure SetRegion(Value:TRegionType);
procedure SetParent(Value:TWinControl); override;
procedure SetTop(Value:integer); virtual;
procedure SetLeft(Value:integer); virtual;
procedure Setwidth(Value:integer); virtual;
procedure SetHeight(Value:integer); virtual;
function GetRegion:TRegionType;
procedure size;
public
constructor Create(Aowner:TComponent); override;
destructor Destroy; override;
procedure RefreshRegion;
published
property Draggable:boolean read FDraggable write FDraggable default true;
property CycleInterval: Cardinal read FCycleInterval write SetCycleInterval;
property PALENTRIES:Integer read FPALENTRIES write FPALENTRIES default 80;
property BackMove:Boolean read FBackMove write SetBackMove;
property Top write settop;
property Left write setleft;
property Width write setwidth;
property Height write setheight;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Custom', [TCoolTitleBar]);
end;
{----------------------------------建立控件------------------------------------}
constructor TCoolTitleBar.Create(Aowner:TComponent);
begin
inherited; //Create(Aowner);
hNum:=1;
FPALENTRIES:=80;
FCycleInterval:=100;
Align := alTop;
Alignment:=taLeftJustify;
BevelInner:=bvLowered;
BevelOuter :=bvRaised;
BorderWidth :=2;
Fregion := TRegionType.Create;
Dummy := TRegionType.Create;
Fregion.Fregion := 0;
Fregion.owner := self;
Draggable := true;
CycleTimer := TTimer.Create(Self);
CycleTimer.Enabled := False;
CycleTimer.Interval := FCycleInterval;
CycleTimer.OnTimer := TimerCycle;
pbAnm:=TPaintBox.Create(Self);
pbAnm.Parent:=Self;
pbAnm.ParentColor :=True;
pbAnm.ParentFont :=True;
pbAnm.Align :=alClient;
end;
procedure TCoolTitleBar.pbAnmMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
//拖动窗体
If button = mbleft then
begin
releasecapture;
TWincontrol(Parent.Parent).Perform(WM_syscommand, $F012, 0);
end;
end;
procedure TCoolTitleBar.SegmentColor(Entry:integer);
begin
if hNum>=PALENTRIES-1 then hNum:=1 Else inc(hNum,1);
pe:= LogicalPalette.palPalEntry[Entry];
iRed := pe.peRed;
iGreen := pe.peGreen;
pNum := 512 div PALENTRIES;
If (hNum <= PALENTRIES div 2) Then
iBlue := hNum * pNum
Else
iBlue := (PALENTRIES - hNum) * pNum;
pbAnm.Canvas.Pen.Color := RGB(0,0,iBlue);
pbAnm.Canvas.Brush.Color := RGB(0,0,iBlue);
pbAnm.Canvas.Font.Color:= RGB(255,255,255);
end;
procedure TCoolTitleBar.MakeSpectrumSegments;
var
Counter:Integer;
TotalWidth:Integer;
StartPoint:Integer;
EndPoint:Integer;
begin
//---------------------在指定的动画区域画方格实现动画运转--------------------
TotalWidth:=pbAnm.Width;
For Counter := 0 To (PALENTRIES-1) do begin
StartPoInt := (TotalWIdth * Counter) div PALENTRIES;
EndPoInt := (TotalWIdth * (Counter + 1)) div PALENTRIES;
pbAnm.Canvas.Pen.Width :=1;
hEntryNum:=Counter;
SegmentColor(hEntryNum);
pbAnm.Canvas.RoundRect(EndPoInt,pbAnm.Height,StartPoInt, 0,0,0);
SetBKMode(pbAnm.Canvas.Handle,TRANSPARENT);
pbAnm.Canvas.TextOut(20,2,Self.Caption)
end;
//---------------------------------------------------------------------------
end;
procedure TCoolTitleBar.SetTop(Value:integer);
begin
inherited top := 0;
end;
procedure TCoolTitleBar.SetLeft(Value:integer);
begin
inherited left := 0;
end;
procedure TCoolTitleBar.RefreshRegion;
begin
FRegion.FRegion := ExtCreateRegion (nil, FOrgSize, FOrgRgn^);
SetWindowRgn (parent.handle, FRegion.Fregion, true);
end;
destructor TCoolTitleBar.destroy;
begin
If FOrgRgn <> Nil then
FreeMem (FOrgRgn, FOrgSize);
if fregion.fregion <> 0 then deleteobject (fregion.fregion);
Dummy.Free;
FRegion.free;
inherited;
end;
function TCoolTitleBar.GetRegion:TRegionType;
begin
result := FRegion;
end;
procedure TCoolTitleBar.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
//拖动窗体
If button = mbleft then
begin
releasecapture;
TWincontrol(Parent).Perform(WM_syscommand, $F012, 0);
end;
end;
procedure TCoolTitleBar.SetRegion(Value:TRegionType);
begin
if Value <> nil then
begin
FRegion := Value;
FRegion.owner := self;
end;
end;
procedure TCoolTitleBar.SetParent(Value:TWinControl);
begin
inherited;
if Value <> nil then
if not (Value is TWinControl) then
begin
raise Exception.Create ('Drop the CoolTitleBar on a FORM!');
end else
with TWincontrol (Value) do
begin
if Value is TForm then
begin
TForm(Value).BorderStyle := bsNone;
TForm(Value).Position:=poScreenCenter;
Self.Caption :=TForm(Value).Caption;
end;
end;
top := 0;
left := 0;
end;
procedure TCoolTitleBar.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
message.Result := 1;
end;
procedure TCoolTitleBar.size;
var
size : integer;
rgndata : pRGNData;
xf : TXform;
begin
if (fregion.fregion<>0) then
begin
size := getregiondata (FRegion.FRegion, 0, nil);
getmem (rgndata, size);
getregiondata (FRegion.FRegion, size, rgndata);
xf.eM11 := 1;
xf.eM12 := 0;
xf.eM21 := 0;
xf.eM22 := 1;
xf.eDx := 0;
xf.eDy := 0;
FRegion.FRegion := ExtCreateRegion (nil, size, rgndata^);
if not (csDesigning in ComponentState) and (FRegion.FRegion <> 0) then
SetWindowRgn (parent.handle, FRegion.Fregion, true);
end;
end;
procedure TCoolTitleBar.Setwidth(Value:integer);
begin
inherited Width := Value;
// Size;
end;
procedure TCoolTitleBar.SetHeight(Value:integer);
begin
inherited Height := Value;
// Size;
end;
procedure TCoolTitleBar.SetCycleInterval(Value: Cardinal);
begin
FCycleInterval := Value;
CycleTimer.Interval := FCycleInterval;
end;
procedure TCoolTitleBar.TimerCycle(Sender: TObject);
begin
//AnimateDemoPalette;
MakeSpectrumSegments;
end;
procedure TCoolTitleBar.SetBackMove(Value: Boolean);
begin
FBackMove := Value;
if Value then CycleTimer.Enabled := Value else CycleTimer.Enabled := False;
end;
end.