painting Grid [message #76358] |
Wed, 23 April 2003 15:30  |
Eclipse User |
|
|
|
Originally posted by: junost.gmx.de
Hello
in my editor I want to draw a Grid (points) in background. So I modified
the paintFigure -method of FreeformLayer -class. But with small a grid
pattern it becomes very slow. The reason is that with every adding or moving
of a figure the whole area is repainted.
How can I solve this problem?
Alexander M
|
|
|
|
Re: painting Grid [message #76404 is a reply to message #76374] |
Wed, 23 April 2003 15:53   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
Here is code to paint black dots on white background spaced every 3 pixels.
I can't imagine a grid any smaller.
I cannot detect any performance hit from displaying this grid.
protected void paintFigure(Graphics g) {
g.setForegroundColor(ColorConstants.white);
Rectangle region = new Rectangle();
g.getClip(region);
g.setBackgroundColor(ColorConstants.black);
g.fillRectangle(region);
g.setLineWidth(2);
for (int i=region.x - 2; i<region.right()+2; i++)
if (i % 3 == 0)
g.drawLine(i, region.y-2, i, region.bottom()+2);
for (int i=region.y-2; i<region.bottom()+2; i++)
if (i % 3 == 0)
g.drawLine(region.x-2, i, region.right()+2, i);
}
"Randy Hudson" <none@us.ibm.com> wrote in message
news:b86por$mbe$1@rogue.oti.com...
> When you add a figure, it gets added with its default bounds, which are
(0,
> 0, 64, 36). Then, the figure is positioned by its constraint, causing an
> erase at its original location. So, the damage region is the union of its
> default location and its location after the layout occurs.
>
> I don't see why drawing a grid should be slow. Please post the code you
are
> using to draw the grid.
>
> "Alexander M
|
|
|
Re: painting Grid [message #76436 is a reply to message #76374] |
Wed, 23 April 2003 16:00   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
"Randy Hudson" <none@us.ibm.com> wrote in message
news:b86por$mbe$1@rogue.oti.com...
> When you add a figure, it gets added with its default bounds, which are
(0,
> 0, 64, 36). Then, the figure is positioned by its constraint, causing an
> erase at its original location. So, the damage region is the union of its
> default location and its location after the layout occurs.
BTW, one way for us to fix this would be to have the default size of a
figure be (0,0). That way, when it calls erase(), nothing will happen
because the erase region will be an empty Rectangle.
|
|
|
Re: painting Grid [message #76467 is a reply to message #76436] |
Wed, 23 April 2003 17:21  |
Eclipse User |
|
|
|
Originally posted by: junost.gmx.de
Thnk you very much, your code works very good.
My code was not very efficient. I draw points instead of lines.
|
|
|
Powered by
FUDForum. Page generated in 0.02540 seconds