From: Darren S. <ds...@us...> - 2005-01-12 18:45:16
|
Update of /cvsroot/xine/gnome-xine/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30180/src Modified Files: time_widget.c time_widget.h Log Message: Make sure that the image covers the area allocated to the widget (by resizing). Optimise the font setup and get the parent window from the widget. Index: time_widget.c =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/time_widget.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- time_widget.c 12 Jan 2005 00:35:34 -0000 1.4 +++ time_widget.c 12 Jan 2005 18:45:04 -0000 1.5 @@ -35,7 +35,7 @@ #include "player.h" #define TIME_WIDGET_WIDTH (90) -#define TIME_WIDGET_HEIGHT (12+14*3) +#define TIME_WIDGET_HEIGHT (40) struct time_widget_s { @@ -45,17 +45,19 @@ PangoFontDescription *pfd, *pfd_big; GdkPixmap *pixmap; + gint width, height; GdkGC *black_gc, *blue_gc, *white_gc; }; -static gboolean expose_event_cb (GtkWidget *, GdkEventExpose *, gpointer); - static void paint_tw (time_widget_t *tw) { gint pos_stream, pos_time, length_time; + if (!tw->pixmap) + return; + gdk_draw_rectangle (tw->pixmap, tw->black_gc, TRUE, 0, 0, - TIME_WIDGET_WIDTH, TIME_WIDGET_HEIGHT); + tw->width, tw->height); if ((xine_get_status (stream) == XINE_STATUS_PLAY) && (xine_get_pos_length (stream, &pos_stream, &pos_time, &length_time))) @@ -91,15 +93,6 @@ } } -time_widget_t *create_time_widget (GtkWidget **w) -{ - time_widget_t *tw = (time_widget_t *) malloc (sizeof (time_widget_t)); - memset (tw, 0, sizeof (*tw)); - *w = tw->w = gtk_image_new (); - gtk_widget_set_size_request (tw->w, TIME_WIDGET_WIDTH, TIME_WIDGET_HEIGHT); - return tw; -} - static gint update_time_widget_cb (gpointer tw) { gdk_threads_enter (); @@ -109,11 +102,13 @@ return TRUE; } -void postinit_time_widget (GtkWidget *window, time_widget_t *tw) +static void tw_create_pixmap (time_widget_t *tw, gint width, gint height) { - GtkRequisition size; - gtk_widget_size_request (tw->w, &size); - tw->pixmap = gdk_pixmap_new (tw->w->window, size.width, size.height, -1); + GtkWidget *window = gtk_widget_get_toplevel (tw->w); + + tw->width = width; + tw->height = height; + tw->pixmap = gdk_pixmap_new (tw->w->window, width, height, -1); tw->black_gc = gdk_gc_new (tw->pixmap); alloc_color (window, tw->black_gc, 0, 0, 0); @@ -124,27 +119,44 @@ tw->blue_gc = gdk_gc_new (tw->pixmap); alloc_color (window, tw->blue_gc, 20000, 20000, 65535); - /* pango stuff (antialiased font rendering) */ + gdk_draw_rectangle (tw->pixmap, tw->black_gc, TRUE, 0, 0, width, height); + gtk_image_set_from_pixmap (GTK_IMAGE(tw->w), tw->pixmap, NULL); +} - tw->pfd = pango_font_description_new (); - pango_font_description_set_family (tw->pfd, "Sans"); - pango_font_description_set_weight (tw->pfd, PANGO_WEIGHT_BOLD); - pango_font_description_set_size (tw->pfd, 8*PANGO_SCALE); - tw->pfd_big = pango_font_description_new (); - pango_font_description_set_family (tw->pfd_big, "Sans"); - pango_font_description_set_weight (tw->pfd_big, PANGO_WEIGHT_BOLD); - pango_font_description_set_size (tw->pfd_big, 12*PANGO_SCALE); +static gboolean tw_configure_cb (GtkWidget *widget, GtkAllocation *event, + time_widget_t *tw) +{ + if (tw->w->parent && tw->w->window && + (!tw->pixmap || event->width != tw->width || event->height != tw->height)) + tw_create_pixmap (tw, event->width, event->height); + return FALSE; +} +time_widget_t *create_time_widget (GtkWidget **w) +{ + time_widget_t *tw = (time_widget_t *) malloc (sizeof (time_widget_t)); + memset (tw, 0, sizeof (*tw)); + *w = tw->w = gtk_image_new (); + gtk_widget_set_size_request (tw->w, TIME_WIDGET_WIDTH, TIME_WIDGET_HEIGHT); + g_signal_connect (G_OBJECT(tw->w), "size-allocate", + G_CALLBACK(tw_configure_cb), tw); + return tw; +} + +void postinit_time_widget (time_widget_t *tw) +{ + GtkRequisition size; + gtk_widget_size_request (tw->w, &size); + + /* pango stuff (antialiased font rendering) */ + + tw->pfd = pango_font_description_from_string ("Sans Bold 8"); tw->pl = gtk_widget_create_pango_layout (tw->w, NULL); pango_layout_set_font_description (tw->pl, tw->pfd); + tw->pfd_big = pango_font_description_from_string ("Sans Bold 12"); tw->pl_big = gtk_widget_create_pango_layout (tw->w, NULL); pango_layout_set_font_description (tw->pl_big, tw->pfd_big); - /* display... */ - - gdk_draw_rectangle (tw->pixmap, tw->black_gc, TRUE, 0, 0, - TIME_WIDGET_WIDTH, TIME_WIDGET_HEIGHT); - gtk_image_set_from_pixmap (GTK_IMAGE(tw->w), tw->pixmap, NULL); gtk_timeout_add (500, update_time_widget_cb, tw); } Index: time_widget.h =================================================================== RCS file: /cvsroot/xine/gnome-xine/src/time_widget.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- time_widget.h 9 Apr 2004 21:41:01 -0000 1.1 +++ time_widget.h 12 Jan 2005 18:45:04 -0000 1.2 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004 the xine-project + * Copyright (C) 2004-2005 the xine-project * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -29,7 +29,6 @@ time_widget_t *create_time_widget (GtkWidget **w); -void postinit_time_widget (GtkWidget *window, time_widget_t *tw) ; +void postinit_time_widget (time_widget_t *tw); #endif - |