Eclipse Community Forums Forum Search:

Home » Eclipse Projects » GEF » Question about Figure.translateToAbsolute/translateToRelative
Question about Figure.translateToAbsolute/translateToRelative Mon, 30 December 2002 22:00
 Eclipse User
Originally posted by: mhanner.rational.com

I'm trying to determine if a figure is visible withing scrollpane viewport.
The following picture hopefully clarifies what I am trying to do.
+------------------------+ A
| |
| +------------------+ B
| | |
| | |
| | F |
| | |
| +------------------+
| |
+------------------------+

A, B are both Scrollpanes with FreeFormViewports. F is a child of B and B
is a child of A.
My logic is:
1. translate everything to absolute coordinates
2. calculate the scrollpane 'visible' area
3. test if F is within #2

// f is the figure
// sp can be either A or B
boolean isVisible( Figure f, Scrollpane sp )
{
// translate to absolute coordinates
Rectangle spAbs = sp.getClientArea().getBounds().getCopy();
sp.translateToAbsolute( spAbs );
Rectangle fAbs = f.getBounds().getCopy();
f.translateToAbsolute( fAbs );

// calculate visible area
point p = sp.getViewport().getViewLocation();
p = p.getTranslated( spAbs.getLocation() ); //convert to absolute
coords
int w = sp.getViewport().getHorizontalRangeModel().getExtent();
int h = sp.getViewport().getVerticalRangeModel().getExtent();
Rectangle visible = new Rectangle( p.x, p.y, w, h );

return (visible.contains( f.getTopLeft() ) || visible.contains(
f.getBottomRight() ) );
}

I've also tried converting f's bounds relative to 'sp' without success;
i.e.,
fAbs = spAbs.getCopy();
f.translateToRelative( fAbs );

My questions are:
1. How do the translateToXXX methods works (draw2d coordiate system)?
2. is my logic correct?

Michael.
Re: Question about Figure.translateToAbsolute/translateToRelative [message #51829 is a reply to message #51722] Thu, 02 January 2003 16:28
 Eclipse User
Originally posted by: hudsonr.us.eye-bee-em.com

What you are describing is the same thing that happens when a figure
requests to be repainted. DeferredUpdateManager records the requesting
figure and the rectangle that is damaged in a collection. Then, when the
paint occurs, the update manager walks up the parent chain, performing first
a translateToParent(rect), and then an intersection with the parent's bounds
(client area is really more correct, but is slightly slower).

Look at repairDamage in that class.

I assume you are trying to determine whether F is visible to the user? If
not, what do you intend to do? Hide connections?

"Michael Hanner" <mhanner@rational.com> wrote in message
news:auqf0l\$6u0\$1@rogue.oti.com...
> I'm trying to determine if a figure is visible withing scrollpane
viewport.
> The following picture hopefully clarifies what I am trying to do.
> +------------------------+ A
> | |
> | +------------------+ B
> | | |
> | | |
> | | F |
> | | |
> | +------------------+
> | |
> +------------------------+
>
> A, B are both Scrollpanes with FreeFormViewports. F is a child of B and B
> is a child of A.
> My logic is:
> 1. translate everything to absolute coordinates
> 2. calculate the scrollpane 'visible' area
> 3. test if F is within #2
>
> // f is the figure
> // sp can be either A or B
> boolean isVisible( Figure f, Scrollpane sp )
> {
> // translate to absolute coordinates
> Rectangle spAbs = sp.getClientArea().getBounds().getCopy();
> sp.translateToAbsolute( spAbs );
> Rectangle fAbs = f.getBounds().getCopy();
> f.translateToAbsolute( fAbs );
>
> // calculate visible area
> point p = sp.getViewport().getViewLocation();
> p = p.getTranslated( spAbs.getLocation() ); //convert to absolute
> coords
> int w = sp.getViewport().getHorizontalRangeModel().getExtent();
> int h = sp.getViewport().getVerticalRangeModel().getExtent();
> Rectangle visible = new Rectangle( p.x, p.y, w, h );
>
> return (visible.contains( f.getTopLeft() ) || visible.contains(
> f.getBottomRight() ) );
> }
>
> I've also tried converting f's bounds relative to 'sp' without success;
> i.e.,
> fAbs = spAbs.getCopy();
> f.translateToRelative( fAbs );
>
> My questions are:
> 1. How do the translateToXXX methods works (draw2d coordiate system)?
> 2. is my logic correct?
>
>
> Michael.
>
>
>
>
>
 Previous Topic: Need Help: Application not found Next Topic: Optimization in Draw2D : PointList
Goto Forum:

Current Time: Wed Jun 20 21:20:36 GMT 2018