📄 gdregionlist.pas
字号:
unit GDRegionList;
interface
uses GdClasses,Classes,Graphics,Dialogs,Types;
Type
TGDSkinRegions=class;
TGdSkinRegion=class(TGDRegion)
private
FBitmap:TBitmap;
FSkinRegions:TGDSkinRegions;
FRegionChangeEvent:TNotifyEvent;
procedure SetSkinRegions(const Value: TGDSkinRegions);
protected
procedure ReadState(Reader: TReader); override;
procedure RegionChange;override;
procedure SetParentComponent(AParent: TComponent); override;
public
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
function GetParentComponent: TComponent; override;
function HasParent: Boolean; override;
property SkinRegions: TGDSkinRegions read FSkinRegions write SetSkinRegions;
property Bitmap:TBitmap read FBitmap;
published
property OnRegionChange:TNotifyEvent read FRegionChangeEvent write FRegionChangeEvent;
end;
TGDSkinRegions=class(TComponent)
private
FRegions:TList;
FBitmap:TBitmap;
function GetRegionCount: Integer;
function GetRegions(Index: Integer): TGdSkinRegion;
procedure SetBitmap(const Value: TBitmap);
protected
procedure AddRegion(Region:TGdSkinRegion);
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
procedure RemoveRegion(Region:TGdSkinRegion);
procedure BitmapChange(Sender: TObject);
public
constructor Create(AOwner: TComponent);override;
destructor Destroy;override;
property Regions[Index:Integer]:TGdSkinRegion read GetRegions;
property RegionCount:Integer read GetRegionCount;
published
property Bitmap:TBitmap read FBitmap write SetBitmap;
end;
implementation
{ TGdSkinRegion }
constructor TGdSkinRegion.Create(AOwner: TComponent);
begin
inherited;
FBitmap:=TBitmap.Create;
end;
destructor TGdSkinRegion.Destroy;
begin
if SkinRegions <> nil then SkinRegions.RemoveRegion(Self);
FBitmap.Free;
inherited;
end;
function TGdSkinRegion.GetParentComponent: TComponent;
begin
if SkinRegions <> nil then
Result := SkinRegions else
Result := inherited GetParentComponent;
end;
function TGdSkinRegion.HasParent: Boolean;
begin
if SkinRegions <> nil then
Result := True else
Result := inherited HasParent;
end;
procedure TGdSkinRegion.ReadState(Reader: TReader);
begin
inherited ReadState(Reader);
if Reader.Parent is TGDSkinRegions then
SkinRegions := TGDSkinRegions(Reader.Parent);
end;
procedure TGdSkinRegion.RegionChange;
var
ARect:TRect;
begin
if not ((SkinRegions<>Nil) and not SkinRegions.Bitmap.Empty) then Exit;
ARect:=Rect(0,0,Abs(Rigth-Left),Abs(Bottom-Top));
FBitmap.Width:=ARect.Right;
FBitmap.Height:=ARect.Bottom;
FBitmap.Canvas.CopyRect(ARect,SkinRegions.Bitmap.Canvas,GetRect);
if Assigned(FRegionChangeEvent) then FRegionChangeEvent(Self);
inherited;
end;
procedure TGdSkinRegion.SetParentComponent(AParent: TComponent);
begin
if not (csLoading in ComponentState) and (AParent is TGDSkinRegions) then
SkinRegions := TGDSkinRegions(AParent);
end;
procedure TGdSkinRegion.SetSkinRegions(const Value: TGDSkinRegions);
begin
if FSkinRegions <> Value then
begin
if FSkinRegions<>Nil then FSkinRegions.RemoveRegion(Self);
if Value<>Nil then
begin
Value.AddRegion(Self);
RegionChange;
end;
end;
end;
{ TGDSkinRegions }
procedure TGDSkinRegions.AddRegion(Region: TGdSkinRegion);
begin
FRegions.Add(Region);
Region.FSkinRegions:=Self;
Region.FreeNotification(Self);
end;
procedure TGDSkinRegions.BitmapChange(Sender: TObject);
var
i:Integer;
begin
for i:=0 to FRegions.Count-1 do
TGdSkinRegion(FRegions.Items[i]).RegionChange;
end;
constructor TGDSkinRegions.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FRegions:=TList.Create;
FBitmap:=TBitmap.Create;
FBitmap.OnChange:=BitmapChange;
end;
destructor TGDSkinRegions.Destroy;
begin
while FRegions.Count>0 do TGdSkinRegion(FRegions.Last).Free;
FRegions.Free;
FBitmap.Free;
inherited Destroy;
end;
procedure TGDSkinRegions.GetChildren(Proc: TGetChildProc;
Root: TComponent);
var
I: Integer;
SkinRegion: TGdSkinRegion;
begin
for I := 0 to FRegions.Count - 1 do
begin
SkinRegion := FRegions.List[I];
if SkinRegion.Owner = Root then Proc(SkinRegion);
end;
end;
function TGDSkinRegions.GetRegionCount: Integer;
begin
Result:=FRegions.Count;
end;
function TGDSkinRegions.GetRegions(Index: Integer): TGdSkinRegion;
begin
if Index in [0..FRegions.Count-1] then
Result:=TGdSkinRegion(FRegions.Items[Index]);
end;
procedure TGDSkinRegions.RemoveRegion(Region: TGdSkinRegion);
begin
if FRegions.Remove(Region)>=0 then
Region.FSkinRegions:=Nil;
end;
procedure TGDSkinRegions.SetBitmap(const Value: TBitmap);
begin
FBitmap.Assign(Value);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -