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

📄 teelineargauge.pas

📁 BCB第三方组件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    IAxisDone:=True;
  end;
end;

procedure TCustomGaugeMinMax.SetGreenLine(const Value: TGaugePointerRange);
begin
  FGreenLine.Assign(Value);
end;

procedure TCustomGaugeMinMax.SetHand(const Value: TGaugeSeriesPointer);
begin
  FHand.Assign(Value);
end;

procedure TCustomGaugeMinMax.SetMaximum(const Value: TChartValue);
begin
  SetDoubleProperty(FMaximum,Value);
end;

procedure TCustomGaugeMinMax.SetMinimum(const Value: TChartValue);
begin
  SetDoubleProperty(FMinimum,Value);
end;

procedure TCustomGaugeMinMax.SetMinorDist(const Value: Integer);
begin
  SetIntegerProperty(FMinorDist,Value);
end;

procedure TCustomGaugeMinMax.SetMinorTicks(const Value: TGaugeSeriesPointer);
begin
  FMinorTicks.Assign(Value);
end;

procedure TCustomGaugeMinMax.SetRedLine(const Value: TGaugePointerRange);
begin
  FRedLine.Assign(Value);
end;

procedure TCustomGaugeMinMax.SetTicks(const Value: TGaugeSeriesPointer);
begin
  FTicks.Assign(Value);
end;

procedure TCustomGaugeMinMax.DrawAllValues;
begin
  inherited;
  DrawAxis;
  DrawHand;
end;

procedure TCustomGaugeMinMax.DrawAxisTick(const Inner,InnerPlus,InnerMinus,Outer,OuterPlus,OuterMinus:TPoint);
begin
  Ticks.Draw(Inner, InnerPlus, InnerMinus, Outer, OuterPlus, OuterMinus);
end;

procedure TCustomGaugeMinMax.DrawAxisMinorTick(const Inner,Outer:TPoint);
var tmp : Integer;
begin
  tmp:=MinorTicks.HorizSize div 2;

  MinorTicks.Draw(Inner, TeePoint(Inner.X + tmp, Inner.Y),
                  TeePoint(Inner.X - tmp, Inner.Y), Outer,
                  TeePoint(Inner.X + tmp, Inner.Y + MinorTicks.VertSize),
                  TeePoint(Inner.X - tmp, Inner.Y + MinorTicks.VertSize));
end;

procedure TCustomGaugeMinMax.SetValues;
begin
  inherited;
  IRange:=(Maximum - Minimum);
end;

procedure TCustomGaugeMinMax.AddSampleValues(NumValues: Integer;
  OnlyMandatory: Boolean);
begin
  Value:=Minimum+Random(Round(Maximum-Minimum));
end;

{ TGaugePointerRange }

procedure TGaugePointerRange.Draw(const StartAngle,EndAngle:Double;
                                  const Rectangle:TRect);

var
  tmpSin : Extended;
  tmpCos : Extended;
  count  : Integer;
  circle : TPointArray;
  tmpX   : Integer;
  tmpY   : Integer;

  procedure AddPoint(const radius:Double);
  begin
    circle[count].X:=tmpX+Round(radius * tmpCos);
    circle[count].Y:=tmpY+Round(radius * tmpSin);
    Inc(count);
  end;

var tmp,
    sweepAngle    : Integer;
    tmpStartAngle : Double;
    tmpEndAngle   : Double;
    i             : Integer;
    containerMin  : Integer;
    a,b,
    theta         : Double;
begin
  if Visible then
  begin
    PrepareCanvas(ParentChart.Canvas, Color);

    sweepAngle:=Abs(Round(EndAngle-StartAngle));

    tmpStartAngle:=StartAngle+90;
    tmpEndAngle:=tmpStartAngle+sweepAngle;

    tmp:=Round(tmpEndAngle)-Round(tmpStartAngle);

    if tmp<2 then
       Exit;

    SetLength(circle,2*tmp);

    containerMin:=Min((Rectangle.Right-Rectangle.Left),(Rectangle.Bottom-Rectangle.Top));

    RectCenter(Rectangle,tmpX,tmpY);

    count:=0;

    //CDI this is a circle
    for i:=Round(tmpStartAngle) to Round(tmpEndAngle)-1 do
    begin
      SinCos(i*TeePiStep,tmpSin,tmpCos);
      AddPoint(containerMin*0.5);
    end;

    a:= containerMin*0.5;
    b:= -VertSize*0.01;

    //CDI and this is a logarithmic spiral drawn backwards so last/first
    //points of graphicspath draw ok.
    for i:=Round(tmpEndAngle)-1 downto Round(tmpStartAngle) do
    begin
      theta:= i * TeePiStep;
      SinCos(theta,tmpSin,tmpCos);
      AddPoint(a * Exp(theta * b));
    end;

    if Gradient.Visible then
    begin
      Gradient.Angle:= Round(StartAngle - 90);
      ParentChart.Canvas.PolygonGradient(circle,Gradient);
    end
    else
       ParentChart.Canvas.Polygon(circle);

    // Release memory
    circle:=nil;
  end;
end;

procedure TGaugePointerRange.SetEndValue(const Value: Double);
begin
  if FEndValue<>Value then
  begin
    FEndValue:=Value;
    Repaint;
  end;
end;

procedure TGaugePointerRange.SetStartValue(const Value: Double);
begin
  if FStartValue<>Value then
  begin
    FStartValue:=Value;
    Repaint;
  end;
end;

{ TGaugeSeriesPointer }
procedure TGaugeSeriesPointer.SetValues(x, y, horiz, vert:Integer);
begin
  IStartAngle := 90 + (ArcTan2(Shadow.VertSize,Shadow.HorizSize) * (180/Pi));
  PXMinus := x - horiz;
  PXPlus := x + horiz;
  PYMinus := y - vert;
  PYPlus := y + vert;

  PXMinusSmall := PXMinus + 2;
  PXPlusSmall := PXPlus - 2;

  PYMinusSmall := PYMinus + (horiz * 2);
  PYPlusSmall := PYPlus - (horiz * 2);
end;

procedure TGaugeSeriesPointer.Draw(const Inner, InnerPlus, InnerMinus, Outer, OuterPlus, OuterMinus:TPoint);
begin
  if Visible then
  begin
    if GaugeStyle=gpTick then
    begin
      PrepareCanvas(ParentChart.Canvas,Color);
      ParentChart.Canvas.Polygon([OuterPlus, OuterMinus, InnerMinus, InnerPlus]);
    end
    else
    begin
      PrepareCanvas(ParentChart.Canvas,Color);

      if GaugeStyle=gpMinorTick then
         Draw(Outer.X, Outer.Y, Color, psCircle)
      else
         Draw(Outer.X, Outer.Y, Color, Style);
    end;
  end;
end;

procedure TGaugeSeriesPointer.SetGaugeStyle(const Value: TGaugePointerStyles);
begin
  if FGaugeStyle<>Value then
  begin
    FGaugeStyle:=Value;
    Repaint;
  end;
end;

procedure TLinearGaugeEditor.FormShow(Sender: TObject);
var tmp : TFormTeeAxis;
begin
  inherited;

  with Gauge as TCustomGaugeMinMax do
  begin
    UDStartGreen.Position:=Round(GreenLine.StartValue);
    UDEndGreen.Position:=Round(GreenLine.EndValue);

    UDStartRed.Position:=Round(RedLine.StartValue);
    UDEndRed.Position:=Round(RedLine.EndValue);

    EMax.Text:=FloatToStr(Maximum);
    EMin.Text:=FloatToStr(Minimum);
    EFormat.Text:=ValueFormat;

    CBLabels.Checked:=Axis.Labels;

    tmp:=TFormTeeAxis.CreateAxis(Self,Axis);
    tmp.PageTitle.Parent:=TabTitle;
    tmp.PageAxis.ActivePage:=tmp.TabTitle;
    tmp.PageAxisChange(tmp);

    UDMinorSize.Position:=MinorTicks.Size;
    UDMinorCount.Position:=Axis.MinorTickCount;
    UDTicks.Position:=Ticks.VertSize;
    UDTicksDist.Position:=MinorTickDistance;
  end;
end;

procedure TLinearGaugeEditor.Button1Click(Sender: TObject);
begin
  EditSeriesPointer(Self,(Gauge as TCustomGaugeMinMax).Ticks);
end;

procedure TLinearGaugeEditor.Button2Click(Sender: TObject);
begin
  EditSeriesPointer(Self,(Gauge as TCustomGaugeMinMax).MinorTicks);
end;

procedure TLinearGaugeEditor.CBLabelsClick(Sender: TObject);
begin
  (Gauge as TCustomGaugeMinMax).Axis.Labels:=CBLabels.Checked;
end;

procedure TLinearGaugeEditor.Button3Click(Sender: TObject);
begin
  EditTeeFontEx(Self,(Gauge as TCustomGaugeMinMax).Axis.LabelsFont);
end;

procedure TLinearGaugeEditor.EFormatChange(Sender: TObject);
begin
  if Showing then
     (Gauge as TCustomGaugeMinMax).ValueFormat:=EFormat.Text;
end;

procedure TLinearGaugeEditor.BGreenClick(Sender: TObject);
begin
  if Sender=BGreen then
     EditSeriesPointer(Self,(Gauge as TCustomGaugeMinMax).GreenLine)
  else
     EditSeriesPointer(Self,(Gauge as TCustomGaugeMinMax).RedLine);
end;

procedure TLinearGaugeEditor.EStartGreenChange(Sender: TObject);

  procedure SetStartValue(AText:TEdit; ALine:TGaugePointerRange);
  var tmp : Double;
  begin
    if TryStrToFloat(AText.Text,tmp) then
       ALine.StartValue:=tmp;
  end;

begin
  if Showing then
     if Sender=EStartGreen then
        SetStartValue(EStartGreen,(Gauge as TCustomGaugeMinMax).GreenLine)
     else
        SetStartValue(EStartRed,(Gauge as TCustomGaugeMinMax).RedLine);
end;

procedure TLinearGaugeEditor.EEndGreenChange(Sender: TObject);

  procedure SetStartValue(AText:TEdit; ALine:TGaugePointerRange);
  var tmp : Double;
  begin
     if TryStrToFloat(AText.Text,tmp) then
        ALine.EndValue:=tmp;
  end;

begin
  if Showing then
     if Sender=EEndGreen then
        SetStartValue(EEndGreen,(Gauge as TCustomGaugeMinMax).GreenLine)
     else
        SetStartValue(EEndRed,(Gauge as TCustomGaugeMinMax).RedLine);
end;

procedure TLinearGaugeEditor.EMinChange(Sender: TObject);
var tmp : Double;
begin
  if Showing then
     if TryStrToFloat(EMin.Text,tmp) then
        (Gauge as TCustomGaugeMinMax).Minimum:=tmp;
end;

procedure TLinearGaugeEditor.EMaxChange(Sender: TObject);
var tmp : Double;
begin
  if Showing then
     if TryStrToFloat(EMax.Text,tmp) then
        (Gauge as TCustomGaugeMinMax).Maximum:=tmp;
end;

procedure TLinearGaugeEditor.BValueAreaClick(Sender: TObject);
begin
  EditTeeCustomShape(Self,(Gauge as TLinearGauge).ValueArea,True)
end;

procedure TLinearGaugeEditor.BMaxIndicatorClick(Sender: TObject);
begin
  EditSeriesPointer(Self,(Gauge as TLinearGauge).MaxValueIndicator);
end;

procedure TLinearGaugeEditor.Button6Click(Sender: TObject);
begin
  EditTeeFontEx(Self,(Gauge as TCustomGaugeMinMax).Axis.LabelsFont);
end;

procedure TLinearGaugeEditor.Edit2Change(Sender: TObject);
begin
  if Showing then
     (Gauge as TCustomGaugeMinMax).MinorTicks.Size:=UDMinorSize.Position;
end;

procedure TLinearGaugeEditor.EMinorChange(Sender: TObject);
begin
  if Showing then
     (Gauge as TCustomGaugeMinMax).Axis.MinorTickCount:=UDMinorCount.Position;
end;

procedure TLinearGaugeEditor.ETicksChange(Sender: TObject);
begin
  if Showing then
     (Gauge as TCustomGaugeMinMax).Ticks.VertSize:=UDTicks.Position;
end;

procedure TLinearGaugeEditor.ETicksDistChange(Sender: TObject);
begin
  if Showing then
     (Gauge as TCustomGaugeMinMax).MinorTickDistance:=UDTicksDist.Position;
end;

procedure TLinearGaugeEditor.BLinearHandClick(Sender: TObject);
begin
  EditSeriesPointer(Self,(Gauge as TLinearGauge).Hand);
end;

initialization
  RegisterTeeSeries(TLinearGauge, {$IFNDEF CLR}@{$ENDIF}TeeMsg_LinearGauge,
                                  {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryGauges,1);
  RegisterClass(TLinearGaugeEditor);
finalization
  UnRegisterTeeSeries([TLinearGauge]);
end.

⌨️ 快捷键说明

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