Home » Modeling » GMF (Graphical Modeling Framework) » Editor background image and zooming performance problem
Editor background image and zooming performance problem [message #165588] |
Mon, 17 December 2007 04:53  |
Eclipse User |
|
|
|
Originally posted by: mail.micke.gmail.com
Hi,
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 #165652 is a reply to message #165588] |
Mon, 17 December 2007 09:45  |
Eclipse User |
|
|
|
Originally posted by: mail.micke.gmail.com
Hmm,
think I posted this to the wrong forum. Will post to the GEF forum instead.
Sorry for the double posting,
Mike
Mikael Andersson wrote:
> Hi,
> 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
|
|
|
Goto Forum:
Current Time: Wed Aug 20 22:19:52 EDT 2025
Powered by FUDForum. Page generated in 0.04782 seconds
|