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

📄 teelegendscrollbar.pas

📁 TeeChart7Source 控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
        if Self.FHorizontal then
           ThumbBegin:=R.Left
        else
           ThumbBegin:=R.Top;

        Inc(ThumbBegin,FSize+Round(Position*tmpItemSize));
        ThumbEnd:=ThumbBegin+ThumbSize+1;

        tmpR:=ThumbRectangle;
        Rectangle(tmpR);

        if Self.FBevel<>bvNone then
        begin
          Dec(tmpR.Right);
          DrawBevel(ParentChart.Canvas,Self.FBevel,tmpR,1);
        end;
      end;
    end;
  end;
end;

Procedure TTeeScrollBar.ApplyScroll(Delta:Double; ActivateTimer:Boolean);

  Procedure DoChange(const NewValue:Double);
  begin
    Position:=Round(NewValue);
    DoScroll;

    if ActivateTimer and FirstTime and FAutoRepeat then
    begin
      if not Assigned(FTimer) then
      begin
        FTimer:=TTimer.Create(Self);
        FTimer.OnTimer:=DoTimer;
      end;

      FTimer.Interval:=FInitial;
      FTimer.Enabled:=True;
    end;
  end;

begin
  if Delta<0 then
  begin
    Delta:=Math.Max(-Position,Delta);

    if Position>(Delta+1) then
       DoChange(Position+Delta);
  end
  else
  begin
//    Delta:=Math.Min(L.TotalLegendItems-CurrentCount,Delta);

    if (Position+Delta-1)<(TotalCount-CurrentCount) then
       DoChange(Position+Delta);
  end;
end;

Procedure TTeeScrollBar.ProcessClick(const P:TPoint);
var tmp : Integer;
begin
  OldPoint:=P;

  FInThumb:=False;
  FInDec:=False;
  FInInc:=False;

  if ClickedDec(P) then
  begin
    FInDec:=True;
    ApplyScroll(-1,True)
  end
  else
  if ClickedInc(P) then
  begin
    FInInc:=True;
    ApplyScroll(1,True)
  end
  else
  if ClickedThumb(P) then
     FInThumb:=True
  else
  if PointInRect(MainRectangle,P.X,P.Y) then
  begin
    if Horizontal then tmp:=P.X else tmp:=P.Y;
    if tmp<ThumbBegin then
       ApplyScroll(-DeltaMain,True)
    else
    if tmp>ThumbEnd then
       ApplyScroll(DeltaMain,True)
  end;
end;

Function TTeeScrollBar.CalcDelta(A,B:Integer):Double;
var tmpR : TRect;
begin
  if A=B then result:=0
  else
  begin
    tmpR:=ScrollRectangle;
    if Horizontal then
       result:=(TotalCount)/((tmpR.Right-tmpR.Left)/Abs(A-B))
    else
       result:=(TotalCount)/((tmpR.Bottom-tmpR.Top)/Abs(A-B));

    if A<B then result:=-result;
  end;
end;

Procedure TTeeScrollBar.MouseMove(X,Y:Integer);
var tmp : Double;
begin
  if FInThumb then
  begin
    if Horizontal then tmp:=CalcDelta(X,OldPoint.X)
                  else tmp:=CalcDelta(Y,OldPoint.Y);
    if Abs(tmp)>=1 then
    begin
      ApplyScroll(tmp,False);
      OldPoint.X:=X;
      OldPoint.Y:=Y;
    end;
  end;
end;

Procedure TTeeScrollBar.MouseUp;
begin
  FInThumb:=False;
  FInDec:=False;
  FInInc:=False;

  FirstTime:=True;
  if Assigned(FTimer) then FTimer.Enabled:=False;

  Repaint;
end;

Procedure TTeeScrollBar.DoScroll;
begin
  if Assigned(FOnScrolled) then FOnScrolled(Self);
end;

procedure TTeeScrollBar.SetThumbBrush(const Value: TChartBrush);
begin
  FThumbBrush.Assign(Value);
end;

procedure TTeeScrollBar.SetBevel(const Value: TPanelBevel);
begin
  if FBevel<>Value then
  begin
    FBevel:=Value;
    Repaint;
  end;
end;

procedure TTeeScrollBar.ChartEvent(AEvent:TChartToolEvent);
begin
  if AEvent=cteAfterDraw then Draw;
end;

procedure TTeeScrollBar.DoTimer(Sender: TObject);
begin
  ProcessClick(OldPoint);
  if FTimer.Interval>50 then FTimer.Interval:=50;
end;

procedure TTeeScrollBar.SetHorizontal(const Value: Boolean);
begin
  SetBooleanProperty(FHorizontal,Value);
end;

procedure TTeeScrollBar.ChartMouseEvent(AEvent: TChartMouseEvent;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  case AEvent of
    cmeDown: ProcessClick(TeePoint(X,Y));
    cmeMove: MouseMove(X,Y);
    cmeUp: MouseUp;
  end;
end;

function TTeeScrollBar.CurrentCount: Integer;
begin
  result:=ThumbLength;
end;

function TTeeScrollBar.GetPosition: Integer;
begin
  result:=FPosition;
end;

class function TTeeScrollBar.Description: String;
begin
  result:='Scrollbar';
end;

procedure TTeeScrollBar.SetBackColor(const Value: TColor);
begin
  SetColorProperty(FBackColor,Value);
end;

class function TTeeScrollBar.GetEditorClass: String;
begin
  result:='TScrollBarEditor';
end;

procedure TTeeScrollBar.SetPosition(Value: Integer);
begin
  SetIntegerProperty(FPosition,Value);
  if Assigned(FOnSetPosition) then
     FOnSetPosition(Self,Value);
end;

procedure TTeeScrollBar.SetArrowBrush(const Value: TChartBrush);
begin
  FArrowBrush.Assign(Value);
end;

function TTeeScrollBar.DeltaMain: Integer;
begin
  result:=CurrentCount div 4;
end;

function TTeeScrollBar.ShouldDraw(var R: TRect): Boolean;
begin
  result:=TotalCount>0;
end;

function TTeeScrollBar.TotalCount: Integer;
begin
  result:=Max;
end;

procedure TTeeScrollBar.SetSize(const Value: Integer);
begin
  if FSize<>Value then
  begin
    SetIntegerProperty(FSize,Value);
    if Assigned(FOnChangeSize) then
       FOnChangeSize(Self);
  end;
end;

{ TLegendScrollBar }

function TLegendScrollBar.ShouldDraw(var R:TRect):Boolean;
begin
  L:=TCustomChart(ParentChart).Legend;

  result:= L.Visible and (L.LastValue>-1) and
           ((DrawStyle=dsAlways) or (L.LastValue<L.TotalLegendItems));

  if result then
  begin
    FHorizontal:=not L.Vertical;
    R:=L.ShapeBounds;
  end;
end;

function TLegendScrollBar.TotalCount:Integer;
begin
  if ParentChart.MaxPointsPerPage>0 then
     result:=ParentChart.NumPages
  else
     result:=L.TotalLegendItems+L.FirstValue;
end;

function TLegendScrollBar.CurrentCount:Integer;
begin
  if ParentChart.MaxPointsPerPage>0 then
     result:=1
  else
     result:=L.LastValue-L.FirstValue+1;
end;

function TLegendScrollBar.GetPosition:Integer;
begin
  if ParentChart.MaxPointsPerPage>0 then
     result:=ParentChart.Page-1
  else
     result:=L.FirstValue;
end;

procedure TLegendScrollBar.SetPosition(Value:Integer);
begin
  if ParentChart.MaxPointsPerPage>0 then
     ParentChart.Page:=Value+1
  else
     L.FirstValue:=Value;
end;

procedure TLegendScrollBar.LegendCalcSize(Sender:TCustomChartLegend; var ASize:Integer);
begin
  if Active and ShouldDraw(R) then
     Inc(ASize,Size+1);
end;

type TLegendAccess=class(TCustomChartLegend);

procedure TLegendScrollBar.SetParentChart(const Value: TCustomAxisPanel);
begin
  inherited;
  if Assigned(ParentChart) then
     TLegendAccess(TCustomChart(ParentChart).Legend).FOnCalcSize:=LegendCalcSize;
end;

class function TLegendScrollBar.Description: String;
begin
  result:=TeeMsg_LegendScrollbar;
end;

function TLegendScrollBar.DeltaMain: Integer;
begin
  if ParentChart.MaxPointsPerPage>0 then
     result:=1
  else
     result:=inherited DeltaMain;
end;

{ TScrollbarEditor }

procedure TScrollbarEditor.FormShow(Sender: TObject);
begin
  TeeScroll:=TTeeScrollBar(Tag);

  if Assigned(TeeScroll) then
  begin
    ButtonPen1.LinkPen(TeeScroll.Pen);
    ComboBox1.ItemIndex:=Ord(TeeScroll.Bevel);
    CBAuto.Checked:=TeeScroll.AutoRepeat;
    UpDown1.Position:=TeeScroll.Size;
    UpDown2.Position:=TeeScroll.InitialDelay;
    ButtonColor1.LinkProperty(TeeScroll,'BackColor');
  end;
end;

procedure TScrollbarEditor.Button1Click(Sender: TObject);
begin
  EditChartBrush(Self,TeeScroll.ThumbBrush)
end;

procedure TScrollbarEditor.Button2Click(Sender: TObject);
begin
  EditChartBrush(Self,TeeScroll.Brush)
end;

procedure TScrollbarEditor.ComboBox1Change(Sender: TObject);
begin
  TeeScroll.Bevel:=TPanelBevel(ComboBox1.ItemIndex);
end;

procedure TScrollbarEditor.CBAutoClick(Sender: TObject);
begin
  TeeScroll.AutoRepeat:=CBAuto.Checked;
end;

procedure TScrollbarEditor.Edit1Change(Sender: TObject);
begin
  if Assigned(TeeScroll) then
     TeeScroll.Size:=UpDown1.Position;
end;

procedure TScrollbarEditor.Button3Click(Sender: TObject);
begin
  EditChartBrush(Self,TeeScroll.ArrowBrush)
end;

procedure TScrollbarEditor.Edit2Change(Sender: TObject);
begin
  if Assigned(TeeScroll) then
     TeeScroll.InitialDelay:=UpDown2.Position;
end;

procedure TTeeScrollBar.SetParentChart(const Value: TCustomAxisPanel);
begin
  inherited;
  Repaint;
end;

procedure TTeeScrollBar.SetGradient(const Value: TTeeGradient);
begin
  FGradient.Assign(Value);
end;

procedure TScrollbarEditor.Button4Click(Sender: TObject);
begin
  EditTeeGradient(Self,TeeScroll.Gradient)
end;

procedure TTeeScrollBar.SetMinSize(const Value: Integer);
begin
  SetIntegerProperty(FMinSize,Value);
end;

initialization
  RegisterClass(TScrollbarEditor);
  RegisterTeeTools([TLegendScrollBar]);
finalization
  UnRegisterTeeTools([TLegendScrollBar]);
end.

⌨️ 快捷键说明

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