Embbed a SDL surface into a gtk



Hello,

I'm trying to embbed a SDL surface into a gtk application. I don't know much about writing new widgets or dealing with cairo, but I also didn't find any up-to-date solutions on the internet.

The steps I did so far:

1. wrote a new class, GtkSdl which inherts from GtkLayout, because I also want to make the surface scrollable with scrollbars, so it seems to be better than inheriting from GtkDrawingArea(?)
2. overwrote the draw function with gtk_sdl_draw
3. in gtk_sdl_draw:
3.1. got the x/y position of the scrollbars and the with/height with the value / page_size attributes of the adjustment
The code looks like:

GtkAdjustment *hadj = gtk_layout_get_hadjustment(GTK_LAYOUT(widget));
GtkAdjustment *vadj = gtk_layout_get_vadjustment(GTK_LAYOUT(widget));
	
gdouble x = (gint)gtk_adjustment_get_value(hadj);
gdouble width = (gint)gtk_adjustment_get_page_size(hadj);
gdouble y = (gint)gtk_adjustment_get_value(vadj);
gdouble height = (gint)gtk_adjustment_get_page_size(vadj);	

Is this a valid way to get those datas? I didn't got any other ideas by reading through the api

3.2. blit the big surface to a smaller on that matches the width and height of the step above

I guess this is the point where I have to get the small sdl surface onto the cairo context. I found this link: http://cairographics.org/SDL/ If I do so, how can I get the new cairo_surface to the cairo context? I tried something like this:

cairo_set_source_surface(cr, cairo_surface, 0, 0);	

but it really doesn't seems to be working. How to do this more correctly?

Greetings


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