PDA

View Full Version : OSD: No no alpha transparency when working in buffer?



Erstam
May 26th, 2005, 07:34 AM
I'm currently testing the OSD. Drawing text to screen with transparent background works fine. But when I work on the buffer the transparency is lost.

Here is the code:



1 function OnPaint()
2 print('Paint')
3 myosd:CopyBufferToScreen()
4 end
5
6 if ( myosd ~= nil ) then
7 myosd:Destroy()
8 myosd=nil;
9 end
10
11 if ( myosd == nil ) then
12 myosd = osd.CreateOSD(0)
13 myosd:Topmost(true)
14 end
15
16 myosd:OnEvent(osd.OnPaint,OnPaint);
17
18 green = osd.MakeARGB(255,0,255,0)
19 trans = osd.MakeARGB(0,0,0,0)
20 greenbrush = osd.CreateSolidBrush(green)
21 transbrush = osd.CreateSolidBrush(trans)
22
23 OSDtext = "Zoom Player"
24
25 w,h=myosd:MeasureString(OSDtext,"Arial",36)
26 myosd:Size(w+10,h+10)
27 myosd:Position(100,100)
28
29 myosd:WorkOnBuffer(true)
30 myosd:FillRectangle(0,0, w+10,h+10, transbrush);
31 myosd:DrawString(OSDtext,"Arial", 36,5,5, greenbrush)
32 myosd:WorkOnBuffer(false)
33 myosd:Show()

When I remove lines 16, 29 and 33 and put line 32 to line 28 then the transparency works.

Is the buffer not capable of alpha transparency?

Erstam

Erstam
May 26th, 2005, 07:55 AM
I have to correct myself: Drawing text to screen with transparent (alpha transparent) background works, but the transparent background of the OSD does not update. If I move a window below the OSD, it does not shine through.

If I use the "SetTransparancy" method, updating works (in both buffered and unbuffered mode), but that is just a workaround, since it defines a whole color (a RGB value, not an ARGB value) as having a certain transparency.

BTW: The method "SetTransparancy" is misspelled. Shouldn' it be "SetTransparency"?

Erstam

birty
May 26th, 2005, 08:12 AM
Transparancy is probably just the american spelling, the english spelling is indeed Transparency

Mark F
May 26th, 2005, 09:17 AM
Nope. We don't spell anything having to do with see-through-colour as "Transparancy". :D

Ron
May 26th, 2005, 09:56 AM
hmm, so what IS the proper US spelling?

Mark F
May 26th, 2005, 11:31 AM
As Birty said: transparency

Ron
May 26th, 2005, 11:33 AM
Thanks!

Erstam
July 13th, 2005, 02:16 AM
Ok, the spelling issue is resolved now, but the original problem still is present.

There seems to be something wrong with alpha transparency or I'm to dumb to understand this thing correctly. Here is what I think: With osd.MakeARGB(a,r,g,b) I can select an RGB value and an alpha transparency that controls the opacity of the color (from 0 = completely transparent to 255 = solid color).

However the attached script does not produce a semi-transparent red background, instead it is solid.

If I specify the semi-transparent red color with the SetTransparency function, not only this color, but every other is semi-transparent as well.

Could you have a look into this issue?

Erstam

Promixis
July 13th, 2005, 04:07 AM
Have you looked at the osd.lua file? The code there will help. I use OSD:Clear (transparentcolor) which seems to work. See line 797 of the Text class and also look at the base class.

Erstam
July 13th, 2005, 05:37 AM
Maybe I'm to dumb. I followed you advice with OSD:clear. The following snippet should create an OSD with a semi-transparent red background. "red50brush" is a brush with the ARGB value (128,255,0,0).



movieosd:WorkOnBuffer(true)
movieosd:Clear (osd.Colors.Black) -- required for alpha/transparents osds
movieosd:FillRectangle (0,0,200,150,red50brush)
movieosd:DrawRectangle (0,0,200,150,whitepen)
movieosd:DrawStringFull("Test for alpha transparency","Arial Black",16,10,10,180,130,1,0,whitebrush)
movieosd:Line(10,80,100,130, blackpen)
movieosd:ScaleDrawImage(image, 110,80,80,60)
movieosd:WorkOnBuffer(false)
movieosd:CopyBufferToScreen()
movieosd:Show()


But unfortunately the background is not transparent (as the attached image shows).

Can you give me a hint to what I did wrong?

Erstam

Promixis
July 13th, 2005, 05:42 AM
Hi,

can you post the entire lua snippet. I don't see anything obvious...

Erstam
July 13th, 2005, 05:47 AM
Here you are!

Promixis
July 13th, 2005, 05:52 AM
you had

movieosd:SetTransparency(red50,128)


commented out. it works here ;)

Erstam
July 13th, 2005, 06:12 AM
When I use SetTransparency not only the color I specify is transparent but also everything else (as the attached picture shows). How can I just set the background to semi-transparent?

And if I need SetTransparency, what does that alpha value in MakeARGB do?

Erstam

birty
July 13th, 2005, 06:45 AM
i think the alpha value is mainly for drawing one osd item on top of another, for example you could draw a box and have the background colour of the osd come through

Ron
July 13th, 2005, 07:16 AM
Correct the alpha value is just for drawing osd items over eachother. If you want a transparant window you'll use SetTrancparancy. This one can do 2 things. either make the whole window transpararent as per your screenshot or just key out 1 color.

Erstam
July 13th, 2005, 08:00 AM
Ok, that clears things up.

But how do I key out just one color? In my screenshot I used movieosd:SetTransparency(red50,128), so I expected it to just key out the red50 with 50% transparency. But instead the whole osd became semi-transparent.

Erstam