mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-07 03:02:17 +00:00
examples: Use cairo instead of to-be-deprecated GDK API
Fixes bug #625001.
This commit is contained in:
parent
5011cb2392
commit
c1982cd6fe
4 changed files with 45 additions and 37 deletions
|
@ -2463,11 +2463,14 @@ handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
|
||||||
if (state < GST_STATE_PAUSED) {
|
if (state < GST_STATE_PAUSED) {
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
GdkWindow *window = gtk_widget_get_window (widget);
|
GdkWindow *window = gtk_widget_get_window (widget);
|
||||||
GtkStyle *style = gtk_widget_get_style (widget);
|
cairo_t *cr;
|
||||||
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
gdk_draw_rectangle (window, style->black_gc, TRUE, 0, 0,
|
cr = gdk_cairo_create (window);
|
||||||
allocation.width, allocation.height);
|
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||||
|
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
|
||||||
|
cairo_fill (cr);
|
||||||
|
cairo_destroy (cr);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2449,11 +2449,14 @@ handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
|
||||||
if (state < GST_STATE_PAUSED) {
|
if (state < GST_STATE_PAUSED) {
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
GdkWindow *window = gtk_widget_get_window (widget);
|
GdkWindow *window = gtk_widget_get_window (widget);
|
||||||
GtkStyle *style = gtk_widget_get_style (widget);
|
cairo_t *cr;
|
||||||
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
gdk_draw_rectangle (window, style->black_gc, TRUE, 0, 0,
|
cr = gdk_cairo_create (window);
|
||||||
allocation.width, allocation.height);
|
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||||
|
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
|
||||||
|
cairo_fill (cr);
|
||||||
|
cairo_destroy (cr);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,29 +45,36 @@ gtk_widget_get_allocation (GtkWidget * w, GtkAllocation * a)
|
||||||
static GtkWidget *video_window = NULL;
|
static GtkWidget *video_window = NULL;
|
||||||
static GstElement *sink = NULL;
|
static GstElement *sink = NULL;
|
||||||
static gulong embed_xid = 0;
|
static gulong embed_xid = 0;
|
||||||
static GdkGC *trans_gc = NULL;
|
static GdkColor trans_color;
|
||||||
|
static gboolean trans_color_set = FALSE;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
redraw_overlay (GtkWidget * widget)
|
redraw_overlay (GtkWidget * widget)
|
||||||
{
|
{
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
GdkWindow *window = gtk_widget_get_window (widget);
|
GdkWindow *window = gtk_widget_get_window (widget);
|
||||||
GtkStyle *style = gtk_widget_get_style (widget);
|
cairo_t *cr;
|
||||||
|
|
||||||
|
cr = gdk_cairo_create (window);
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
gdk_draw_rectangle (window, style->white_gc, TRUE, 0, 0,
|
|
||||||
allocation.width, allocation.height);
|
|
||||||
|
|
||||||
if (trans_gc) {
|
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||||
|
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
|
||||||
|
cairo_fill (cr);
|
||||||
|
|
||||||
|
if (trans_color_set) {
|
||||||
guint x, y;
|
guint x, y;
|
||||||
guint h = allocation.height * 0.75;
|
guint h = allocation.height * 0.75;
|
||||||
|
|
||||||
gdk_draw_rectangle (window, trans_gc, TRUE, 0, 0, allocation.width, h);
|
gdk_cairo_set_source_color (cr, &trans_color);
|
||||||
|
cairo_rectangle (cr, 0, 0, allocation.width, h);
|
||||||
|
cairo_fill (cr);
|
||||||
|
|
||||||
for (y = h; y < allocation.height; y++) {
|
for (y = h; y < allocation.height; y++) {
|
||||||
for (x = 0; x < allocation.width; x++) {
|
for (x = 0; x < allocation.width; x++) {
|
||||||
if (((x & 1) || (y & 1)) && (x & 1) != (y & 1)) {
|
if (((x & 1) || (y & 1)) && (x & 1) != (y & 1)) {
|
||||||
gdk_draw_point (window, trans_gc, x, y);
|
cairo_move_to (cr, x, y);
|
||||||
|
cairo_paint (cr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,18 +134,14 @@ msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
|
||||||
/* When state of the pipeline changes to paused or playing we start updating scale */
|
/* When state of the pipeline changes to paused or playing we start updating scale */
|
||||||
switch (GST_STATE_TRANSITION (old, new)) {
|
switch (GST_STATE_TRANSITION (old, new)) {
|
||||||
case GST_STATE_CHANGE_READY_TO_PAUSED:{
|
case GST_STATE_CHANGE_READY_TO_PAUSED:{
|
||||||
GdkWindow *window = gtk_widget_get_window (video_window);
|
|
||||||
|
|
||||||
g_object_get (G_OBJECT (sink), "colorkey", &color, NULL);
|
g_object_get (G_OBJECT (sink), "colorkey", &color, NULL);
|
||||||
if (color != -1) {
|
if (color != -1) {
|
||||||
GdkColor trans_color = { 0,
|
trans_color.red = (color & 0xff0000) >> 8;
|
||||||
(color & 0xff0000) >> 8,
|
trans_color.green = (color & 0xff00);
|
||||||
(color & 0xff00),
|
trans_color.blue = (color & 0xff) << 8;
|
||||||
(color & 0xff) << 8
|
trans_color_set = TRUE;
|
||||||
};
|
} else {
|
||||||
|
trans_color_set = FALSE;
|
||||||
trans_gc = gdk_gc_new (window);
|
|
||||||
gdk_gc_set_rgb_fg_color (trans_gc, &trans_color);
|
|
||||||
}
|
}
|
||||||
handle_resize_cb (video_window, NULL, NULL);
|
handle_resize_cb (video_window, NULL, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -106,29 +106,28 @@ handle_expose_cb (GtkWidget * widget, GdkEventExpose * event,
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
GdkWindow *window;
|
GdkWindow *window;
|
||||||
GtkStyle *style;
|
GtkStyle *style;
|
||||||
|
cairo_t *cr;
|
||||||
|
|
||||||
style = gtk_widget_get_style (widget);
|
style = gtk_widget_get_style (widget);
|
||||||
window = gtk_widget_get_window (widget);
|
window = gtk_widget_get_window (widget);
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
cr = gdk_cairo_create (window);
|
||||||
|
|
||||||
|
gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
|
||||||
|
|
||||||
/* we should only redraw outside of the video rect! */
|
/* we should only redraw outside of the video rect! */
|
||||||
/*
|
cairo_rectangle (cr, 0, event->area.y, r->x, event->area.height);
|
||||||
gdk_draw_rectangle (widget->window, widget->style->bg_gc[0], TRUE,
|
cairo_rectangle (cr, r->x + r->w, event->area.y,
|
||||||
0, 0, widget->allocation.width, widget->allocation.height);
|
|
||||||
gdk_draw_rectangle (widget->window, widget->style->bg_gc[0], TRUE,
|
|
||||||
event->area.x, event->area.y, event->area.width, event->area.height);
|
|
||||||
*/
|
|
||||||
gdk_draw_rectangle (window, style->bg_gc[0], TRUE,
|
|
||||||
0, event->area.y, r->x, event->area.height);
|
|
||||||
gdk_draw_rectangle (window, style->bg_gc[0], TRUE,
|
|
||||||
r->x + r->w, event->area.y,
|
|
||||||
allocation.width - (r->x + r->w), event->area.height);
|
allocation.width - (r->x + r->w), event->area.height);
|
||||||
|
|
||||||
gdk_draw_rectangle (window, style->bg_gc[0], TRUE,
|
cairo_rectangle (cr, event->area.x, 0, event->area.width, r->y);
|
||||||
event->area.x, 0, event->area.width, r->y);
|
cairo_rectangle (cr, event->area.x, r->y + r->h,
|
||||||
gdk_draw_rectangle (window, style->bg_gc[0], TRUE,
|
|
||||||
event->area.x, r->y + r->h,
|
|
||||||
event->area.width, allocation.height - (r->y + r->h));
|
event->area.width, allocation.height - (r->y + r->h));
|
||||||
|
|
||||||
|
cairo_fill (cr);
|
||||||
|
|
||||||
|
cairo_destroy (cr);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
g_print ("expose(%p)\n", widget);
|
g_print ("expose(%p)\n", widget);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue