📄 dynamicskinform.pas
字号:
MI_ROLLUPNAME = 'DSF_ROLLUP';
MI_CHILDITEM = '_DSFCHILDITEM';
WM_MDICHANGESIZE = WM_USER + 206;
WM_MDICHILDMAX = WM_USER + 207;
WM_MDICHILDRESTORE = WM_USER + 208;
function GetDynamicSkinFormComponent;
var
i: Integer;
begin
Result := nil;
for i := 0 to AForm.ComponentCount - 1 do
if AForm.Components[i] is TspDynamicSkinForm
then
begin
Result := (AForm.Components[i] as TspDynamicSkinForm);
Break;
end;
end;
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;
//============= 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.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;
procedure TspActiveSkinObject.ReDraw;
begin
if Morphing
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 not Morphing 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;
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;
begin
if MoveActive and not IsNullRect(ActiveButtonRect)
then BRect := ActiveButtonRect
else BRect := ButtonRect;
Buffer := TBitMap.Create;
Buffer.Width := RectWidth(SkinRect);
Buffer.Height := RectHeight(SkinRect);
BR := CalcButtonRect(FButtonPos);
//
with Buffer.Canvas do
begin
case TrackKind of
tkHorizontal:
begin
if IsNullRect(ActiveSkinRect)
then
CopyRect(Rect(0, 0, Buffer.Width, Buffer.Height),
Picture.Canvas, SkinRect)
else
begin
CopyRect(Rect(0, 0, FButtonPos.X, Buffer.Height),
ActivePicture.Canvas,
Rect(ActiveSkinRect.Left, ActiveSkinRect.Top,
ActiveSkinRect.Left + FButtonPos.X, ActiveSkinRect.Bottom));
CopyRect(Rect(FButtonPos.X, 0, Buffer.Width, Buffer.Height),
Picture.Canvas,
Rect(SkinRect.Left + FButtonPos.X, SkinRect.Top,
SkinRect.Right, SkinRect.Bottom));
end;
end;
tkVertical:
begin
if IsNullRect(ActiveSkinRect)
then
CopyRect(Rect(0, 0, Buffer.Width, Buffer.Height),
Picture.Canvas, SkinRect)
else
begin
CopyRect(Rect(0, 0, Buffer.Width, FButtonPos.Y),
Picture.Canvas,
Rect(SkinRect.Left, SkinRect.Top,
SkinRect.Right, SkinRect.Top + FButtonPos.Y));
CopyRect(Rect(0, FButtonPos.Y, Buffer.Width, Buffer.Height),
ActivePicture.Canvas,
Rect(ActiveSkinRect.Left, ActiveSkinRect.Top + FButtonPos.Y,
ActiveSkinRect.Right, ActiveSkinRect.Bottom));
end;
end;
end;
CopyRect(BR, ActivePicture.Canvas, BRect);
end;
Cnvs.Draw(ObjectRect.Left, ObjectRect.Top, Buffer);
Buffer.Free;
end;
procedure TspSkinTrackBarObject.MouseDown(X, Y: Integer; Button: TMouseButton);
var
X1, Y1: Integer;
begin
X1 := X - ObjectRect.Left;
Y1 := Y - ObjectRect.Top;
if PtInRect(CalcButtonRect(FButtonPos), Point(X1, Y1)) and (Button = mbLeft)
then
begin
MoveActive := True;
FOldMPoint.X := X1;
FOldMPoint.Y := Y1;
if not IsNullRect(ActiveButtonRect)
then Parent.DrawSkinObject(Self);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -