⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sxskinupdown.pas

📁 skin components for design of your applicastions
💻 PAS
📖 第 1 页 / 共 4 页
字号:
begin
 if Enabled and not FDownUp and not FDownDown then
  StartChangingEffect(gcaHighlightOut);
 FMouseOver:=False;
 if FMouseOverUp then
  InternalMouseLeaveUpButton;
 if FMouseOverDown then
  InternalMouseLeaveDownButton;
 if Enabled and not FDownUp and not FDownDown then
  ResetUpDownParams([udrpInvalidateOnStyleChange]);
end;

procedure TSXSkinCustomUpDown.InternalMouseEnterUpButton;
begin
 if Enabled and FEnabledUp and not FDownUp then
  StartUpButtonChangingEffect(gcaHighlightIn);
 FMouseOverUp:=True;
 if Enabled and not FDownUp then
  ResetUpDownParams([udrpInvalidateUpButtonOnStyleChange]);
end;

procedure TSXSkinCustomUpDown.InternalMouseLeaveUpButton;
begin
 if Enabled and FEnabledUp and not FDownUp then
  StartUpButtonChangingEffect(gcaHighlightOut);
 FMouseOverUp:=False;
 if Enabled and not FDownUp then
  ResetUpDownParams([udrpInvalidateUpButtonOnStyleChange]);
end;

procedure TSXSkinCustomUpDown.InternalMouseEnterDownButton;
begin
 if Enabled and FEnabledDown and not FDownDown then
  StartDownButtonChangingEffect(gcaHighlightIn);
 FMouseOverDown:=True;
 if Enabled and not FDownDown then
  ResetUpDownParams([udrpInvalidateDownButtonOnStyleChange]);
end;

procedure TSXSkinCustomUpDown.InternalMouseLeaveDownButton;
begin
 if Enabled and FEnabledDown and not FDownDown then
  StartDownButtonChangingEffect(gcaHighlightOut);
 FMouseOverDown:=False;
 if Enabled and not FDownDown then
  ResetUpDownParams([udrpInvalidateDownButtonOnStyleChange]);
end;

procedure TSXSkinCustomUpDown.MouseLeave;
begin
 if FMouseOver then
  InternalMouseLeave;
 inherited;
end;

procedure TSXSkinCustomUpDown.MouseMove(Shift:TShiftState;X,Y:Integer);
var B:Boolean;
    P:TPoint;
begin
 inherited;
 if Enabled then
  begin
   P:=Point(X,Y);
   B:=(X>=0) and (X<Width) and (Y>=0) and (Y<Height) and CapturesMouseAt(X,Y);
   if B<>FMouseOver then
    begin
     if B then InternalMouseEnter else
      InternalMouseLeave;
    end;
   if FMouseOver then
    begin
     B:=PtInRect(FUpButtonRect,P) and UpButtonCapturesMouseAt(X,Y);
     if B<>FMouseOverUp then
      begin
       if B then InternalMouseEnterUpButton else
        InternalMouseLeaveUpButton;
      end;
     B:=PtInRect(FDownButtonRect,P) and DownButtonCapturesMouseAt(X,Y);
     if B<>FMouseOverDown then
      begin
       if B then InternalMouseEnterDownButton else
        InternalMouseLeaveDownButton;
      end;
    end;
   if not FMouseOver then
    begin
     if FMouseOverUp then
      InternalMouseLeaveUpButton;
     if FMouseOverDown then
      InternalMouseLeaveDownButton;
    end;
  end;
end;

procedure TSXSkinCustomUpDown.MouseDown(Button:TMouseButton;Shift:TShiftState;X,Y:Integer);
var      P:TPoint;
 NeedTimer:Boolean;
begin
 if Enabled and (Button=mbLeft) then
  begin
   NeedTimer:=False;
   if EnabledUp and FMouseOverUp then
    begin
     StartChangingEffect(gcaDown);
     StartUpButtonChangingEffect(gcaDown);
     FDownUp:=True;
     SetFocus;
     ResetUpDownParams([udrpInvalidateOnStyleChange,udrpInvalidateUpButtonOnStyleChange]);
     //
     DoClick(True);
     P:=ScreenToClient(Mouse.CursorPos);
     SendMessage(Handle,WM_MOUSEMOVE,0,P.X or (P.Y shl 16));
     //
     NeedTimer:=True;
    end;
   if EnabledDown and FMouseOverDown then
    begin
     StartChangingEffect(gcaDown);
     StartDownButtonChangingEffect(gcaDown);
     FDownDown:=True;
     SetFocus;
     ResetUpDownParams([udrpInvalidateOnStyleChange,udrpInvalidateDownButtonOnStyleChange]);
     //
     DoClick(False);
     P:=ScreenToClient(Mouse.CursorPos);
     SendMessage(Handle,WM_MOUSEMOVE,0,P.X or (P.Y shl 16));
     //
     NeedTimer:=True;
    end;
   if NeedTimer then
    begin
     SeqClickNum:=0;
     KillTimer(Handle,1);
     SetTimer(Handle,1,500,nil);
    end;
  end;
 inherited;
end;

procedure TSXSkinCustomUpDown.MouseUp(Button:TMouseButton;Shift:TShiftState;X,Y:Integer);
begin
 if Enabled then
  begin
   StartChangingEffect(gcaUp);
   KillTimer(Handle,1);
   if FDownUp then
    begin
     StartUpButtonChangingEffect(gcaUp);
     FDownUp:=False;
     ResetUpDownParams([udrpInvalidateUpButtonOnStyleChange]);
    end;
   if FDownDown then
    begin
     StartDownButtonChangingEffect(gcaUp);
     FDownDown:=False;
     ResetUpDownParams([udrpInvalidateDownButtonOnStyleChange]);
    end;
   ResetUpDownParams([udrpInvalidateOnStyleChange]);
  end;
 inherited;
end;

procedure TSXSkinCustomUpDown.DoClick(UpButton:Boolean);
begin
 if Assigned(FOnClick) then
  FOnClick(Self,UpButton);
end;

procedure TSXSkinCustomUpDown.InvalidateUpButton;
begin
 if HandleAllocated then
  InvalidateRect(Handle,@FUpButtonRect,False);
end;

procedure TSXSkinCustomUpDown.InvalidateDownButton;
begin
 if HandleAllocated then
  InvalidateRect(Handle,@FDownButtonRect,False);
end;

procedure TSXSkinCustomUpDown.DoThreadActions;
begin
 if not (csDestroying in ComponentState) then
  begin
   Inc(FUpDownDoneSteps);
   Inc(FUpButtonDoneSteps);
   Inc(FDownButtonDoneSteps);
   if (FThread<>nil) and not FThread.Suspended and
      (not HasTransformEffect(FLastUpDownTransform) or (FUpDownDoneSteps>=FLastUpDownTransform.StepsNum)) and
      (not HasTransformEffect(FLastUpButtonTransform) or (FUpButtonDoneSteps>=FLastUpButtonTransform.StepsNum)) and
      (not HasTransformEffect(FLastDownButtonTransform) or (FDownButtonDoneSteps>=FLastDownButtonTransform.StepsNum)) then
    begin
     FThread.Suspend;
    end;
   if HasTransformEffect(FLastUpDownTransform) and (FUpDownDoneSteps<=FLastUpDownTransform.StepsNum) then
    begin
     if HandleAllocated then
      InvalidateRect(Handle,nil,False);
    end else
     begin
      if HasTransformEffect(FLastUpButtonTransform) and (FUpButtonDoneSteps<=FLastUpButtonTransform.StepsNum) then
       InvalidateUpButton;
      if HasTransformEffect(FLastDownButtonTransform) and (FDownButtonDoneSteps<=FLastDownButtonTransform.StepsNum) then
       InvalidateDownButton;
     end;
   Update;
  end;
end;

procedure TSXSkinCustomUpDown.CreateThreadIfNeeded;
begin
 if FThread=nil then
  begin
   FThread:=TSXSkinCustomUpDownThread.Create;
   FThread.Control:=Self;
  end;
end;

procedure TSXSkinCustomUpDown.GetUpDownTransformEffect(Action:TSXGlyphChangeAction;
           var Effect:TSXTransformEffectData);
var  A:Integer;
 Style:TSXSkinUpDownStyle;
begin
 FillChar(Effect,sizeof(Effect),0);
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
   if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinUpDownStyle) then
    begin
     Style:=TSXSkinUpDownStyle(SkinLibrary.Styles[A]);
     case Action of
      gcaHighlightIn:  Effect:=Style.HInUpDownEffect;
      gcaHighlightOut: Effect:=Style.HOutUpDownEffect;
      gcaDown:         Effect:=Style.DownUpDownEffect;
      gcaUp:           Effect:=Style.UpUpDownEffect;
      gcaEnable:       Effect:=Style.EnableUpDownEffect;
      gcaDisable:      Effect:=Style.DisableUpDownEffect;
      gcaFocus:        Effect:=Style.FocusUpDownEffect;
      gcaUnfocus:      Effect:=Style.UnfocusUpDownEffect;
     end;
    end;
  end;
end;

procedure TSXSkinCustomUpDown.GetUpButtonTransformEffect(Action:TSXGlyphChangeAction;
           var Effect:TSXTransformEffectData);
var   A:Integer;
  Style:TSXSkinUpDownStyle;
 BStyle:TSXSkinButtonStyle;
begin
 FillChar(Effect,sizeof(Effect),0);
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
   if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinUpDownStyle) then
    begin
     Style:=TSXSkinUpDownStyle(SkinLibrary.Styles[A]);
     A:=SkinLibrary.Styles.GetIndexByName(Style.UpButton);
     if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinButtonStyle) then
      begin
       BStyle:=TSXSkinButtonStyle(SkinLibrary.Styles[A]);
       case Action of
        gcaHighlightIn:  Effect:=BStyle.HInButtonEffect;
        gcaHighlightOut: Effect:=BStyle.HOutButtonEffect;
        gcaDown:         Effect:=BStyle.DownButtonEffect;
        gcaUp:           Effect:=BStyle.UpButtonEffect;
        gcaEnable:       Effect:=BStyle.EnableButtonEffect;
        gcaDisable:      Effect:=BStyle.DisableButtonEffect;
        gcaFocus:        Effect:=BStyle.FocusButtonEffect;
        gcaUnfocus:      Effect:=BStyle.UnfocusButtonEffect;
       end;
      end;
    end;
  end;
end;

procedure TSXSkinCustomUpDown.GetDownButtonTransformEffect(Action:TSXGlyphChangeAction;
           var Effect:TSXTransformEffectData);
var   A:Integer;
  Style:TSXSkinUpDownStyle;
 BStyle:TSXSkinButtonStyle;
begin
 FillChar(Effect,sizeof(Effect),0);
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
   if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinUpDownStyle) then
    begin
     Style:=TSXSkinUpDownStyle(SkinLibrary.Styles[A]);
     A:=SkinLibrary.Styles.GetIndexByName(Style.DownButton);
     if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinButtonStyle) then
      begin
       BStyle:=TSXSkinButtonStyle(SkinLibrary.Styles[A]);
       case Action of
        gcaHighlightIn:  Effect:=BStyle.HInButtonEffect;
        gcaHighlightOut: Effect:=BStyle.HOutButtonEffect;
        gcaDown:         Effect:=BStyle.DownButtonEffect;
        gcaUp:           Effect:=BStyle.UpButtonEffect;
        gcaEnable:       Effect:=BStyle.EnableButtonEffect;
        gcaDisable:      Effect:=BStyle.DisableButtonEffect;
        gcaFocus:        Effect:=BStyle.FocusButtonEffect;
        gcaUnfocus:      Effect:=BStyle.UnfocusButtonEffect;
       end;
      end;
    end;
  end;
end;

procedure TSXSkinCustomUpDown.StartChangingEffect(T:TSXGlyphChangeAction);
var         B:TBitmap32;
          Rgn:HRGN;
    Transform:TSXTransformEffectData;
begin
 GetUpDownTransformEffect(T,Transform);
 if HasTransformEffect(Transform) then
  begin
   CreateThreadIfNeeded;
   //
   B:=TBitmap32.Create;
   B.DrawMode:=dmBlend;
   B.CombineMode:=cmMerge;
   B.SetSize(Width,Height);
   B.Clear(0);
   Rgn:=CreateRectRgn(0,0,Width,Height);
   PaintCurrentBlendedUDStyle(B,0,0,Rect(0,0,Width,Height),Rgn);
   if not (HasTransformEffect(FLastUpDownTransform) and (FUpDownDoneSteps<FLastUpDownTransform.StepsNum)) and
           Transform.DrawCaption then
    PaintOverStyleButtonsToBitmap(B,0,0,Rect(0,0,Width,Height),Rgn);
   DeleteObject(Rgn);
   FLastUpDown.Free;
   FLastUpDown:=B;
   //
   FUpDownDoneSteps:=1;
   if FThread.Suspended then
    FThread.Resume;
  end;
 FLastUpDownTransform:=Transform;
end;

procedure TSXSkinCustomUpDown.StartUpButtonChangingEffect(T:TSXGlyphChangeAction);
var         B:TBitmap32;
          Rgn:HRGN;
       BWidth:Integer;
      BHeight:Integer;
    Transform:TSXTransformEffectData;
begin
 GetUpButtonTransformEffect(T,Transform);
 if HasTransformEffect(Transform) then
  begin
   CreateThreadIfNeeded;
   //
   BWidth:=FUpButtonRect.Right-FUpButtonRect.Left;
   BHeight:=FUpButtonRect.Bottom-FUpButtonRect.Top;
   B:=TBitmap32.Create;
   B.DrawMode:=dmBlend;
   B.CombineMode:=cmMerge;
   B.SetSize(BWidth,BHeight);
   B.Clear(0);
   Rgn:=CreateRectRgn(0,0,BWidth,BHeight);
   PaintBlendedUpButtonStyle(B,0,0,Rect(0,0,BWidth,BHeight),Rgn);
   DeleteObject(Rgn);
   FLastUpButton.Free;
   FLastUpButton:=B;
   //
   FUpButtonDoneSteps:=1;
   if FThread.Suspended then
    FThread.Resume;
  end;
 FLastUpButtonTransform:=Transform;
end;

procedure TSXSkinCustomUpDown.StartDownButtonChangingEffect(T:TSXGlyphChangeAction);
var         B:TBitmap32;
          Rgn:HRGN;
       BWidth:Integer;
      BHeight:Integer;
    Transform:TSXTransformEffectData;
begin
 GetDownButtonTransformEffect(T,Transform);
 if HasTransformEffect(Transform) then
  begin
   CreateThreadIfNeeded;
   //
   BWidth:=FDownButtonRect.Right-FDownButtonRect.Left;
   BHeight:=FDownButtonRect.Bottom-FDownButtonRect.Top;
   B:=TBitmap32.Create;
   B.DrawMode:=dmBlend;
   B.CombineMode:=cmMerge;
   B.SetSize(BWidth,BHeight);
   B.Clear(0);
   Rgn:=CreateRectRgn(0,0,BWidth,BHeight);
   PaintBlendedDownButtonStyle(B,0,0,Rect(0,0,BWidth,BHeight),Rgn);
   DeleteObject(Rgn);
   FLastDownButton.Free;
   FLastDownButton:=B;
   //
   FDownButtonDoneSteps:=1;
   if FThread.Suspended then
    FThread.Resume;
  end;
 FLastDownButtonTransform:=Transform;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -