Skip to content

Commit

Permalink
gtkui: fix album art column left/right/center alignment (fixes #2878)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Dec 27, 2022
1 parent 637f410 commit c1e9ed3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugins/gtkui/playlist/ddblistview.c
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ ddb_listview_list_render_album_art (DdbListview *listview, cairo_t *cr, DdbListv
if (listview->datasource->is_album_art_column(c->user_data) && x + c->width > clip->x) {
fill_list_background(listview, cr, x, y, c->width, grp->height-priv->grouptitle_height, clip);
if (priv->grouptitle_height > 0) {
listview->renderer->draw_album_art(listview, cr, grp, c->user_data, min_y, grp_next_y, x, y, c->width, grp->height-priv->grouptitle_height);
listview->renderer->draw_album_art(listview, cr, grp, c->user_data, min_y, grp_next_y, x, y, c->width, grp->height-priv->grouptitle_height, c->align_right);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/gtkui/playlist/ddblistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ typedef struct {

typedef struct {
void (*draw_group_title) (DdbListview *listview, cairo_t *drawable, DdbListviewIter iter, int x, int y, int width, int height, int group_depth);
void (*draw_album_art) (DdbListview *listview, cairo_t *cr, DdbListviewGroup *grp, void *user_data, int pinned, int next_y, int x, int y, int width, int height);
void (*draw_album_art) (DdbListview *listview, cairo_t *cr, DdbListviewGroup *grp, void *user_data, int pinned, int next_y, int x, int y, int width, int height, int alignment);
void (*draw_column_data) (DdbListview *listview, cairo_t *cr, DdbListviewIter it, int idx, int align, void *user_data, GdkColor *fg_clr, int x, int y, int width, int height, int even);
} ddb_listview_renderer_t;

Expand Down
16 changes: 12 additions & 4 deletions plugins/gtkui/playlist/playlistrenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ cover_draw_cairo (GdkPixbuf *pixbuf, int x, int min_y, int max_y, int width, int
}

void
pl_common_draw_album_art (DdbListview *listview, cairo_t *cr, DdbListviewGroup *grp, void *user_data, int min_y, int next_y, int x, int y, int width, int height) {
pl_common_draw_album_art (DdbListview *listview, cairo_t *cr, DdbListviewGroup *grp, void *user_data, int min_y, int next_y, int x, int y, int width, int height, int alignment) {
int art_width = width - ART_PADDING_HORZ * 2;
int art_height = height - ART_PADDING_VERT * 2;
if (art_width < 8 || art_height < 8 || !grp->head) {
Expand Down Expand Up @@ -311,13 +311,21 @@ pl_common_draw_album_art (DdbListview *listview, cairo_t *cr, DdbListviewGroup *
availableSize.height = art_height;
GtkAllocation desiredSize = covermanager_desired_size_for_image_size(cm, size, availableSize);

GdkPixbuf *scaled_image = covermanager_create_scaled_image(cm, image, desiredSize);
int scaled_image_width = gdk_pixbuf_get_width(scaled_image);
int scaled_image_height = gdk_pixbuf_get_height(scaled_image);

// center horizontally
if (size.width < size.height) {
art_x += art_width/2 - desiredSize.width/2;
if (alignment == 1) { // align
art_x += art_width - scaled_image_width;
}
else if (alignment == 2) { // center
art_x += art_width/2 - scaled_image_width/2;
}
}

GdkPixbuf *scaled_image = covermanager_create_scaled_image(cm, image, desiredSize);
cover_draw_cairo(scaled_image, art_x, min_y, next_y, art_width, art_height, cr, CAIRO_FILTER_FAST);
cover_draw_cairo(scaled_image, art_x, min_y, next_y, scaled_image_width, scaled_image_height, cr, CAIRO_FILTER_FAST);
g_object_unref(scaled_image);

gobj_unref(image);
Expand Down
2 changes: 1 addition & 1 deletion plugins/gtkui/playlist/playlistrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ void
main_draw_group_title (DdbListview *listview, cairo_t *drawable, DdbListviewIter it, int x, int y, int width, int height, int group_depth);

void
pl_common_draw_album_art (DdbListview *listview, cairo_t *cr, DdbListviewGroup *grp, void *user_data, int min_y, int next_y, int x, int y, int width, int height);
pl_common_draw_album_art (DdbListview *listview, cairo_t *cr, DdbListviewGroup *grp, void *user_data, int min_y, int next_y, int x, int y, int width, int height, int alignment);

#endif /* playlistrenderer_h */
2 changes: 1 addition & 1 deletion plugins/gtkui/playlist/plcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int
pl_common_is_album_art_column (void *user_data);

void
pl_common_draw_album_art (DdbListview *listview, cairo_t *cr, DdbListviewGroup *group, void *user_data, int min_y, int next_y, int x, int y, int width, int height);
pl_common_draw_album_art (DdbListview *listview, cairo_t *cr, DdbListviewGroup *group, void *user_data, int min_y, int next_y, int x, int y, int width, int height, int alignment);

gboolean
list_handle_keypress (DdbListview *ps, int keyval, int state, int iter);
Expand Down

0 comments on commit c1e9ed3

Please sign in to comment.