summaryrefslogtreecommitdiff
path: root/plugins/gtkui
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-02-28 17:19:35 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-02-28 17:19:35 +0100
commit41030c8ee688af283f56b47d0a80f88aa2d4c53d (patch)
treee119d4719c9c8ada330a91531883d1870e9525a6 /plugins/gtkui
parentcec1ac93d89ddf1c4c24cbfa87e1d00230c926c0 (diff)
album art column WIP
Diffstat (limited to 'plugins/gtkui')
-rw-r--r--plugins/gtkui/ddblistview.c66
-rw-r--r--plugins/gtkui/ddblistview.h10
-rw-r--r--plugins/gtkui/deadbeef.glade2
-rw-r--r--plugins/gtkui/interface.c2
-rw-r--r--plugins/gtkui/mainplaylist.c42
5 files changed, 78 insertions, 44 deletions
diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c
index ff9c4f18..b8b419f7 100644
--- a/plugins/gtkui/ddblistview.c
+++ b/plugins/gtkui/ddblistview.c
@@ -68,6 +68,7 @@ G_DEFINE_TYPE (DdbListview, ddb_listview, GTK_TYPE_TABLE);
struct _DdbListviewColumn {
char *title;
int width;
+ int minheight;
struct _DdbListviewColumn *next;
void *user_data;
unsigned align_right : 1;
@@ -105,7 +106,7 @@ ddb_listview_list_expose (DdbListview *ps, int x, int y, int w, int h);
void
ddb_listview_list_render_row_background (DdbListview *ps, DdbListviewIter it, int even, int cursor, int x, int y, int w, int h);
void
-ddb_listview_list_render_row_foreground (DdbListview *ps, DdbListviewIter it, int even, int cursor, int x, int y, int w, int h);
+ddb_listview_list_render_row_foreground (DdbListview *ps, DdbListviewIter it, int even, int cursor, int group_y, int x, int y, int w, int h);
void
ddb_listview_list_render_row (DdbListview *ps, int row, DdbListviewIter it, int expose);
void
@@ -607,7 +608,7 @@ ddb_listview_list_render (DdbListview *listview, int x, int y, int w, int h) {
if (grp_y + GROUP_TITLE_HEIGHT + (i+1) * listview->rowheight >= y + listview->scrollpos && grp_y + GROUP_TITLE_HEIGHT + i * listview->rowheight< y + h + listview->scrollpos) {
gdk_draw_rectangle (listview->backbuf, listview->list->style->bg_gc[GTK_STATE_NORMAL], TRUE, -listview->hscrollpos, grp_y + GROUP_TITLE_HEIGHT + i * listview->rowheight - listview->scrollpos, listview->totalwidth, listview->rowheight);
ddb_listview_list_render_row_background (listview, it, (idx + 1 + i) & 1, (idx+i) == listview->binding->cursor () ? 1 : 0, -listview->hscrollpos, grp_y + GROUP_TITLE_HEIGHT + i * listview->rowheight - listview->scrollpos, listview->totalwidth, listview->rowheight);
- ddb_listview_list_render_row_foreground (listview, it, (idx + 1 + i) & 1, (idx+i) == listview->binding->cursor () ? 1 : 0, -listview->hscrollpos, grp_y + GROUP_TITLE_HEIGHT + i * listview->rowheight - listview->scrollpos, listview->totalwidth, listview->rowheight);
+ ddb_listview_list_render_row_foreground (listview, it, (idx + 1 + i) & 1, (idx+i) == listview->binding->cursor () ? 1 : 0, i * listview->rowheight, -listview->hscrollpos, grp_y + GROUP_TITLE_HEIGHT + i * listview->rowheight - listview->scrollpos, listview->totalwidth, listview->rowheight);
}
DdbListviewIter next = listview->binding->next (it);
listview->binding->unref (it);
@@ -618,6 +619,7 @@ ddb_listview_list_render (DdbListview *listview, int x, int y, int w, int h) {
int filler = grpheight - (GROUP_TITLE_HEIGHT + listview->rowheight * grp->num_items);
if (filler > 0) {
gtk_paint_flat_box (treeview->style, listview->backbuf, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, treeview, "cell_even_ruled", x, grp_y - listview->scrollpos + GROUP_TITLE_HEIGHT + listview->rowheight * grp->num_items, w, filler);
+ ddb_listview_list_render_row_foreground (listview, NULL, 0, 0, grp->num_items * listview->rowheight, -listview->hscrollpos, grp_y - listview->scrollpos + GROUP_TITLE_HEIGHT + listview->rowheight * grp->num_items, listview->totalwidth, filler);
}
grp_y += grpheight;
@@ -1015,7 +1017,7 @@ ddb_listview_list_setup_hscroll (DdbListview *ps) {
// returns -1 if row not found
int
-ddb_listview_list_get_drawinfo (DdbListview *listview, int row, int *even, int *cursor, int *x, int *y, int *w, int *h) {
+ddb_listview_list_get_drawinfo (DdbListview *listview, int row, int *even, int *cursor, int *group_y, int *x, int *y, int *w, int *h) {
DdbListviewGroup *grp = listview->groups;
int idx = 0;
int idx2 = 0;
@@ -1027,6 +1029,7 @@ ddb_listview_list_get_drawinfo (DdbListview *listview, int row, int *even, int *
int idx_in_group = row - idx;
*even = (idx2 + 1 + idx_in_group) & 1;
*cursor = (row == listview->binding->cursor ()) ? 1 : 0;
+ *group_y = idx_in_group * listview->rowheight;
*x = -listview->hscrollpos;
*y += GROUP_TITLE_HEIGHT + (row - idx) * listview->rowheight;
*w = listview->totalwidth;
@@ -1046,14 +1049,15 @@ ddb_listview_list_render_row (DdbListview *listview, int row, DdbListviewIter it
int even;
int cursor;
int x, y, w, h;
- if (ddb_listview_list_get_drawinfo (listview, row, &even, &cursor, &x, &y, &w, &h) == -1) {
+ int group_y;
+ if (ddb_listview_list_get_drawinfo (listview, row, &even, &cursor, &group_y, &x, &y, &w, &h) == -1) {
return;
}
draw_begin ((uintptr_t)listview->backbuf);
ddb_listview_list_render_row_background (listview, it, even, cursor, x, y, w, h);
if (it) {
- ddb_listview_list_render_row_foreground (listview, it, even, cursor, x, y, w, h);
+ ddb_listview_list_render_row_foreground (listview, it, even, cursor, group_y, x, y, w, h);
}
draw_end ();
if (expose) {
@@ -1088,7 +1092,7 @@ ddb_listview_list_render_row_background (DdbListview *ps, DdbListviewIter it, in
}
void
-ddb_listview_list_render_row_foreground (DdbListview *ps, DdbListviewIter it, int even, int cursor, int x, int y, int w, int h) {
+ddb_listview_list_render_row_foreground (DdbListview *ps, DdbListviewIter it, int even, int cursor, int group_y, int x, int y, int w, int h) {
int width, height;
draw_get_canvas_size ((uintptr_t)ps->backbuf, &width, &height);
if (it && ps->binding->is_selected (it)) {
@@ -1105,7 +1109,7 @@ ddb_listview_list_render_row_foreground (DdbListview *ps, DdbListviewIter it, in
int cidx = 0;
for (c = ps->columns; c; c = c->next, cidx++) {
int cw = c->width;
- ps->binding->draw_column_data (ps, ps->backbuf, it, cidx, x, y, cw, h);
+ ps->binding->draw_column_data (ps, ps->backbuf, it, cidx, group_y, x, y, cw, h);
x += cw;
}
}
@@ -1926,6 +1930,9 @@ ddb_listview_header_motion_notify_event (GtkWidget *widget,
int newx = ev_x > x + MIN_COLUMN_WIDTH ? ev_x : x + MIN_COLUMN_WIDTH;
c->width = newx-x;
+ if (c->minheight) {
+ ddb_listview_build_groups (ps);
+ }
ddb_listview_list_setup_hscroll (ps);
ddb_listview_header_render (ps);
ddb_listview_header_expose (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height);
@@ -2257,21 +2264,16 @@ ddb_listview_is_scrolling (DdbListview *listview) {
return listview->dragwait;
}
-// columns
-void
-ddb_listview_column_insert (DdbListview *listview, int before, const char *title, int width, int align_right, void *user_data);
-void
-ddb_listview_column_remove (DdbListview *listview, int idx);
-
/////// column management code
DdbListviewColumn *
-ddb_listview_column_alloc (const char *title, int width, int align_right, void *user_data) {
+ddb_listview_column_alloc (const char *title, int width, int align_right, int minheight, void *user_data) {
DdbListviewColumn * c = malloc (sizeof (DdbListviewColumn));
memset (c, 0, sizeof (DdbListviewColumn));
c->title = strdup (title);
c->width = width;
c->align_right = align_right;
+ c->minheight = minheight;
c->user_data = user_data;
return c;
}
@@ -2288,8 +2290,8 @@ ddb_listview_column_get_count (DdbListview *listview) {
}
void
-ddb_listview_column_append (DdbListview *listview, const char *title, int width, int align_right, void *user_data) {
- DdbListviewColumn* c = ddb_listview_column_alloc (title, width, align_right, user_data);
+ddb_listview_column_append (DdbListview *listview, const char *title, int width, int align_right, int minheight, void *user_data) {
+ DdbListviewColumn* c = ddb_listview_column_alloc (title, width, align_right, minheight, user_data);
int idx = 0;
DdbListviewColumn * columns = listview->columns;
if (columns) {
@@ -2308,8 +2310,8 @@ ddb_listview_column_append (DdbListview *listview, const char *title, int width,
}
void
-ddb_listview_column_insert (DdbListview *listview, int before, const char *title, int width, int align_right, void *user_data) {
- DdbListviewColumn *c = ddb_listview_column_alloc (title, width, align_right, user_data);
+ddb_listview_column_insert (DdbListview *listview, int before, const char *title, int width, int align_right, int minheight, void *user_data) {
+ DdbListviewColumn *c = ddb_listview_column_alloc (title, width, align_right, minheight ,user_data);
if (listview->columns) {
DdbListviewColumn * prev = NULL;
DdbListviewColumn * next = listview->columns;
@@ -2363,16 +2365,16 @@ ddb_listview_column_remove (DdbListview *listview, int idx) {
DdbListviewColumn *next = c->next->next;
ddb_listview_column_free (listview, c->next);
c->next = next;
+ listview->binding->columns_changed (listview);
return;
}
c = c->next;
- idx++;
+ i++;
}
if (!c) {
trace ("ddblv: attempted to remove column that is not in list\n");
}
- listview->binding->columns_changed (listview);
}
void
@@ -2414,7 +2416,7 @@ ddb_listview_column_move (DdbListview *listview, DdbListviewColumn *which, int i
}
int
-ddb_listview_column_get_info (DdbListview *listview, int col, const char **title, int *width, int *align_right, void **user_data) {
+ddb_listview_column_get_info (DdbListview *listview, int col, const char **title, int *width, int *align_right, int *minheight, void **user_data) {
DdbListviewColumn *c;
int idx = 0;
for (c = listview->columns; c; c = c->next, idx++) {
@@ -2422,6 +2424,7 @@ ddb_listview_column_get_info (DdbListview *listview, int col, const char **title
*title = c->title;
*width = c->width;
*align_right = c->align_right;
+ *minheight = c->minheight;
*user_data = c->user_data;
return 0;
}
@@ -2430,7 +2433,7 @@ ddb_listview_column_get_info (DdbListview *listview, int col, const char **title
}
int
-ddb_listview_column_set_info (DdbListview *listview, int col, const char *title, int width, int align_right, void *user_data) {
+ddb_listview_column_set_info (DdbListview *listview, int col, const char *title, int width, int align_right, int minheight, void *user_data) {
DdbListviewColumn *c;
int idx = 0;
for (c = listview->columns; c; c = c->next, idx++) {
@@ -2439,6 +2442,7 @@ ddb_listview_column_set_info (DdbListview *listview, int col, const char *title,
c->title = strdup (title);
c->width = width;
c->align_right = align_right;
+ c->minheight = minheight;
c->user_data = user_data;
return 0;
}
@@ -2470,6 +2474,14 @@ ddb_listview_build_groups (DdbListview *listview) {
char str[1024];
char curr[1024];
+ int min_height= 0;
+ DdbListviewColumn *c;
+ for (c = listview->columns; c; c = c->next) {
+ if (c->minheight && c->width > min_height) {
+ min_height = c->width;
+ }
+ }
+
GROUP_TITLE_HEIGHT = DEFAULT_GROUP_TITLE_HEIGHT;
DdbListviewIter it = listview->binding->head ();
while (it) {
@@ -2483,8 +2495,8 @@ ddb_listview_build_groups (DdbListview *listview) {
grp->num_items = listview->binding->count ();
GROUP_TITLE_HEIGHT = 0;
grp->height = GROUP_TITLE_HEIGHT + grp->num_items * listview->rowheight;
-// if (grp->height < 100) {
-// grp->height = 100;
+// if (grp->height < min_height) {
+// grp->height = min_height;
// }
listview->fullheight = grp->height;
listview->fullheight += GROUP_TITLE_HEIGHT;
@@ -2494,9 +2506,9 @@ ddb_listview_build_groups (DdbListview *listview) {
strcpy (str, curr);
DdbListviewGroup *newgroup = malloc (sizeof (DdbListviewGroup));
if (grp) {
-// if (grp->height < 100) {
-// grp->height = 100;
-// }
+ if (grp->height - GROUP_TITLE_HEIGHT < min_height) {
+ grp->height = min_height + GROUP_TITLE_HEIGHT;
+ }
listview->fullheight += grp->height;
grp->next = newgroup;
}
diff --git a/plugins/gtkui/ddblistview.h b/plugins/gtkui/ddblistview.h
index d3a547eb..a39e4fa7 100644
--- a/plugins/gtkui/ddblistview.h
+++ b/plugins/gtkui/ddblistview.h
@@ -73,7 +73,7 @@ typedef struct {
// callbacks
void (*draw_group_title) (DdbListview *listview, GdkDrawable *drawable, DdbListviewIter iter, int x, int y, int width, int height);
- void (*draw_column_data) (DdbListview *listview, GdkDrawable *drawable, DdbListviewIter iter, int column, int x, int y, int width, int height);
+ void (*draw_column_data) (DdbListview *listview, GdkDrawable *drawable, DdbListviewIter iter, int column, int group_y, int x, int y, int width, int height);
void (*list_context_menu) (DdbListview *listview, DdbListviewIter iter, int idx);
void (*header_context_menu) (DdbListview *listview, int col);
void (*handle_doubleclick) (DdbListview *listview, DdbListviewIter iter, int idx);
@@ -175,15 +175,15 @@ ddb_listview_is_scrolling (DdbListview *listview);
int
ddb_listview_column_get_count (DdbListview *listview);
void
-ddb_listview_column_append (DdbListview *listview, const char *title, int width, int align_right, void *user_data);
+ddb_listview_column_append (DdbListview *listview, const char *title, int width, int align_right, int minheight, void *user_data);
void
-ddb_listview_column_insert (DdbListview *listview, int before, const char *title, int width, int align_right, void *user_data);
+ddb_listview_column_insert (DdbListview *listview, int before, const char *title, int width, int align_right, int minheight, void *user_data);
void
ddb_listview_column_remove (DdbListview *listview, int idx);
int
-ddb_listview_column_get_info (DdbListview *listview, int col, const char **title, int *width, int *align_right, void **user_data);
+ddb_listview_column_get_info (DdbListview *listview, int col, const char **title, int *width, int *align_right, int *minheight, void **user_data);
int
-ddb_listview_column_set_info (DdbListview *listview, int col, const char *title, int width, int align_right, void *user_data);
+ddb_listview_column_set_info (DdbListview *listview, int col, const char *title, int width, int align_right, int minheight, void *user_data);
void
ddb_listview_build_groups (DdbListview *listview);
diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade
index ca64e2c1..6849df03 100644
--- a/plugins/gtkui/deadbeef.glade
+++ b/plugins/gtkui/deadbeef.glade
@@ -1916,6 +1916,7 @@ Album
Title
Length
Track
+Album Art
Custom</property>
<property name="add_tearoffs">False</property>
<property name="focus_on_click">True</property>
@@ -2767,7 +2768,6 @@ SOCKS5_HOSTNAME</property>
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="position">0</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c
index 6863b64a..31af601c 100644
--- a/plugins/gtkui/interface.c
+++ b/plugins/gtkui/interface.c
@@ -1337,6 +1337,7 @@ create_editcolumndlg (void)
gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Title");
gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Length");
gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Track");
+ gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Album Art");
gtk_combo_box_append_text (GTK_COMBO_BOX (id), "Custom");
hbox31 = gtk_hbox_new (FALSE, 8);
@@ -1659,7 +1660,6 @@ create_prefwin (void)
gtk_widget_show (hpaned1);
gtk_container_add (GTK_CONTAINER (notebook2), hpaned1);
gtk_container_set_border_width (GTK_CONTAINER (hpaned1), 12);
- gtk_paned_set_position (GTK_PANED (hpaned1), 0);
scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwindow2);
diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c
index 20d82267..3405e4fb 100644
--- a/plugins/gtkui/mainplaylist.c
+++ b/plugins/gtkui/mainplaylist.c
@@ -32,6 +32,8 @@
//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
#define trace(fmt,...)
+#define min(x,y) ((x)<(y)?(x):(y))
+
static uintptr_t play16_pixbuf;
static uintptr_t pause16_pixbuf;
static uintptr_t buffering16_pixbuf;
@@ -178,7 +180,7 @@ append_column_from_textdef (DdbListview *listview, const uint8_t *def) {
memset (inf, 0, sizeof (col_info_t));
inf->format = strdup (fmt);
inf->id = id;
- ddb_listview_column_append (listview, title, width, align, inf);
+ ddb_listview_column_append (listview, title, width, align, id == DB_COLUMN_ALBUM_ART ? width : 0, inf);
}
void
@@ -202,7 +204,7 @@ on_add_column_activate (GtkMenuItem *menuitem,
memset (inf, 0, sizeof (col_info_t));
inf->format = strdup (format);
inf->id = id;
- ddb_listview_column_insert (last_playlist, active_column, title, 100, align, inf);
+ ddb_listview_column_insert (last_playlist, active_column, title, 100, align, id == DB_COLUMN_ALBUM_ART ? 100 : 0, inf);
ddb_listview_refresh (last_playlist, DDB_REFRESH_COLUMNS | DDB_REFRESH_LIST | DDB_REFRESH_HSCROLL | DDB_EXPOSE_LIST | DDB_EXPOSE_COLUMNS);
}
gtk_widget_destroy (dlg);
@@ -222,7 +224,8 @@ on_edit_column_activate (GtkMenuItem *menuitem,
int width;
int align_right;
col_info_t *inf;
- int res = ddb_listview_column_get_info (last_playlist, active_column, &title, &width, &align_right, (void **)&inf);
+ int minheight;
+ int res = ddb_listview_column_get_info (last_playlist, active_column, &title, &width, &align_right, &minheight, (void **)&inf);
if (res == -1) {
trace ("attempted to edit non-existing column\n");
return;
@@ -249,7 +252,7 @@ on_edit_column_activate (GtkMenuItem *menuitem,
free (inf->format);
inf->format = strdup (format);
inf->id = id;
- ddb_listview_column_set_info (last_playlist, active_column, title, width, align, inf);
+ ddb_listview_column_set_info (last_playlist, active_column, title, width, align, id == DB_COLUMN_ALBUM_ART ? width : 0, inf);
ddb_listview_refresh (last_playlist, DDB_REFRESH_COLUMNS | DDB_REFRESH_LIST | DDB_EXPOSE_LIST | DDB_EXPOSE_COLUMNS);
}
@@ -277,16 +280,27 @@ void main_selection_changed (DdbListviewIter it, int idx) {
ddb_listview_draw_row (search, idx, it);
}
-void main_draw_column_data (DdbListview *listview, GdkDrawable *drawable, DdbListviewIter it, int column, int x, int y, int width, int height) {
+void main_draw_column_data (DdbListview *listview, GdkDrawable *drawable, DdbListviewIter it, int column, int group_y, int x, int y, int width, int height) {
const char *ctitle;
int cwidth;
int calign_right;
col_info_t *cinf;
- int res = ddb_listview_column_get_info (listview, column, &ctitle, &cwidth, &calign_right, (void **)&cinf);
+ int minheight;
+ int res = ddb_listview_column_get_info (listview, column, &ctitle, &cwidth, &calign_right, &minheight, (void **)&cinf);
if (res == -1) {
return;
}
- if (it == deadbeef->streamer_get_playing_track () && cinf->id == DB_COLUMN_PLAYING) {
+ if (cinf->id == DB_COLUMN_ALBUM_ART) {
+ if (group_y < cwidth) {
+ int h = cwidth - group_y;
+ h = min (height, h);
+ gdk_draw_rectangle (drawable, GTK_WIDGET (listview)->style->white_gc, TRUE, x, y, width, h);
+ GdkPixbuf *pixbuf = gdk_pixbuf_scale_simple ((GdkPixbuf *)play16_pixbuf, width, width, GDK_INTERP_BILINEAR);
+ gdk_draw_pixbuf (drawable, GTK_WIDGET (listview)->style->white_gc, pixbuf, 0, group_y, x, y, width, h, GDK_RGB_DITHER_NONE, 0, 0);
+ g_object_unref (pixbuf);
+ }
+ }
+ else if (it == deadbeef->streamer_get_playing_track () && cinf->id == DB_COLUMN_PLAYING) {
int paused = deadbeef->get_output ()->state () == OUTPUT_STATE_PAUSED;
int buffering = !deadbeef->streamer_ok_to_read (-1);
uintptr_t pixbuf;
@@ -301,7 +315,7 @@ void main_draw_column_data (DdbListview *listview, GdkDrawable *drawable, DdbLis
}
draw_pixbuf ((uintptr_t)drawable, pixbuf, x + cwidth/2 - 8, y + height/2 - 8, 0, 0, 16, 16);
}
- else {
+ else if (it) {
char text[1024];
deadbeef->pl_format_title (it, -1, text, sizeof (text), cinf->id, cinf->format);
GdkColor *color = NULL;
@@ -638,7 +652,8 @@ rewrite_column_config (DdbListview *listview, const char *name) {
int width;
int align_right;
col_info_t *info;
- ddb_listview_column_get_info (listview, i, &title, &width, &align_right, (void **)&info);
+ int minheight;
+ ddb_listview_column_get_info (listview, i, &title, &width, &align_right, &minheight, (void **)&info);
write_column_config (name, i, title, width, align_right, info->id, info->format);
}
}
@@ -652,6 +667,12 @@ main_columns_changed (DdbListview *listview) {
}
}
+void main_col_free_user_data (void *data) {
+ if (data) {
+ free (data);
+ }
+}
+
DdbListviewBinding main_binding = {
// rows
.count = main_get_count,
@@ -682,6 +703,7 @@ DdbListviewBinding main_binding = {
// columns
.col_sort = main_col_sort,
.columns_changed = main_columns_changed,
+ .col_free_user_data = main_col_free_user_data,
// callbacks
.handle_doubleclick = main_handle_doubleclick,
@@ -700,7 +722,7 @@ add_column_helper (DdbListview *listview, const char *title, int width, int id,
memset (inf, 0, sizeof (col_info_t));
inf->id = id;
inf->format = strdup (format);
- ddb_listview_column_append (listview, title, width, align_right, inf);
+ ddb_listview_column_append (listview, title, width, align_right, id == DB_COLUMN_ALBUM_ART ? width : 0, inf);
}
void