Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Zoom In/out from a particular Node (Read 4635 times)
unisnk
Junior Member
**
Offline


D'Oh!

Posts: 59
Joined: Sep 3rd, 2008
Zoom In/out from a particular Node
Nov 28th, 2008 at 2:28pm
Print Post  
Hi,

See this Image:



I can zoom the diagram with ZoomIn and ZoomOut methods.

With ZoomIn I obtain this result (I can't see the selection anymore because the chart zooms on top left corner):



I want that Zoom "centers" on selected node, as shown in the following image:



Any hints?

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Zoom In/out from a particular Node
Reply #1 - Nov 28th, 2008 at 3:27pm
Print Post  
  
Back to top
 
IP Logged
 
unisnk
Junior Member
**
Offline


D'Oh!

Posts: 59
Joined: Sep 3rd, 2008
Re: Zoom In/out from a particular Node
Reply #2 - Dec 2nd, 2008 at 4:35pm
Print Post  
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):
Code
Select All
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
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Zoom In/out from a particular Node
Reply #3 - Dec 3rd, 2008 at 6:24am
Print Post  
You could first set the scroll position so that the active box is centered, and then use the code that preserves the center while zooming:

Code
Select All
Private Sub CenterOnActiveBox()
	Dim widthPixels As Single
	Dim heightPixels As Single

	widthPixels = ScaleX(fcx.Width, vbTwips, vbPixels)
	heightPixels = ScaleY(fcx.Height, vbTwips, vbPixels)

	Dim centerBeforeZoomX As Long
	Dim centerBeforeZoomY As Long

	fcx.ClientPtToDocPt widthPixels / 2, heightPixels / 2, _
		centerBeforeZoomX, centerBeforeZoomY

	Dim dx As Integer, cx As Integer
	cx = (fcx.ActiveBox.Left + fcx.ActiveBox.Right) / 2
	dx = cx - centerBeforeZoomX

	Dim dy As Integer, cy As Integer
	cy = (fcx.ActiveBox.Top + fcx.ActiveBox.bottom) / 2
	dy = cy - centerBeforeZoomY

	fcx.ScrollX = fcx.ScrollX + dx
	fcx.ScrollY = fcx.ScrollY + dy

	fcx.ZoomFactor = fcx.ZoomFactor + 10

	Dim centerAfterZoomX As Long
	Dim centerAfterZoomY As Long

	fcx.ClientPtToDocPt widthPixels / 2, heightPixels / 2, _
		centerAfterZoomX, centerAfterZoomY

	'this restores the center point
	fcx.ScrollX = fcx.ScrollX + cx - centerAfterZoomX
	fcx.ScrollY = fcx.ScrollY + cy - centerAfterZoomY
End Sub
 



Note that width/heightPixels in the code above are the width and height of the control, while in your code they refer to the size of the screen.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
unisnk
Junior Member
**
Offline


D'Oh!

Posts: 59
Joined: Sep 3rd, 2008
Re: Zoom In/out from a particular Node
Reply #4 - Dec 3rd, 2008 at 12:06pm
Print Post  
Well, It works... but because I took the screen size instead of the document size, the box is not perfectly at the center of the screen.

Unfortunately it seems there aren't the ScaleX/ScaleY functions in Delphi and I didn't find an alternative method to get the document size.

Any hints?

Thank you in advance!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Zoom In/out from a particular Node
Reply #5 - Dec 3rd, 2008 at 12:32pm
Print Post  
The ScaleX/Y calls above just return the pixel width/height of the control as placed on the form. Doesn't the Delphi ActiveX wrapper class add Width / Height properties that return the size in pixels?
  
Back to top
 
IP Logged
 
unisnk
Junior Member
**
Offline


D'Oh!

Posts: 59
Joined: Sep 3rd, 2008
Re: Zoom In/out from a particular Node
Reply #6 - Dec 3rd, 2008 at 1:08pm
Print Post  
it seems that works just calling the following code:

Code
Select All
widthPixels := fcx.Width;
heightPixels := fcx.Height;
 



more simple than I thought... I hope it continues to work well in other tests Grin
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Zoom In/out from a particular Node
Reply #7 - Dec 3rd, 2008 at 1:12pm
Print Post  
8)
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint