It helped partially because the function zooms on the middle of the screen, while I need to zoom on a particular selected item (box, arrow or table)
However with your hints, I was able to write a function that does something similar but I've the problem that the object appears on top-left of the screen after Zooming.
This is the code (Delphi):
procedure btnNewZoomInClick;
var
widthPixels, heightPixels: Single;
H:HDC;
centerBeforeZoomX,centerBeforeZoomY,
centerAfterZoomX,centerAfterZoomY,
FigureX, FigureY,
LeftFig,RightFig,TopFig,BottomFig :Integer ;
begin
if fcx.ActiveItemType = aiNone then
begin
fcx.ZoomFactor := fcx.ZoomFactor +25;
end
else
begin
H:= GetDC(0);
widthPixels := GetDeviceCaps(H,HORZRES) ;
heightPixels := GetDeviceCaps(H,VERTRES) ;
fcx.ClientPtToDocPt(round(widthPixels/2),round(heightPixels/2),
centerBeforeZoomX, centerBeforeZoomY);
fcx.ZoomFactor := fcx.ZoomFactor +25;
if fcx.ActiveItemType = aiTable then
fcx.ActiveTable.BoundingRect(LeftFig,TopFig,RightFig,BottomFig);
if fcx.ActiveItemType = aiArrow then
fcx.ActiveArrow.BoundingRect(LeftFig,TopFig,RightFig,BottomFig);
if fcx.ActiveItemType = aiBox then
fcx.ActiveBox.BoundingRect(LeftFig,TopFig,RightFig,BottomFig);
fcx.ClientPtToDocPt(round(widthPixels/2),round(heightPixels/2),
centerAfterZoomX, centerAfterZoomY);
//I get the "middle" of currently selected object...
FigureX := (LeftFig+RightFig) div 2;
FigureY := (TopFig+BottomFig) div 2;
// old code:
// fcx.ScrollX := fcx.ScrollX + centerBeforeZoomX - centerAfterZoomX;
// fcx.ScrollY := fcx.ScrollY + centerBeforeZoomY - centerAfterZoomY;
//I'm trying to scroll the chart: where am I wrong?
fcx.ScrollX := FigureX - (centerBeforeZoomX- centerAfterZoomX );
fcx.ScrollY := FigureY - (centerBeforeZoomY- centerAfterZoomY );
end;
end;
this is what I get:
BEFORE Zooming:

AFTER Zooming:

(It's Wrong because selected box is not on the center of the screen)
Probably I'm wrong on the last two lines of the code, can you help me?
Thanks