Page 1 of 1
Restricting TCursorTool Range
Posted: Mon Sep 21, 2009 4:23 pm
by 10054271
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
Posted: Tue Sep 22, 2009 8:10 am
by yeray
Hi skassan,
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;
Re: Restricting TCursorTool Range
Posted: Tue Sep 22, 2009 1:06 pm
by 10054271
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.
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];
}
}
//---------------------------------------------------------------------------