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

📄 iplotlegend.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      FColumnList.AddObject('', Pointer(FInnerRect.Left));

      if FItemViewStartIndex <> -1 then
        begin
          for x := FItemViewStartIndex to ItemCount-1 do
            begin
              LegendItem       := (FItemList.Objects[x] as TiPlotLegendItem);
              LegendItem.ARow  := RowIndex;
              LegendItem.ACol  := ColumnIndex;
              LegendItem.ALeft := Integer(FColumnList.Objects[LegendItem.ACol-1]);
              LegendItem.ATop  := CurrentTop;

              if ColumnIndex = 1 then ActualRowCount := RowIndex;

              CurrentTop       := CurrentTop + FMaxItemHeight + FRowSpacingPixels;
              Inc(RowIndex);

              if (RowIndex > RowCount) and (x <> ItemCount-1) then
                begin
                  RowIndex   := 1;
                  CurrentTop := FItemsRect.Top;
                  Inc(ColumnIndex);
                  if ColumnIndex > FActualWrapColCount then
                    begin
                      FItemViewStopIndex := x;
                      Break;
                    end;
                  if (FColumnList.Count -1) < ColumnIndex then FColumnList.AddObject('', Pointer(FInnerRect.Left + (FItemWidth + FWrapSpacingPixels)*(ColumnIndex-1)));
                end;
            end;
        end;
      //---------------------------------------------------------------------------------------------------------
      FRequiredWidth  := MarginLeftPixels + (FActualWrapColCount*(FItemWidth) + FWrapSpacingPixels*(FActualWrapColCount -1)) + MarginRightPixels;
      FRequiredHeight := MarginTopPixels  + FColumnTitlesHeightPixels + FColumnTitlesMarginPixels + RowCount*(FMaxItemHeight + FRowSpacingPixels) - FRowSpacingPixels + MarginBottomPixels;

      if ItemCount > RowCount*FActualWrapColCount then
        begin
          FUpButton.Visible    := True;
          FDownButton.Visible  := True;                                          
          FUpButton.DrawRect   := Rect(FItemsRect.Right-17, FItemsRect.Top,       FItemsRect.Right, FItemsRect.Top+17);
          FDownButton.DrawRect := Rect(FItemsRect.Right-17, FItemsRect.Bottom-17, FItemsRect.Right, FItemsRect.Bottom);

          FRequiredWidth       := FRequiredWidth + 25;
        end
      else
        begin
          FUpButton.Visible   := False;
          FDownButton.Visible := False;
          FItemViewStartIndex := 0;
        end;
    end;
  //---------------------------------------------------------------------------------------------------------
  if FWrapColSpacingAuto and Horizontal and (FActualWrapColCount > 1) then
    begin
      ActualWidth      := FItemsRect.Right - FItemsRect.Left -25;
      ActualColSpacing := Trunc((ActualWidth - FActualWrapColCount*FItemWidth)/(FActualWrapColCount - 1));

      for x := 0 to ItemCount-1 do
        begin
          LegendItem       := (FItemList.Objects[x] as TiPlotLegendItem);
          LegendItem.ALeft := FInnerRect.Left + (FItemWidth + ActualColSpacing)*(LegendItem.ACol-1);
        end;

      for x := 0 to FColumnList.Count-1 do
        FColumnList.Objects[x] := Pointer(FInnerRect.Left + (FItemWidth + ActualColSpacing)*x);
    end;
  //---------------------------------------------------------------------------------------------------------
  if FWrapRowSpacingAuto and (not Horizontal) and (ActualRowCount > 1) then
    begin
      FRowSpacingPixels := Trunc((MaxHeight - FMaxItemHeight*ActualRowCount)/(ActualRowCount - 1));

      for x := 0 to ItemCount-1 do
        begin
          LegendItem      := (FItemList.Objects[x] as TiPlotLegendItem);
          LegendItem.ATop := FInnerRect.Top + (LegendItem.ARow-1)*(FMaxItemHeight + FRowSpacingPixels);
          if FColumnTitlesVisible then LegendItem.ATop := LegendItem.ATop + FColumnTitlesHeightPixels + FColumnTitlesMarginPixels;
        end;
    end;
  //---------------------------------------------------------------------------------------------------------

  FUpButton.Enabled   := FItemViewStartIndex <> 0;
  FDownButton.Enabled := FItemViewStopIndex <> (ItemCount -1);
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.Draw(const Canvas: TCanvas; const BackGroundColor: TColor);
var
  iChannel    : TiPlotChannelCustom;
  AText       : String;
  ARect       : TRect;
  x           : Integer;
  YPos        : Integer;
  CenterPoint : TPoint;
  Item        : TiPlotLegendItem;
begin
  if not Visible         then Exit;
  if FItemList.Count = 0 then Exit;
  CalcRects(Canvas);

  with Canvas, DrawRect do
    begin
      Brush.Style := bsSolid;
      Pen.Style   := psSolid;

      if not FBackGroundTransparent then
        begin
          Brush.Color := FBackGroundColor;
          FillRect(DrawRect);
        end;

      DrawColumnTitles(Canvas);
                                
      Font.Color := $FFEEDD; //Borland Bug Hack.
      Font.Assign(FFont);
      Brush.Style := bsClear;

      YPos := FItemsRect.Top;

      for x := 0 to FItemList.Count-1 do
        TiPlotChannelCustomAccess((FItemList.Objects[x] as TiPlotLegendItem).Channel).LegendRect := Rect(0,0,0,0);

      for x := FItemViewStartIndex to FItemViewStopIndex do
        begin
          Item := FItemList.Objects[x] as TiPlotLegendItem;
          iChannel := Item.Channel;

          ARect := Rect(Item.ALeft + FColumnStartChannel,                           Item.ATop,
                        Item.ALeft + FColumnStartChannel + FMaxWidthChannelLabel+1, Item.ATop + Item.MaxHeight);

          TiPlotChannelCustomAccess(iChannel).LegendRect := ARect;

          if FShowColumnLine then DrawLine(Canvas, Item.ALeft + FColumnStartLine, Item.ATop + FItemHeight div 2, iChannel.Color, iChannel.TraceLineStyle);

          if FShowColumnMarker then
            begin
              CenterPoint := Point(Item.ALeft + FColumnStartMarker + FMaxWidthMarker div 2, Item.ATop + FItemHeight div 2);
              TiPlotChannelCustomAccess(iChannel).DrawMarker(Canvas, -1, CenterPoint);
            end;

          if Trim(iChannel.TitleText) <> '' then AText := iChannel.TitleText else AText := iChannel.Name;

          if TiPlotChannelCustomAccess(iChannel).UserSelected then
            begin
              Brush.Style := bsSolid;
              Brush.Color := FSelectedItemBackGroundColor;
              FillRect(TiPlotChannelCustomAccess(iChannel).LegendRect);
              Font.Assign(FSelectedItemFont);
            end
          else
            begin
              Brush.Style := bsClear;
              Font.Assign(FFont);
            end;

          case FChannelNameColorStyle of
            iplcncsChannelColor   : Font.Color := iChannel.Color;
            iplcncsXAxisFontColor : if Assigned(TiPlotChannelCustomAccess(iChannel).XAxis) then Font.Color := TiPlotChannelCustomAccess(iChannel).XAxis.LabelsFont.Color;
            iplcncsYAxisFontColor : if Assigned(TiPlotChannelCustomAccess(iChannel).YAxis) then Font.Color := TiPlotChannelCustomAccess(iChannel).YAxis.LabelsFont.Color;
          end;


          iDrawText(Canvas, AText, ARect, [itfHLeft, itfVTop, itfWordBreak, itfWordEllipsis]);

          Brush.Style := bsClear;
          Font.Assign(FFont);

          if FShowColumnXName then
            begin
              AText := GetXAxisNameText(iChannel);
              ARect := Rect(Item.ALeft + FColumnStartXName, Item.ATop, Item.ALeft + FColumnStartXName + FMaxWidthXName, Item.ATop + FItemHeight);
              iDrawText(Canvas, AText, ARect, [itfHLeft, itfVCenter]);
            end;

          if FShowColumnYName then
            begin
              AText := GetYAxisNameText(iChannel);
              ARect := Rect(Item.ALeft + FColumnStartYName, Item.ATop, Item.ALeft + FColumnStartYName + FMaxWidthYName, Item.ATop + FItemHeight);
              iDrawText(Canvas, AText, ARect, [itfHLeft, itfVCenter]);
            end;

          if (FShowColumnXValue2) then
            begin
              if FCursorAllChannels then
                AText := iChannel.DataCursorXText
              else
                AText := GetXAxisValueText(iChannel);
              ARect      := Rect(Item.ALeft + FColumnStartXValue, Item.ATop, Item.ALeft + FColumnStartXValue + FMaxWidthXValue, Item.ATop + FItemHeight);
              iDrawText(Canvas, AText, ARect, [itfHRight, itfVCenter]);
            end;

          if (FShowColumnYValue2) then
            begin
              if FCursorAllChannels then
                AText := iChannel.DataCursorYText
              else
                AText := GetYAxisValueText(iChannel);
              ARect      := Rect(Item.ALeft + FColumnStartYValue, Item.ATop, Item.ALeft + FColumnStartYValue + FMaxWidthYValue, Item.ATop + FItemHeight);
              iDrawText(Canvas, AText, ARect, [itfHRight, itfVCenter]);
            end;

          if (FShowColumnYMax) then
            begin
              AText      := GetYAxisMaxText(iChannel);
              ARect      := Rect(Item.ALeft + FColumnStartYMax, Item.ATop, Item.ALeft + FColumnStartYMax + FMaxWidthYMax, Item.ATop + FItemHeight);
              iDrawText(Canvas, AText, ARect, [itfHRight, itfVCenter]);
            end;

          if (FShowColumnYMin) then
            begin
              AText      := GetYAxisMinText(iChannel);
              ARect      := Rect(Item.ALeft + FColumnStartYMin, Item.ATop, Item.ALeft + FColumnStartYMin + FMaxWidthYMin, Item.ATop + FItemHeight);
              iDrawText(Canvas, AText, ARect, [itfHRight, itfVCenter]);
            end;

          if (FShowColumnYMean) then
            begin
              AText      := GetYAxisMeanText(iChannel);
              ARect      := Rect(Item.ALeft + FColumnStartYMean, Item.ATop, Item.ALeft + FColumnStartYMean + FMaxWidthYMean, Item.ATop + FItemHeight);
              iDrawText(Canvas, AText, ARect, [itfHRight, itfVCenter]);
            end;

          YPos := YPos + Item.MaxHeight + FRowSpacingPixels;
        end;
    end;

  DrawUpButton  (Canvas);
  DrawDownButton(Canvas);

  if UserSelected then
    begin
      Canvas.Brush.Style := bsClear;
      Canvas.Font.Color := clWhite;
      if Horizontal then iDrawFocusRect2(Canvas, Rect(DrawRect.Left,   DrawRect.Top+2, DrawRect.Right,   DrawRect.Bottom-2))
        else             iDrawFocusRect2(Canvas, Rect(DrawRect.Left+2, DrawRect.Top,   DrawRect.Right-2, DrawRect.Bottom  ))
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotLegend.DrawColumnTitles(const Canvas: TCanvas);
var
  x     : Integer;
  ATop  : Integer;
  ARect : TRect;
  ALeft : Integer;
begin
  if not FColumnTitlesVisible then Exit;
  
  with Canvas do
    begin
      Font.Assign(FColumnTitlesFont);
      Brush.Style := bsClear;
                                                                                   
      for x := 0 to FColumnList.Count - 1 do
        begin
          ALeft := Integer(FColumnList.Objects[x]);
          ATop  := FColumnTitlesRect.Top;

          ARect := Rect(0, ATop, 0, ATop + FColumnTitlesHeightPixels);

⌨️ 快捷键说明

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