Vista Sidebar Gadget, Transparent Backgrounds, and Font Color

by Filip Stanek 9. May 2008 12:30

We've had a request from a client to build a Windows Vista Sidebar Gadget.  The background on the gadget is to be somewhat see-through.  So I've played around with gadgets, and noticed that when I make a semi-transparent background on the gadget, the font color gets all messed up.  For example, I wanted white text on a blue background with 50% opacity, and the font appeared blueish, even though it was supposed to be white.  If I turn off the opacity on the background, the font becomes white, but as long as there's opacity, the font is messed up.

Well, after doing some research, it appears there is a way to display the proper font color on transparent backgrounds, although I didn't find this anywhere on the Microsoft site.  The trick is to use JavaScript and the addTextObject() method.  Here's an example of some code, and the resulting gadget:

 

   1: <html> 
   2:   <head> 
   3:     <title>Sample Gadget</title> 
   4:     <style> 
   5:       body { width: 120px; height: 200px; font-size: 12px; margin: 0; font-family: Verdana; color: #FFFFFF; } 
   6:       .gadget { margin: 3px; } 
   7:     </style> 
   8:   </head> 
   9:   <body> 
  10:     <div class="gadget"> 
  11:       <div>This text is not white.</div> 
  12:     </div> 
  13:     <g:background id="background" src="images\bgblue.png" style="width:100%;height:100%;z-index: -1; position: absolute; top: 0; left: 0;" opacity="50"></g:background> 
  14:     <script language="javascript" type="text/javascript">
   1: document.getElementById("background").addTextObject("This text is white.", "Verdana", 12, "white", 3, 50);
</script>
  15:   </body> 
  16: </html>

Tags: ,

Windows Development

Comments

  • Comments (2)

+0 Vote Up     Vote Down # Kevin United States on 5/9/2008 10:53:09 PM

Kevin

Yo Filip, you can also just do it with a 24-bit png (not sure if thats what you did in your example) and a div relatively positioned over the background.

Example here: http://ync.net/Dev/Transparent/

I've experienced issues with CSS transparency on any element with text. It not only applies the transparency to the element's background image but also to the text inside the element, which is pretty retarded.

- Kevin

Reply

+0 Vote Up     Vote Down # Adam Poland on 2/17/2010 11:01:02 AM

Adam

Kevin, we talk about Windows gadgets, and they use MSIE renderer (Trident) - so 24-bit png-s won't help here. There is one more problem: if you display one png over another - you'll have pink artifacts instead of transparency in top png. Well, I've never seen a transparent Windows gadget, and I think that's the reason why. But addTextObject hack is very cool and it's a way to do semi-transparent gadget, if you obey no transparent png-s over png-s limitation. Or... Filip - is it a method to place an image similar to addTextObject? Maybe the image could use transparency without artifacts?

Anyway, I'm trying to restyle some of downloaded gadgets to my desktop style - and the transparency problem is the wall. I see no simple way to make gadgets semi-transparent - or achieve "OSD" style effect. I use Windows 7 - so no, Microsoft didn't fix the bug since Vista.

Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading




Tag cloud

About Filip Stanek

Death Note Pic I'm a developer at ACG Multimedia in Cincinnati, OH. Besides working with ASP.NET, Flash, and other web technologies, I enjoy playing chess, video games, etc.

Currently playing:
- Final Fantasy XIII
E-mail me Send mail

Recent Comments

Comment RSS

Month List

Page List