Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Editor background image and zooming performance problem
Editor background image and zooming performance problem [message #240309] Mon, 17 December 2007 14:47 Go to next message
Eclipse UserFriend
Originally posted by: mail.micke.gmail.com

Hi,
first of all sorry for the double posting, initially posted to the GMF
newsgroup, but think that was the wrong place and posting here instead.


Just starting to try and learn GMF et al. and ran into a problem a while
ago.

Via this [1] post I found out how to add a background image to my
editor, but as soon as I zoom (doesn't matter how much I zoom, 1% is
enough).

This is the code I have to draw the background image:

public class FreeFormLayerWithImageBGR extends FreeformLayer {
Image image;
DiagramEditPart dep;

public FreeFormLayerWithImageBGR(final Image img, DiagramEditPart
dep) {
super();
image = img;
this.dep = dep;
}

public Image getImage() {
return image;
}

public void setImage(Image image) {
this.image = image;
}

protected void paintFigure(Graphics graphics) {

if (getImage() != null) {
Rectangle targetRect = getBounds().getCopy();

Rectangle r = getBounds().getCopy();
dep.getFigure().translateToParent(r);
r.intersect(dep.getFigure().getClientArea());

org.eclipse.swt.graphics.Rectangle imgBox =
getImage().getBounds();

System.out.printf("r=(%d,%d,%d,%d)\n",
r.x, r.y, r.width, r.height);

System.out.printf("(%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",
imgBox.x, imgBox.y, imgBox.width, imgBox.height,
targetRect.x, targetRect.y, targetRect.width,
targetRect.height);

long t1 = System.currentTimeMillis();
System.out.println("Start draw image");
/*
graphics.drawImage(getImage(), 0, 0, imgBox.width,
imgBox.height,
targetRect.x, targetRect.y, targetRect.width,
targetRect.height);
*/
graphics.drawImage(getImage(), 0, 0);
System.out.println("End draw image, took
"+(System.currentTimeMillis()-t1) +" ms");
}

super.paintFigure(graphics);
}

@Override
public Rectangle getFreeformExtent() {
// TODO Auto-generated method stub
//return super.getFreeformExtent();

return new Rectangle(0,0, image.getBounds().width/10,
image.getBounds().height/10);
}


}

Output when running with zoom at 125% (without any zooming I get 0 or 1 ms):
r=(0,0,1309,1639)
(0,0,1309,1639) -> (0,0,1309,1639)
Start draw image
End draw image, took 2684 ms
r=(0,0,1309,1639)
(0,0,1309,1639) -> (0,0,1309,1639)
Start draw image
End draw image, took 2771 ms
r=(0,0,1309,1639)
(0,0,1309,1639) -> (0,0,1309,1639)
Start draw image
End draw image, took 2827 ms
r=(0,0,1309,1639)
(0,0,1309,1639) -> (0,0,1309,1639)
Start draw image
End draw image, took 3356 ms

[1]
http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.tools. gef/msg17797.html

Does this post belong in the GMF news group? Perhaps I should post to
the GEF one.

Extremely grateful for any suggestions,
Mike
Re: Editor background image and zooming performance problem [message #240319 is a reply to message #240309] Wed, 19 December 2007 11:44 Go to previous message
Eclipse UserFriend
Originally posted by: mail.micke.gmail.com

Any suggestions at all would be appreciated, currently I don't know
enough of the involved frameworks to fully understand how the zooming is
implemented and what I've done wrong.

Mike

Mikael Andersson wrote:
> Hi,
> first of all sorry for the double posting, initially posted to the GMF
> newsgroup, but think that was the wrong place and posting here instead.
>
>
> Just starting to try and learn GMF et al. and ran into a problem a while
> ago.
>
> Via this [1] post I found out how to add a background image to my
> editor, but as soon as I zoom (doesn't matter how much I zoom, 1% is
> enough).
>
> This is the code I have to draw the background image:
>
> public class FreeFormLayerWithImageBGR extends FreeformLayer {
> Image image;
> DiagramEditPart dep;
>
> public FreeFormLayerWithImageBGR(final Image img, DiagramEditPart
> dep) {
> super();
> image = img;
> this.dep = dep;
> }
>
> public Image getImage() {
> return image;
> }
>
> public void setImage(Image image) {
> this.image = image;
> }
>
> protected void paintFigure(Graphics graphics) {
>
> if (getImage() != null) {
> Rectangle targetRect = getBounds().getCopy();
>
> Rectangle r = getBounds().getCopy();
> dep.getFigure().translateToParent(r);
> r.intersect(dep.getFigure().getClientArea());
>
> org.eclipse.swt.graphics.Rectangle imgBox =
> getImage().getBounds();
>
> System.out.printf("r=(%d,%d,%d,%d)\n",
> r.x, r.y, r.width, r.height);
>
> System.out.printf("(%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",
> imgBox.x, imgBox.y, imgBox.width, imgBox.height,
> targetRect.x, targetRect.y, targetRect.width,
> targetRect.height);
>
> long t1 = System.currentTimeMillis();
> System.out.println("Start draw image");
> /*
> graphics.drawImage(getImage(), 0, 0, imgBox.width,
> imgBox.height,
> targetRect.x, targetRect.y, targetRect.width,
> targetRect.height);
> */
> graphics.drawImage(getImage(), 0, 0);
> System.out.println("End draw image, took
> "+(System.currentTimeMillis()-t1) +" ms");
> }
>
> super.paintFigure(graphics);
> }
>
> @Override
> public Rectangle getFreeformExtent() {
> // TODO Auto-generated method stub
> //return super.getFreeformExtent();
>
> return new Rectangle(0,0, image.getBounds().width/10,
> image.getBounds().height/10);
> }
>
>
> }
>
> Output when running with zoom at 125% (without any zooming I get 0 or 1
> ms):
> r=(0,0,1309,1639)
> (0,0,1309,1639) -> (0,0,1309,1639)
> Start draw image
> End draw image, took 2684 ms
> r=(0,0,1309,1639)
> (0,0,1309,1639) -> (0,0,1309,1639)
> Start draw image
> End draw image, took 2771 ms
> r=(0,0,1309,1639)
> (0,0,1309,1639) -> (0,0,1309,1639)
> Start draw image
> End draw image, took 2827 ms
> r=(0,0,1309,1639)
> (0,0,1309,1639) -> (0,0,1309,1639)
> Start draw image
> End draw image, took 3356 ms
>
> [1]
> http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.tools. gef/msg17797.html
>
>
> Does this post belong in the GMF news group? Perhaps I should post to
> the GEF one.
>
> Extremely grateful for any suggestions,
> Mike
Previous Topic:GEF Junit Testing
Next Topic:EclipseZone non update times-11/4-12/16
Goto Forum:
  


Current Time: Thu Apr 25 17:43:08 GMT 2024

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

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

Back to the top