Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Faulty coordinates when using translateToAbsolute & scrolling
Faulty coordinates when using translateToAbsolute & scrolling [message #237253] Wed, 22 July 2009 17:43 Go to next message
Eclipse UserFriend
Originally posted by: nbe.informatik.uni-kiel.de

Hi all!

I've got an annoying problem I hope you can help me with.

I'm currently trying to develope a highlight effect on an existing
editor where i draw a red rectangle over some existing figure.
It basically works like this:

public void execute() {

// search a layer we can draw on
RootEditPart rootEP = objectToHighlight.getRoot();

if(rootEP instanceof RenderedDiagramRootEditPart){
IFigure layer = ((RenderedDiagramRootEditPart)
rootEP).getLayer(RenderedDiagramRootEditPart.FEEDBACK_LAYER) ;

// get Figure to the EditPart
IFigure selectedFigure = objectToHighlight.getFigure();
// get same bounds as the selected figure ...
Rectangle bounds = selectedFigure.getBounds().getCopy();
// ... but in absolute coordinates
selectedFigure.translateToAbsolute(bounds);

// set the bounds of the Figure that will do the highlighting
highlightFigure.setBounds(bounds);

// add the new highlight figure to the layer
layer.add(highlightFigure);

// schedule a repaint of the feedback layer
layer.invalidate();
}

It works generally well, however, if I scroll or zoom in the main window
the calculated coordinates become wrong. The highlightFigure gets
painted with an offset, e.g. if i scrolled 20 pixels to the right, the
highlightFigure is 20 pixels left to the objectToHighlight where it
should be.
Before translateToAbsolute the coordinates are plausible...
This also seems not to be related to my choice of paint layer, tried a
couple of others with same behaviour.

Any ideas? Help would be greatly appreciated!

Cheers, Nils
Re: Faulty coordinates when using translateToAbsolute & scrolling [message #237283 is a reply to message #237253] Thu, 23 July 2009 09:18 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
Hi Nils,

I can reproduce this. While zooming works fine, the layer does not seem to
consider scrolling when getting painted, so coordinates (0,0) are not top
left of the visible area, but somewhere else when the view gets scrolled.

A workaround I found is to scale the bounds yourself without translating.
Use
bounds.scale(rootEP.getZoomManager().getZoom());
instead of
selectedFigure.translateToAbsolute(bounds);

Maybe someone who really knows what happens can shed some light on this?

Could this be a bug or did we miss something?

Regards, Peter
Re: Faulty coordinates when using translateToAbsolute & scrolling [message #237289 is a reply to message #237283] Thu, 23 July 2009 09:30 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
Sorry, you need to cast getRoot before trying my workaround:

if(this.getRoot() instanceof RenderedDiagramRootEditPart){
RenderedDiagramRootEditPart rootEP =
(RenderedDiagramRootEditPart)this.getRoot();
Re: Faulty coordinates when using translateToAbsolute & scrolling [message #237295 is a reply to message #237283] Thu, 23 July 2009 09:44 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Hi,
I'm no expert with the behavour of GMF, but when doing some web
development I noticed that the mouse position didn't take into account the
scroll amount!
So when positioning something (absolute position) according to the
co-ordinates determained by the mouse, the position was incorrect.

Your issue seams to be producing the same problem, so maby it requires the
same solution???
That solution was to get hold of the amount the user has scrolled and
minus that from the position.

Hope this was useful,
Gary
Re: Faulty coordinates when using translateToAbsolute & scrolling [message #237307 is a reply to message #237295] Thu, 23 July 2009 11:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nbe.informatik.uni-kiel.de

Gary schrieb:
> Hi,
> I'm no expert with the behavour of GMF, but when doing some web
> development I noticed that the mouse position didn't take into account
> the scroll amount!
> So when positioning something (absolute position) according to the
> co-ordinates determained by the mouse, the position was incorrect.
>
> Your issue seams to be producing the same problem, so maby it requires
> the same solution???
> That solution was to get hold of the amount the user has scrolled and
> minus that from the position.
>
> Hope this was useful,
> Gary
>
Thanks for your input. I had the same idea and compared all the parent
objects when scrolled and when not. However i can't find any difference
at all. Maybe anyone knows where to grab to scrolling values?

Peter, i tried your workaround, but this gives me another (if
scroll-independent) offset upwards and to the left for all items except
for the top level node... Any ideas?
Re: Faulty coordinates when using translateToAbsolute & scrolling [message #237355 is a reply to message #237307] Fri, 24 July 2009 07:09 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
Well, here's another try, getting the absolute position of the figure
(considering both zoom and scrolling), and manually remove
scrolling-offset afterwards again.

Again, I'm just trying to get it to work, I don't know how it is supposed
to be done...

selectedFigure.translateToAbsolute(bounds);

IFigure parentFigure = selectedFigure.getParent();
while( parentFigure != null ) {
if(parentFigure instanceof Viewport) {
Viewport viewport = (Viewport)parentFigure;
bounds.translate(
viewport.getHorizontalRangeModel().getValue(),
viewport.getVerticalRangeModel().getValue());
parentFigure = null;
}
else {
parentFigure = parentFigure.getParent();
}
}
Re: Faulty coordinates when using translateToAbsolute & scrolling [message #237457 is a reply to message #237253] Fri, 24 July 2009 20:55 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Nils,

I think you are missing the translation back to the relative co-ords before
setting the bounds.
If you have a look at the NonResizableEditPolicy in GMF it may shed some
light on the issue.
protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {

IFigure feedback = getDragSourceFeedbackFigure();


PrecisionRectangle rect = new
PrecisionRectangle(getInitialFeedbackBounds().getCopy());

getHostFigure().translateToAbsolute(rect);

rect.translate(request.getMoveDelta());

rect.resize(request.getSizeDelta());

.....


feedback.translateToRelative(rect);

feedback.setBounds(rect);

}

Regards,

- James.



"Nils B." <nbe@informatik.uni-kiel.de> wrote in message
news:h47j35$9ep$1@build.eclipse.org...
> Hi all!
>
> I've got an annoying problem I hope you can help me with.
>
> I'm currently trying to develope a highlight effect on an existing
> editor where i draw a red rectangle over some existing figure.
> It basically works like this:
>
> public void execute() {
>
> // search a layer we can draw on
> RootEditPart rootEP = objectToHighlight.getRoot();
>
> if(rootEP instanceof RenderedDiagramRootEditPart){
> IFigure layer = ((RenderedDiagramRootEditPart)
> rootEP).getLayer(RenderedDiagramRootEditPart.FEEDBACK_LAYER) ;
>
> // get Figure to the EditPart
> IFigure selectedFigure = objectToHighlight.getFigure();
> // get same bounds as the selected figure ...
> Rectangle bounds = selectedFigure.getBounds().getCopy();
> // ... but in absolute coordinates
> selectedFigure.translateToAbsolute(bounds);
>
> // set the bounds of the Figure that will do the highlighting
> highlightFigure.setBounds(bounds);
>
> // add the new highlight figure to the layer
> layer.add(highlightFigure);
>
> // schedule a repaint of the feedback layer
> layer.invalidate();
> }
>
> It works generally well, however, if I scroll or zoom in the main window
> the calculated coordinates become wrong. The highlightFigure gets
> painted with an offset, e.g. if i scrolled 20 pixels to the right, the
> highlightFigure is 20 pixels left to the objectToHighlight where it
> should be.
> Before translateToAbsolute the coordinates are plausible...
> This also seems not to be related to my choice of paint layer, tried a
> couple of others with same behaviour.
>
> Any ideas? Help would be greatly appreciated!
>
> Cheers, Nils
Previous Topic:layout connections
Next Topic:How to catch double-click on tree view
Goto Forum:
  


Current Time: Sun Mar 29 22:48:43 GMT 2020

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

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

Back to the top