From: phantomjinx <pha...@us...> - 2011-04-29 22:00:00
|
commit 7a5fb5e9e495f02f553a364e981e67447f66e207 Author: phantomjinx <p.g...@ph...> Date: Fri Apr 29 21:39:41 2011 +0000 Gdk to Cairo migration of coverart display * Migrate GdkColor use to GdkRGBA * cairo_region_t replaces GdkRegion * Replaces expose event with draw event which already provide a cairo context to draw on. * Horizontal scroll bars no longer have an update-policy property plugins/cover_display/cover_display.xml | 1 - plugins/cover_display/display_coverart.c | 84 ++++++++++------------------ plugins/cover_display/display_coverart.h | 4 +- plugins/details_editor/details_editor.xml | 1 - 4 files changed, 32 insertions(+), 58 deletions(-) --- diff --git a/plugins/cover_display/cover_display.xml b/plugins/cover_display/cover_display.xml index 1f47d88..afb6aec 100644 --- a/plugins/cover_display/cover_display.xml +++ b/plugins/cover_display/cover_display.xml @@ -116,7 +116,6 @@ <object class="GtkHScale" id="cover_display_scaler"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="update_policy">discontinuous</property> <property name="digits">0</property> <property name="draw_value">False</property> </object> diff --git a/plugins/cover_display/display_coverart.c b/plugins/cover_display/display_coverart.c index 47dae76..019839b 100644 --- a/plugins/cover_display/display_coverart.c +++ b/plugins/cover_display/display_coverart.c @@ -79,8 +79,8 @@ dnd_coverart_drag_motion(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, static void set_cover_dimensions(Cover_Item *cover, int cover_index, gdouble img_width, gdouble img_height); static void coverart_sort_images(GtkSortType order); static void set_slider_range(gint index); -static GdkColor *convert_hexstring_to_gdk_color(gchar *hexstring); -static gboolean on_drawing_area_exposed(GtkWidget *draw_area, GdkEventExpose *event); +static GdkRGBA *convert_hexstring_to_rgba(const gchar *hexstring); +static gboolean on_drawing_area_drawn(GtkWidget *draw_area, cairo_t *cairo_draw_context, gpointer data); static void draw(cairo_t *cairo_context); static void redraw(gboolean force_pixbuf_update); @@ -212,7 +212,7 @@ void coverart_init_display(GtkWidget *parent, gchar *gladepath) { gtk_box_pack_start(GTK_BOX(cdwidget->canvasbox), GTK_WIDGET(cdwidget->draw_area), TRUE, TRUE, 0); /* create the expose event for the drawing area */ - g_signal_connect (G_OBJECT (cdwidget->draw_area), "expose_event", G_CALLBACK (on_drawing_area_exposed), NULL); + g_signal_connect (G_OBJECT (cdwidget->draw_area), "draw", G_CALLBACK (on_drawing_area_drawn), NULL); gtk_widget_add_events(cdwidget->draw_area, GDK_BUTTON_PRESS_MASK); /* set up some callback events on the main scaled image */ g_signal_connect(G_OBJECT(cdwidget->draw_area), "button-press-event", G_CALLBACK(on_main_cover_image_clicked), NULL); @@ -308,11 +308,11 @@ void coverart_block_change(gboolean val) { */ static void draw_string(cairo_t *cairo_context, const gchar *text, gdouble x, gdouble y) { static PangoFontDescription *desc = NULL; - GdkColor *color = coverart_get_foreground_display_color(); + GdkRGBA *color = coverart_get_foreground_display_color(); PangoLayout *layout; PangoRectangle extents; - gdk_cairo_set_source_color(cairo_context, color); + cairo_set_source_rgba(cairo_context, color->red, color->green, color->blue, color->alpha); g_free(color); if (!desc) { @@ -345,11 +345,11 @@ static void redraw(gboolean force_pixbuf_update) { g_return_if_fail(gtk_widget_get_window(GTK_WIDGET(cdwidget->draw_area))); force_pixbuf_covers = force_pixbuf_update; - GdkRegion *region = gdk_drawable_get_clip_region(gtk_widget_get_window(GTK_WIDGET(cdwidget->draw_area))); + cairo_region_t *region = gdk_window_get_clip_region(gtk_widget_get_window(GTK_WIDGET(cdwidget->draw_area))); /* redraw the cairo canvas completely by exposing it */ gdk_window_invalidate_region(gtk_widget_get_window(GTK_WIDGET(cdwidget->draw_area)), region, TRUE); gdk_window_process_updates(gtk_widget_get_window(GTK_WIDGET(cdwidget->draw_area)), TRUE); - gdk_region_destroy(region); + cairo_region_destroy(region); if (g_list_length(album_key_list) <= 1) { gtk_widget_set_sensitive(GTK_WIDGET(cdwidget->cdslider), FALSE); @@ -374,10 +374,10 @@ static void draw(cairo_t *cairo_context) { gint cover_index[] = { 0, 8, 1, 7, 2, 6, 3, 5, 4 }; /* Draw the background */ - GdkColor *color = coverart_get_background_display_color(); + GdkRGBA *color = coverart_get_background_display_color(); cairo_save(cairo_context); - gdk_cairo_set_source_color(cairo_context, color); + cairo_set_source_rgba(cairo_context, color->red, color->green, color->blue, color->alpha); cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); cairo_paint(cairo_context); cairo_restore(cairo_context); @@ -623,7 +623,8 @@ static void set_cover_dimensions(Cover_Item *cover, int cover_index, gdouble img gint PANEL_WIDTH = 0, PANEL_HEIGHT = 0; gint CONTBOX_WIDTH = 0, CONTBOX_HEIGHT = 0; - gdk_drawable_get_size(GDK_DRAWABLE(gtk_widget_get_window(cdwidget->canvasbox)), &PANEL_WIDTH, &PANEL_HEIGHT); + PANEL_WIDTH = gtk_widget_get_allocated_width(cdwidget->canvasbox); + PANEL_HEIGHT = gtk_widget_get_allocated_height(cdwidget->canvasbox); gtk_widget_get_size_request(cdwidget->controlbox, &CONTBOX_WIDTH, &CONTBOX_HEIGHT); // If panel width not been rendered default to minimum @@ -772,10 +773,10 @@ static void set_highlight(Cover_Item *cover, gint index, cairo_t * cr) { * */ static void set_shadow_reflection(Cover_Item *cover, cairo_t *cr) { - GdkColor *color = coverart_get_background_display_color(); - gdouble r = ((gdouble) (color->red >> 8)) / 255; - gdouble g = ((gdouble) (color->green >> 8)) / 255; - gdouble b = ((gdouble) (color->blue >> 8)) / 255; + GdkRGBA *color = coverart_get_background_display_color(); + gdouble r = color->red; + gdouble g = color->green; + gdouble b = color->blue; g_free(color); cairo_save(cr); @@ -1007,20 +1008,11 @@ void coverart_track_changed(Track *track, gint signal) { * Returns: * boolean indicating whether other handlers should be run. */ -static gboolean on_drawing_area_exposed(GtkWidget *draw_area, GdkEventExpose *event) { +static gboolean on_drawing_area_drawn(GtkWidget *draw_area, cairo_t *cairo_draw_context, gpointer data) { if (!draw_area || !gtk_widget_get_window(draw_area)) return FALSE; - cairo_t *cairo_draw_context; - - /* get a cairo_t */ - cairo_draw_context = gdk_cairo_create(gtk_widget_get_window(draw_area)); - - /* set a clip region for the expose event */ - cairo_rectangle(cairo_draw_context, event->area.x, event->area.y, event->area.width, event->area.height); - cairo_clip(cairo_draw_context); draw(cairo_draw_context); - cairo_destroy(cairo_draw_context); return FALSE; } @@ -1415,22 +1407,12 @@ void coverart_select_cover(Track *track) { * Returns: * boolean indicating whether other handlers should be run. */ -static gboolean on_coverart_preview_dialog_exposed(GtkWidget *drawarea, GdkEventExpose *event, gpointer data) { +static gboolean on_coverart_preview_dialog_drawn(GtkWidget *draw_area, cairo_t *cairo_draw_context, gpointer data) { GdkPixbuf *image = data; - /* Draw the image using cairo */ - cairo_t *cairo_context; - - /* get a cairo_t */ - cairo_context = gdk_cairo_create(gtk_widget_get_window(drawarea)); - /* set a clip region for the expose event */ - cairo_rectangle(cairo_context, event->area.x, event->area.y, event->area.width, event->area.height); - cairo_clip(cairo_context); - - gdk_cairo_set_source_pixbuf(cairo_context, image, 0, 0); - cairo_paint(cairo_context); + gdk_cairo_set_source_pixbuf(cairo_draw_context, image, 0, 0); + cairo_paint(cairo_draw_context); - cairo_destroy(cairo_context); return FALSE; } @@ -1490,7 +1472,7 @@ static void display_coverart_image_dialog(GdkPixbuf *image) { /* Set the draw area's minimum size */ gtk_widget_set_size_request(drawarea, pixwidth, pixheight); - g_signal_connect (G_OBJECT (drawarea), "expose_event", G_CALLBACK (on_coverart_preview_dialog_exposed), scaled); + g_signal_connect (G_OBJECT (drawarea), "draw", G_CALLBACK (on_coverart_preview_dialog_drawn), scaled); /* Display the dialog and block everything else until the * dialog is closed. @@ -1688,9 +1670,9 @@ void coverart_set_cover_from_file() { * of the coverart display, which is selected from the preferences. * */ -GdkColor *coverart_get_background_display_color() { +GdkRGBA *coverart_get_background_display_color() { gchar *hex_string; - GdkColor *color; + GdkRGBA *color; if (album_key_list == NULL) hex_string = "#FFFFFF"; @@ -1699,7 +1681,7 @@ GdkColor *coverart_get_background_display_color() { else prefs_get_string_value("coverart_display_bg_color", &hex_string); - color = convert_hexstring_to_gdk_color(hex_string); + color = convert_hexstring_to_rgba(hex_string); return color; } @@ -1711,9 +1693,9 @@ GdkColor *coverart_get_background_display_color() { * foreground color refers to the color used by the artist and album text. * */ -GdkColor *coverart_get_foreground_display_color() { +GdkRGBA *coverart_get_foreground_display_color() { gchar *hex_string; - GdkColor *color; + GdkRGBA *color; if (album_key_list == NULL) hex_string = "#000000"; @@ -1722,7 +1704,7 @@ GdkColor *coverart_get_foreground_display_color() { else prefs_get_string_value("coverart_display_fg_color", &hex_string); - color = convert_hexstring_to_gdk_color(hex_string); + color = convert_hexstring_to_rgba(hex_string); return color; } @@ -2035,17 +2017,11 @@ static void dnd_coverart_drag_data_received(GtkWidget *widget, GdkDragContext *d * * @GdkColor */ -static GdkColor *convert_hexstring_to_gdk_color(gchar *hexstring) { - GdkColor *colour; - GdkColormap *map; - map = gdk_colormap_get_system(); - - colour = g_malloc(sizeof(GdkColor)); - - if (!gdk_color_parse(hexstring, colour)) - return NULL; +static GdkRGBA *convert_hexstring_to_rgba(const gchar *hexstring) { + GdkRGBA *colour; - if (!gdk_colormap_alloc_color(map, colour, FALSE, TRUE)) + colour = g_malloc(sizeof(GdkRGBA)); + if (!gdk_rgba_parse(colour, hexstring)) return NULL; return colour; diff --git a/plugins/cover_display/display_coverart.h b/plugins/cover_display/display_coverart.h index 962d766..8a3afe8 100644 --- a/plugins/cover_display/display_coverart.h +++ b/plugins/cover_display/display_coverart.h @@ -180,7 +180,7 @@ void coverart_select_cover (Itdb_Track *track); * of the coverart display, which is selected from the preferences. * */ -GdkColor *coverart_get_background_display_color (); +GdkRGBA *coverart_get_background_display_color (); /** * coverart_get_foreground_display_color: @@ -190,7 +190,7 @@ GdkColor *coverart_get_background_display_color (); * foreground color refers to the color used by the artist and album text. * */ -GdkColor *coverart_get_foreground_display_color (); +GdkRGBA *coverart_get_foreground_display_color (); /** * diff --git a/plugins/details_editor/details_editor.xml b/plugins/details_editor/details_editor.xml index b878004..9d760bd 100644 --- a/plugins/details_editor/details_editor.xml +++ b/plugins/details_editor/details_editor.xml @@ -2492,7 +2492,6 @@ simultaneously</property> <object class="GtkHScale" id="details_scale_23"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="update_policy">discontinuous</property> <property name="digits">0</property> <property name="value_pos">right</property> </object> |