Page 1 of 1

c++builder How to prohibit dragging legends

Posted: Mon Jul 24, 2023 1:32 am
by 16494694
How to prohibit dragging legends?

Re: c++builder How to prohibit dragging legends

Posted: Mon Jul 24, 2023 7:22 am
by yeray
Hello,

I don't understand what do you mean. The legend isn't draggable by default.
Could you please expand?

Re: c++builder How to prohibit dragging legends

Posted: Mon Jul 24, 2023 8:31 am
by 16494694
Why is it possible to drag by default?
How to prevent the legend from being dragged?

Re: c++builder How to prohibit dragging legends

Posted: Mon Jul 24, 2023 9:34 am
by yeray
Hello,
wrote:
Mon Jul 24, 2023 8:31 am
Why is it possible to drag by default?
Sorry but it should not be draggable by default.
Check the code and the form in your project.

If you still find problems with it, please arrange a simple example project we can run as-is to reproduce the problem here.
Thanks in advance.

Re: c++builder How to prohibit dragging legends

Posted: Tue Jul 25, 2023 7:17 am
by 16494694
I found the reason。
I added a selection tool to achieve drag and drop annotation functionality。
This causes the legend to also be dragged. How to solve this problem???

Re: c++builder How to prohibit dragging legends

Posted: Thu Jul 27, 2023 2:33 am
by 16494694
Does anyone answer my question???

Re: c++builder How to prohibit dragging legends

Posted: Thu Jul 27, 2023 6:43 am
by yeray
Hello,

Indeed, the TAnnotationTool doesn't support dragging. However, the TRectangleTool does.
So, instead of having a TAnnotationTool and adding a TSelectorTool to add dragging support to it, you could just use a TRectangleTool.

Re: c++builder How to prohibit dragging legends

Posted: Fri Jul 28, 2023 9:12 am
by 16494694
Due to requirements, I can only use Annotation. How can I prevent dragging legends?
Please provide a demo of c++builder。

Re: c++builder How to prohibit dragging legends

Posted: Fri Jul 28, 2023 2:27 pm
by yeray
Hello,

You can't make the TSelectorTool not to detect the Legend. So, instead of using the TSelectorTool, I'd implement the TAnnotationTool dragging myself.

Code: Select all

#include <VclTee.Chart.hpp>
#include <VclTee.Series.hpp>
#include <VclTee.TeeTools.hpp>

Code: Select all

private:	// User declarations
	TChart* Chart1;
	TAnnotationTool* Annotation;
	TPoint* annotationOffset;
	bool annotationDragging;
	void __fastcall ChartMouseDown(TObject *Sender, TMouseButton Button,
								   TShiftState Shift, int X, int Y);
	void __fastcall ChartMouseMove(TObject *Sender, TShiftState Shift,
								   int X, int Y);
	void __fastcall ChartMouseUp(TObject *Sender, TMouseButton Button,
								 TShiftState Shift, int X, int Y);

Code: Select all

void __fastcall TForm1::FormCreate(TObject *Sender)
{
	Chart1 = new TChart(this);
	Chart1->Parent = this;
	Chart1->Align = alClient;
	Chart1->Color = clWhite;
	Chart1->Gradient->Visible = False;
	Chart1->Walls->Back->Color = clWhite;
	Chart1->Walls->Back->Gradient->Visible = False;
	Chart1->View3D = False;

	for (int i=0; i < 2; i++) {
	  TFastLineSeries* fastLine = new TFastLineSeries(this);
	  Chart1->AddSeries(fastLine);
	  fastLine->FillSampleValues();
	}

	Annotation = new TAnnotationTool(this);
	Chart1->Tools->Add(Annotation);
	Annotation->Left = 100;
	Annotation->Top = 100;
	Annotation->Text = "Annotation tool";

	Chart1->OnMouseDown = ChartMouseDown;
	Chart1->OnMouseMove = ChartMouseMove;
	Chart1->OnMouseUp = ChartMouseUp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartMouseDown(TObject *Sender, TMouseButton Button,
									   TShiftState Shift, int X, int Y)
{
	if (Annotation->Clicked(X,Y))
	{
		annotationDragging = true;
		annotationOffset = new TPoint(X-Annotation->Left,Y-Annotation->Top);
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartMouseMove(TObject *Sender, TShiftState Shift,
									   int X, int Y)
{
	if ((!annotationDragging) and (Annotation->Clicked(X,Y)))
	{
		Chart1->Cursor = crHandPoint;
		Chart1->CancelMouse = true;
	}

	if (annotationDragging)
	{
		Annotation->Left = X-annotationOffset->X;
		Annotation->Top = Y-annotationOffset->Y;
		Chart1->CancelMouse = true;
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartMouseUp(TObject *Sender, TMouseButton Button,
									 TShiftState Shift, int X, int Y)
{
	if (annotationDragging)
	{
		Chart1->Zoom->Active = false;
		Chart1->CancelMouse = true;
	}

	annotationDragging = false;
}

Re: c++builder How to prohibit dragging legends

Posted: Tue Aug 01, 2023 6:46 am
by 16494694
How to obtain a legend pointer for the Chart1MouseUp function???

Re: c++builder How to prohibit dragging legends

Posted: Wed Aug 02, 2023 9:11 am
by yeray
Hello,

You can access the Legend with Chart1->Legend. Ie:

Code: Select all

void __fastcall TForm1::ChartMouseUp(TObject *Sender, TMouseButton Button,
									 TShiftState Shift, int X, int Y)
{
	//...

	Chart1->Legend->Color = clRed;
}

Re: c++builder How to prohibit dragging legends

Posted: Thu Aug 03, 2023 2:58 am
by 16494694
How to determine whether the selected item is a legend in the Chart1MouseUp function???

Re: c++builder How to prohibit dragging legends

Posted: Thu Aug 03, 2023 6:24 am
by yeray
Hello,

You can check if the Legend is in a given position with the Clicked function. Ie:

Code: Select all

	if (Chart1->Legend->Clicked(X, Y) > -1)
	{
		Chart1->Legend->Color = clRed;
	}
	else
	{
		Chart1->Legend->Color = clWhite;
	}

Re: c++builder How to prohibit dragging legends

Posted: Tue Aug 08, 2023 1:22 am
by 16494694
How to prevent the legend from being dragged during the chartmousemove event, as shown in the following example???

Re: c++builder How to prohibit dragging legends

Posted: Wed Aug 23, 2023 1:57 pm
by yeray
wrote:
Tue Aug 08, 2023 1:22 am
How to prevent the legend from being dragged during the chartmousemove event, as shown in the following example???
Sorry, in what example?