Issue with Graphics.setAlpha [message #222138] |
Fri, 25 August 2006 14:53 |
Eclipse User |
|
|
|
Originally posted by: cricard.businessobjects.com
Hello everybody,
I currently have a problem displaying some text on an alpha-blended figure.
At first, I thought the draw2D Label was doing something bad in its
paintFigure(), so I tried to minimize the risk by only writing the two or
three instructions I was interested in... to no avail.
All I want to do is have a translucent rectangular figure that displays some
text, and reacts to clicks (e.g. each one toggles its selection state,
rendered out by appropriately turning it opaque or not).
Here's the rather straightforward code:
class ToggleFigure extends Figure {
public void ToggleFigure () {
setForegroundColor(ColorConstants.red);
setBackgroundColor(ColorConstants.lightGray);
setBorder(new LineBorder());
setOpaque(false);
}
@Override
protected boolean isMouseEventTarget() {
return true;
}
@Override
public void handleMousePressed(MouseEvent event) {
setOpaque(! isOpaque());
}
@Override
public void paintFigure(Graphics graphics) {
graphics.setAlpha(100);
if(isOpaque())
graphics.fillRectangle(bounds);
graphics.translate(bounds.x, bounds.y);
graphics.drawString("Text", 0, 0);
}
}
The attached .png depicts my instanciating two such figures, and what
happens when I click on the first figure, then on the second: the latter
displays a badly scaled "Text" string.
Clicking on it again and again (thus selecting and unselecting it) doesn't
get rid of the unappropriate scaling, although repaint() is obviously
called.
However, if right after the bug I repeat the whole operation (click first
then second), or provoke an update by dragging another window over the badly
displayed text, the painting is OK again... until the next bug.
Removing the graphics.setAlpha(100) instruction solves the problem, at the
expense of alpha-blending of course.
However, drawing the string *then* filling the rectangle (something the
Label class cannot afford because it must do its job independently of alpha
painting) works fine under all circumstances:
@Override
public void paintFigure(Graphics graphics) {
graphics.setAlpha(100);
graphics.translate(bounds.x, bounds.y);
graphics.drawString("Text", 0, 0);
graphics.translate(-bounds.x, -bounds.y);
if(isOpaque())
graphics.fillRectangle(bounds);
}
Moral of the story: don't rely too much on alpha-blended Labels, and even if
it's the case pay extra attention to the order in which you call
fillRectangle and drawString (or drawText, for that matter).
Anyway, it would be greatly appreciated to have this bug solved, because
colleagues have already experienced several seemingly related issues (for
which a workaround fortunately exists).
Christophe.
-
Attachment: ZoomBug.png
(Size: 1.34KB, Downloaded 231 times)
|
|
|
Re: Issue with Graphics.setAlpha [message #222149 is a reply to message #222138] |
Fri, 25 August 2006 15:01 |
Eclipse User |
|
|
|
Originally posted by: cricard.businessobjects.com
Whoops, forgot to provide my configuration:
org.eclipse.swt.win32.win32.x86 (3.2.0.v3232m)
org.eclipse.gef (3.2.0.v20060626)
org.eclipse.gef.source (3.2.0.v20060626)
|
|
|
|
Re: Issue with Graphics.setAlpha [message #222275 is a reply to message #222157] |
Tue, 29 August 2006 11:26 |
Eclipse User |
|
|
|
Originally posted by: mateu.yabar.justinmind.com
I don't know if this is what you want, but I use a panel with transparency
and it works fine. the code is the following:
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.swt.SWT;
/**
* Panel with transparency
*/
public class TransparentPanel extends Panel {
public void setTransparentFill(int value) {
m_transparencyValue = value;
}
private int m_transparencyValue = 50;
private int m_transparencyValueOutline = 50;
public void paint(Graphics graphics) {
graphics.setAlpha(m_transparencyValue);
graphics.setAntialias(SWT.ON);
super.paint(graphics);
}
}
"Randy Hudson" <none@us.ibm.com> escribi
|
|
|
Re: Issue with Graphics.setAlpha [message #222290 is a reply to message #222275] |
Tue, 29 August 2006 15:48 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
The class below does not contain a main() method that shows the problem.
Refer to other posts or the draw2d.examples project to create a simple
draw2d app.
"exquisitus" <mateu.yabar@justinmind.com> wrote in message
news:ed188q$9pd$1@utils.eclipse.org...
>I don't know if this is what you want, but I use a panel with transparency
>and it works fine. the code is the following:
>
> import org.eclipse.draw2d.Graphics;
> import org.eclipse.draw2d.Panel;
> import org.eclipse.draw2d.RectangleFigure;
> import org.eclipse.swt.SWT;
>
> /**
> * Panel with transparency
> */
> public class TransparentPanel extends Panel {
>
> public void setTransparentFill(int value) {
> m_transparencyValue = value;
> }
>
> private int m_transparencyValue = 50;
>
> private int m_transparencyValueOutline = 50;
>
> public void paint(Graphics graphics) {
> graphics.setAlpha(m_transparencyValue);
> graphics.setAntialias(SWT.ON);
> super.paint(graphics);
> }
> }
>
>
>
> "Randy Hudson" <none@us.ibm.com> escribi
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03607 seconds