summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-06-24 21:35:35 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-06-24 21:35:35 +0200
commitc4c49d34513458a2cb73bff87c6fe73b10a2c350 (patch)
tree2273f84d016502be67ef103910cff434d6db67ae
parent131aab4658e3ea81416b476192c652657484002f (diff)
volumebar improvements
-rw-r--r--main.c2
-rw-r--r--plugins/gtkui/ddbvolumebar.c55
-rw-r--r--plugins/gtkui/ddbvolumebar.h1
3 files changed, 27 insertions, 31 deletions
diff --git a/main.c b/main.c
index b30c61b3..1238a4c5 100644
--- a/main.c
+++ b/main.c
@@ -623,6 +623,7 @@ main (int argc, char *argv[]) {
pl_init ();
conf_load (); // required by some plugins at startup
+ volume_set_db (conf_get_float ("playback.volume", 0)); // volume need to be initialized before plugins start
messagepump_init (); // required to push messages while handling commandline
plug_load_all (); // required to add files to playlist from commandline
pl_load_all ();
@@ -652,7 +653,6 @@ main (int argc, char *argv[]) {
atexit (atexit_handler); // helps to save in simple cases
// start all subsystems
- volume_set_db (conf_get_float ("playback.volume", 0));
plug_trigger_event_playlistchanged ();
streamer_init ();
diff --git a/plugins/gtkui/ddbvolumebar.c b/plugins/gtkui/ddbvolumebar.c
index a9191cff..1efa2881 100644
--- a/plugins/gtkui/ddbvolumebar.c
+++ b/plugins/gtkui/ddbvolumebar.c
@@ -155,31 +155,11 @@ ddb_volumebar_init(DdbVolumeBar *volumebar)
{
}
-#define DRAW_DEBUG 0
-
void
volumebar_draw (GtkWidget *widget) {
if (!widget) {
return;
}
-#if DRAW_DEBUG
- gdk_draw_rectangle (widget->window, widget->style->bg_gc[0], TRUE, 0, 0, widget->allocation.width, widget->allocation.height);
- GdkGC **gc[] = {
- widget->style->fg_gc,
- widget->style->bg_gc,
- widget->style->light_gc,
- widget->style->dark_gc,
- widget->style->mid_gc,
- widget->style->text_gc,
- widget->style->base_gc,
- widget->style->text_aa_gc
- };
- for (int i = 0; i < 8; i++) {
- for (int state = 0; state < 5; state++) {
- gdk_draw_rectangle (widget->window, gc[i][state], TRUE, i * 8, state * 5, 8, 5);
- }
- }
-#else
GdkDrawable *volumebar_backbuf = GDK_DRAWABLE (widget->window);
float range = -deadbeef->volume_get_min_db ();
int n = widget->allocation.width / 4;
@@ -207,9 +187,17 @@ volumebar_draw (GtkWidget *widget) {
gdk_draw_rectangle (volumebar_backbuf, back_gc, TRUE, _x + widget->allocation.x, _y + widget->allocation.y, _w, _h);
}
}
+ if (DDB_VOLUMEBAR (widget)->show_dbs) {
+ draw_begin ((uintptr_t)widget->window);
+ draw_init_font (widget->style);
+ char s[100];
+ int db = deadbeef->volume_get_db ();
+ snprintf (s, sizeof (s), "%s%ddB", db < 0 ? "" : "+", db);
+ draw_text (widget->allocation.x, widget->allocation.y, widget->allocation.width, 0, s);
+ draw_end ();
+ }
g_object_unref (back_gc);
g_object_unref (front_gc);
-#endif
}
gboolean
@@ -243,16 +231,19 @@ gboolean
on_volumebar_button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
- float range = -deadbeef->volume_get_min_db ();
- float volume = (event->x - widget->allocation.x)/ widget->allocation.width * range - range;
- if (volume < -range) {
- volume = -range;
- }
- if (volume > 0) {
- volume = 0;
+ if (event->button == 1) {
+ float range = -deadbeef->volume_get_min_db ();
+ float volume = (event->x - widget->allocation.x)/ widget->allocation.width * range - range;
+ if (volume < -range) {
+ volume = -range;
+ }
+ if (volume > 0) {
+ volume = 0;
+ }
+ deadbeef->volume_set_db (volume);
+ DDB_VOLUMEBAR (widget)->show_dbs = 1;
+ gtk_widget_queue_draw (widget);
}
- deadbeef->volume_set_db (volume);
- gtk_widget_queue_draw (widget);
return FALSE;
}
@@ -261,6 +252,10 @@ gboolean
on_volumebar_button_release_event (GtkWidget *widget,
GdkEventButton *event)
{
+ if (event->button == 1) {
+ DDB_VOLUMEBAR (widget)->show_dbs = 0;
+ gtk_widget_queue_draw (widget);
+ }
return FALSE;
}
diff --git a/plugins/gtkui/ddbvolumebar.h b/plugins/gtkui/ddbvolumebar.h
index 192f1545..530e556e 100644
--- a/plugins/gtkui/ddbvolumebar.h
+++ b/plugins/gtkui/ddbvolumebar.h
@@ -38,6 +38,7 @@ typedef void * DdbVolumeBarColIter;
struct _DdbVolumeBar {
GtkWidget parent;
+ int show_dbs;
};
struct _DdbVolumeBarClass {