Cross (+) into Canvas to X/Y values...

Cross (+) into Canvas to X/Y values...

Post by Henriqu » Fri, 27 Jun 2003 04:59:44



Hi for all...

I need to make dynamic cross on canvas that show me the graph X/Y values, like's a gun's aim(+), only to indicate a point in the area, without to be static...Example:

Y ____________
 |    |     |
 |    |     |
 -----|------ <- Mouse Cross (X, Y)
 |    |     |
 |    |     |
 ------------ X

In this case: X = XTotal/2 and Y = YTotal/2...Now, other case:

Y____________
 | |        |
 | |        |
 | |        |
 |-|--------| <- Mouse Cross (X, Y)
 | |        |
 ------------ X

where, X ~< XTotal/2 and Y ~< YTotal/2...

thank's,

Henrique.

 
 
 

Cross (+) into Canvas to X/Y values...

Post by Eudy Silv » Fri, 27 Jun 2003 06:55:59


I'm using a PaintBox as an example:

void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender,
       TShiftState Shift, int X, int Y)
{
static int LastX = -1, LastY = -1;

PaintBox1->Canvas->Pen->Color = clBlue;
// erase the previous cross-hair
PaintBox1->Canvas->Pen->Mode = pmNotXor;
// horiontal line
PaintBox1->Canvas->MoveTo(0, LastY);
PaintBox1->Canvas->LineTo(PaintBox1->BoundsRect.Right, LastY);
// vertical line
PaintBox1->Canvas->MoveTo(LastX, 0);
PaintBox1->Canvas->LineTo(LastX, PaintBox1->BoundsRect.Bottom);

// draw the current cross-hair
// horizontal line
PaintBox1->Canvas->MoveTo(0, Y);
PaintBox1->Canvas->LineTo(PaintBox1->BoundsRect.Right, Y);
// vertical line
PaintBox1->Canvas->MoveTo(X, 0);
PaintBox1->Canvas->LineTo(X, PaintBox1->BoundsRect.Bottom);

LastX = X;
LastY = Y;
Caption = IntToStr(X) + ":" + IntToStr(Y);

Quote:}

Eudy