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

📄 qiplotdatacursor.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 4 页
字号:

  DoUpdate;

  with Canvas, FDataView do
    begin
      if FUseChannelColor and Assigned(Channel) then Pen.Color := Channel.Color else Pen.Color := FColor;

      Pen.Width := 0;
      Pen.Style := psSolid;

      if FPointer1Show then
        begin
          if FMouseDownPointer1 then Pen.Width := 0 else Pen.Width := FPointerPenWidth;
          DrawPointer(Canvas, FPointer1Position, FPointer1Orientation, FPointer1Rect);
        end;

      if FPointer2Show then
        begin
          if FMouseDownPointer2 then Pen.Width := 0 else Pen.Width := FPointerPenWidth;
          DrawPointer(Canvas, FPointer2Position, FPointer2Orientation, FPointer2Rect);
        end;

                                     FHintShowing := FHintShow;
      if FChannelName = '<All>' then FHintShowing := False;
      if FHintHideOnRelease and not FMouseDownPointer1 and not FMouseDownPointer2 then FHintShowing := False;
      if FHintShowing then DrawHint(Canvas, BackgroundColor);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.DrawPointer(const Canvas: TCanvas; Position: Double; Orientation: TiOrientation; var PointerRect: TRect);
var
  PositionPixels : Integer;
begin
  with Canvas, FDataView do
    begin
      case Orientation of
         ioVertical   : begin
                          PositionPixels := FDataView.PositionPercentToPixelsX(Position);
                          PolyLine([Point(PositionPixels, DrawRect.Top), Point(PositionPixels, DrawRect.Bottom)]);
                          PointerRect := Rect(PositionPixels-5, DrawRect.Top, PositionPixels+6, DrawRect.Bottom);
                        end;
         else           begin
                          PositionPixels := (FDataView.PositionPercentToPixelsY(Position));
                          PolyLine([Point(DrawRect.Left, PositionPixels), Point(DrawRect.Right, PositionPixels)]);
                          PointerRect := Rect(DrawRect.Left, PositionPixels - 5, DrawRect.Right, PositionPixels + 6);
                        end;
      end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.DoUpdate;
var
  x : Integer;
begin
  TiPlotComponentAccess(Owner).DoBeforeDataCursorUpdate(Self);
  
  if ChannelName = '<All>' then
    begin
      for x := 0 to TiPlotComponentAccess(Owner).Master.ChannelManager.Count-1 do
        TiPlotChannelCustomAccess(TiPlotComponentAccess(Owner).Master.ChannelManager.Items[x]).DataCursorUpate(Self);
    end
  else if Assigned(Channel) then TiPlotChannelCustomAccess(Channel).DataCursorUpate(Self);
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.SetVisible(const Value: Boolean);
begin
  inherited;
  if Value then DoUpdate;
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.AddMenuItems(PopupMenu: TPopUpMenu);
var
  x               : Integer;
  MenuItem        : TiMenuItem;
  StyleMenuItem   : TMenuItem;
  OptionsMenuItem : TMenuItem;
  ChannelMenuItem : TMenuItem;
  PlotComponent   : TiPlotComponent;
  AText           : String;
begin
  inherited;

  ChannelMenuItem            := TMenuItem.Create(PopupMenu);
  ChannelMenuItem.Caption    := GetTranslation('Channel');
  PopupMenu.Items.Add(ChannelMenuItem);

  if FChannelAllowAll then
    begin
      MenuItem            := TiMenuItem.Create(PopupMenu);
      MenuItem.Caption    := GetTranslation('<All>');
      MenuItem.OnClick    := AllChannelsMenuItemClick;
      MenuItem.Checked    := ChannelName = '<All>';
      ChannelMenuItem.Add(MenuItem);
    end;

  PlotComponent := Owner as TiPlotComponent;
  for x := 0 to PlotComponent.ChannelCount - 1 do
    begin
      if not PlotComponent.Channel[x].Visible then Continue;
      
      MenuItem            := TiMenuItem.Create(PopupMenu);
      AText               := PlotComponent.Channel[x].TitleText;
      AText := StringReplace(AText, #13+#10, '', [rfReplaceAll, rfIgnoreCase]);
      MenuItem.Caption    := AText;
      MenuItem.AString    := PlotComponent.Channel[x].Name;
      MenuItem.Checked    := MenuItem.AString = ChannelName;
      MenuItem.OnClick    := ChannelNameMenuItemClick;
      ChannelMenuItem.Add(MenuItem);
    end;

  StyleMenuItem            := TMenuItem.Create(PopupMenu);
  StyleMenuItem.Caption    := GetTranslation('Style');
  PopupMenu.Items.Add(StyleMenuItem);

  MenuItem            := TiMenuItem.Create(PopupMenu);
  MenuItem.Caption    := GetTranslation(FMenuItemCaptionValueXY);
  MenuItem.OnClick    := StyleValueXYMenuItemClick;
  MenuItem.Checked    := FStyle = ipcsValueXY;
  MenuItem.Visible    := FMenuItemVisibleValueXY;
  StyleMenuItem.Add(MenuItem);

  MenuItem            := TiMenuItem.Create(PopupMenu);
  MenuItem.Caption    := GetTranslation(FMenuItemCaptionValueX);
  MenuItem.OnClick    := StyleValueXMenuItemClick;
  MenuItem.Checked    := FStyle = ipcsValueX;
  MenuItem.Visible    := FMenuItemVisibleValueX;
  StyleMenuItem.Add(MenuItem);

  MenuItem            := TiMenuItem.Create(PopupMenu);
  MenuItem.Caption    := GetTranslation(FMenuItemCaptionValueY);
  MenuItem.OnClick    := StyleValueYMenuItemClick;
  MenuItem.Checked    := FStyle = ipcsValueY;
  MenuItem.Visible    := FMenuItemVisibleValueY;
  StyleMenuItem.Add(MenuItem);

  MenuItem            := TiMenuItem.Create(PopupMenu);
  MenuItem.Caption    := GetTranslation(FMenuItemCaptionDeltaX);
  MenuItem.OnClick    := StyleDeltaXMenuItemClick;
  MenuItem.Checked    := FStyle = ipcsDeltaX;
  MenuItem.Visible    := FMenuItemVisibleDeltaX;
  StyleMenuItem.Add(MenuItem);

  MenuItem            := TiMenuItem.Create(PopupMenu);
  MenuItem.Caption    := GetTranslation(FMenuItemCaptionDeltaY);
  MenuItem.OnClick    := StyleDeltaYMenuItemClick;
  MenuItem.Checked    := FStyle = ipcsDeltaY;
  MenuItem.Visible    := FMenuItemVisibleDeltaY;
  StyleMenuItem.Add(MenuItem);

  MenuItem            := TiMenuItem.Create(PopupMenu);
  MenuItem.Caption    := GetTranslation(FMenuItemCaptionInverseDeltaX);
  MenuItem.OnClick    := StyleInverseDeltaXMenuItemClick;
  MenuItem.Checked    := FStyle = ipcsInverseDeltaX;
  MenuItem.Visible    := FMenuItemVisibleInverseDeltaX;
  StyleMenuItem.Add(MenuItem);

  if FMenuUserCanChangeOptions then
    begin
      OptionsMenuItem            := TiMenuItem.Create(PopupMenu);
      OptionsMenuItem.Caption    := GetTranslation('Options');
      PopupMenu.Items.Add(OptionsMenuItem);

      MenuItem            := TiMenuItem.Create(PopupMenu);
      MenuItem.Caption    := GetTranslation('Use Channel Color');
      MenuItem.OnClick    := UseChannelColorMenuItemClick;
      MenuItem.Checked    := FUseChannelColor;
      OptionsMenuItem.Add(MenuItem);

      MenuItem            := TiMenuItem.Create(PopupMenu);
      MenuItem.Caption    := GetTranslation('Hide Hint On Release');
      MenuItem.OnClick    := HideHintOnReleaseMenuItemClick;
      MenuItem.Checked    := FHintHideOnRelease;
      OptionsMenuItem.Add(MenuItem);
    end;

  MenuItem         := TiMenuItem.Create(PopupMenu);
  MenuItem.Caption := GetTranslation('Flip Alignment');
  MenuItem.OnClick := FlipMenuItemClick;
  MenuItem.Enabled := (FStyle in [ipcsValueXY, ipcsValueX, ipcsValueY]) and (UpperCase(FChannelName) <> UpperCase('<All>'));
  PopupMenu.Items.Add(MenuItem);

  AddEditMenuItems(PopupMenu);
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.AllChannelsMenuItemClick(Sender: TObject);
var
  x : Integer;
begin
  ChannelName := '<All>';

  for x := 0 to TiPlotComponentAccess(Owner).Master.ChannelManager.Count-1 do
    TiPlotComponentAccess(Owner).Master.ChannelManager.Items[x].UserSelected := False;
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.ChannelNameMenuItemClick(Sender: TObject);
begin
  ChannelName := (Sender as TiMenuItem).AString;
  if Assigned(Channel) then TiPlotChannelCustomAccess(Channel).SetUserSelected(True);
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.FlipMenuItemClick(Sender: TObject);
begin
  if FHintOrientationSide = iosTopLeft then FHintOrientationSide := iosBottomRight else FHintOrientationSide := iosTopLeft;
  TriggerInvalidateNow(Self);
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.UseChannelColorMenuItemClick(Sender: TObject);
begin
  FUseChannelColor := not FUseChannelColor;
  TriggerInvalidateNow(Self);
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.HideHintOnReleaseMenuItemClick(Sender: TObject);
begin
  FHintHideOnRelease := not FHintHideOnRelease;
  TriggerInvalidateNow(Self);
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.StyleDeltaXMenuItemClick       (Sender: TObject);begin Style := ipcsDeltaX;        end;
procedure TiPlotDataCursor.StyleDeltaYMenuItemClick       (Sender: TObject);begin Style := ipcsDeltaY;        end;
procedure TiPlotDataCursor.StyleValueXMenuItemClick       (Sender: TObject);begin Style := ipcsValueX;        end;
procedure TiPlotDataCursor.StyleValueXYMenuItemClick      (Sender: TObject);begin Style := ipcsValueXY;       end;
procedure TiPlotDataCursor.StyleValueYMenuItemClick       (Sender: TObject);begin Style := ipcsValueY;        end;
procedure TiPlotDataCursor.StyleInverseDeltaXMenuItemClick(Sender: TObject);begin Style := ipcsInverseDeltaX; end;
//****************************************************************************************************************************************************
function TiPlotDataCursor.GetMousePointer(APoint: TPoint): TCursor;
begin
  Result := crHandPoint;
end;
//****************************************************************************************************************************************************
procedure TiPlotDataCursor.SetData(XValue, YValue: Double; Status: TiPlotDataPointStatus);
begin
  if (XValue <> FValueX) or (YValue <> FValueY) or (Status <> FStatus) then
    begin
      FValueX := XValue;
      FValueY := YValue;
      FStatus := Status;

      TiPlotComponentAccess(Owner).DataCursorChange(Self);
    end;
end;
//****************************************************************************************************************************************************
function TiPlotDataCursor.GetPointer1Pixels: Integer;
begin
  Result := 0;
  if not Assigned(FDataView) then Exit;
  case FPointer1Orientation of
    ioVertical : Result := FDataView.PositionPercentToPixelsX(FPointer1Position);
    else         Result := FDataView.PositionPercentToPixelsY(FPointer1Position)
  end;
end;
//****************************************************************************************************************************************************
function TiPlotDataCursor.GetPointer2Pixels: Integer;
begin
  Result := 0;
  if not Assigned(FDataView) then Exit;
  case FPointer2Orientation of
    ioVertical : Result := FDataView.PositionPercentToPixelsX(FPointer2Position);
    else         Result := FDataView.PositionPercentToPixelsY(FPointer2Position)
  end;
end;
//****************************************************************************************************************************************************
end.

⌨️ 快捷键说明

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