Restricting TCursorTool Range
Restricting TCursorTool Range
Is there a way to restrict the range of a TCursorTool? I'm using two cursors to mark the beginning and end of a range. I'd like to restrict the movement such that the beginning is always before the end. Currently, I'm intercepting the OnCursorChange events, and redrawing the cursor where I want it if it's out of bounds. But that's not a very visually pleasing effect.
Re: Restricting TCursorTool Range
Hi skassan,
Maybe you could consider using ColorLine tool that seems to look better with the following example:
Maybe you could consider using ColorLine tool that seems to look better with the following example:
Code: Select all
procedure TForm1.ChartTool1DragLine(Sender: TColorLineTool);
begin
if ChartTool1.Value > 20 then ChartTool1.Value := 20;
if ChartTool1.Value < 10 then ChartTool1.Value := 10;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Restricting TCursorTool Range
Agreed, that's much better visually. But I think it's more important to give the user the feedback during the drag so they can have better precision with their placement. The cursor is also much easier to use from my perspective, with snap and the ability to know which point the cursor is over without having to iterate through the whole series.
What I've decided to go with is this. Instead of repositioning the cursor the user is dragging, I let that cursor "push" the other cursor if necessary to keep their relative positions.
What I've decided to go with is this. Instead of repositioning the cursor the user is dragging, I let that cursor "push" the other cursor if necessary to keep their relative positions.
Code: Select all
void __fastcall TMDIChild::BeginCursorChange(TCursorTool *Sender,
int x, int y, const double XValue, const double YValue,
TChartSeries *Series, int ValueIndex)
{
// Don't allow the beginning to move after the end.
if (XValue >= EndCursor->XValue &&
ValueIndex < Series->Count() - 1)
{
EndCursor->XValue = Series->XValues->Value[ValueIndex + 1];
}
}
//---------------------------------------------------------------------------
void __fastcall TMDIChild::EndCursorChange(TCursorTool *Sender,
int x, int y, const double XValue, const double YValue,
TChartSeries *Series, int ValueIndex)
{
// Don't allow the end to move before the beginning.
if (XValue <= BeginCursor->XValue &&
ValueIndex > 0)
{
BeginCursor->XValue = Series->XValues->Value[ValueIndex - 1];
}
}
//---------------------------------------------------------------------------