Skip to main content



      Home
Home » Eclipse Projects » GEF » Draw2D Bug?
Draw2D Bug? [message #247726] Mon, 16 March 2009 14:27 Go to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

Hello!

I`m developing an editor with GMF and for that I draw my nodes with
draw2D. At the moment I use Eclipse 3.5M5 with GEF 3.5.0M5.

I have some nodes where I draw a circle within another graphical form.
The circle should be filled, so I draw the line and then I fill the
circle like this:

public void paintFigure(Graphics graphics) {
super.paintFigure(graphics);

graphics.pushState();

// get the bounds of the node
Rectangle r = getBounds();
int x = r.x + lineWidth / 2;
int y = r.y + lineWidth / 2;
int w = r.width - Math.max(1, lineWidth);
int h = r.height - Math.max(1, lineWidth);

// draw and fill circle
Rectangle circle = new Rectangle(0, 0, w, h);
circle.performTranslate(x, y);

graphics.setForegroundColor(ColorConstants.lightGray);
graphics.drawOval(circle);

graphics.setBackgroundColor(ColorConstants.blue);
graphics.fillOval(circle);

graphics.popState();
}

Looks very normal and easy, but the result doesn`t look normal:
http://i42.tinypic.com/v4ymh2.jpg
(I made the inner circle blue that you can see the difference better;
normally it`s also lightGray.)
The fill-method doesn`t fill the circle entirely. On the bottom right is
a sickle-shaped area which isn`t covered.

I already found a work-around: I make a second circle, which is 1px
higher and wider than the original circle and fill that circle.
But I don`t think this is the way it was intended to be used...

Is this a Bug or am I doing something wrong?

Best wishes
Julia
Re: Draw2D Bug? [message #247757 is a reply to message #247726] Tue, 17 March 2009 18:48 Go to previous message
Eclipse UserFriend
This seems like a rounding error which is common in Draw2D since it works
with ints. One could use the PrecisionXXX classes which store the
dimensions as doubles but most built-in implementations do not do their
calculations with the preciseXXX() values. My workaround is (besides using
paths which are stored as floats but have performance impact) to use large
dimension values so that rounding errors don't accumulate, and then scale
the zoom levels (see ZoomManager#setZoomLevels() and #setUIMultiplier()).
This may not be related to this problem, but should be a general hint to
overcome Draw2D's rounding mechanism.
Previous Topic:List of standard GEF keyboard shortcuts?
Next Topic:[Announce] GEF 3.5.0 I200903161158 is available
Goto Forum:
  


Current Time: Tue Apr 15 03:11:25 EDT 2025

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

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

Back to the top