Re: Transparency



GtkDrawingArea has it's own window, you can draw the image in the expose event,
the expose event can be triggered by 'gtk_widget_draw( psDrawingArea, &rect );'

Here is the expose event handler(sorry, I didn't clean it up). Please note, the
image must have a alpha(transparncy) channel in order to make it transparent.

Thanks

Yanxin

/*===========================================================================
##  "expose_event" for drawing_area
##===========================================================================*/

int igcallback_imageExpose(
 GtkWidget *psWidget, GdkEventExpose *psEvent, gpointer pvData )
{
 GdkRectangle sArea, sBounds, sIntersection;
 /* Get the psImage */
 tsClientImage *psImage = NULL;
    GdkPixbuf *psPixbuf = NULL;
 GdkPixmap *psPixmap = NULL;
 GdkBitmap *psMask = NULL;

 if( !pvData )
  return TRUE;

 psImage = (tsClientImage *)pvData;

 igmain_log( "igcallback_imageExpose()\n" );
 igmain_indent ++;

 /* Set the pixbuf. We use original pixbuf for the button image, scaled pixbuf
 ** for the pure image.
 */
 psPixbuf = psImage->psPixbuf;
 psMask = psImage->psMask;

 /* Field has been disassociated from image (display nothing). */
 if ( !psPixbuf ) {
  igmain_log( "No pixbuf, return\n" );
  igmain_indent --;
  return TRUE;
 }

 /* Ensure an event was passed. */
 if ( !psEvent ) {
  igmain_log( "No event, return\n" );
  igmain_indent --;
  return TRUE;
 }

 /* Ensure the widget is visible and has been mapped to the display. */
 if ( !GTK_WIDGET_VISIBLE( psWidget ) || !GTK_WIDGET_MAPPED( psWidget ) ) {
  igmain_log( "Widget not visible or mapped\n" );
  igmain_indent --;
  return TRUE;
 }

 sBounds.x      = 0;
 sBounds.y      = 0;
 sBounds.width  = gdk_pixbuf_get_width( psPixbuf );
 sBounds.height = gdk_pixbuf_get_height( psPixbuf );

 igmain_log(
  "   bounds: x:%5d y:%5d width:%5d height:%5d\n",
  sBounds.x, sBounds.y, sBounds.width, sBounds.height );

 /* Determine the visible area that needs to be redrawn. */
 sArea = psEvent->area;


 /* If the area to be redrawn does not intersect with the bounds
    of the image, we do nothing, thereby causing nothing to be drawn.
    In the future, we may have to explicitly clear this area. */
 if ( !gdk_rectangle_intersect( &sBounds, &sArea, &sIntersection ) ) {
  igmain_log( "Image does not intersect\n" );
  igmain_indent --;
  return TRUE;
 }


gdk_window_set_back_pixmap ( psWidget->window, NULL, FALSE );

gdk_window_shape_combine_mask( psWidget->window, psMask, 0, 0 );



    if ( gdk_pixbuf_get_has_alpha( psPixbuf ) ) {
        gdk_draw_rgb_32_image(
   psWidget->window,
   psWidget->style->black_gc,
   sIntersection.x, sIntersection.y,
   sIntersection.width, sIntersection.height, GDK_RGB_DITHER_MAX,
   gdk_pixbuf_get_pixels( psPixbuf )
    + ( sIntersection.y * gdk_pixbuf_get_rowstride( psPixbuf ) )
    + ( sIntersection.x * gdk_pixbuf_get_n_channels( psPixbuf ) ),
    gdk_pixbuf_get_rowstride( psPixbuf ) );
 }
 else
 {
  gdk_draw_rgb_image(
   psWidget->window,
   psWidget->style->white_gc ,
   sIntersection.x, sIntersection.y,
   sIntersection.width, sIntersection.height, GDK_RGB_DITHER_NORMAL,
   gdk_pixbuf_get_pixels( psPixbuf )
    + ( sIntersection.y * gdk_pixbuf_get_rowstride( psPixbuf ) )
    + ( sIntersection.x * gdk_pixbuf_get_n_channels( psPixbuf) ),
   gdk_pixbuf_get_rowstride( psPixbuf ) );
 }



 igmain_indent --;
 return TRUE;
}

Nabil Sayegh wrote:

On Mon, 2002-09-09 at 23:52, yanxin wrote:
  gdk_window_shape_combine_mask( psWidget->window, psMask, 0, 0 ) will do
it, you need to get the mask of your image.

Thanks a lot.
Where shall I put the pixmap ?
Is an eventbox enough ?

cu
--
 e-trolley Sayegh & John, Nabil Sayegh
 Tel.: 0700 etrolley /// 0700 38765539
 Fax.: +49 69 8299381-8
 PGP : www.e-trolley.de

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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