Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Issue with Graphics.setAlpha
Issue with Graphics.setAlpha [message #222138] Fri, 25 August 2006 14:53 Go to next message
Eclipse UserFriend
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 205 times)
Re: Issue with Graphics.setAlpha [message #222149 is a reply to message #222138] Fri, 25 August 2006 15:01 Go to previous messageGo to next message
Eclipse UserFriend
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 #222157 is a reply to message #222138] Fri, 25 August 2006 17:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Please open a bug report either showing the fix or provide a test case that
can be executed. Since you aren't using scaling, I'm completely stumped.
Re: Issue with Graphics.setAlpha [message #222275 is a reply to message #222157] Tue, 29 August 2006 11:26 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Issue with Graphics.setAlpha [message #222363 is a reply to message #222290] Thu, 31 August 2006 07:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mateu.yabar.justinmind.com

Sorry, my awnser (I'm the new exquisitus) was for crici, I was trying to
solve his problem, not explaining it.


"Randy Hudson" <none@us.ibm.com> escribi
Re: Issue with Graphics.setAlpha [message #223039 is a reply to message #222157] Mon, 18 September 2006 15:30 Go to previous message
Eclipse UserFriend
Originally posted by: cricard.businessobjects.com

Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=152555 seemed to be very
similar.
I added a simple program that shows it all (and yes, zooming is involved ;)

"Randy Hudson" <none@us.ibm.com> wrote in message
news:ecnbpi$ncd$1@utils.eclipse.org...
> Please open a bug report either showing the fix or provide a test case
> that can be executed. Since you aren't using scaling, I'm completely
> stumped.
>
Previous Topic:Printing the title in header or footer of the page
Next Topic:GEF application, not plug-in!
Goto Forum:
  


Current Time: Tue Apr 23 06:31:40 GMT 2024

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

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

Back to the top