c++builder How to prohibit dragging legends

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

c++builder How to prohibit dragging legends

Post by » Mon Jul 24, 2023 1:32 am

How to prohibit dragging legends?

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: c++builder How to prohibit dragging legends

Post by Yeray » Mon Jul 24, 2023 7:22 am

Hello,

I don't understand what do you mean. The legend isn't draggable by default.
Could you please expand?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

Re: c++builder How to prohibit dragging legends

Post by » Mon Jul 24, 2023 8:31 am

Why is it possible to drag by default?
How to prevent the legend from being dragged?
Attachments
1122.png
1122.png (11.86 KiB) Viewed 21502 times

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: c++builder How to prohibit dragging legends

Post by Yeray » Mon Jul 24, 2023 9:34 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

Re: c++builder How to prohibit dragging legends

Post by » Tue Jul 25, 2023 7:17 am

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???
Attachments
444.png
444.png (7.09 KiB) Viewed 21460 times
334455.png
334455.png (13.83 KiB) Viewed 21460 times

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

Re: c++builder How to prohibit dragging legends

Post by » Thu Jul 27, 2023 2:33 am

Does anyone answer my question???

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: c++builder How to prohibit dragging legends

Post by Yeray » Thu Jul 27, 2023 6:43 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

Re: c++builder How to prohibit dragging legends

Post by » Fri Jul 28, 2023 9:12 am

Due to requirements, I can only use Annotation. How can I prevent dragging legends?
Please provide a demo of c++builder。

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: c++builder How to prohibit dragging legends

Post by Yeray » Fri Jul 28, 2023 2:27 pm

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;
}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

Re: c++builder How to prohibit dragging legends

Post by » Tue Aug 01, 2023 6:46 am

How to obtain a legend pointer for the Chart1MouseUp function???

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: c++builder How to prohibit dragging legends

Post by Yeray » Wed Aug 02, 2023 9:11 am

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;
}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

Re: c++builder How to prohibit dragging legends

Post by » Thu Aug 03, 2023 2:58 am

How to determine whether the selected item is a legend in the Chart1MouseUp function???

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: c++builder How to prohibit dragging legends

Post by Yeray » Thu Aug 03, 2023 6:24 am

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;
	}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Newbie
Newbie
Posts: 27
Joined: Wed Nov 09, 2022 12:00 am

Re: c++builder How to prohibit dragging legends

Post by » 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???

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: c++builder How to prohibit dragging legends

Post by Yeray » Wed Aug 23, 2023 1:57 pm

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?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply