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

📄 suiprogressbar.pas

📁 SUIPack是一款为Delphi和C++Builder开发的所见即所得的界面增强VCL组件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
////////////////////////////////////////////////////////////////////////////////
//
//
//  FileName    :   SUIProgressBar.pas
//  Creator     :   Shen Min
//  Date        :   2002-05-27 V1
//                  2006-06-14 V6
//  Comment     :
//
//  Copyright (c) 2002-2006 Sunisoft
//  http://www.sunisoft.com
//  Email: support@sunisoft.com
//
////////////////////////////////////////////////////////////////////////////////

unit SUIProgressBar;

interface

{$I SUIPack.inc}

uses Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, ComCtrls,
     Graphics, Forms, Math,
     SUIPublic, SUIThemes, SUIMgr, SUI2Define;

type
    TsuiProgressBarOrientation = (suiHorizontal, suiVertical);

    TsuiProgressBar = class(TCustomPanel)
    private
        m_Max : Integer;
        m_Min : Integer;
        m_Position : Integer;
        m_UIStyle : TsuiUIStyle;
        m_FileTheme : TsuiFileTheme;        
        m_Orientation : TsuiProgressBarOrientation;
        m_BorderColor : TColor;
        m_Color : TColor;
        m_Picture : TPicture;
        m_ShowCaption : Boolean;
        m_CaptionColor : TColor;
        m_SmartShowCaption : Boolean;
        m_SelfChanging : Boolean;
        m_B1, m_B2, m_B3 : TBitmap;

        procedure SetMax(const Value: Integer);
        procedure SetMin(const Value: Integer);
        procedure SetPosition(const Value: Integer);
        procedure SetUIStyle(const Value: TsuiUIStyle);
        procedure SetOrientation(const Value: TsuiProgressBarOrientation);
        procedure SetColor(const Value: TColor);
        procedure SetBorderColor(const Value: TColor);
        procedure SetPicture(const Value: TPicture);
        procedure SetShowCaption(const Value: Boolean);
        procedure SetCaptionColor(const Value: TColor);
        procedure SetSmartShowCaption(const Value: Boolean);
        procedure SetFileTheme(const Value: TsuiFileTheme);
        
        procedure UpdateProgress();
        procedure UpdatePicture();
        function GetWidthFromPosition(nWidth : Integer) : Integer;
        function GetPercentFromPosition() : Integer;
        procedure WMERASEBKGND(var Msg : TMessage); message WM_ERASEBKGND;
        procedure OnPicChange(Sender : TObject);

    protected
        procedure Paint(); override;
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;                

    public
        constructor Create(AOwner : TComponent); override;
        destructor Destroy(); override;

        procedure StepBy(Delta : Integer);
        procedure StepIt();

    published
        property Anchors;
        property BiDiMode;
        property FileTheme : TsuiFileTheme read m_FileTheme write SetFileTheme;                    
        property UIStyle : TsuiUIStyle read m_UIStyle write SetUIStyle;
        property CaptionColor : TColor read m_CaptionColor write SetCaptionColor;
        property ShowCaption : Boolean read m_ShowCaption write SetShowCaption;
        property SmartShowCaption : Boolean read m_SmartShowCaption write SetSmartShowCaption;
        property Max : Integer read m_Max write SetMax;
        property Min : Integer read m_Min write SetMin;
        property Position : Integer read m_Position write SetPosition;
        property Orientation : TsuiProgressBarOrientation read m_Orientation write SetOrientation;
        property BorderColor : TColor read m_BorderColor write SetBorderColor;
        property Color : TColor read m_Color write SetColor;
        property Picture : TPicture read m_Picture write SetPicture;
        property Visible;

        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        
        property OnClick;

    end;

implementation

uses SUIForm;

{ TsuiProgressBar }

constructor TsuiProgressBar.Create(AOwner: TComponent);
begin
    inherited;

    ControlStyle := ControlStyle - [csAcceptsControls];
    m_Picture := TPicture.Create();
    m_Picture.OnChange := OnPicChange;
    m_SelfChanging := false;

    m_B1 := nil;
    m_B2 := nil;
    m_B3 := nil;

    m_Min := 0;
    m_Max := 100;
    m_Position := 50;
    m_Orientation := suiHorizontal;
    m_BorderColor := clBlack;
    m_Color := clBtnFace;
    m_CaptionColor := clBlack;

    Height := 12;
    Width := 150;
    Caption := '50%';
    m_ShowCaption := true;
    Color := clBtnFace;

    UIStyle := GetSUIFormStyle(AOwner);

    UpdateProgress();
end;

destructor TsuiProgressBar.Destroy;
begin
    m_Picture.Free();
    m_Picture := nil;

    if m_B1 <> nil then
    begin
        m_B1.Free();
        m_B1 := nil;
    end;

    if m_B2 <> nil then
    begin
        m_B2.Free();
        m_B2 := nil;
    end;

    if m_B3 <> nil then
    begin
        m_B3.Free();
        m_B3 := nil;
    end;

    inherited;
end;

function TsuiProgressBar.GetPercentFromPosition: Integer;
begin
    if m_Max <> m_Min then
        Result := Trunc((m_Position - m_Min) / (m_Max - m_Min) * 100)
    else
        Result := 0;
end;

function TsuiProgressBar.GetWidthFromPosition(nWidth : Integer): Integer;
begin
    Result := 0;

    if (
        (m_Max <= m_Min) or
        (m_Position <= m_Min)
    ) then
        Exit;

    Result := nWidth;
    if m_Position > m_Max then
        Exit;

    Result := Trunc((m_Position - m_Min) / (m_Max - m_Min) * nWidth);
end;

procedure TsuiProgressBar.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
    inherited;

    if (
        (Operation = opRemove) and
        (AComponent = m_FileTheme)
    )then
    begin
        m_FileTheme := nil;
        SetUIStyle(SUI_THEME_DEFAULT);          
    end;
end;

procedure TsuiProgressBar.OnPicChange(Sender: TObject);
begin
    Repaint();
end;

procedure SpitDrawVertical(Source : TBitmap; ACanvas : TCanvas; ARect : TRect; BorderWidth : Integer);
var
    R, SR : TRect;
    H : Integer;
begin
    if ARect.Left < 0 then
        Exit;
    Source.PixelFormat := pf24Bit;
    if BorderWidth = 0 then
        BorderWidth := Source.Height div 3;
    H := ARect.Bottom - ARect.Top;

    SR := Rect(0, 0, Source.Width, Min(H, BorderWidth));
    R := Rect(ARect.Left, ARect.Top, ARect.Right, ARect.Top + Min(BorderWidth, H));
    ACanvas.CopyRect(R, Source.Canvas, SR);

    SR := Rect(0, Source.Height - BorderWidth, Source.Width, Source.Height);
    R := Rect(ARect.Left, ARect.Bottom - BorderWidth, ARect.Right, ARect.Bottom);
    ACanvas.CopyRect(R, Source.Canvas, SR);

    SR := Rect(0, BorderWidth, Source.Width, Source.Height - BorderWidth);
    R := Rect(ARect.Left, ARect.Top + BorderWidth, ARect.Right, ARect.Bottom - BorderWidth);
    ACanvas.CopyRect(R, Source.Canvas, SR);
end;

procedure SpitDrawHorizontal(Source : TBitmap; ACanvas : TCanvas; ARect : TRect; BorderWidth : Integer);
var
    R, SR : TRect;
    H : Integer;
begin
    if ARect.Left < 0 then
        Exit;
    Source.PixelFormat := pf24Bit;        
    H := ARect.Right - ARect.Left;

    SR := Rect(0, 0, Min(H, BorderWidth), Source.Height);
    R := Rect(ARect.Left, ARect.Top, ARect.Left + Min(BorderWidth, H), ARect.Bottom);
    ACanvas.CopyRect(R, Source.Canvas, SR);

    SR := Rect(Source.Width - BorderWidth, 0, Source.Width, Source.Height);
    R := Rect(ARect.Right - BorderWidth, ARect.Top, ARect.Right, ARect.Bottom);
    ACanvas.CopyRect(R, Source.Canvas, SR);

    SR := Rect(BorderWidth, 0, Source.Width - BorderWidth, Source.Height);
    R := Rect(ARect.Left + BorderWidth, ARect.Top, ARect.Right - BorderWidth, ARect.Bottom);
    ACanvas.CopyRect(R, Source.Canvas, SR);
end;

procedure TsuiProgressBar.Paint;
var
    nProgressWidth : Integer;
    Buf : TBitmap;
    R : TRect;
    OutUIStyle : TsuiUIStyle;
    B : Boolean;
begin
    Buf := TBitmap.Create();
    Buf.Width := ClientWidth;
    Buf.Height := ClientHeight;

⌨️ 快捷键说明

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