Faulty coordinates when using translateToAbsolute & scrolling [message #237253] |
Wed, 22 July 2009 13:43  |
Eclipse User |
|
|
|
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 #237457 is a reply to message #237253] |
Fri, 24 July 2009 16:55  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.19989 seconds