diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/gtkui/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.c | 159 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.h | 4 | ||||
-rw-r--r-- | plugins/gtkui/ddbvolumebar.c | 268 | ||||
-rw-r--r-- | plugins/gtkui/ddbvolumebar.h | 52 | ||||
-rw-r--r-- | plugins/gtkui/deadbeef.glade | 13 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 7 | ||||
-rw-r--r-- | plugins/gtkui/interface.c | 23 |
8 files changed, 345 insertions, 182 deletions
diff --git a/plugins/gtkui/Makefile.am b/plugins/gtkui/Makefile.am index 196eaa23..a244a553 100644 --- a/plugins/gtkui/Makefile.am +++ b/plugins/gtkui/Makefile.am @@ -11,6 +11,7 @@ gtkui_la_SOURCES = gtkui.c gtkui.h\ pluginconf.c\ parser.c parser.h\ ddbtabstrip.c ddbtabstrip.h\ + ddbvolumebar.c ddbvolumebar.h\ trkproperties.c trkproperties.h gtkui_la_LDFLAGS = -module diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index 9053b4c2..60f509eb 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -34,6 +34,7 @@ #include "ddblistview.h" #include "ddbtabstrip.h" +#include "ddbvolumebar.h" #include "search.h" #include "progress.h" #include "../../session.h" @@ -611,125 +612,6 @@ on_seekbar_button_release_event (GtkWidget *widget, return FALSE; } - - -static GdkPixmap *volumebar_backbuf; - -void -volumebar_draw (GtkWidget *widget) { - if (!widget) { - return; - } - gdk_draw_rectangle (volumebar_backbuf, widget->style->bg_gc[0], TRUE, 0, 0, widget->allocation.width, widget->allocation.height); - cairo_t *cr; - cr = gdk_cairo_create (volumebar_backbuf); - if (!cr) { - return; - } - float range = -deadbeef->volume_get_min_db (); - int n = widget->allocation.width / 4; - float vol = (range + deadbeef->volume_get_db ()) / range * n; - float h = 16; - for (int i = 0; i < n; i++) { - float iy = (float)i + 3; - if (i <= vol) { - theme_set_cairo_source_rgb (cr, COLO_VOLUMEBAR_FRONT); - } - else { - theme_set_cairo_source_rgb (cr, COLO_VOLUMEBAR_BACK); - } - cairo_rectangle (cr, i * 4, (widget->allocation.height/2-h/2) + h - 1 - (h* i / n), 3, h * iy / n); - cairo_fill (cr); - } - - cairo_destroy (cr); -} - -void -volumebar_expose (GtkWidget *widget, int x, int y, int w, int h) { - gdk_draw_drawable (widget->window, widget->style->black_gc, volumebar_backbuf, x, y, x, y, w, h); -} - -gboolean -on_volumebar_configure_event (GtkWidget *widget, - GdkEventConfigure *event, - gpointer user_data) -{ - if (volumebar_backbuf) { - g_object_unref (volumebar_backbuf); - volumebar_backbuf = NULL; - } - volumebar_backbuf = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1); - volumebar_draw (widget); - return FALSE; -} - -gboolean -on_volumebar_expose_event (GtkWidget *widget, - GdkEventExpose *event, - gpointer user_data) -{ - volumebar_expose (widget, event->area.x, event->area.y, event->area.width, event->area.height); - return FALSE; -} - - -gboolean -on_volumebar_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event, - gpointer user_data) -{ - if (event->state & GDK_BUTTON1_MASK) { - float range = -deadbeef->volume_get_min_db (); - float volume = event->x / widget->allocation.width * range - range; - if (volume > 0) { - volume = 0; - } - if (volume < -range) { - volume = -range; - } - deadbeef->volume_set_db (volume); - volumebar_draw (widget); - volumebar_expose (widget, 0, 0, widget->allocation.width, widget->allocation.height); - } - return FALSE; -} - -gboolean -on_volumebar_button_press_event (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) -{ - float range = -deadbeef->volume_get_min_db (); - float volume = event->x / widget->allocation.width * range - range; - if (volume < -range) { - volume = -range; - } - if (volume > 0) { - volume = 0; - } - deadbeef->volume_set_db (volume); - volumebar_draw (widget); - volumebar_expose (widget, 0, 0, widget->allocation.width, widget->allocation.height); - return FALSE; -} - - -gboolean -on_volumebar_button_release_event (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) -{ - return FALSE; -} - -void -volumebar_notify_changed (void) { - GtkWidget *widget = lookup_widget (mainwin, "volumebar"); - volumebar_draw (widget); - volumebar_expose (widget, 0, 0, widget->allocation.width, widget->allocation.height); -} - gboolean on_mainwin_delete_event (GtkWidget *widget, GdkEvent *event, @@ -745,37 +627,6 @@ on_mainwin_delete_event (GtkWidget *widget, return TRUE; } - - - -gboolean -on_volumebar_scroll_event (GtkWidget *widget, - GdkEventScroll *event, - gpointer user_data) -{ - float range = -deadbeef->volume_get_min_db (); - float vol = deadbeef->volume_get_db (); - if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT) { - vol += 1; - } - else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT) { - vol -= 1; - } - if (vol > 0) { - vol = 0; - } - else if (vol < -range) { - vol = -range; - } - deadbeef->volume_set_db (vol); - GtkWidget *volumebar = lookup_widget (mainwin, "volumebar"); - volumebar_draw (volumebar); - volumebar_expose (volumebar, 0, 0, volumebar->allocation.width, volumebar->allocation.height); - return FALSE; -} - - - gboolean on_mainwin_configure_event (GtkWidget *widget, GdkEventConfigure *event, @@ -1466,3 +1317,11 @@ create_tabstrip_widget (gchar *widget_name, gchar *string1, gchar *string2, return ddb_tabstrip_new (); } + +GtkWidget* +create_volumebar_widget (gchar *widget_name, gchar *string1, gchar *string2, + gint int1, gint int2) +{ + return ddb_volumebar_new (); +} + diff --git a/plugins/gtkui/callbacks.h b/plugins/gtkui/callbacks.h index c6065a78..7a02aa43 100644 --- a/plugins/gtkui/callbacks.h +++ b/plugins/gtkui/callbacks.h @@ -713,3 +713,7 @@ create_ddb_listview_widget (gchar *widget_name, gchar *string1, gchar *string2, GtkWidget* create_tabstrip_widget (gchar *widget_name, gchar *string1, gchar *string2, gint int1, gint int2); + +GtkWidget* +create_volumebar_widget (gchar *widget_name, gchar *string1, gchar *string2, + gint int1, gint int2); diff --git a/plugins/gtkui/ddbvolumebar.c b/plugins/gtkui/ddbvolumebar.c new file mode 100644 index 00000000..9e2dfe46 --- /dev/null +++ b/plugins/gtkui/ddbvolumebar.c @@ -0,0 +1,268 @@ +/* + DeaDBeeF - ultimate music player for GNU/Linux systems with X11 + Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include <string.h> +#include "ddbvolumebar.h" +#include "drawing.h" +#include "gtkui.h" +#include "interface.h" +#include "support.h" + +G_DEFINE_TYPE (DdbVolumeBar, ddb_volumebar, GTK_TYPE_WIDGET); + +static void +ddb_volumebar_send_configure (DdbVolumeBar *darea) +{ + GtkWidget *widget; + GdkEvent *event = gdk_event_new (GDK_CONFIGURE); + + widget = GTK_WIDGET (darea); + + event->configure.window = g_object_ref (widget->window); + event->configure.send_event = TRUE; + event->configure.x = widget->allocation.x; + event->configure.y = widget->allocation.y; + event->configure.width = widget->allocation.width; + event->configure.height = widget->allocation.height; + + gtk_widget_event (widget, event); + gdk_event_free (event); +} + +static void +ddb_volumebar_realize (GtkWidget *widget) { + DdbVolumeBar *darea = DDB_VOLUMEBAR (widget); + GdkWindowAttr attributes; + gint attributes_mask; + + if (GTK_WIDGET_NO_WINDOW (widget)) + { + GTK_WIDGET_CLASS (ddb_volumebar_parent_class)->realize (widget); + } + else + { + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + + attributes.window_type = GDK_WINDOW_CHILD; + attributes.x = widget->allocation.x; + attributes.y = widget->allocation.y; + attributes.width = widget->allocation.width; + attributes.height = widget->allocation.height; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.visual = gtk_widget_get_visual (widget); + attributes.colormap = gtk_widget_get_colormap (widget); + attributes.event_mask = gtk_widget_get_events (widget); + attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK; + + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; + + widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), + &attributes, attributes_mask); + gdk_window_set_user_data (widget->window, darea); + + widget->style = gtk_style_attach (widget->style, widget->window); + gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + } + + ddb_volumebar_send_configure (DDB_VOLUMEBAR (widget)); +} + +static void +ddb_volumebar_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + g_return_if_fail (DDB_IS_VOLUMEBAR (widget)); + g_return_if_fail (allocation != NULL); + + widget->allocation = *allocation; + + if (GTK_WIDGET_REALIZED (widget)) + { + if (!GTK_WIDGET_NO_WINDOW (widget)) + gdk_window_move_resize (widget->window, + allocation->x, allocation->y, + allocation->width, allocation->height); + + ddb_volumebar_send_configure (DDB_VOLUMEBAR (widget)); + } +} + +gboolean +on_volumebar_expose_event (GtkWidget *widget, + GdkEventExpose *event); + +gboolean +on_volumebar_motion_notify_event (GtkWidget *widget, + GdkEventMotion *event); + +gboolean +on_volumebar_button_press_event (GtkWidget *widget, + GdkEventButton *event); + +gboolean +on_volumebar_button_release_event (GtkWidget *widget, + GdkEventButton *event); + +gboolean +on_volumebar_scroll_event (GtkWidget *widget, + GdkEventScroll *event); + +gboolean +on_volumebar_configure_event (GtkWidget *widget, + GdkEventConfigure *event); + +static void +ddb_volumebar_class_init(DdbVolumeBarClass *class) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + widget_class->realize = ddb_volumebar_realize; + widget_class->size_allocate = ddb_volumebar_size_allocate; + widget_class->expose_event = on_volumebar_expose_event; + widget_class->button_press_event = on_volumebar_button_press_event; + widget_class->button_release_event = on_volumebar_button_release_event; + widget_class->configure_event = on_volumebar_configure_event; + widget_class->motion_notify_event = on_volumebar_motion_notify_event; + widget_class->scroll_event = on_volumebar_scroll_event; +} + +GtkWidget * ddb_volumebar_new() { + return g_object_new (DDB_TYPE_VOLUMEBAR, NULL); +} + +static void +ddb_volumebar_init(DdbVolumeBar *volumebar) +{ +} + +void +volumebar_draw (GtkWidget *widget) { + if (!widget) { + return; + } + GdkDrawable *volumebar_backbuf = GDK_DRAWABLE (widget->window); + gdk_draw_rectangle (volumebar_backbuf, widget->style->bg_gc[0], TRUE, 0, 0, widget->allocation.width, widget->allocation.height); + float range = -deadbeef->volume_get_min_db (); + int n = widget->allocation.width / 4; + float vol = (range + deadbeef->volume_get_db ()) / range * n; + float h = 17; + for (int i = 0; i < n; i++) { + float iy = (float)i + 3; + int _x = i * 4; + int _h = h * iy / n; +// float _y = (widget->allocation.height/2-h/2) + h - 1 - (h* iy / n); + int _y = widget->allocation.height/2-h/2; + _y += (h - _h); + int _w = 3; + if (i <= vol) { + gdk_draw_rectangle (volumebar_backbuf, widget->style->bg_gc[GTK_STATE_SELECTED], TRUE, _x, _y, _w, _h); + } + else { + gdk_draw_rectangle (volumebar_backbuf, widget->style->dark_gc[GTK_STATE_SELECTED], TRUE, _x, _y, _w, _h); + } + } +} + +gboolean +on_volumebar_expose_event (GtkWidget *widget, + GdkEventExpose *event) +{ + volumebar_draw (widget); + return FALSE; +} + +gboolean +on_volumebar_motion_notify_event (GtkWidget *widget, + GdkEventMotion *event) +{ + if (event->state & GDK_BUTTON1_MASK) { + float range = -deadbeef->volume_get_min_db (); + float volume = event->x / widget->allocation.width * range - range; + if (volume > 0) { + volume = 0; + } + if (volume < -range) { + volume = -range; + } + deadbeef->volume_set_db (volume); + volumebar_draw (widget); + } + return FALSE; +} + +gboolean +on_volumebar_button_press_event (GtkWidget *widget, + GdkEventButton *event) +{ + float range = -deadbeef->volume_get_min_db (); + float volume = event->x / widget->allocation.width * range - range; + if (volume < -range) { + volume = -range; + } + if (volume > 0) { + volume = 0; + } + deadbeef->volume_set_db (volume); + volumebar_draw (widget); + return FALSE; +} + + +gboolean +on_volumebar_button_release_event (GtkWidget *widget, + GdkEventButton *event) +{ + return FALSE; +} + +void +volumebar_notify_changed (void) { + GtkWidget *widget = lookup_widget (mainwin, "volumebar"); + volumebar_draw (widget); +} + +gboolean +on_volumebar_scroll_event (GtkWidget *widget, + GdkEventScroll *event) +{ + float range = -deadbeef->volume_get_min_db (); + float vol = deadbeef->volume_get_db (); + if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT) { + vol += 1; + } + else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT) { + vol -= 1; + } + if (vol > 0) { + vol = 0; + } + else if (vol < -range) { + vol = -range; + } + deadbeef->volume_set_db (vol); + GtkWidget *volumebar = lookup_widget (mainwin, "volumebar"); + volumebar_draw (volumebar); + return FALSE; +} + +gboolean +on_volumebar_configure_event (GtkWidget *widget, + GdkEventConfigure *event) +{ + return FALSE; +} + diff --git a/plugins/gtkui/ddbvolumebar.h b/plugins/gtkui/ddbvolumebar.h new file mode 100644 index 00000000..192f1545 --- /dev/null +++ b/plugins/gtkui/ddbvolumebar.h @@ -0,0 +1,52 @@ +/* + DeaDBeeF - ultimate music player for GNU/Linux systems with X11 + Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef __DDBVOLUMEBAR_H +#define __DDBVOLUMEBAR_H + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define DDB_TYPE_VOLUMEBAR (ddb_volumebar_get_type ()) +#define DDB_VOLUMEBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), DDB_TYPE_VOLUMEBAR, DdbVolumeBar)) +#define DDB_VOLUMEBAR_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST((obj), DDB_TYPE_VOLUMEBAR, DdbVolumeBarClass)) +#define DDB_IS_VOLUMEBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DDB_TYPE_VOLUMEBAR)) +#define DDB_IS_VOLUMEBAR_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), DDB_TYPE_VOLUMEBAR)) +#define DDB_VOLUMEBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DDB_TYPE_VOLUMEBAR, DdbVolumeBarClass)) + +typedef struct _DdbVolumeBar DdbVolumeBar; +typedef struct _DdbVolumeBarClass DdbVolumeBarClass; + +typedef void * DdbVolumeBarIter; +typedef void * DdbVolumeBarColIter; + +struct _DdbVolumeBar { + GtkWidget parent; +}; + +struct _DdbVolumeBarClass { + GtkWidgetClass parent_class; +}; + +GType ddb_volumebar_get_type(void) G_GNUC_CONST; +GtkWidget * ddb_volumebar_new(void); + +G_END_DECLS + +#endif // __DDBVOLUMEBAR_H diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index 352d5474..ca64e2c1 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -768,16 +768,13 @@ </child> <child> - <widget class="GtkDrawingArea" id="volumebar"> + <widget class="Custom" id="volumebar"> <property name="width_request">70</property> <property name="visible">True</property> - <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> - <signal name="button_press_event" handler="on_volumebar_button_press_event" last_modification_time="Tue, 11 Aug 2009 18:57:49 GMT"/> - <signal name="button_release_event" handler="on_volumebar_button_release_event" last_modification_time="Tue, 11 Aug 2009 18:57:51 GMT"/> - <signal name="configure_event" handler="on_volumebar_configure_event" last_modification_time="Tue, 11 Aug 2009 18:57:55 GMT"/> - <signal name="expose_event" handler="on_volumebar_expose_event" last_modification_time="Tue, 11 Aug 2009 18:58:00 GMT"/> - <signal name="motion_notify_event" handler="on_volumebar_motion_notify_event" last_modification_time="Tue, 11 Aug 2009 18:58:05 GMT"/> - <signal name="scroll_event" handler="on_volumebar_scroll_event" last_modification_time="Tue, 18 Aug 2009 18:44:31 GMT"/> + <property name="creation_function">create_volumebar_widget</property> + <property name="int1">0</property> + <property name="int2">0</property> + <property name="last_modification_time">Thu, 18 Feb 2010 20:13:13 GMT</property> </widget> <packing> <property name="padding">2</property> diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 1830a9c5..fa5a95ec 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -276,8 +276,7 @@ on_trayicon_scroll_event (GtkWidget *widget, } deadbeef->volume_set_db (vol); GtkWidget *volumebar = lookup_widget (mainwin, "volumebar"); - volumebar_draw (volumebar); - volumebar_expose (volumebar, 0, 0, volumebar->allocation.width, volumebar->allocation.height); + gdk_window_invalidate_rect (volumebar->window, NULL, FALSE); return FALSE; } @@ -508,8 +507,8 @@ gtkui_on_frameupdate (DB_event_t *ev, uintptr_t data) { static int gtkui_on_volumechanged (DB_event_t *ev, uintptr_t data) { - void volumebar_notify_changed (void); // FIXME: do it properly - volumebar_notify_changed (); + GtkWidget *volumebar = lookup_widget (mainwin, "volumebar"); + gdk_window_invalidate_rect (volumebar->window, NULL, FALSE); return 0; } diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index 643c7c7e..6863b64a 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -490,11 +490,12 @@ create_mainwin (void) gtk_widget_set_size_request (seekbar, 200, -1); gtk_widget_set_events (seekbar, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); - volumebar = gtk_drawing_area_new (); + volumebar = create_volumebar_widget ("volumebar", "", "", 0, 0); gtk_widget_show (volumebar); gtk_box_pack_start (GTK_BOX (hbox2), volumebar, FALSE, TRUE, 2); gtk_widget_set_size_request (volumebar, 70, -1); - gtk_widget_set_events (volumebar, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); + GTK_WIDGET_UNSET_FLAGS (volumebar, GTK_CAN_FOCUS); + GTK_WIDGET_UNSET_FLAGS (volumebar, GTK_CAN_DEFAULT); tabstrip = create_tabstrip_widget ("tabstrip", "", "", 0, 0); gtk_widget_show (tabstrip); @@ -653,24 +654,6 @@ create_mainwin (void) g_signal_connect ((gpointer) seekbar, "motion_notify_event", G_CALLBACK (on_seekbar_motion_notify_event), NULL); - g_signal_connect ((gpointer) volumebar, "button_press_event", - G_CALLBACK (on_volumebar_button_press_event), - NULL); - g_signal_connect ((gpointer) volumebar, "button_release_event", - G_CALLBACK (on_volumebar_button_release_event), - NULL); - g_signal_connect ((gpointer) volumebar, "configure_event", - G_CALLBACK (on_volumebar_configure_event), - NULL); - g_signal_connect ((gpointer) volumebar, "expose_event", - G_CALLBACK (on_volumebar_expose_event), - NULL); - g_signal_connect ((gpointer) volumebar, "motion_notify_event", - G_CALLBACK (on_volumebar_motion_notify_event), - NULL); - g_signal_connect ((gpointer) volumebar, "scroll_event", - G_CALLBACK (on_volumebar_scroll_event), - NULL); /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (mainwin, mainwin, "mainwin"); |