Page 1 of 1
TeeChart cursor pos to chart pos (CalcPosPoint equivalent)
Posted: Thu Oct 14, 2010 3:05 pm
by 10550006
I am trying to see if my cursor is in a certain position inside of a TTreeNodeShape or on the Tree.
I see how to do it with a TChart (CacPosPoint in the help doc, "Custom drawing on the Chart"), is there an equivalent for TTree.
I can do it just fine, if the chart is not zoomed, but as soon as I zoom, I can't figure out the math to get me the correct chart coordinate with zoom level and scroll bar position.
Re: TeeChart cursor pos to chart pos (CalcPosPoint equivalent)
Posted: Mon Oct 18, 2010 10:40 am
by yeray
Hi,
I'd do it with the Clicked method. Have you tried it?
The following works fine for me here:
Code: Select all
procedure TForm1.Tree1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if TreeNodeShape1.Clicked(X,Y) then Caption:='over the shape'
else Caption:='';
end;
Re: TeeChart cursor pos to chart pos (CalcPosPoint equivalent)
Posted: Mon Oct 18, 2010 1:58 pm
by 10550006
Yes, I do this, but I need to know if the mouse is in a certain spot in the shape.
Example : If mouse is over top half or shape then Caption := 'Top Section' else if in bottom half then Caption := 'Bottom Section'
node := tttGraphic.ClickedShape(x, y);
realY := tttGraphic.HorzScrollBar.Position;
if (realY > (node.Top + (node.Height div2))) and
(realY < node.Top) then
begin
tttGraphic.Hint := 'Top Section'
end
else if (realY < (node.Top + (node.Height div2))) and
(realY > (node.Top+node.Height)) then
begin
tttGraphic.Hint := 'Bottom Section'
end;
This works fine with a 100% zoom, but as soon as I change the zoom it will no longer work. I tried multiplying x,y by the zoom %, but that didn't work. I need to translate the mouse X,Y position to the Graphic position.
Thanks,
Steve
Re: TeeChart cursor pos to chart pos (CalcPosPoint equivalent)
Posted: Mon Oct 18, 2010 3:55 pm
by 10550006
Never mind, I found it.
tttGraphic.Canvas.Calculate2DPosition(realX, realY, 0);
Re: TeeChart cursor pos to chart pos (CalcPosPoint equivalent)
Posted: Mon Oct 18, 2010 5:12 pm
by yeray
Hi,
I'm glad to see you've found it!