From: "Rorschach", on 17/11/2008 03:54 :

> I wanna write a little battery-indicator in C with GTK. It's already working
> nicly in the console and I know how to write a trayicon with gtk but what
> I don't know is: how can I show the current capacity of the battery? I mean
> shall I do 100 pictures (1-100%) and if the capacity changes just show
> the corresponding new picture? This is imo a bad solution because I have
> to ship 100 pictures with my application.

I can't imagine the images being too large to ship a hundred of them.  Unless 
you're expecting someone to be using it on a full-screen sized widget.


> But how else can I realize this? Painting the image on-the-fly? Just showing 
> the battery and painting it's content on-the-fly?

The combination approach is something I've used a number of times.  Ship the 
battery graphic, and graphics of any ornaments you might need, at appropriate 
sizes, and then overlay the battery level using any of many methods.  The ones 
I've used are;

1) Include 100 level images (although simply having as many as the number of 
pixels you're expecting it to be in height is enough) of just the guage itself. 
 This is only needed if the body of the guage image changes somehow, like an 
edge or inner glow or something that can't be achieved to stretching.  (I only 
had five images when I did this, but they were 98x98 pixels each)

2) Paint the guage onto the resized/prepared battery image.  You can get a 
little bit creative here to keep it looking nice, by mixing your paint colour 
with the existing image.  If you have an alpha channel you're not using, for 
example, the guage can be a flat colour "behind" the base image, and 
compositing will let "glass" type look show through.  You can also ship a 
second image with just the guage portion, and paint that before applying it to 
the base image, again, over or under depending on your needs, and with or 
without stretching.

3) A trick I've used in one project, was to draw a short "near empty" indicator 
graphic, and split it into two caps.  The middle was simply filled with the 
bottom row of pixels of the upper cap.  And by drawing it in black and white, I 
could do the relatively expensive manual colouring work at load-time to produce 
three coloured versions in memory from the one image on disk.  It was then just 
a matter of splicing the images together over top of the base graphic as needed 
(mildly tedious but quite doable).


Good luck.


Fredderic


------------------------------------------------------------
Graphic Design School
Love Graphic Design? Find a school near you. Click Now.
http://tagline.excite.com/fc/BK72PcZbtOKJiH5Dl1BzFGLPxHc1cH5ceH5aAmwSTULJFHVp1at57l/
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to