📄 dynamicskinform.pas
字号:
function GetMDIChildDynamicSkinFormComponent;
var
i: Integer;
begin
Result := nil;
for i := 0 to Application.MainForm.MDIChildCount - 1 do
begin
Result := GetDynamicSkinFormComponent(Application.MainForm.MDIChildren[i]);
if (Result <> nil) and (Result.WindowState = wsMaximized)
then
Break
else
Result := nil;
end;
end;
function GetMDIChildDynamicSkinFormComponent2;
begin
if (Application.MainForm <> nil) and (Application.MainForm.ActiveMDIChild <> nil)
then
Result := GetDynamicSkinFormComponent(Application.MainForm.ActiveMDIChild)
else
Result := nil;
end;
//============= TbsSkinComponent ============= //
constructor TspSkinComponent.Create(AOwner: TComponent);
begin
inherited;
FSkinData := nil;
end;
procedure TspSkinComponent.SetSkinData(Value: TspSkinData);
begin
FSkinData := Value;
end;
procedure TspSkinComponent.Notification;
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FSkinData) then FSkinData := nil;
end;
procedure TspSkinComponent.BeforeChangeSkinData;
begin
end;
procedure TspSkinComponent.ChangeSkinData;
begin
end;
//============= TspActiveSkinObject =============//
constructor TspActiveSkinObject.Create;
begin
Parent := AParent;
SD := Parent.SkinData;
Enabled := True;
Visible := True;
FMorphKf := 0;
if AData <> nil
then
begin
with AData do
begin
Self.IDName := IDName;
Self.Hint := Hint;
Self.SkinRectInAPicture := SkinRectInAPicture;
Self.SkinRect := SkinRect;
Self.ActiveSkinRect := ActiveSkinRect;
Self.InActiveSkinRect:= InActiveSkinRect;
Self.Morphing := Morphing;
Self.MorphKind := MorphKind;
Self.CursorIndex := CursorIndex;
Self.RollUp := RollUp;
if (ActivePictureIndex <> - 1) and
(ActivePictureIndex < SD.FActivePictures.Count)
then
ActivePicture := TBitMap(SD.FActivePictures.Items[ActivePictureIndex])
else
begin
ActivePicture := nil;
ActiveSkinRect := NullRect;
end;
end;
ObjectRect := SkinRect;
if RollUp then Picture := SD.FRollUpPicture else Picture := SD.FPicture;
end;
end;
function TspActiveSkinObject.EnableMorphing: Boolean;
begin
Result := Morphing and (Parent.SkinData <> nil) and
Parent.SkinData.EnableSkinEffects;
end;
procedure TspActiveSkinObject.ReDraw;
begin
if EnableMorphing
then Parent.MorphTimer.Enabled := True
else Parent.DrawSkinObject(Self);
end;
procedure TspActiveSkinObject.DblClick;
begin
end;
procedure TspActiveSkinObject.MouseDown(X, Y: Integer; Button: TMouseButton);
begin
Parent.MouseDownEvent(IDName, X, Y, ObjectRect, Button);
end;
procedure TspActiveSkinObject.MouseUp(X, Y: Integer; Button: TMouseButton);
begin
if FMouseIn then Parent.MouseUpEvent(IDName, X, Y, ObjectRect, Button);
end;
procedure TspActiveSkinObject.MouseMove(X, Y: Integer);
begin
Parent.MouseMoveEvent(IDName, X, Y, ObjectRect);
end;
procedure TspActiveSkinObject.MouseEnter;
begin
FMouseIn := True;
Active := True;
if not IsNullRect(ActiveSkinRect) then ReDraw;
Parent.MouseEnterEvent(IDName);
end;
procedure TspActiveSkinObject.MouseLeave;
begin
FMouseIn := False;
Active := False;
if not IsNullRect(ActiveSkinRect) then ReDraw;
Parent.MouseLeaveEvent(IDName);
end;
function TspActiveSkinObject.CanMorphing;
begin
Result := (Active and (MorphKf < 1)) or
(not Active and (MorphKf > 0));
end;
procedure TspActiveSkinObject.DoMorphing;
begin
if Active
then MorphKf := MorphKf + MorphInc
else MorphKf := MorphKf - MorphInc;
Parent.DrawSkinObject(Self);
end;
procedure TspActiveSkinObject.Draw;
procedure CreateObjectImage(B: TBitMap; AActive: Boolean);
begin
B.Width := RectWidth(ObjectRect);
B.Height := RectHeight(ObjectRect);
with B.Canvas do
begin
if AActive
then
CopyRect(Rect(0, 0, B.Width, B.Height), ActivePicture.Canvas, ActiveSkinRect)
else
if SkinRectInApicture
then
CopyRect(Rect(0, 0, B.Width, B.Height), ActivePicture.Canvas, SkinRect)
else
CopyRect(Rect(0, 0, B.Width, B.Height), Picture.Canvas, SkinRect);
end;
end;
var
PBuffer, APBuffer: TspEffectBmp;
Buffer, ABuffer: TBitMap;
ASR, SR: TRect;
begin
ASR := ActiveSkinRect;
SR := SkinRect;
if (Parent.SkinData = nil) or ((Parent.SkinData <> nil) and (Parent.SkinData.Empty))
then
Exit;
if Enabled and (not Parent.GetFormActive) and (not IsNullRect(InActiveSkinRect))
then
begin
Cnvs.CopyRect(ObjectRect, ActivePicture.Canvas, InActiveSkinRect)
end
else
if not EnableMorphing or
((Active and (MorphKf = 1)) or (not Active and (MorphKf = 0)))
then
begin
if Active and not IsNullRect(ASR)
then
Cnvs.CopyRect(ObjectRect, ActivePicture.Canvas, ASR)
else
if UpDate or SkinRectInApicture
then
begin
if SkinRectInApicture
then
Cnvs.CopyRect(ObjectRect, ActivePicture.Canvas, SR)
else
Cnvs.CopyRect(ObjectRect, Picture.Canvas, SR);
end;
end
else
begin
Buffer := TBitMap.Create;
ABuffer := TBitMap.Create;
CreateObjectImage(Buffer, False);
CreateObjectImage(ABuffer, True);
PBuffer := TspEffectBmp.CreateFromhWnd(Buffer.Handle);
APBuffer := TspEffectBmp.CreateFromhWnd(ABuffer.Handle);
case MorphKind of
mkDefault: PBuffer.Morph(APBuffer, MorphKf);
mkGradient: PBuffer.MorphGrad(APBuffer, MorphKf);
mkLeftGradient: PBuffer.MorphLeftGrad(APBuffer, MorphKf);
mkRightGradient: PBuffer.MorphRightGrad(APBuffer, MorphKf);
mkLeftSlide: PBuffer.MorphLeftSlide(APBuffer, MorphKf);
mkRightSlide: PBuffer.MorphRightSlide(APBuffer, MorphKf);
mkPush: PBuffer.MorphPush(APBuffer, MorphKf);
end;
PBuffer.Draw(Cnvs.Handle, ObjectRect.Left, ObjectRect.Top);
PBuffer.Free;
APBuffer.Free;
Buffer.Free;
ABuffer.Free;
end;
end;
procedure TspActiveSkinObject.SetMorphKf(Value: Double);
begin
FMorphKf := Value;
if FMorphKf < 0 then FMorphKf := 0 else
if FMorphKf > 1 then FMorphKf := 1;
end;
procedure TspUserObject.Draw;
begin
Parent.PaintEvent(IDName, Cnvs, ObjectRect);
end;
//============= TspSkinTrackBarObject ============//
constructor TspSkinTrackBarObject.Create;
begin
inherited Create(AParent, AData);
with TspDataSkinTrackBar(AData) do
begin
Self.ButtonRect := ButtonRect;
Self.ActiveButtonRect := ActiveButtonRect;
Self.BeginPoint := BeginPoint;
Self.EndPoint := EndPoint;
Self.MinValue := MinValue;
Self.MaxValue := MaxValue;
Self.MouseDownChangeValue := MouseDownChangeValue;
Self.ButtonTransparent := ButtonTransparent;
Self.ButtonTransparentColor := ButtonTransparentColor;
end;
if abs(BeginPoint.Y - EndPoint.Y) < abs(EndPoint.X - BeginPoint.X)
then
TrackKind := tkHorizontal
else
TrackKind := tkVertical;
FValue := MinValue;
FButtonPos := CalcButtonPos(FValue);
end;
function TspSkinTrackBarObject.CalcButtonRect;
var
L, T: Integer;
begin
L := P.X - RectWidth(ButtonRect) div 2;
T := P.Y - RectHeight(ButtonRect) div 2;
Result := Rect(L, T,
L + RectWidth(ButtonRect), T + RectHeight(ButtonRect));
end;
function TspSkinTrackBarObject.CalcValue;
var
kf: Double;
begin
kf := 0;
case TrackKind of
tkHorizontal:
kf := (FButtonPos.X - BeginPoint.X) / (EndPoint.X - BeginPoint.X);
tkVertical:
kf := 1 - (FButtonPos.Y - EndPoint.Y) / (BeginPoint.Y - EndPoint.Y);
end;
Result := MinValue + Round((MaxValue - MinValue) * kf);
end;
function TspSkinTrackBarObject.CalcButtonPos;
var
kf: Double;
begin
kf := (Value - MinValue) / (MaxValue - MinValue);
case TrackKind of
tkHorizontal:
Result := Point(BeginPoint.X + Round((EndPoint.X - BeginPoint.X) * kf),
BeginPoint.Y);
tkVertical:
Result := Point(BeginPoint.X,
EndPoint.Y + Round((BeginPoint.Y - EndPoint.Y) *
(1 - kf)));
end;
end;
procedure TspSkinTrackBarObject.SimplySetValue;
begin
FValue := AValue;
if FValue < MinValue then FValue := MinValue;
if FValue > MaxValue then FValue := MaxValue;
FOldButtonPos := FbuttonPos;
FButtonPos := CalcButtonPos(Value);
Parent.TrackBarChangeValueEvent(IDName, FValue);
end;
procedure TspSkinTrackBarObject.SetValue;
begin
if FValue <> AValue
then
begin
FValue := AValue;
if FValue < MinValue then FValue := MinValue;
if FValue > MaxValue then FValue := MaxValue;
FOldButtonPos := FbuttonPos;
FButtonPos := CalcButtonPos(Value);
Parent.DrawSkinObject(Self);
Parent.TrackBarChangeValueEvent(IDName, FValue);
end;
end;
procedure TspSkinTrackBarObject.SetButtonPos;
begin
if (FButtonPos.X <> AValue.X) or (FButtonPos.Y <> AValue.Y)
then
begin
FOldButtonPos := FbuttonPos;
FButtonPos := AValue;
FValue := CalcValue(FButtonPos);
Parent.DrawSkinObject(Self);
Parent.TrackBarChangeValueEvent(IDName, FValue);
end;
end;
procedure TspSkinTrackBarObject.Draw;
var
BRect: TRect;
Buffer: TBitMap;
BR: TRect;
B: TBitMap;
begin
if (Parent.SkinData = nil) or ((Parent.SkinData <> nil) and (Parent.SkinData.Empty))
then
Exit;
if MoveActive and not IsNullRect(ActiveButtonRect)
then BRect := ActiveButtonRect
else BRect := ButtonRect;
Buffer := TBitMap.Create;
Buffer.Width
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -