Page 1 of 1

TCursorTool.cursor?

Posted: Tue Apr 19, 2011 1:46 am
by 9342039
Hi,

Is there a way to change the TControl.cursor property of TCursorTool? It's the drag icon when you put the mouse pointer over the CursorTool. I'd like to remove it completely so the user won't try to drag the CursorTool. Well you see, the way to move the CursorTool in my software is by FollowMouse. So if the user click the CursorTool, it will turn FollowMouse on and another click will turn it off. But most users when the move the mouse over the CursorTool, seing the drag icon, they immediately try to click and drag the CursorTool, which is NOT what I want.
Anyway, changing the TCursorTool.Cursor doesn't do anything.

Thanks in advance.

Re: TCursorTool.cursor?

Posted: Tue Apr 19, 2011 9:11 am
by 9350556
Disabling the drag cursor is a good suggestion, it would be useful for me too.

In the mean time you can set the ClickTolerance to 0 (instead of the default 3) to reduce the chance to see the drag icon.

Re: TCursorTool.cursor?

Posted: Tue Apr 19, 2011 12:56 pm
by yeray
Hello Bert,

I'm afraid it's not possible to disable the dragging appearance of the Cursor Tool. However it is possible to disable the AllowDrag property in the TColorLineTool so you could use mouse events to control two Color Lines. Her it is an example:

Code: Select all

uses Series, TeeTools;

type
 TColorLineClicked=(clcNone,clcHorizontal,clcVertical,clcBoth);

var ClickedMode: TColorLineClicked;
    MouseX, MouseY: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;

  Chart1.AddSeries(TPointSeries).FillSampleValues();

  with Chart1.Tools.Add(TColorLineTool) as TColorLineTool do
  begin
    Axis:=Chart1.Axes.Bottom;
    Value:=Chart1[0].XValues.MaxValue / 2;
    AllowDrag:=false;
  end;

  with Chart1.Tools.Add(TColorLineTool) as TColorLineTool do
  begin
    Axis:=Chart1.Axes.Left;
    Value:=Chart1[0].YValues.MinValue + Chart1[0].YValues.Range / 2;
    AllowDrag:=false;
  end;

  ClickedMode:=clcNone;
end;

procedure TForm1.Chart1Click(Sender: TObject);
begin
  if ClickedMode = clcNone then
  begin
    if (Chart1.Tools[0] as TColorLineTool).Clicked(MouseX, MouseY) then
      ClickedMode:=clcVertical;

    if (Chart1.Tools[1] as TColorLineTool).Clicked(MouseX, MouseY) then
    begin
      if ClickedMode=clcVertical then
        ClickedMode:=clcBoth
      else
        ClickedMode:=clcHorizontal;
    end;
  end
  else ClickedMode:=clcNone;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  MouseX:=X;
  MouseY:=Y;

  if ((ClickedMode=clcBoth) or (ClickedMode=clcVertical)) then
    (Chart1.Tools[0] as TColorLineTool).Value:=Chart1.Axes.Bottom.CalcPosPoint(X);
  if ((ClickedMode=clcBoth) or (ClickedMode=clcHorizontal)) then
    (Chart1.Tools[1] as TColorLineTool).Value:=Chart1.Axes.Left.CalcPosPoint(Y);
end;

Re: TCursorTool.cursor?

Posted: Tue Apr 19, 2011 9:27 pm
by 9342039
Reducing the drag tolerance wont help since I still need the cursors to be easily clickable to activate the followMouse.
So, no way at all to alter this than tinker with the source then? All good. Thanks anyway.

Re: TCursorTool.cursor?

Posted: Wed Apr 20, 2011 1:19 pm
by yeray
Hello,

If you want to add some tolerance to the TColorLineTool, you could do the "clicked" method manually as follows:

Code: Select all

uses Series, TeeTools;

type
 TColorLineClicked=(clcNone,clcHorizontal,clcVertical,clcBoth);

var ClickedMode: TColorLineClicked;
    MouseX, MouseY, ClickTolerance: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;

  Chart1.AddSeries(TPointSeries).FillSampleValues();

  with Chart1.Tools.Add(TColorLineTool) as TColorLineTool do
  begin
    Axis:=Chart1.Axes.Bottom;
    Value:=Chart1[0].XValues.MaxValue / 2;
    AllowDrag:=false;
  end;

  with Chart1.Tools.Add(TColorLineTool) as TColorLineTool do
  begin
    Axis:=Chart1.Axes.Left;
    Value:=Chart1[0].YValues.MinValue + Chart1[0].YValues.Range / 2;
    AllowDrag:=false;
  end;

  ClickedMode:=clcNone;
  ClickTolerance:=20;
end;

procedure TForm1.Chart1Click(Sender: TObject);
begin
  if ClickedMode = clcNone then
  begin
    with (Chart1.Tools[0] as TColorLineTool) do
      if (Abs(MouseX-Axis.CalcPosValue(Value))<ClickTolerance) then
      ClickedMode:=clcVertical;

    with (Chart1.Tools[1] as TColorLineTool) do
      if (Abs(MouseY-Axis.CalcPosValue(Value))<ClickTolerance) then
      begin
        if ClickedMode=clcVertical then
          ClickedMode:=clcBoth
        else
          ClickedMode:=clcHorizontal;
      end;
  end
  else ClickedMode:=clcNone;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  MouseX:=X;
  MouseY:=Y;

  if ((ClickedMode=clcBoth) or (ClickedMode=clcVertical)) then
    (Chart1.Tools[0] as TColorLineTool).Value:=Chart1.Axes.Bottom.CalcPosPoint(X);
  if ((ClickedMode=clcBoth) or (ClickedMode=clcHorizontal)) then
    (Chart1.Tools[1] as TColorLineTool).Value:=Chart1.Axes.Left.CalcPosPoint(Y);
end;
Doesn't it work as you want?

Re: TCursorTool.cursor?

Posted: Thu Apr 21, 2011 4:18 am
by 9342039
I'm a bit confused. Is TColorLineTool works the same way as TCursorTool?

Re: TCursorTool.cursor?

Posted: Thu Apr 21, 2011 3:40 pm
by yeray
Hello,

Not exactly. They are designed for different purposes. Please, take a look at the examples in the features demo program included with the installation to have an idea about it.