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

📄 bsbuttongroup.pas

📁 一套非常优秀的皮肤组件包
💻 PAS
📖 第 1 页 / 共 5 页
字号:
begin
  if FShowBorder
  then
    PaintBorder
  else
    inherited;
end;

procedure TbsSkinButtonGroup.PaintBorder;
begin
  if (SkinData <> nil) and (not SkinData.Empty) and
     (SkinData.GetControlIndex('panel') <> -1)
  then
    PaintSkinBorder
  else
    PaintDefaultBorder;  
end;

procedure TbsSkinButtonGroup.PaintDefaultBorder;
var
  DC: HDC;
  Cnvs: TControlCanvas;
  R: TRect;
begin
  DC := GetWindowDC(Handle);
  Cnvs := TControlCanvas.Create;
  Cnvs.Handle := DC;
  R := Rect(0, 0, Width, Height);
  InflateRect(R, -2, -2);

  if R.Bottom > R.Top
  then
    ExcludeClipRect(Cnvs.Handle,R.Left, R.Top, R.Right, R.Bottom);

  with Cnvs do
  begin
    Pen.Color := clBtnShadow;
    Brush.Style := bsClear;
    Rectangle(0, 0, Width, Height);
    Pen.Color := clBtnFace;
    Rectangle(1, 1, Width - 1, Height - 1);
  end;
  Cnvs.Handle := 0;
  ReleaseDC(Handle, DC);
  Cnvs.Free;
end;


procedure TbsSkinButtonGroup.PaintSkinBorder;
var
  LeftBitMap, TopBitMap, RightBitMap, BottomBitMap: TBitMap;
  DC: HDC;
  Cnvs: TControlCanvas;
  OX, OY: Integer;
  PanelData: TbsDataSkinPanelControl;
  CIndex: Integer;
  FSkinPicture: TBitMap;
  NewLTPoint, NewRTPoint, NewLBPoint, NewRBPoint: TPoint;
  NewClRect: TRect;
begin
  CIndex := SkinData.GetControlIndex('panel');
  PanelData := TbsDataSkinPanelControl(SkinData.CtrlList[CIndex]);

  DC := GetWindowDC(Handle);
  Cnvs := TControlCanvas.Create;
  Cnvs.Handle := DC;
  LeftBitMap := TBitMap.Create;
  TopBitMap := TBitMap.Create;
  RightBitMap := TBitMap.Create;
  BottomBitMap := TBitMap.Create;
  //
  with PanelData do
  begin
  OX := Width - RectWidth(SkinRect);
  OY := Height - RectHeight(SkinRect);
  NewLTPoint := LTPoint;
  NewRTPoint := Point(RTPoint.X + OX, RTPoint.Y);
  NewLBPoint := Point(LBPoint.X, LBPoint.Y + OY);
  NewRBPoint := Point(RBPoint.X + OX, RBPoint.Y + OY);
  NewClRect := Rect(ClRect.Left, ClRect.Top,
    ClRect.Right + OX, ClRect.Bottom + OY);
  //
  FSkinPicture := TBitMap(FSD.FActivePictures.Items[panelData.PictureIndex]);
  CreateSkinBorderImages(LTPoint, RTPoint, LBPoint, RBPoint, ClRect,
      NewLTPoint, NewRTPoint, NewLBPoint, NewRBPoint, NewCLRect,
      LeftBitMap, TopBitMap, RightBitMap, BottomBitMap,
      FSkinPicture, SkinRect, Width, Height, False, False, False, False);
  end;
  if NewClRect.Bottom > NewClRect.Top
  then
    ExcludeClipRect(Cnvs.Handle,
      NewClRect.Left, NewClRect.Top, NewClRect.Right, NewClRect.Bottom);

  Cnvs.Draw(0, 0, TopBitMap);
  Cnvs.Draw(0, TopBitMap.Height, LeftBitMap);
  Cnvs.Draw(Width - RightBitMap.Width, TopBitMap.Height, RightBitMap);
  Cnvs.Draw(0, Height - BottomBitMap.Height, BottomBitMap);
  //
  TopBitMap.Free;
  LeftBitMap.Free;
  RightBitMap.Free;
  BottomBitMap.Free;
  Cnvs.Handle := 0;
  ReleaseDC(Handle, DC);
  Cnvs.Free;
end;

procedure TbsSkinButtonGroup.WMSIZE;
begin
  inherited;
  if FShowBorder then PaintBorder;
end;

procedure TbsSkinButtonGroup.WMNCCALCSIZE;
var
  PanelData: TbsDataSkinPanelControl;
  CIndex: Integer;
begin
  if FShowBorder
  then
    begin
      if (SkinData <> nil) and (not SkinData.Empty) and
         (SkinData.GetControlIndex('panel') <> -1)
      then
        begin
          CIndex := SkinData.GetControlIndex('panel');
          PanelData := TbsDataSkinPanelControl(SkinData.CtrlList[CIndex]);
          with PanelData, TWMNCCALCSIZE(Message).CalcSize_Params^.rgrc[0] do
          begin
            Inc(Left, ClRect.Left);
            Inc(Top,  ClRect.Top);
            Dec(Right, RectWidth(SkinRect) - ClRect.Right);
            Dec(Bottom, RectHeight(SkinRect) - ClRect.Bottom);
            if Right < Left then Right := Left;
            if Bottom < Top then Bottom := Top;
          end;
        end
      else
        begin
          with TWMNCCALCSIZE(Message).CalcSize_Params^.rgrc[0] do
          begin
            Inc(Left, 2);
            Inc(Top,  2);
            Dec(Right, 2);
            Dec(Bottom, 2);
            if Right < Left then Right := Left;
            if Bottom < Top then Bottom := Top;
          end;
        end;
    end
  else
    inherited;
end;

procedure TbsSkinButtonGroup.WMEraseBkgnd;
begin
  if not FromWMPaint
  then
    PaintWindow(Message.DC);
end;

procedure TbsSkinButtonGroup.SetShowBorder;
begin
  if FShowBorder <> Value
  then
    begin
      FShowBorder := Value;
      RecreateWnd;
   end;
end;

function TbsSkinButtonGroup.CreateButton: TbsGrpButtonItem;
begin
  Result := GetButtonClass.Create(FButtonItems);
end;

procedure TbsSkinButtonGroup.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
end;

destructor TbsSkinButtonGroup.Destroy;
begin
  if FSkinScrollBar <> nil then FSkinScrollBar.Free;
  FSkinScrollBar := nil;
  FDragImageList.Free;
  FButtonItems.Free;
  FImageChangeLink.Free;
  inherited;
end;

function TbsSkinButtonGroup.GetButtonClass: TbsGrpButtonItemClass;
begin
  Result := TbsGrpButtonItem;
end;

function TbsSkinButtonGroup.GetButtonRect(const Index: Integer): TRect;
var
  ButtonsPerRow: Integer;
  HiddenCount: Integer;
  Item: Integer;
  Row, Col: Integer;
begin
  ButtonsPerRow := CalcButtonsPerRow;
  HiddenCount := FHiddenItems*ButtonsPerRow;
  { Subtract out what we can't see }
  Item := Index - HiddenCount;

  Row := Item div ButtonsPerRow;
  Result.Top := Row*FButtonHeight;
  if bsgboFullSize in FButtonOptions then
  begin
    Result.Left := 0;
    Result.Right := ClientWidth - GetScrollSize;
  end
  else
  begin
    Col := Item mod ButtonsPerRow;
    Result.Left := Col*FButtonWidth;
    Result.Right := Result.Left + FButtonWidth;
  end;
  Result.Bottom := Result.Top + FButtonHeight;
end;

function TbsSkinButtonGroup.GetButtonsClass: TbsGrpButtonItemsClass;
begin
  Result := TbsGrpButtonItems;
end;

procedure TbsSkinButtonGroup.ImageListChange(Sender: TObject);
begin
  UpdateAllButtons;
end;

procedure TbsSkinButtonGroup.Notification(AComponent: TComponent;
  Operation: TOperation);
var
  I: Integer;
begin
  inherited;
  if (Operation = opRemove) then
  begin
    if AComponent = Images then
      Images := nil
    else
      if AComponent is TBasicAction then
        for I := 0 to FButtonItems.Count - 1 do
          if AComponent = FButtonItems[I].Action then
            FButtonItems[I].Action := nil;
  end;
end;

procedure TbsSkinButtonGroup.Paint;

procedure DrawSkinBGRect(R: TRect);
var
  PanelData: TbsDataSkinPanelControl;
  w, h, X, Y, XCnt, YCnt: Integer;
  Buffer: TBitMap;
  FSkinPicture: TBitMap;
begin
  PanelData := TbsDataSkinPanelControl(SkinData.CtrlList[SkinData.GetControlIndex('panel')]);
  Buffer := TBitMap.Create;
  with PanelData do
  begin
    FSkinPicture := TBitMap(SkinData.FActivePictures.Items[PictureIndex]);
    Buffer.Width := RectWidth(ClRect);
    Buffer.Height := RectHeight(ClRect);
    Buffer.Canvas.CopyRect(Rect(0, 0, Buffer.Width, Buffer.Height),
        FSkinPicture.Canvas,
          Rect(SkinRect.Left + ClRect.Left, SkinRect.Top + ClRect.Top,
               SkinRect.Left + ClRect.Right,
               SkinRect.Top + ClRect.Bottom));
      w := RectWidth(ClRect);
      h := RectHeight(ClRect);
      XCnt := RectWidth(R) div w;
      YCnt := RectHeight(R) div h;
      for X := 0 to XCnt do
      for Y := 0 to YCnt do
        Canvas.Draw(X * w + R.Left, Y * h + R.Top, Buffer);
  end;
  Buffer.Free;
end;

var
  ButtonCount: Integer;
  RowsSeen, ButtonsPerRow: Integer;
  HiddenCount, VisibleCount: Integer;
  CurOffset: TPoint;
  RowPos: Integer;
  X: Integer;
  ItemRect: TRect;
  ActualWidth, ActualHeight: Integer;
  DrawState: TbsButtonDrawState;
begin
  //
  Canvas.Brush.Color := clBtnFace;
  //
  ButtonCount := FButtonItems.Count;
  if ButtonCount > 0 then
  begin
    RowsSeen := CalcRowsSeen;
    ButtonsPerRow := CalcButtonsPerRow;
    HiddenCount := FHiddenItems * ButtonsPerRow;
    VisibleCount := RowsSeen*ButtonsPerRow;
      
    if (HiddenCount + VisibleCount) > ButtonCount then
      VisibleCount := ButtonCount - HiddenCount; { We can see more items than we have }

    CurOffset.X := 0; { Start at the very top left }
    CurOffset.Y := 0;
    RowPos := 0;
    if bsgboFullSize in ButtonOptions then
      ActualWidth := ClientWidth - GetScrollSize
    else
      ActualWidth := FButtonWidth;
    ActualHeight := FButtonHeight;

    for X := HiddenCount to HiddenCount + VisibleCount - 1 do
    begin
      ItemRect := Bounds(CurOffset.X, CurOffset.Y, ActualWidth, ActualHeight);
      DrawState := [];
      if X = FHotIndex then
      begin
        Include(DrawState, bsbdsHot);
        if X = FDownIndex then
          Include(DrawState, bsbdsDown);
      end;
      if X = FItemIndex then
        Include(DrawState, bsbdsSelected);

      if X = FInsertTop then
        Include(DrawState, bsbdsInsertTop)
      else if X = FInsertBottom then
        Include(DrawState, bsbdsInsertBottom)
      else if X = FInsertRight then
        Include(DrawState, bsbdsInsertRight)
      else if X = FInsertLeft then
        Include(DrawState, bsbdsInsertLeft);
      if (X = FFocusIndex) and Focused then
        Include(DrawState, bsbdsFocused);

      DrawButton(X, Canvas, ItemRect, DrawState);
      Inc(RowPos);
      { Should we go to the next line? }
      if RowPos >= ButtonsPerRow then
      begin
        { Erase to the end }
        Inc(CurOffset.X, ActualWidth);
         if (SkinData <> nil) and (not Skindata.Empty) and
            (SkinData.GetControlIndex('panel') <> -1)
        then
          DrawSkinBGRect(Rect(CurOffset.X, CurOffset.Y, ClientWidth - GetScrollSize,
          CurOffset.Y + ActualHeight))
        else
          DoFillRect(Rect(CurOffset.X, CurOffset.Y, ClientWidth - GetScrollSize,
          CurOffset.Y + ActualHeight));
        RowPos := 0;
        CurOffset.X := 0;
        Inc(CurOffset.Y, ActualHeight);
      end
      else
        Inc(CurOffset.X, ActualWidth);
    end;
    { Erase to the end }
    if (SkinData <> nil) and (not Skindata.Empty) and
       (SkinData.GetControlIndex('panel') <> -1)
    then
      DrawSkinBGRect(Rect(CurOffset.X, CurOffset.Y,
        ClientWidth - GetScrollSize, CurOffset.Y + ActualHeight))
    else
      DoFillRect(Rect(CurOffset.X, CurOffset.Y,
        ClientWidth - GetScrollSize, CurOffset.Y + ActualHeight));
    { Erase to the bottom }
    if (SkinData <> nil) and (not Skindata.Empty) and
       (SkinData.GetControlIndex('panel') <> -1)
    then
      DrawSkinBGRect(Rect(0, CurOffset.Y + ActualHeight, ClientWidth - GetScrollSize, ClientHeight))
    else
      DoFillRect(Rect(0, CurOffset.Y + ActualHeight, ClientWidth - GetScrollSize, ClientHeight));
  end
  else
    begin
      if (SkinData <> nil) and (not Skindata.Empty) and
         (SkinData.GetControlIndex('panel') <> -1)
      then
        DrawSkinBGRect(Rect(0, 0, ClientWidth - GetScrollSize, ClientHeight))
      else
        DoFillRect(ClientRect);
    end;  
end;

function TbsSkinButtonGroup.CalcButtonsPerRow: Integer;
begin
  if bsgboFullSize in ButtonOptions then
    Result := 1
  else
  begin
    Result := (ClientWidth - GetScrollSize) div FButtonWidth;
    if Result = 0 then
      Result := 1;
  end;
end;

function TbsSkinButtonGroup.CalcRowsSeen: Integer;
begin
  Result := ClientHeight div FButtonHeight
end;

procedure TbsSkinButtonGroup.Resize;
var
  RowsSeen: Integer;
  ButtonsPerRow: Integer;
  TotalRowsNeeded: Integer;
  ScrollInfo: TScrollInfo;
begin
  inherited;
  { Reset the original position }
  FHiddenItems := 0;

  { How many rows can we show? }
  RowsSeen := CalcRowsSeen;
  ButtonsPerRow := CalcButtonsPerRow;

  { Do we have to take the scrollbar into consideration? }
  if (ButtonsPerRow*RowsSeen < FButtonItems.Count) then

⌨️ 快捷键说明

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