Re: [gtk-list] Pixmap animation/replace-on-the-fly



On 12/10/98 D. Emilio Grimaldo Tunon uttered the following other thing:
> HI (hello?!)
> 	Can anybody point me to a relatively simple pixmap
> animation example? or at least something to replace a pixmap
> in a button with another pixmap on the fly. I say simple because
> I don't want to download terabytes of GNOME code just to use
> 0.5% of it, besides my sysadmin wouldn't be happy with that
> either...

GtkWidget *button;
GtkWidget *pixmap;
GdkPixmap *pix1;
GdkBitmap *mask1;
GdkPixmap *pix2;
GdkBitmap *mask2;

/* Create the button without a label */
button = gtk_button_new ();

/* Generate your pixmap */
pix1 = gdk_pixmap_create_from_xpm (window, &mask1, style->bg[GTK_STATE_NORMAL],
                                  xpm_filename);
pix2 = gdk_pixmap_create_from_xpm (window, &mask2, style->bg[GTK_STATE_NORMAL],
                                  xpm_filename);

/* Create a gtk pixmap */
pixmap = gtk_pixmap_new (pix1, mask1);

/* Add the pixmap to the button */
gtk_container_add (GTK_CONTAINER (button), pixmap);

gtk_widget_show (pixmap);
gtk_widget_show (button);

/* When you want to switch, change the pixmap 
 * Typically, you would probably set up a periodic timer to do this for
 * an animation
 */
gtk_pixmap_set (GTK_PIXMAP (pixmap), pix2, mask2);


There you go.  Or, you could embed a drawing_area in the button instead
of the pixmap, and then use standard gdk commands to animate or draw on
the "button".

Brandon
-- 
 Brandon Long         "Its much more fun to be sand than oil in the
 MD6 Crash Test Dummy         machinery of life."
 Intel Corporation                   -- Unknown
          I'm too low on the totem pole to speak for Intel.
                  http://www.fiction.net/blong/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]