Graphics setAlpha() and connectors [message #235670] |
Thu, 14 June 2007 05:01  |
Eclipse User |
|
|
|
Originally posted by: johan.piculell.ericsson.com
Hi. I have figures in my graphical editor that inherits from Label,
contains an icon and a text. In order to get different background colors
with transparency I have overridden paintFigure() and uses setAlpha() on
the Graphics object. I have however two issues with this:
1. If I do this in my subclassed Label class:
...
setAlpha(100);
graphics.fillRectangle(getBounds());
setAlpha(255);
do rest of the drawing just as in Label.paintFigure()
...
Then the icon does not appear at all, instead I did a pushState before
setAlpha(100) and poped the state before drawing the rest and this works
fine. But I'm curious why and if this really is correct behavior. Seems to
me like icon drawing gets messed up if you touched the alpha stuff on the
graphics object.
2. For some reason all connectors also gets affected by the setAlpha()
call. This is a complete mystery for me, cannot see the relation here at
all, especially not since connectors are in a separate layer even.
Could this be a bug?
regards
/Johan
|
|
|
|
|
|
|
Re: Graphics setAlpha() and connectors [message #235751 is a reply to message #235731] |
Fri, 15 June 2007 04:50   |
Eclipse User |
|
|
|
Originally posted by: johan.piculell.ericsson.com
Johan Piculell wrote:
> Mark Levison wrote:
>> Johan Piculell wrote:
>>> Mark Levison wrote:
>>>> Johan Piculell wrote:
>>>>> Hi. I have figures in my graphical editor that inherits from Label,
>>>>> contains an icon and a text. In order to get different background
>>>>> colors with transparency I have overridden paintFigure() and uses
>>>>> setAlpha() on the Graphics object. I have however two issues with this:
>>>>>
>>>>> 1. If I do this in my subclassed Label class:
>>>>> ..
>>>>> setAlpha(100);
>>>>> graphics.fillRectangle(getBounds());
>>>>> setAlpha(255);
>>>>> do rest of the drawing just as in Label.paintFigure()
>>>>> ..
>>>>>
>>>>> Then the icon does not appear at all, instead I did a pushState
>>>>> before setAlpha(100) and poped the state before drawing the rest and
>>>>> this works fine. But I'm curious why and if this really is correct
>>>>> behavior. Seems to me like icon drawing gets messed up if you
>>>>> touched the alpha stuff on the graphics object.
>>>>
>>>> I'm going from memory here but doesn't setting the alpha push you
>>>> into advanced graphics mode?
>>>>
>>> Not quite sure if I follow, you mean this is the reason for the first
>>> issue?
>> Sorry I've not had enough sleep this week. I'm saying that setting your
>> Alpha may have an unintended side effect. In particular I think that the
>> alpha is part of the GDI+ and probably causes the advanced graphics mode
>> to be set (think SetGraphics(hdc, GM_ADVANCED)
>> http://msdn2.microsoft.com/en-us/library/ms532671.aspx). I suspect the
>> only way to clear it is by poping the state (not that I've checked).
>>
>> Now the real question is - why does advanced graphics mode screw up the
>> drawing of your labels?
>>
>> Distant memory says that text rendering in Advanced Graphics Mode can
>> have some funky issues.
>>
>> I suspect that's part of why Sun implemented Java2D on top of DirectX
>> (don't quote me on any of this - I've just spent the past few years
>> doing WinForms development work).
>>
>> Hope this provides some hints.
>>
>> Cheers
>> Mark Levison
>> ------------------------------------------------------------ ----------
>> Blog: http://www.notesfromatooluser.com/
>> Most Popular posts:
>> Aperture vs. Lightroom - best comparisons
>> http://www.notesfromatooluser.com/2007/02/aperture_vs_lig.ht ml
>> Scrum in a Nutshell Presentation
>> http://www.notesfromatooluser.com/2007/05/scrum_in_a_nuts.ht ml
>> Getting Things Done!!! Can't Keep Track of all the tasks you have to do?
>> Need a better Tool to Implement GTD?
>> http://www.notesfromatooluser.com/2006/12/getting_things_.ht ml
> Thanks Mark. Forgot to mention that this is on Linux... but now you gave
> me the idea of testing on Win as well to see what happens. Will do that
> as soon as I find some time, might give me some leads.
> Time for me to get some sleep now as well ;)
> /Johan
Have now conducted some tests on windows:
- On windows I don't have to push and pop the state, setting alpha back to
255 works excellent there.
- The connectors does not get affected at all no matter how I draw my
figures, good!
- It is also possible to make icons transparent on windows, did not work
on Linux (but this does not matter much to me)
As I see it this connector issue is an annoying bug on Linux, the rest I
can live with. File a bugzilla? Is this SWT related or GEF?
regards
/Johan
|
|
|
|
|
|
|
|
Re: Graphics setAlpha() and connectors [message #239700 is a reply to message #235670] |
Fri, 09 November 2007 08:39  |
Eclipse User |
|
|
|
Originally posted by: simon.worknotes.org
I was going nuts. Tried my code on Mac and Windows - OK. I had just
reached the same conclusion when I came across your thread.
Sincerely, Thanks.
Johan Piculell wrote:
> Hi. I have figures in my graphical editor that inherits from Label,
> contains an icon and a text. In order to get different background colors
> with transparency I have overridden paintFigure() and uses setAlpha() on
> the Graphics object. I have however two issues with this:
>
> 1. If I do this in my subclassed Label class:
> ..
> setAlpha(100);
> graphics.fillRectangle(getBounds());
> setAlpha(255);
> do rest of the drawing just as in Label.paintFigure()
> ..
>
> Then the icon does not appear at all, instead I did a pushState before
> setAlpha(100) and poped the state before drawing the rest and this works
> fine. But I'm curious why and if this really is correct behavior. Seems
> to me like icon drawing gets messed up if you touched the alpha stuff on
> the graphics object.
>
> 2. For some reason all connectors also gets affected by the setAlpha()
> call. This is a complete mystery for me, cannot see the relation here at
> all, especially not since connectors are in a separate layer even.
> Could this be a bug?
>
> regards
> /Johan
>
|
|
|
Powered by
FUDForum. Page generated in 0.04311 seconds