Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Question about Figure.translateToAbsolute/translateToRelative
Question about Figure.translateToAbsolute/translateToRelative [message #51722] Mon, 30 December 2002 22:00 Go to next message
Eclipse UserFriend
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?

Thanks in advance,

Michael.
Re: Question about Figure.translateToAbsolute/translateToRelative [message #51829 is a reply to message #51722] Thu, 02 January 2003 16:28 Go to previous message
Eclipse UserFriend
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?
>
> Thanks in advance,
>
> Michael.
>
>
>
>
>
Previous Topic:Need help: Problem with Deployment
Next Topic:How to leave the 'selection tool' selected after first usage?
Goto Forum:
  


Current Time: Sun Oct 06 07:30:47 GMT 2024

Powered by FUDForum. Page generated in 0.03353 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top