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

📄 suibutton.pas

📁 suipack ver5控件 suipack ver5控件 suipack ver5控件 suipack ver5控件 suipack ver5控件
💻 PAS
📖 第 1 页 / 共 4 页
字号:
    CheckStateChanged();
end;

procedure TsuiCheckBox.SetEnabled(Value: Boolean);
begin
    inherited;
    Repaint();
end;

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

procedure TsuiCheckBox.SetState(const Value: TCheckBoxState);
begin
    if Value = cbChecked then
        Checked := true
    else
        Checked := false;
end;

procedure TsuiCheckBox.SetTransparent(const Value: Boolean);
begin
    m_Transparent := Value;
    Repaint();
end;

procedure TsuiCheckBox.SetUIStyle(const Value: TsuiUIStyle);
begin
    m_UIStyle := Value;
    Repaint();
end;

procedure TsuiCheckBox.Toggle;
begin

end;

function TsuiCheckBox.WantKeyUp: Boolean;
begin
    Result := True;
end;

procedure TsuiCheckBox.WMERASEBKGND(var Msg: TMessage);
begin
    // do nothing
end;

procedure TsuiCheckBox.WMKeyUp(var Msg: TWMKeyUp);
begin
    inherited;

    if not WantKeyUp() then
        Exit;
    if (
        ((Msg.CharCode = VK_SPACE) or (Msg.CharCode = VK_RETURN)) and
        Focused
    ) then
    begin
        if Enabled then
        begin
            Repaint();
            Click();
        end;
    end;
end;

procedure TsuiCheckBox.WMKillFocus(var Msg: TWMKillFocus);
begin
    inherited;

    Repaint();
end;

procedure TsuiCheckBox.WMSetFocus(var Msg: TWMSetFocus);
begin
    inherited;

    Repaint();
end;

{ TsuiRadioButton }

procedure TsuiRadioButton.CheckStateChanged;
begin
    if Checked then
    begin
        UnCheckGroup();
        if csLoading in ComponentState then
            Exit;
        if Assigned(OnClick) then
            OnClick(self);
    end;
end;

constructor TsuiRadioButton.Create(AOwner: TComponent);
begin
    inherited;
    ControlStyle := ControlStyle + [csDoubleClicks];
end;

procedure TsuiRadioButton.DoClick;
begin
    if not Checked then
        Checked := true;
end;

function TsuiRadioButton.GetPicThemeIndex: Integer;
begin
    Result := SUI_THEME_RADIOBUTTON_IMAGE;
end;

function TsuiRadioButton.GetPicTransparent: Boolean;
begin
    Result := true;
end;

procedure TsuiRadioButton.UnCheckGroup;
var
    i : Integer;
begin
    if Parent = nil then
        Exit;
    for i := 0 to Parent.ControlCount - 1 do
    begin
        if not (Parent.Controls[i] is TsuiRadioButton) then
            continue;
        if (Parent.Controls[i] as TsuiRadioButton).GroupIndex <> GroupIndex then
            continue;
        if (Parent.Controls[i] = self) then
            continue;
        (Parent.Controls[i] as TsuiRadioButton).Checked := false;
    end;
end;

function TsuiRadioButton.WantKeyUp: Boolean;
begin
    Result := False;
end;

procedure TsuiRadioButton.WMSetFocus(var Msg: TWMSetFocus);
var
    Buf : array[0..MAX_PATH - 1] of Char;
begin
    inherited;
    GetClassName(Msg.FocusedWnd, Buf, MAX_PATH);
    if (Buf = 'TsuiRadioGroupButton') and (Msg.FocusedWnd <> Handle) then
        Click();
end;

{ TsuiImageButton }

procedure TsuiImageButton.AutoSizeChanged;
begin
    if Parent = nil then
        Exit;

    if not m_AutoSize then
        Exit;

    if (m_PicNormal.Graphic <> nil) then
    begin
        Height := m_PicNormal.Height;
        Width := m_PicNormal.Width;
    end;
end;

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

    m_PicDisabled := TPicture.Create();
    m_PicNormal := TPicture.Create();
    m_PicMouseDown := TPicture.Create();
    m_PicMouseOn := TPicture.Create();

    m_Stretch := false;
    m_DrawFocused := false;
end;

destructor TsuiImageButton.Destroy;
begin
    m_PicMouseOn.Free();
    m_PicMOuseOn := nil;

    m_PicMouseDown.Free();
    m_PicMouseDown := nil;

    m_PicNormal.Free();
    m_PicMouseDown := nil;

    m_PicDisabled.Free();
    m_PicDisabled := nil;

    inherited;
end;

function TsuiImageButton.GetUIStyle2: TsuiUIStyle;
begin
    Result := FromThemeFile;
end;

procedure TsuiImageButton.PaintButtonDisabled(Buf: TBitmap);
begin
    if m_PicDisabled.Graphic <> nil then
        Buf.Assign(m_PicDisabled)
    else if m_PicNormal.Graphic <> nil then
        Buf.Assign(m_PicNormal);
end;

procedure TsuiImageButton.PaintButtonMouseDown(Buf: TBitmap);
begin
    if m_PicMouseDown.Graphic <> nil then
        Buf.Assign(m_PicMouseDown)
    else if m_PicNormal.Graphic <> nil then
        Buf.Assign(m_PicNormal);
end;

procedure TsuiImageButton.PaintButtonMouseOn(Buf: TBitmap);
begin
    if m_PicMouseOn.Graphic <> nil then
        Buf.Assign(m_PicMouseOn)
    else if m_PicNormal.Graphic <> nil then
        Buf.Assign(m_PicNormal);
end;

procedure TsuiImageButton.PaintButtonNormal(Buf: TBitmap);
begin
    if m_PicNormal.Graphic <> nil then
        Buf.Assign(m_PicNormal);
end;

procedure TsuiImageButton.PaintFocus(ACanvas: TCanvas);
begin
    if m_DrawFocused then
        inherited
end;

procedure TsuiImageButton.PaintPic(ACanvas: TCanvas; Bitmap: TBitmap);
begin
    if Bitmap = nil then
        Exit;
    if (Bitmap.Width = 0) or (Bitmap.Height = 0) then
        Exit;

    Bitmap.TransparentColor := Bitmap.Canvas.Pixels[0, 0];

    if m_Stretch then
        Acanvas.StretchDraw(rect(0, 0, Width, Height), Bitmap)
    else
        ACanvas.Draw(0, 0, Bitmap);
end;

procedure TsuiImageButton.SetDrawFocused(const Value: Boolean);
begin
    m_DrawFocused := Value;
    Repaint();
end;

procedure TsuiImageButton.SetPicDisabledF(const Value: TPicture);
begin
    m_PicDisabled.Assign(Value);
    AutoSizeChanged();
    Repaint();
end;

procedure TsuiImageButton.SetPicMouseDownF(const Value: TPicture);
begin
    m_PicMouseDown.Assign(Value);
    AutoSizeChanged();
    Repaint();
end;

procedure TsuiImageButton.SetPicMouseOnF(const Value: TPicture);
begin
    m_PicMouseOn.Assign(Value);
    AutoSizeChanged();
    Repaint();
end;

procedure TsuiImageButton.SetPicNormalF(const Value: TPicture);
begin
    m_PicNormal.Assign(Value);
    AutoSizeChanged();
    Repaint();
end;

procedure TsuiImageButton.SetStretch(const Value: Boolean);
begin
    m_Stretch := Value;

    Repaint();
end;

{ TsuiControlButton }

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

    m_ThemeID := 0;
    m_PicIndex := 0;
    m_PicCount := 0;
    TabStop := false;
    UIStyle := SUI_THEME_DEFAULT;
    FileTheme := nil;
end;

procedure TsuiControlButton.PaintButtonDisabled(Buf: TBitmap);
var
    OutUIStyle : TsuiUIStyle;
begin
    if UsingFileTheme(FileTheme, UIStyle, OutUIStyle) then
        m_FileTheme.GetBitmap(m_ThemeID, Buf, m_PicCount, m_PicIndex)
    else
        GetInsideThemeBitmap(OutUIStyle, m_ThemeID, Buf, m_PicCount, m_PicIndex);
end;

procedure TsuiControlButton.PaintButtonMouseDown(Buf: TBitmap);
var
    OutUIStyle : TsuiUIStyle;
begin
    if UsingFileTheme(FileTheme, UIStyle, OutUIStyle) then
        m_FileTheme.GetBitmap(m_ThemeID, Buf, m_PicCount, m_PicIndex)
    else
        GetInsideThemeBitmap(OutUIStyle, m_ThemeID, Buf, m_PicCount, m_PicIndex);
end;

procedure TsuiControlButton.PaintButtonMouseOn(Buf: TBitmap);
var
    OutUIStyle : TsuiUIStyle;
begin
    if UsingFileTheme(FileTheme, UIStyle, OutUIStyle) then
        m_FileTheme.GetBitmap(m_ThemeID, Buf, m_PicCount, m_PicIndex + 1)
    else
        GetInsideThemeBitmap(OutUIStyle, m_ThemeID, Buf, m_PicCount, m_PicIndex + 1);
end;

procedure TsuiControlButton.PaintButtonNormal(Buf: TBitmap);
var
    OutUIStyle : TsuiUIStyle;
begin
    if UsingFileTheme(FileTheme, UIStyle, OutUIStyle) then
        m_FileTheme.GetBitmap(m_ThemeID, Buf, m_PicCount, m_PicIndex)
    else
        GetInsideThemeBitmap(OutUIStyle, m_ThemeID, Buf, m_PicCount, m_PicIndex);
    Height := Buf.Height;
    Width := Buf.Width;
end;

procedure TsuiControlButton.PaintPic(ACanvas: TCanvas; Bitmap: TBitmap);
begin
    if Bitmap = nil then
        Exit;
    if (Bitmap.Width = 0) or (Bitmap.Height = 0) then
        Exit;

    Bitmap.TransparentColor := Bitmap.Canvas.Pixels[0, 0];
    ACanvas.Draw(0, 0, Bitmap);
    Width := Bitmap.Width;
    Height := Bitmap.Height;
end;

procedure TsuiControlButton.SetPicCount(const Value: Integer);
begin
    m_PicCount := Value;
    Repaint();
end;

procedure TsuiControlButton.SetPicIndex(const Value: Integer);
begin
    m_PicIndex := Value;
    Repaint();
end;

procedure TsuiControlButton.SetThemeID(const Value: Integer);
begin
    m_ThemeID := Value;
    Repaint();
end;

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

{ TsuiToolBarSpeedButton }

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

    m_Glyph := TBitmap.Create();
    Height := 18;
    Width := 18;
end;

destructor TsuiToolBarSpeedButton.Destroy;
begin
    m_Glyph.Free();

    inherited;
end;

procedure TsuiToolBarSpeedButton.MouseEnter(var Msg: TMessage);
begin
    m_MouseIn := true;
    Repaint();    
end;

procedure TsuiToolBarSpeedButton.MouseLeave(var Msg: TMessage);
begin
    m_MouseIn := false;
    Repaint();
end;

procedure TsuiToolBarSpeedButton.Paint;
var
    Buf : TBitmap;
begin
    Glyph.Transparent := true;
    Buf := TBitmap.Create();
    Buf.Width := Width;
    Buf.Height := Height;
    Buf.Canvas.Brush.Color := Color;
    Buf.Canvas.FillRect(ClientRect);
    if not Glyph.Empty then
    begin
        if m_MouseIn then
        begin
            Buf.Canvas.Brush.Color := clBlack;
            Buf.Canvas.FrameRect(ClientRect);
        end;

        Buf.Canvas.Draw(1, 1, Glyph);
    end;
    Canvas.Draw(0, 0, Buf);
    Buf.Free();
end;

procedure TsuiToolBarSpeedButton.SetGlyph(const Value: TBitmap);
begin
    m_Glyph.Assign(Value);
end;

procedure TsuiToolBarSpeedButton.WMERASEBKGND(var Msg: TMessage);
begin
    // do nothing
end;

{ TsuiArrowButton }

procedure TsuiArrowButton.PaintPic(ACanvas: TCanvas; Bitmap: TBitmap);
var
    W, H: Integer;
begin
    SpitDraw(Bitmap, ACanvas, ClientRect, PicTransparent);
    ACanvas.Brush.Color := clBlack;
    ACanvas.Pen.Color := clBlack;
    W := (Width - 6) div 2;
    H := (Height - 3) div 2;
    if m_Arrow = suiUp then
        ACanvas.Polygon([Point(W, H + 3), Point(W + 3, H), Point(W + 6, H + 3)]);
    if m_Arrow = suiDown then
        ACanvas.Polygon([Point(W, H), Point(W + 3, H + 3), Point(W + 6, H)]);
end;

procedure TsuiArrowButton.PaintText(ACanvas: TCanvas; Text: String);
begin
    // do nothing
end;

procedure TsuiArrowButton.SetArrow(const Value: TsuiArrowButtonType);
begin
    m_Arrow := Value;
    Repaint();
end;

procedure TsuiArrowButton.UIStyleChanged;
var
    OutUIStyle : TsuiUIStyle;
begin
    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
        Transparent := m_FileTheme.GetBool(SUI_THEME_BUTTON_TRANSPARENT_BOOL)
    else
        Transparent := GetInsideThemeBool(OutUIStyle, SUI_THEME_BUTTON_TRANSPARENT_BOOL);
end;

end.

⌨️ 快捷键说明

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