TsTrackBar Add feature : ShowProgressFrom

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #53801
    JM-DG
    Participant

      If you want to modify the file yourself, here are the modifications :

      Code:
      private
      FShowProgressFrom: Integer;
      procedure SetShowProgressFrom(Value: Integer);

      published
      property ShowProgressFrom: Integer read FShowProgressFrom write SetShowProgressFrom default 0;

      Add to TsTrackBar.Create

      Code:
      FShowProgressFrom := 0;

      Replace procedure TsTrackBar.PaintBar with

      Code:
      procedure TsTrackBar.PaintBar;
      var
      w, h, i, j, pos: integer;
      aRect, sRect: TRect;
      CI: TCacheInfo;
      begin
      aRect := ChannelRect;
      i := SkinData.SkinManager.GetMaskIndex(TrackBarNdx, s_SliderChannelMask);
      if SkinData.SkinManager.IsValidImgIndex(i) then begin
      CI := MakeCacheInfo(FCommonData.FCacheBmp);
      pos := SendMessage(Handle, TBM_GETPOS, 0, 0);

      case Orientation of
      trHorizontal: begin
      h := HeightOfImage(SkinData.SkinManager.ma) – 1;
      w := HeightOf(aRect);
      aRect.Top := aRect.Top + (w – h) div 2;
      aRect.Bottom := aRect.Top + h;
      InflateRect(aRect, -1, 0);
      DrawSkinRect(FCommonData.FCacheBmp, aRect, CI, SkinData.SkinManager.ma, integer(ControlIsActive(FCommonData)), True);
      if ShowProgress then begin
      sRect := aRect;
      i := Round(WidthOf(aRect) * (pos – Min) / (Max – Min));
      j := Round(WidthOf(aRect) * (ShowProgressFrom – Min) / (Max – Min));
      if reversed then
      begin
      if(pos < ShowProgressFrom)then
      begin
      sRect.Left := sRect.Right – j;
      sRect.Right := sRect.Right – i;
      end else
      begin
      sRect.Left := sRect.Right – i;
      sRect.Right := sRect.Right – j;
      end;
      end else
      begin
      if(pos < ShowProgressFrom)then
      begin
      sRect.Right := sRect.Left + j;
      sRect.Left := sRect.Left + i;
      end else
      begin
      sRect.Right := sRect.Left + i;
      sRect.Left := sRect.Left + j;
      end;
      end;

      PaintProgress(sRect, True);
      end;
      end;

      trVertical: begin
      h := WidthOfImage(SkinData.SkinManager.ma) – 1;
      w := WidthOf(aRect);
      aRect.Left := aRect.Left + (w – h) div 2;
      aRect.Right := aRect.Left + h;
      InflateRect(aRect, 0, -1);
      DrawSkinRect(FCommonData.FCacheBmp, aRect, CI, SkinData.SkinManager.ma, integer(ControlIsActive(FCommonData)), True);
      if ShowProgress then begin
      sRect := aRect;
      i := Round(HeightOf(aRect) * (pos – Min) / (Max – Min));
      j := Round(HeightOf(aRect) * (ShowProgressFrom – Min) / (Max – Min));
      if Reversed then
      begin
      if(pos < ShowProgressFrom)then
      begin
      sRect.Top := sRect.Bottom – j;
      sRect.Bottom := sRect.Bottom – i;
      end else
      begin
      sRect.Top := sRect.Bottom – i;
      sRect.Bottom := sRect.Bottom – j;
      end;
      end else begin
      if(pos < ShowProgressFrom)then
      begin
      sRect.Bottom := sRect.Top + j;
      sRect.Top := sRect.Top + i;
      end else
      begin
      sRect.Bottom := sRect.Top + i;
      sRect.Top := sRect.Top + j;
      end;
      end;

      PaintProgress(sRect, False);
      end;
      end;
      end;
      end;

      if Orientation = trHorizontal then
      PaintTicksHor
      else
      PaintTicksVer;
      end;

      Replace procedure TsTrackBar.StdPaintBar with

      Code:
      procedure TsTrackBar.StdPaintBar(Bmp: TBitmap);
      var
      i, j, pos: integer;
      aRect, sRect: TRect;
      {$IFDEF DELPHI7UP}
      Details: TThemedElementDetails;
      te: TThemedTrackBar;
      {$ENDIF}
      begin
      aRect := ChannelRect;
      {$IFDEF DELPHI7UP}
      if acThemesEnabled then begin
      if Orientation = trVertical then
      te := ttbTrack
      else
      te := ttbTrackVert;

      Details := acThemeServices.GetElementDetails(te);
      acThemeServices.DrawElement(Bmp.Canvas.Handle, Details, aRect);
      InflateRect(aRect, -1, -1);
      end
      else
      {$ENDIF}
      begin
      Frame3D(Bmp.Canvas, aRect, clBtnShadow, clBtnHighlight, 1);
      Frame3D(Bmp.Canvas, aRect, cl3DDkShadow, cl3DLight, 1);
      FillDC(Bmp.Canvas.Handle, aRect, clWindow);
      end;
      if ShowProgress then begin
      sRect := aRect;
      pos := SendMessage(Handle, TBM_GETPOS, 0, 0);
      if Orientation = trVertical then begin
      i := Round(HeightOf(aRect) * (pos – Min) / (Max – Min));
      j := Round(HeightOf(aRect) * (ShowProgressFrom – Min) / (Max – Min));
      if Reversed then
      begin
      if(pos < ShowProgressFrom)then
      begin
      sRect.Top := sRect.Bottom – j;
      sRect.Bottom := sRect.Bottom – i;
      end else
      begin
      sRect.Top := sRect.Bottom – i;
      sRect.Bottom := sRect.Bottom – j;
      end;
      end else begin
      if(pos < ShowProgressFrom)then
      begin
      sRect.Bottom := sRect.Top + j;
      sRect.Top := sRect.Top + i;
      end else
      begin
      sRect.Bottom := sRect.Top + i;
      sRect.Top := sRect.Top + j;
      end;
      end;
      end
      else begin
      i := Round(WidthOf(aRect) * (pos – Min) / (Max – Min));
      j := Round(WidthOf(aRect) * (ShowProgressFrom – Min) / (Max – Min));
      if reversed then
      begin
      if(pos < ShowProgressFrom)then
      begin
      sRect.Left := sRect.Right – j;
      sRect.Right := sRect.Right – i;
      end else
      begin
      sRect.Left := sRect.Right – i;
      sRect.Right := sRect.Right – j;
      end;
      end else
      begin
      if(pos < ShowProgressFrom)then
      begin
      sRect.Right := sRect.Left + j;
      sRect.Left := sRect.Left + i;
      end else
      begin
      sRect.Right := sRect.Left + i;
      sRect.Left := sRect.Left + j;
      end;
      end;
      end;

      FillRect32(Bmp, sRect, ColorToRGB(clHighLight));
      end;
      if Orientation = trHorizontal then
      PaintTicksHor
      else
      PaintTicksVer;
      end;

      Add this procedure

      Code:
      procedure TsTrackBar.SetShowProgressFrom(Value: Integer);
      begin
      if FShowProgressFrom Value then begin
      if Value < Min then Value := Min;
      if Value > Max then Value := Max;
      FShowProgressFrom := Value;
      if not (csLoading in ComponentState) and SkinData.Skinned then
      SkinData.Invalidate
      end;
      end;
      #53818
      Support
      Keymaster

        Thank you for a code, I will add it in the nearest release.

      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.