Added two event handlers to the drawing area (untested)

This commit is contained in:
Pierre Pronchery 2012-12-20 03:05:19 +01:00
parent 91a7d6008e
commit 78bc8d390c

View File

@ -50,6 +50,7 @@ struct _Camera
GtkWidget * infobar_label;
#endif
GtkWidget * area;
GdkPixmap * pixmap;
};
@ -61,6 +62,10 @@ static int _camera_ioctl(Camera * camera, unsigned long request,
/* callbacks */
static gboolean _camera_on_closex(gpointer data);
static gboolean _camera_on_drawing_area_configure(GtkWidget * widget,
GdkEventConfigure * event, gpointer data);
static gboolean _camera_on_drawing_area_expose(GtkWidget * widget,
GdkEventExpose * event, gpointer data);
static gboolean _camera_on_open(gpointer data);
static gboolean _camera_on_refresh(gpointer data);
@ -144,6 +149,11 @@ Camera * camera_new(void)
gtk_box_pack_start(GTK_BOX(vbox), camera->infobar, FALSE, TRUE, 0);
#endif
camera->area = gtk_drawing_area_new();
camera->pixmap = NULL;
g_signal_connect(camera->area, "configure-event", G_CALLBACK(
_camera_on_drawing_area_configure), camera);
g_signal_connect(camera->area, "expose-event", G_CALLBACK(
_camera_on_drawing_area_expose), camera);
gtk_box_pack_start(GTK_BOX(vbox), camera->area, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(camera->window), vbox);
gtk_widget_show_all(camera->window);
@ -155,6 +165,8 @@ Camera * camera_new(void)
/* camera_delete */
void camera_delete(Camera * camera)
{
if(camera->pixmap != NULL)
g_object_unref(camera->pixmap);
if(camera->window != NULL)
gtk_widget_destroy(camera->window);
if(camera->source != 0)
@ -234,6 +246,57 @@ static gboolean _camera_on_closex(gpointer data)
}
/* camera_on_drawing_area_configure */
static gboolean _camera_on_drawing_area_configure(GtkWidget * widget,
GdkEventConfigure * event, gpointer data)
{
/* XXX this code is inspired from GQcam */
Camera * camera = data;
GtkAllocation allocation;
GdkGC * gc;
GdkColor black = { 0, 0, 0, 0 };
GdkColor white = { 0xffffffff, 0xffff, 0xffff, 0xffff };
if(camera->pixmap != NULL)
g_object_unref(camera->pixmap);
/* FIXME requires Gtk+ 2.18 */
gtk_widget_get_allocation(widget, &allocation);
camera->pixmap = gdk_pixmap_new(widget->window, allocation.width,
allocation.height, -1);
/* FIXME this code is untested */
gc = gdk_gc_new(widget->window);
gdk_gc_set_background(gc, &white);
gdk_gc_set_foreground(gc, &black);
/* FIXME is it not better to scale the previous pixmap for now? */
gdk_draw_rectangle(camera->pixmap, gc, TRUE, 0, 0, allocation.width,
allocation.height);
g_object_unref(gc);
return TRUE;
}
/* camera_on_drawing_area_expose */
static gboolean _camera_on_drawing_area_expose(GtkWidget * widget,
GdkEventExpose * event, gpointer data)
{
/* XXX this code is inspired from GQcam */
Camera * camera = data;
GtkAllocation allocation;
GdkGC * gc;
/* FIXME requires Gtk+ 2.18 */
gtk_widget_get_allocation(widget, &allocation);
/* FIXME this code is untested */
gc = gdk_gc_new(widget->window);
gdk_draw_pixmap(widget->window, gc, camera->pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
g_object_unref(gc);
return FALSE;
}
/* camera_on_open */
static gboolean _camera_on_open(gpointer data)
{