SDL_surface as gtk widget

Cheers all,

I am trying to figure out how to convert a 32bit RGBA SDL surface (i.e.
the pixel data of a surface) into a GtkWidget (i.e. a GtkImage).

This is not entirely SDL related - but I though someone might have done
that before and it doesn’t hurt to ask.

Bye
Andreas

Hi,

In reply to myself, some helpful chap from the gtk mailing list gave me
the insight.

Here is the code:

/* Drawing callback */
int gtkFloatExposeEvent (GtkWidget *widget, GdkEventExpose *event,
gpointer data)
{
SDL_Surface *image=(SDL_Surface *)data;

gdk_window_clear_area (widget->window, event->area.x, event->area.y,
event->area.width, event->area.height);
gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
&event->area);
gdk_draw_rgb_32_image(widget->window,
widget->style->fg_gc[widget->state],0,0,image->w, image->h,
GDK_RGB_DITHER_NORMAL,image->pixels,image->pitch);
gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],NULL);
return 1;
}


/* Create window /
float_window = gtk_window_new(GTK_WINDOW_POPUP);
gtk_widget_realize(GTK_WIDGET(float_window));
gtk_widget_set_usize(GTK_WIDGET(float_window),source->image->w,source->image->h);
gtk_widget_set_uposition(GTK_WIDGET(float_window),x,y);
/
Add drawing area */
drawing_area = gtk_drawing_area_new();
gtk_drawing_area_size (GTK_DRAWING_AREA
(drawing_area),source->image->w, source->image->h);
gtk_signal_connect (GTK_OBJECT (drawing_area), “expose_event”,
GTK_SIGNAL_FUNC(gtkFloatExposeEvent), (void )source->image);
gtk_widget_show(drawing_area);
gtk_container_add(GTK_CONTAINER(float_window), drawing_area);
/
Show popup */
gtk_widget_show(float_window);

Maybe its helpful to someone else.

Ciao
Andreas

Andreas Schiffler wrote:>

Cheers all,

I am trying to figure out how to convert a 32bit RGBA SDL surface (i.e.
the pixel data of a surface) into a GtkWidget (i.e. a GtkImage).

This is not entirely SDL related - but I though someone might have done
that before and it doesn’t hurt to ask.

Bye
Andreas