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

📄 suiprogressbar.pas

📁 SUIPack是一款为Delphi和C++Builder开发的所见即所得的界面增强VCL组件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    if m_Orientation = suiHorizontal then
    begin
        if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) and (m_B1 <> nil) and (m_B2 <> nil) and (m_B3 <> nil) then
        begin
            Buf.Canvas.Brush.Color := Color;
            Buf.Canvas.FillRect(ClientRect);
            R := Rect(0, 0, Buf.Width, Buf.Height);

            Inc(R.Left, m_B1.Width);
            Dec(R.Right, m_B3.Width);
            R.Right := GetWidthFromPosition(Buf.Width - m_B1.Width - m_B3.Width) + m_B1.Width;

            SpitDrawVertical(m_B1, Buf.Canvas, Rect(0, R.Top, R.Left, R.Bottom), 2);
            SpitDrawVertical(m_Picture.Bitmap, Buf.Canvas, R, 2);
            R := Rect(R.Right, R.Top, Buf.Width - m_B3.Width, R.Bottom);
            SpitDrawVertical(m_B2, Buf.Canvas, R, 2);
            R := Rect(Buf.Width - m_B3.Width, R.Top, Buf.Width, R.Bottom);
            SpitDrawVertical(m_B3, Buf.Canvas, R, 2);
            B := true;
        end
        else
        begin
            nProgressWidth := GetWidthFromPosition(Buf.Width - 1);
            if nProgressWidth = 0 then
                Inc(nProgressWidth);

            if m_Picture.Graphic <> nil then
            begin
                R := Rect(1, 1, nProgressWidth, Buf.Height - 1);
                Buf.Canvas.StretchDraw(R, m_Picture.Graphic);
            end;

            Buf.Canvas.Brush.Color := m_Color;
            R := Rect(nProgressWidth, 1, Buf.Width - 1, Buf.Height - 1);
            Buf.Canvas.FillRect(R);
            B := false;
        end;
    end
    else
    begin
        if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) and (m_B1 <> nil) and (m_B2 <> nil) and (m_B3 <> nil) then
        begin
            Buf.Canvas.Brush.Color := Color;
            Buf.Canvas.FillRect(ClientRect);
            R := Rect(0, 0, Buf.Width, Buf.Height);

            Dec(R.Bottom, m_B1.Height);
            Inc(R.Top, m_B3.Height);
            R.Top := Buf.Height - m_B3.Height - GetWidthFromPosition(Buf.Height - m_B3.Height - m_B1.Height);

            SpitDrawHorizontal(m_B1, Buf.Canvas, Rect(0, R.Bottom, R.Right, R.Bottom + m_B1.Height), 2);
            SpitDrawHorizontal(m_Picture.Bitmap, Buf.Canvas, R, 2);
            R := Rect(R.Left, m_B3.Height, R.Right, R.Top);
            SpitDrawHorizontal(m_B2, Buf.Canvas, R, 2);
            R := Rect(R.Left, 0, R.Right, m_B3.Height);
            SpitDrawHorizontal(m_B3, Buf.Canvas, R, 2);
            B := true;
        end
        else
        begin
            nProgressWidth := Buf.Height - 1 - GetWidthFromPosition(Buf.Height - 1);
            if nProgressWidth = 0 then
                Inc(nProgressWidth);

            if m_Picture.Graphic <> nil then
            begin
                R := Rect(1, Buf.Height - 2, Buf.Width - 1, nProgressWidth - 1);
                Buf.Canvas.StretchDraw(R, m_Picture.Graphic);
            end;

            Buf.Canvas.Brush.Color := m_Color;
            R := Rect(1, nProgressWidth, Buf.Width - 1, 1);
            Buf.Canvas.FillRect(R);
            m_ShowCaption := false;
            B := false;
        end;
    end;

    if m_ShowCaption then
    begin
        Buf.Canvas.Font.Color := m_CaptionColor;
        Buf.Canvas.Brush.Style := bsClear;
        if m_SmartShowCaption and (m_Position = m_Min) then
        else
            Buf.Canvas.TextOut(((Buf.Width - Buf.Canvas.TextWidth(Caption)) div 2), (Buf.Height - Buf.Canvas.TextHeight(Caption)) div 2, Caption);
    end;

    if not B then
    begin
        Buf.Canvas.Brush.Color := m_BorderColor;
        Buf.Canvas.FrameRect(ClientRect);
    end;

    BitBlt(Canvas.Handle, 0, 0, Buf.Width, Buf.Height, Buf.Canvas.Handle, 0, 0, SRCCOPY);
    Buf.Free();
end;

procedure TsuiProgressBar.SetBorderColor(const Value: TColor);
begin
    m_BorderColor := Value;

    Repaint();
end;

procedure TsuiProgressBar.SetCaptionColor(const Value: TColor);
begin
    m_CaptionColor := Value;

    Repaint();
end;

procedure TsuiProgressBar.SetColor(const Value: TColor);
begin
    m_Color := Value;

    Repaint();
end;

procedure TsuiProgressBar.SetFileTheme(const Value: TsuiFileTheme);
begin
    m_FileTheme := Value;
    SetUIStyle(m_UIStyle);
end;

procedure TsuiProgressBar.SetMax(const Value: Integer);
begin
    m_Max := Value;

    UpdateProgress();
end;

procedure TsuiProgressBar.SetMin(const Value: Integer);
begin
    m_Min := Value;

    UpdateProgress();
end;

procedure TsuiProgressBar.SetOrientation(
  const Value: TsuiProgressBarOrientation);
begin
    m_Orientation := Value;

    UpdatePicture();
end;

procedure TsuiProgressBar.SetPicture(const Value: TPicture);
begin
    m_Picture.Assign(Value);

    Repaint();
end;

procedure TsuiProgressBar.SetPosition(const Value: Integer);
begin
    m_Position := Value;

    UpdateProgress();
end;

procedure TsuiProgressBar.SetShowCaption(const Value: Boolean);
begin
    m_ShowCaption := Value;

    Repaint();
end;

procedure TsuiProgressBar.SetSmartShowCaption(const Value: Boolean);
begin
    m_SmartShowCaption := Value;

    Repaint();
end;

procedure TsuiProgressBar.SetUIStyle(const Value: TsuiUIStyle);
begin
    m_UIStyle := Value;

    UpdatePicture();
end;

procedure TsuiProgressBar.StepBy(Delta: Integer);
begin
    Position := Position + Delta;
end;

procedure TsuiProgressBar.StepIt;
begin
    Position := Position + 1;
end;

procedure TsuiProgressBar.UpdatePicture;
var
    OutUIStyle : TsuiUIStyle;
    TempBuf : TBitmap;
begin
    m_SelfChanging := true;
    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
    begin
        m_Picture.Bitmap.Assign(m_FileTheme.GetBitmap(SKIN2_PROGRESSBAR2));
        Color := m_FileTheme.GetColor(SKIN2_CONTROLCOLOR);
        BorderColor := m_FileTheme.GetColor(SKIN2_CONTROLBORDERCOLOR);
        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;
        m_B1 := TBitmap.Create();
        m_B1.PixelFormat := pf24Bit;
        m_B1.Assign(m_FileTheme.GetBitmap(SKIN2_PROGRESSBAR1));
        m_B2 := TBitmap.Create();
        m_B2.PixelFormat := pf24Bit;
        m_B2.Assign(m_FileTheme.GetBitmap(SKIN2_PROGRESSBAR3));
        m_B3 := TBitmap.Create();
        m_B3.PixelFormat := pf24Bit;
        m_B3.Assign(m_FileTheme.GetBitmap(SKIN2_PROGRESSBAR4));

        if Orientation = suiVertical then
        begin
            RoundPicture(m_B1);
            RoundPicture(m_B2);
            RoundPicture(m_B3);            
        end;
    end
    else
    begin
        GetInsideThemeBitmap(OutUIStyle, SUI_THEME_PROGRESSBAR_IMAGE, m_Picture.Bitmap);
        Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BACKGROUND_COLOR);
        BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BORDER_COLOR);
    end;

    if m_Orientation = suiVertical then
    begin
        TempBuf := TBitmap.Create();
        TempBuf.Assign(m_Picture.Bitmap);
        RoundPicture(TempBuf);
        m_Picture.Bitmap.Assign(TempBuf);
        TempBuf.Free();
    end;
    m_SelfChanging := false;
    Repaint();
end;

procedure TsuiProgressBar.UpdateProgress;
begin
    Caption := IntToStr(GetPercentFromPosition()) + '%';

    Repaint();
end;

procedure TsuiProgressBar.WMERASEBKGND(var Msg: TMessage);
begin
    // Do nothing
end;

end.

⌨️ 快捷键说明

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