From 33395ee8bff3e3d4b42bc40823eb9efe88f1611d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 28 Jun 2010 17:54:39 +0100 Subject: new playbutton for cairo drawing --- src/play-button.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ src/play-button.h | 48 ++++++++++++++++++++++++ src/transport-widget.c | 4 +- 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 src/play-button.c create mode 100644 src/play-button.h (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c new file mode 100644 index 0000000..ab441ea --- /dev/null +++ b/src/play-button.c @@ -0,0 +1,100 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "play-button.h" +#include "common-defs.h" +#include + + +typedef struct _PlayButtonPrivate PlayButtonPrivate; + +struct _PlayButtonPrivate +{ + +}; + +#define PLAY_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAY_BUTTON_TYPE, PlayButtonPrivate)) + +/* Gobject boiler plate */ +static void play_button_class_init (PlayButtonClass *klass); +static void play_button_init (PlayButton *self); +static void play_button_dispose (GObject *object); +static void play_button_finalize (GObject *object); + +static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); + +G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); + + +static void +play_button_class_init (PlayButtonClass *klass) +{ + g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); + GtkWidgetClass* widget_class; + + widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->expose_event = play_button_expose; + + gobject_class->dispose = play_button_dispose; + gobject_class->finalize = play_button_finalize; + +} + +static void +play_button_init (PlayButton *self) +{ + g_debug("PlayButton::play_button_init"); +} + +static void +play_button_dispose (GObject *object) +{ + G_OBJECT_CLASS (play_button_parent_class)->dispose (object); +} + +static void +play_button_finalize (GObject *object) +{ + G_OBJECT_CLASS (play_button_parent_class)->finalize (object); +} + +static gboolean +play_button_expose (GtkWidget *button, GdkEventExpose *event) +{ +return FALSE; +} + + + +/** +* play_button_new: +* @returns: a new #PlayButton. +**/ +GtkWidget* +play_button_new() +{ + return g_object_new(PLAY_BUTTON_TYPE, NULL); +} + diff --git a/src/play-button.h b/src/play-button.h new file mode 100644 index 0000000..a1e18f7 --- /dev/null +++ b/src/play-button.h @@ -0,0 +1,48 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see . +*/ +#ifndef __PLAY_BUTTON_H__ +#define __PLAY_BUTTON_H__ + +G_BEGIN_DECLS + +#define PLAY_BUTTON_TYPE (play_button_get_type ()) +#define PLAY_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLAY_BUTTON_TYPE, PlayButton)) +#define PLAY_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLAY_BUTTON_TYPE, PlayButtonClass)) +#define IS_PLAY_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLAY_BUTTON_TYPE)) +#define IS_PLAY_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLAY_BUTTON_TYPE)) +#define PLAY_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLAY_BUTTON_TYPE, PlayButtonClass)) + +typedef struct _PlayButton PlayButton; +typedef struct _PlayButtonClass PlayButtonClass; + +struct _PlayButtonClass { + GtkDrawingAreaClass parent_class; +}; + +struct _PlayButton { + GtkDrawingArea parent; +}; + +GType play_button_get_type (void); +GtkWidget* play_button_new(); + +G_END_DECLS + +#endif + diff --git a/src/transport-widget.c b/src/transport-widget.c index bc9df53..a86e37b 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -34,8 +34,8 @@ typedef struct _TransportWidgetPrivate TransportWidgetPrivate; struct _TransportWidgetPrivate { - GtkWidget* hbox; - GtkWidget* play_button; + //GtkWidget* hbox; + //GtkWidget* play_button; }; enum { -- cgit v1.2.3 From 0e616c323a678732dbd593d0d430507e099fda9f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 28 Jun 2010 21:12:07 +0100 Subject: moving in the right direction --- src/Makefile.am | 2 + src/play-button.c | 82 +++++++++++++++++++++++++++++---- src/play-button.h | 2 + src/sound-service.c | 4 +- src/transport-widget.c | 123 +++++++++---------------------------------------- 5 files changed, 102 insertions(+), 111 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index b33107d..21212d1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,8 @@ libsoundmenu_la_SOURCES = \ transport-widget.h \ metadata-widget.c \ metadata-widget.h \ + play-button.c \ + play-button.h \ indicator-sound.c \ dbus-shared-names.h \ sound-service-client.h diff --git a/src/play-button.c b/src/play-button.c index ab441ea..774b1e6 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -21,10 +21,8 @@ with this program. If not, see . #include "config.h" #endif -#include +#include #include "play-button.h" -#include "common-defs.h" -#include typedef struct _PlayButtonPrivate PlayButtonPrivate; @@ -43,6 +41,7 @@ static void play_button_dispose (GObject *object); static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); +static void draw (GtkWidget* button, cairo_t *cr); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -50,22 +49,32 @@ G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); static void play_button_class_init (PlayButtonClass *klass) { - g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); - GtkWidgetClass* widget_class; + + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); + g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); widget_class->expose_event = play_button_expose; gobject_class->dispose = play_button_dispose; gobject_class->finalize = play_button_finalize; - } static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); + GtkAllocation alloc; + + alloc.width = 100; + alloc.height = 100; + alloc.x = 0; + alloc.y = 0; + + gtk_widget_set_allocation(GTK_WIDGET(self), + &alloc); + //g_free(alloc); } static void @@ -83,11 +92,66 @@ play_button_finalize (GObject *object) static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event) { -return FALSE; + cairo_t *cr; + cr = gdk_cairo_create (button->window); + cairo_rectangle (cr, + event->area.x, event->area.y, + event->area.width, event->area.height); + + cairo_clip(cr); + draw (button, cr); + cairo_destroy (cr); + return FALSE; } +static void +draw (GtkWidget* button, cairo_t *cr) +{ + double x, y; + double radius; + int i; + + x = button->allocation.x + button->allocation.width / 2; + y = button->allocation.y + button->allocation.height / 2; + radius = MIN (button->allocation.width / 2, + button->allocation.height / 2) - 5; + + /* button back */ + cairo_arc (cr, x, y, radius, 0, 2 * M_PI); + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_fill_preserve (cr); + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_stroke (cr); + + /* button ticks */ + for (i = 0; i < 12; i++) + { + int inset; + + cairo_save (cr); /* stack-pen-size */ + + if (i % 3 == 0) + { + inset = 0.2 * radius; + } + else + { + inset = 0.1 * radius; + cairo_set_line_width (cr, 0.5 * + cairo_get_line_width (cr)); + } + + cairo_move_to (cr, + x + (radius - inset) * cos (i * M_PI / 6), + y + (radius - inset) * sin (i * M_PI / 6)); + cairo_line_to (cr, + x + radius * cos (i * M_PI / 6), + y + radius * sin (i * M_PI / 6)); + cairo_stroke (cr); + cairo_restore (cr); /* stack-pen-size */ + } +} - /** * play_button_new: * @returns: a new #PlayButton. diff --git a/src/play-button.h b/src/play-button.h index a1e18f7..4f7cdd0 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -19,6 +19,8 @@ with this program. If not, see . #ifndef __PLAY_BUTTON_H__ #define __PLAY_BUTTON_H__ +#include + G_BEGIN_DECLS #define PLAY_BUTTON_TYPE (play_button_get_type ()) diff --git a/src/sound-service.c b/src/sound-service.c index bcdac07..ea04e4b 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -45,8 +45,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-widget.c b/src/transport-widget.c index a86e37b..07e7402 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -25,8 +25,8 @@ with this program. If not, see . #include "transport-widget.h" #include "common-defs.h" #include +#include "play-button.h" -// TODO: think about leakage: ted ! static DbusmenuMenuitem* twin_item; @@ -34,20 +34,10 @@ typedef struct _TransportWidgetPrivate TransportWidgetPrivate; struct _TransportWidgetPrivate { - //GtkWidget* hbox; - //GtkWidget* play_button; + GtkWidget* hbox; + GtkWidget* play_button; }; -enum { - PLAY, - PAUSE, - NEXT, - PREVIOUS, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - #define TRANSPORT_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRANSPORT_WIDGET_TYPE, TransportWidgetPrivate)) /* Gobject boiler plate */ @@ -60,21 +50,14 @@ static void transport_widget_finalize (GObject *object); static gboolean transport_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event); static gboolean transport_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event); -static void transport_widget_play_clicked (GtkWidget* button, - TransportWidget* self); - + GdkEventButton *event); static void transport_widget_property_update(DbusmenuMenuitem* item, - gchar * property, - GValue * value, - gpointer userdata); -// utility methods -static gchar* transport_widget_toggle_play_label(gint state); + gchar * property, + GValue * value, + gpointer userdata); G_DEFINE_TYPE (TransportWidget, transport_widget, GTK_TYPE_MENU_ITEM); - - static void transport_widget_class_init (TransportWidgetClass *klass) { @@ -84,45 +67,12 @@ transport_widget_class_init (TransportWidgetClass *klass) menu_item_class->hide_on_activate = FALSE; widget_class->button_press_event = transport_widget_button_press_event; - widget_class->button_release_event = transport_widget_button_release_event; - + widget_class->button_release_event = transport_widget_button_release_event; g_type_class_add_private (klass, sizeof (TransportWidgetPrivate)); gobject_class->dispose = transport_widget_dispose; gobject_class->finalize = transport_widget_finalize; - signals[PLAY] = g_signal_new ("play", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[PAUSE] = g_signal_new ("pause", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - - signals[NEXT] = g_signal_new ("next", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[PREVIOUS] = g_signal_new ("previous", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); } static void @@ -131,19 +81,17 @@ transport_widget_init (TransportWidget *self) g_debug("TransportWidget::transport_widget_init"); TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(self); - GtkWidget *hbox; + GtkWidget* hbox; hbox = gtk_hbox_new(TRUE, 2); - gchar* symbol = transport_widget_toggle_play_label(dbusmenu_menuitem_property_get_int(twin_item, DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE)); - priv->play_button = gtk_button_new_with_label(symbol); - //g_free(symbol); - gtk_box_pack_start (GTK_BOX (hbox), priv->play_button, FALSE, TRUE, 0); priv->hbox = hbox; + + priv->play_button = play_button_new(); + + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); - - g_signal_connect(priv->play_button, "clicked", G_CALLBACK(transport_widget_play_clicked), self); gtk_container_add (GTK_CONTAINER (self), priv->hbox); @@ -172,28 +120,17 @@ transport_widget_button_press_event (GtkWidget *menuitem, return FALSE; } - TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - - gtk_widget_event (priv->hbox, (GdkEvent*)event); - gboolean state = g_ascii_strcasecmp(gtk_button_get_label(GTK_BUTTON(priv->play_button)), ">") == 0; + //TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label((gint)state)); - GValue value = {0}; - g_value_init(&value, G_TYPE_BOOLEAN); - g_debug("TransportWidget::menu_press_event - going to send value %i", state); - - g_value_set_boolean(&value, state); - dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); + //GValue value = {0}; + //g_value_init(&value, G_TYPE_BOOLEAN); + //g_debug("TransportWidget::menu_press_event - going to send value %i", state); + //g_value_set_boolean(&value, state); + //dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); return TRUE; } -static void -transport_widget_play_clicked(GtkWidget* button, - TransportWidget* self) -{ - g_debug("Transport_widget_play_clicked"); -} static gboolean transport_widget_button_release_event (GtkWidget *menuitem, @@ -203,9 +140,6 @@ transport_widget_button_release_event (GtkWidget *menuitem, if(IS_TRANSPORT_WIDGET(menuitem) == FALSE){ return FALSE; } - - TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - gtk_widget_event (priv->hbox, (GdkEvent*)event); return TRUE; } @@ -219,23 +153,12 @@ transport_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) { g_debug("transport_widget_update_state - with property %s", property); - int update_value = g_value_get_int(value); - g_debug("transport_widget_update_state - with value %i", update_value); + //int update_value = g_value_get_int(value); + //g_debug("transport_widget_update_state - with value %i", update_value); - TransportWidget* bar = (TransportWidget*)userdata; - TransportWidgetPrivate *priv = TRANSPORT_WIDGET_GET_PRIVATE(bar); + //TransportWidget* bar = (TransportWidget*)userdata; + //TransportWidgetPrivate *priv = TRANSPORT_WIDGET_GET_PRIVATE(bar); - gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label(update_value)); -} - -// will be needed for image swapping -static gchar* transport_widget_toggle_play_label(int play_state) -{ - gchar* label = ">"; - if(play_state == 1){ - label = "||"; - } - return label; } /** -- cgit v1.2.3 From a9186ea33c957a90cb4bfea464244602f4637b37 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 29 Jun 2010 10:16:45 +0100 Subject: more debug --- src/play-button.c | 27 ++++++++++++++++----------- src/transport-widget.c | 10 ++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 774b1e6..8962377 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -65,16 +65,6 @@ static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); - GtkAllocation alloc; - - alloc.width = 100; - alloc.height = 100; - alloc.x = 0; - alloc.y = 0; - - gtk_widget_set_allocation(GTK_WIDGET(self), - &alloc); - //g_free(alloc); } static void @@ -92,9 +82,24 @@ play_button_finalize (GObject *object) static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event) { + GtkAllocation alloc; + + alloc.width = 200; + alloc.height = 600; + alloc.x = 100; + alloc.y = 100; + + gtk_widget_set_allocation(GTK_WIDGET(button), + &alloc); + cairo_t *cr; cr = gdk_cairo_create (button->window); - cairo_rectangle (cr, + + g_debug("PlayButton::Draw - width = %i", button->allocation.width); + g_debug("PlayButton::Draw - event->area.width = %i", event->area.width); + g_debug("PlayButton::Draw - event->area.x = %i", event->area.x); + + cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height); diff --git a/src/transport-widget.c b/src/transport-widget.c index 07e7402..6ff3c04 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -89,6 +89,16 @@ transport_widget_init (TransportWidget *self) priv->play_button = play_button_new(); + GtkAllocation alloc; + + alloc.width = 200; + alloc.height = 600; + alloc.x = 100; + alloc.y = 0; + + gtk_widget_set_allocation(GTK_WIDGET(priv->play_button), + &alloc); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); -- cgit v1.2.3 From 914519bfe7983f250db3bd83a3f4545aa7071d66 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 29 Jun 2010 11:31:22 +0100 Subject: updates --- src/play-button.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 8962377..6b67042 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -51,11 +51,11 @@ play_button_class_init (PlayButtonClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); + //GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); - widget_class->expose_event = play_button_expose; + //widget_class->expose_event = play_button_expose; gobject_class->dispose = play_button_dispose; gobject_class->finalize = play_button_finalize; @@ -64,7 +64,8 @@ play_button_class_init (PlayButtonClass *klass) static void play_button_init (PlayButton *self) { - g_debug("PlayButton::play_button_init"); + g_debug("PlayButton::play_button_init"); + g_signal_connect(GTK_WIDGET(self), "expose-event", G_CALLBACK (play_button_expose), NULL); } static void @@ -86,8 +87,8 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) alloc.width = 200; alloc.height = 600; - alloc.x = 100; - alloc.y = 100; + alloc.x = 10; + alloc.y = 10; gtk_widget_set_allocation(GTK_WIDGET(button), &alloc); @@ -103,7 +104,7 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) event->area.x, event->area.y, event->area.width, event->area.height); - cairo_clip(cr); + //cairo_clip(cr); draw (button, cr); cairo_destroy (cr); return FALSE; @@ -155,6 +156,7 @@ draw (GtkWidget* button, cairo_t *cr) cairo_stroke (cr); cairo_restore (cr); /* stack-pen-size */ } + cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } /** @@ -164,6 +166,8 @@ draw (GtkWidget* button, cairo_t *cr) GtkWidget* play_button_new() { - return g_object_new(PLAY_BUTTON_TYPE, NULL); + GtkWidget* widget = g_object_new(PLAY_BUTTON_TYPE, NULL); + gtk_widget_set_app_paintable (widget, TRUE); + return widget; } -- cgit v1.2.3 From 8dc783c9943dbb1a80579d6f7e70492769b67717 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 29 Jun 2010 14:42:14 +0100 Subject: updates --- src/play-button.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 6b67042..e798668 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -40,7 +40,7 @@ static void play_button_init (PlayButton *self); static void play_button_dispose (GObject *object); static void play_button_finalize (GObject *object); -static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); +static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata); static void draw (GtkWidget* button, cairo_t *cr); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -81,7 +81,7 @@ play_button_finalize (GObject *object) } static gboolean -play_button_expose (GtkWidget *button, GdkEventExpose *event) +play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata) { GtkAllocation alloc; @@ -123,7 +123,7 @@ draw (GtkWidget* button, cairo_t *cr) button->allocation.height / 2) - 5; /* button back */ - cairo_arc (cr, x, y, radius, 0, 2 * M_PI); + cairo_arc (cr, x, y, radius, 0, 2 * G_PI); cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0, 0, 0); @@ -148,11 +148,11 @@ draw (GtkWidget* button, cairo_t *cr) } cairo_move_to (cr, - x + (radius - inset) * cos (i * M_PI / 6), - y + (radius - inset) * sin (i * M_PI / 6)); + x + (radius - inset) * cos (i * G_PI / 6), + y + (radius - inset) * sin (i * G_PI / 6)); cairo_line_to (cr, - x + radius * cos (i * M_PI / 6), - y + radius * sin (i * M_PI / 6)); + x + radius * cos (i * G_PI / 6), + y + radius * sin (i * G_PI / 6)); cairo_stroke (cr); cairo_restore (cr); /* stack-pen-size */ } -- cgit v1.2.3 From f3fc28d63254fe90de5472352256e7df415ab886 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 30 Jun 2010 18:20:45 +0100 Subject: highlighting sorted and a start towards the cairo stuff --- src/metadata-widget.c | 13 ++++++++++++- src/play-button.c | 37 +++++++++++++++++++------------------ src/transport-widget.c | 21 +++++++++++---------- 3 files changed, 42 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index ce3bcd1..28a3839 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -47,6 +47,8 @@ static void metadata_widget_class_init (MetadataWidgetClass *klass); static void metadata_widget_init (MetadataWidget *self); static void metadata_widget_dispose (GObject *object); static void metadata_widget_finalize (GObject *object); +static gboolean metadata_widget_expose_event(GtkWidget* widget, GdkEventExpose* event); + // keyevent consumers static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event); @@ -74,7 +76,7 @@ metadata_widget_class_init (MetadataWidgetClass *klass) widget_class->button_press_event = metadata_widget_button_press_event; widget_class->button_release_event = metadata_widget_button_release_event; - + widget_class->expose_event = metadata_widget_expose_event; g_type_class_add_private (klass, sizeof (MetadataWidgetPrivate)); gobject_class->dispose = metadata_widget_dispose; @@ -152,6 +154,15 @@ metadata_widget_init (MetadataWidget *self) } +static gboolean +metadata_widget_expose_event(GtkWidget* widget, GdkEventExpose* event) +{ + MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); + + gtk_container_propagate_expose(GTK_CONTAINER(widget), priv->hbox, event); + return TRUE; +} + static void metadata_widget_dispose (GObject *object) { diff --git a/src/play-button.c b/src/play-button.c index e798668..d79161b 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -40,7 +40,7 @@ static void play_button_init (PlayButton *self); static void play_button_dispose (GObject *object); static void play_button_finalize (GObject *object); -static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata); +static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); static void draw (GtkWidget* button, cairo_t *cr); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -51,11 +51,11 @@ play_button_class_init (PlayButtonClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - //GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); + GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); - //widget_class->expose_event = play_button_expose; + widget_class->expose_event = play_button_expose; gobject_class->dispose = play_button_dispose; gobject_class->finalize = play_button_finalize; @@ -65,7 +65,7 @@ static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); - g_signal_connect(GTK_WIDGET(self), "expose-event", G_CALLBACK (play_button_expose), NULL); + gtk_widget_set_size_request(GTK_WIDGET(self), 50, 50); } static void @@ -81,18 +81,8 @@ play_button_finalize (GObject *object) } static gboolean -play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata) +play_button_expose (GtkWidget *button, GdkEventExpose *event) { - GtkAllocation alloc; - - alloc.width = 200; - alloc.height = 600; - alloc.x = 10; - alloc.y = 10; - - gtk_widget_set_allocation(GTK_WIDGET(button), - &alloc); - cairo_t *cr; cr = gdk_cairo_create (button->window); @@ -110,14 +100,23 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event, gpointer userdata) return FALSE; } + static void draw (GtkWidget* button, cairo_t *cr) { - double x, y; + double x=50; + double y=30; double radius; - int i; - x = button->allocation.x + button->allocation.width / 2; + int rect_width = 100; + int rect_height = 50; + + cairo_move_to(cr, x+radius, y); + cairo_line_to(cr, x+rect_width-radius, y); + cairo_curve_to(cr, x+rect_width, y, x+rect_width, y, x+rect_width, y+radius); + cairo_line_to(x+w,y+h-r) + cairo_curve_to(cr, + x = button->allocation.x - button->allocation.width / 2; y = button->allocation.y + button->allocation.height / 2; radius = MIN (button->allocation.width / 2, button->allocation.height / 2) - 5; @@ -159,6 +158,8 @@ draw (GtkWidget* button, cairo_t *cr) cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } + + /** * play_button_new: * @returns: a new #PlayButton. diff --git a/src/transport-widget.c b/src/transport-widget.c index 6ff3c04..10c564b 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -45,6 +45,7 @@ static void transport_widget_class_init (TransportWidgetClass *klass); static void transport_widget_init (TransportWidget *self); static void transport_widget_dispose (GObject *object); static void transport_widget_finalize (GObject *object); +static gboolean transport_widget_expose_event(GtkWidget* widget, GdkEventExpose* event); /* UI and dbusmenu callbacks */ static gboolean transport_widget_button_press_event (GtkWidget *menuitem, @@ -68,6 +69,7 @@ transport_widget_class_init (TransportWidgetClass *klass) menu_item_class->hide_on_activate = FALSE; widget_class->button_press_event = transport_widget_button_press_event; widget_class->button_release_event = transport_widget_button_release_event; + widget_class->expose_event = transport_widget_expose_event; g_type_class_add_private (klass, sizeof (TransportWidgetPrivate)); gobject_class->dispose = transport_widget_dispose; @@ -89,16 +91,6 @@ transport_widget_init (TransportWidget *self) priv->play_button = play_button_new(); - GtkAllocation alloc; - - alloc.width = 200; - alloc.height = 600; - alloc.x = 100; - alloc.y = 0; - - gtk_widget_set_allocation(GTK_WIDGET(priv->play_button), - &alloc); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); @@ -120,6 +112,15 @@ transport_widget_finalize (GObject *object) G_OBJECT_CLASS (transport_widget_parent_class)->finalize (object); } +static gboolean +transport_widget_expose_event(GtkWidget* widget, GdkEventExpose* event) +{ + //TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(widget); + //gtk_container_propagate_expose(GTK_CONTAINER(widget),priv->play_button, event); + return TRUE; +} + + /* keyevents */ static gboolean transport_widget_button_press_event (GtkWidget *menuitem, -- cgit v1.2.3 From 40a1f7e531f1a8d841fc855f2ba16b9370a272be Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 1 Jul 2010 13:29:06 +0100 Subject: outline drawn --- src/play-button.c | 71 ++++++++++++++++++-------------------------------- src/transport-widget.c | 4 ++- 2 files changed, 28 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index d79161b..7db2a38 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -65,7 +65,7 @@ static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); - gtk_widget_set_size_request(GTK_WIDGET(self), 50, 50); + gtk_widget_set_size_request(GTK_WIDGET(self), 200, 80); } static void @@ -94,7 +94,7 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) event->area.x, event->area.y, event->area.width, event->area.height); - //cairo_clip(cr); + cairo_clip(cr); draw (button, cr); cairo_destroy (cr); return FALSE; @@ -104,58 +104,37 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) static void draw (GtkWidget* button, cairo_t *cr) { - double x=50; - double y=30; - double radius; + int rect_width = 150; + int rect_height = 30; + + double x= button->allocation.width/2 - rect_width/2; + double y= button->allocation.height/2 -rect_height/2; + double radius=60; - int rect_width = 100; - int rect_height = 50; cairo_move_to(cr, x+radius, y); cairo_line_to(cr, x+rect_width-radius, y); cairo_curve_to(cr, x+rect_width, y, x+rect_width, y, x+rect_width, y+radius); - cairo_line_to(x+w,y+h-r) - cairo_curve_to(cr, - x = button->allocation.x - button->allocation.width / 2; - y = button->allocation.y + button->allocation.height / 2; - radius = MIN (button->allocation.width / 2, - button->allocation.height / 2) - 5; - - /* button back */ - cairo_arc (cr, x, y, radius, 0, 2 * G_PI); + + cairo_line_to(cr, x + rect_width, y + rect_height - radius); + cairo_curve_to(cr, x + rect_width, y + rect_height, x + rect_width, + y + rect_height, x + rect_width - radius, y + rect_height); + + cairo_line_to(cr, x + radius, y + rect_height); + cairo_curve_to(cr, x, y + rect_height, x, y+rect_height, x, y+rect_height-radius); + cairo_line_to(cr, x, y + radius); + cairo_curve_to(cr, x, y, x, y, x + radius, y); + + cairo_arc(cr, x+(rect_width/2), y+(rect_height/2), radius/2, 0, 2 * M_PI); + cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill_preserve (cr); - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_stroke (cr); - /* button ticks */ - for (i = 0; i < 12; i++) - { - int inset; - - cairo_save (cr); /* stack-pen-size */ - - if (i % 3 == 0) - { - inset = 0.2 * radius; - } - else - { - inset = 0.1 * radius; - cairo_set_line_width (cr, 0.5 * - cairo_get_line_width (cr)); - } - - cairo_move_to (cr, - x + (radius - inset) * cos (i * G_PI / 6), - y + (radius - inset) * sin (i * G_PI / 6)); - cairo_line_to (cr, - x + radius * cos (i * G_PI / 6), - y + radius * sin (i * G_PI / 6)); - cairo_stroke (cr); - cairo_restore (cr); /* stack-pen-size */ - } - cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); + // cr.fill() + // cr.stroke() + //cairo_set_source_rgb (cr, 1, 1, 1); + //cairo_stroke (cr); + //cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } diff --git a/src/transport-widget.c b/src/transport-widget.c index 10c564b..ae01c0f 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -74,7 +74,6 @@ transport_widget_class_init (TransportWidgetClass *klass) gobject_class->dispose = transport_widget_dispose; gobject_class->finalize = transport_widget_finalize; - } static void @@ -87,6 +86,9 @@ transport_widget_init (TransportWidget *self) hbox = gtk_hbox_new(TRUE, 2); + //GtkAllocation alloc; + //gtk_widget_get_allocation(GTK_WIDGET(self), &alloc); + //g_debug("allocation width for the transport widget %i", alloc.width); priv->hbox = hbox; priv->play_button = play_button_new(); -- cgit v1.2.3 From b1d159ec617f067753cd3a012697e94c592e2b88 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 1 Jul 2010 18:30:00 +0100 Subject: background working correctly --- src/metadata-widget.c | 6 +++--- src/play-button.c | 52 +++++++++++++++++++++++++++++++++++++------------- src/transport-widget.c | 1 - 3 files changed, 42 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 28a3839..bb9c8a8 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -113,7 +113,7 @@ metadata_widget_init (MetadataWidget *self) gtk_misc_set_alignment(GTK_MISC(artist), (gfloat)0, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(artist), 20); - gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_END); + gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_MIDDLE); priv->artist_label = artist; // Style it up. style_artist_text(self); @@ -124,7 +124,7 @@ metadata_widget_init (MetadataWidget *self) DBUSMENU_METADATA_MENUITEM_TEXT_TITLE)); gtk_misc_set_alignment(GTK_MISC(piece), (gfloat)0, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(piece), 16); - gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_END); + gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_MIDDLE); priv->piece_label = piece; // Style it up. style_title_text(self); @@ -135,7 +135,7 @@ metadata_widget_init (MetadataWidget *self) DBUSMENU_METADATA_MENUITEM_TEXT_ALBUM)); gtk_misc_set_alignment(GTK_MISC(container), (gfloat)0, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(container), 20); - gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_END); + gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_MIDDLE); priv->container_label = container; // Style it up. style_album_text(self); diff --git a/src/play-button.c b/src/play-button.c index 7db2a38..24eea0d 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -42,6 +42,8 @@ static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); static void draw (GtkWidget* button, cairo_t *cr); +static void play_button_draw_background(cairo_t* cr, double x, double y, int width, int height, double radius); + G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -104,14 +106,47 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) static void draw (GtkWidget* button, cairo_t *cr) { + int rect_width = 150; int rect_height = 30; - + double radius=40; double x= button->allocation.width/2 - rect_width/2; double y= button->allocation.height/2 -rect_height/2; - double radius=60; + + //cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + //cairo_paint(cr); + + play_button_draw_background(cr, x, y, rect_width, rect_height, radius); + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0); + cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 256.0); + cairo_pattern_add_color_stop_rgba (pat, 0.4, 256, 256, 256, 160.0); + cairo_pattern_add_color_stop_rgba (pat, 0.6, 256, 256, 256, 256.0); + + cairo_set_source (cr, pat); + cairo_fill (cr); + + //int factor = 10; + //cairo_reset_clip(cr); + play_button_draw_background(cr, x+2.5, y+2.5, rect_width-5, rect_height-5, radius-5); + //cairo_translate(cr, 50, 50); + cairo_set_source_rgba (cr, 256,256,256, 15); + cairo_fill(cr); + //cairo_reset_clip(cr); + cairo_pattern_destroy (pat); + + // cr.fill() + // cr.stroke() + //cairo_set_source_rgb (cr, 1, 1, 1); + //cairo_stroke (cr); + cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); +} + +static void +play_button_draw_background(cairo_t* cr, double x, double y, int rect_width, int rect_height, double radius) +{ cairo_move_to(cr, x+radius, y); cairo_line_to(cr, x+rect_width-radius, y); cairo_curve_to(cr, x+rect_width, y, x+rect_width, y, x+rect_width, y+radius); @@ -125,20 +160,11 @@ draw (GtkWidget* button, cairo_t *cr) cairo_line_to(cr, x, y + radius); cairo_curve_to(cr, x, y, x, y, x + radius, y); - cairo_arc(cr, x+(rect_width/2), y+(rect_height/2), radius/2, 0, 2 * M_PI); - - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_fill_preserve (cr); - - // cr.fill() - // cr.stroke() - //cairo_set_source_rgb (cr, 1, 1, 1); - //cairo_stroke (cr); - //cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); + cairo_arc(cr, x+(rect_width/2), y+(rect_height/2), radius/1.7, 0, 2 * M_PI); + cairo_close_path(cr); } - /** * play_button_new: * @returns: a new #PlayButton. diff --git a/src/transport-widget.c b/src/transport-widget.c index ae01c0f..648370f 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -92,7 +92,6 @@ transport_widget_init (TransportWidget *self) priv->hbox = hbox; priv->play_button = play_button_new(); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); -- cgit v1.2.3 From d79472daaf580062397ef688766cbe48b2cbd992 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 2 Jul 2010 20:04:15 +0100 Subject: cairo is taking some time --- src/play-button.c | 201 ++++++++++++++++++++++++++++++++++++++----------- src/play-button.h | 1 + src/transport-widget.c | 8 +- 3 files changed, 162 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 24eea0d..84b29cc 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -29,7 +29,11 @@ typedef struct _PlayButtonPrivate PlayButtonPrivate; struct _PlayButtonPrivate { - + GdkColor background_colour_fg; + GdkColor background_colour_bg_dark; + GdkColor background_colour_bg_light; + GdkColor foreground_colour_fg; + GdkColor foreground_colour_bg; }; #define PLAY_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAY_BUTTON_TYPE, PlayButtonPrivate)) @@ -42,9 +46,15 @@ static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); static void draw (GtkWidget* button, cairo_t *cr); -static void play_button_draw_background(cairo_t* cr, double x, double y, int width, int height, double radius); +static void play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, double width, double height, double p_radius); +static void play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius); +static void play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius); + + +//static void play_button_draw_play_symbol(cairo_t* cr, double x, double y); +static void play_button_draw_pause_symbol(cairo_t* cr, double x, double y); + - G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -103,68 +113,170 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) } +void +play_button_set_style(GtkWidget* button, GtkStyle* style) +{ + PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); + priv->background_colour_fg = style->fg[GTK_STATE_NORMAL]; + priv->background_colour_bg_dark = style->bg[GTK_STATE_NORMAL]; + priv->background_colour_bg_light = style->base[GTK_STATE_NORMAL]; + priv->foreground_colour_fg = style->fg[GTK_STATE_PRELIGHT]; + priv->foreground_colour_bg = style->bg[GTK_STATE_NORMAL]; +} + static void draw (GtkWidget* button, cairo_t *cr) { - int rect_width = 150; - int rect_height = 30; - double radius=40; - double x= button->allocation.width/2 - rect_width/2; - double y= button->allocation.height/2 -rect_height/2; + //PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); + double rect_width = 115; + double rect_height = 28; + double p_radius = 21; + double y = 15; + double x = 22; + //double radius=35; + //double x= button->allocation.width/2 - rect_width/2; + //double y= button->allocation.height/2 -rect_height/2; + + // Draw the outside drop shadow background + play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); + + // Draw the inside drop shadow background + gint offset = 1.5; + play_button_draw_background_shadow_2(button, cr, x+ offset/2, y + offset/2, rect_width-offset, rect_height-offset, p_radius-offset/2); - //cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); - //cairo_paint(cr); + offset = 3; + // Draw the inside actual background + play_button_draw_background(button, cr, x+offset/2, y + offset/2, rect_width-offset, rect_height-offset, p_radius-offset/2); + + play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x, rect_height/5 +y ); + cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); +} + +static void +play_button_draw_pause_symbol(cairo_t* cr, double x, double y) +{ + cairo_set_line_width (cr, 6.0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to (cr, x, y); + cairo_rel_line_to (cr, 0, 16); + //cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); - play_button_draw_background(cr, x, y, rect_width, rect_height, radius); - cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (x, y, x, y+16); + cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); + cairo_pattern_add_color_stop_rgb(pat, .1, 94/255.0, 93/255.0, 90/255.0); + cairo_set_source (cr, pat); + cairo_stroke(cr); + cairo_close_path(cr); + + cairo_set_line_width (cr, 5.0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to (cr, x+1, y+1); + cairo_rel_line_to (cr, 0, 15); + + pat = cairo_pattern_create_linear (x+1, y+1, x+1, y+16); + cairo_pattern_add_color_stop_rgb(pat, .7, 252/255.0, 252/255.0, 251/255.0); + cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); + cairo_set_source (cr, pat); + cairo_stroke(cr); + cairo_close_path(cr); - pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0); - cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 256.0); - cairo_pattern_add_color_stop_rgba (pat, 0.4, 256, 256, 256, 160.0); - cairo_pattern_add_color_stop_rgba (pat, 0.6, 256, 256, 256, 256.0); + cairo_pattern_destroy (pat); +} + +static void +play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) +{ + double radius=rect_height/2; + cairo_set_line_width (cr, rect_height); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to(cr, x+radius, y+radius); + cairo_line_to(cr, x+rect_width, y+radius); + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (x, y, x, y+rect_height); + cairo_pattern_add_color_stop_rgb(pat, .7, 227/255.0, 222/255.0, 214/255.0); + cairo_pattern_add_color_stop_rgb(pat, .9, 183/255.0, 178/255.0, 172/255.0); + cairo_set_source (cr, pat); + cairo_stroke (cr); + + cairo_close_path(cr); + cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + cairo_set_source (cr, pat); + cairo_fill(cr); + + cairo_close_path(cr); + cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); + cairo_set_line_width (cr, 2); + cairo_stroke(cr); + cairo_close_path(cr); + cairo_pattern_destroy (pat); +} + +static void +play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) +{ + double radius=rect_height/2; + cairo_set_line_width (cr, rect_height); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to(cr, x+radius, y+radius); + cairo_line_to(cr, x+rect_width, y+radius); + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (0, 0, 0, rect_height); + cairo_pattern_add_color_stop_rgb(pat, .2, 36/255.0, 35/255.0, 33/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); - cairo_fill (cr); + cairo_stroke (cr); - //int factor = 10; - //cairo_reset_clip(cr); - play_button_draw_background(cr, x+2.5, y+2.5, rect_width-5, rect_height-5, radius-5); - //cairo_translate(cr, 50, 50); - cairo_set_source_rgba (cr, 256,256,256, 15); + cairo_close_path(cr); + cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + pat = cairo_pattern_create_linear (0, 0, 0, rect_height+(p_radius-rect_height/2)); + cairo_pattern_add_color_stop_rgb(pat, .2, 36/255.0, 35/255.0, 33/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); + cairo_set_source (cr, pat); cairo_fill(cr); - //cairo_reset_clip(cr); + cairo_close_path(cr); cairo_pattern_destroy (pat); - // cr.fill() - // cr.stroke() - //cairo_set_source_rgb (cr, 1, 1, 1); - //cairo_stroke (cr); - cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } static void -play_button_draw_background(cairo_t* cr, double x, double y, int rect_width, int rect_height, double radius) -{ - cairo_move_to(cr, x+radius, y); - cairo_line_to(cr, x+rect_width-radius, y); - cairo_curve_to(cr, x+rect_width, y, x+rect_width, y, x+rect_width, y+radius); - - cairo_line_to(cr, x + rect_width, y + rect_height - radius); - cairo_curve_to(cr, x + rect_width, y + rect_height, x + rect_width, - y + rect_height, x + rect_width - radius, y + rect_height); - - cairo_line_to(cr, x + radius, y + rect_height); - cairo_curve_to(cr, x, y + rect_height, x, y+rect_height, x, y+rect_height-radius); - cairo_line_to(cr, x, y + radius); - cairo_curve_to(cr, x, y, x, y, x + radius, y); - - cairo_arc(cr, x+(rect_width/2), y+(rect_height/2), radius/1.7, 0, 2 * M_PI); +play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) +{ + double radius=rect_height/2; + + cairo_set_line_width (cr, rect_height); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to(cr, x+radius, y+radius); + cairo_line_to(cr, x+rect_width, y+radius); + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (0, 0, 0, rect_height); + cairo_pattern_add_color_stop_rgb(pat, .2, 61/255.0, 60/255.0, 57/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); + cairo_set_source (cr, pat); + cairo_stroke (cr); + cairo_close_path(cr); + cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + pat = cairo_pattern_create_linear (0, 0, 0, rect_height+(p_radius-rect_height/2)); + cairo_pattern_add_color_stop_rgb(pat, .2, 61/255.0, 60/255.0, 57/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); + + cairo_set_source (cr, pat); + cairo_fill(cr); + cairo_close_path(cr); + cairo_pattern_destroy (pat); + } + + /** * play_button_new: * @returns: a new #PlayButton. @@ -172,6 +284,7 @@ play_button_draw_background(cairo_t* cr, double x, double y, int rect_width, int GtkWidget* play_button_new() { + GtkWidget* widget = g_object_new(PLAY_BUTTON_TYPE, NULL); gtk_widget_set_app_paintable (widget, TRUE); return widget; diff --git a/src/play-button.h b/src/play-button.h index 4f7cdd0..6c6aee3 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -42,6 +42,7 @@ struct _PlayButton { }; GType play_button_get_type (void); +void play_button_set_style(GtkWidget* button, GtkStyle* style); GtkWidget* play_button_new(); G_END_DECLS diff --git a/src/transport-widget.c b/src/transport-widget.c index 648370f..6d39a03 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -86,12 +86,12 @@ transport_widget_init (TransportWidget *self) hbox = gtk_hbox_new(TRUE, 2); - //GtkAllocation alloc; - //gtk_widget_get_allocation(GTK_WIDGET(self), &alloc); - //g_debug("allocation width for the transport widget %i", alloc.width); + GtkStyle* style = gtk_rc_get_style(GTK_WIDGET(self)); + priv->hbox = hbox; - priv->play_button = play_button_new(); + play_button_set_style(priv->play_button, style); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); -- cgit v1.2.3 From fedd8fab03ebb4ab9e96090f30eb02dd2a112860 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 5 Jul 2010 13:30:36 +0100 Subject: getting closer to the mock up --- src/Makefile.am | 2 +- src/play-button.c | 90 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 21212d1..71a3068 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ libsoundmenu_la_SOURCES = \ dbus-shared-names.h \ sound-service-client.h -libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Werror -DG_LOG_DOMAIN=\"Indicator-Sound\" +libsoundmenu_la_CFLAGS = $(APPLET_CFLAGS) -Wall -DG_LOG_DOMAIN=\"Indicator-Sound\" libsoundmenu_la_LIBADD = $(APPLET_LIBS) libsoundmenu_la_LDFLAGS = -module -avoid-version diff --git a/src/play-button.c b/src/play-button.c index 84b29cc..775ab53 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -53,6 +53,7 @@ static void play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, //static void play_button_draw_play_symbol(cairo_t* cr, double x, double y); static void play_button_draw_pause_symbol(cairo_t* cr, double x, double y); +static void play_button_draw_previous_symbol(cairo_t* cr, double x, double y); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -142,42 +143,74 @@ draw (GtkWidget* button, cairo_t *cr) play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); // Draw the inside drop shadow background - gint offset = 1.5; - play_button_draw_background_shadow_2(button, cr, x+ offset/2, y + offset/2, rect_width-offset, rect_height-offset, p_radius-offset/2); + gint offset = 4; + play_button_draw_background_shadow_2(button, cr, x + offset-1, y + offset/2, rect_width-offset, rect_height-offset, p_radius-(offset/2)); - offset = 3; + offset = 5; // Draw the inside actual background - play_button_draw_background(button, cr, x+offset/2, y + offset/2, rect_width-offset, rect_height-offset, p_radius-offset/2); + play_button_draw_background(button, cr, x+offset-1, y + offset/2+1, rect_width-offset, rect_height-offset, p_radius-offset/2); - play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x, rect_height/5 +y ); + play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x -1 + offset/2, rect_height/5 +y ); + + play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x + offset/2 + 10, rect_height/5 +y ); + play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset); cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } +static void +play_button_draw_previous_symbol(cairo_t* cr, double x, double y) +{ + cairo_set_line_width (cr, 3); + cairo_move_to (cr, x, y); + gint shape_height = 17; + gint shape_width = 22; + cairo_move_to(x, y); + cairo_rel_line_to (cr, 0, shape_height); + cairo_move_to (cr, x, y+shape_height/2); + cairo_rel_line_to (cr, 15, -shape_height/2); + //cairo_move_to (cr, x, y+shape_height/2); + //cairo_rel_line_to (cr, 15, +shape_height/2); + //cairo_rel_line_to (cr, 15, shape_height/2); + + cairo_pattern_t *pat; + pat = cairo_pattern_create_linear (x, y, x, y+16); + + cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); + cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); + cairo_pattern_add_color_stop_rgb(pat, .6, 123/255.0, 123/255.0, 120/255.0); + cairo_set_source (cr, pat); + cairo_fill(cr); + cairo_close_path(cr); + +} + static void play_button_draw_pause_symbol(cairo_t* cr, double x, double y) { - cairo_set_line_width (cr, 6.0); + cairo_set_line_width (cr, 7); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_move_to (cr, x, y); - cairo_rel_line_to (cr, 0, 16); + cairo_rel_line_to (cr, 0, 18); //cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); cairo_pattern_t *pat; pat = cairo_pattern_create_linear (x, y, x, y+16); cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); - cairo_pattern_add_color_stop_rgb(pat, .1, 94/255.0, 93/255.0, 90/255.0); + cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); + cairo_pattern_add_color_stop_rgb(pat, .6, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); cairo_stroke(cr); cairo_close_path(cr); - cairo_set_line_width (cr, 5.0); + cairo_set_line_width (cr, 5.5); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to (cr, x+1, y+1); - cairo_rel_line_to (cr, 0, 15); + cairo_move_to (cr, x, y+0.75); + cairo_rel_line_to (cr, 0, 16.5); pat = cairo_pattern_create_linear (x+1, y+1, x+1, y+16); - cairo_pattern_add_color_stop_rgb(pat, .7, 252/255.0, 252/255.0, 251/255.0); - cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); + cairo_pattern_add_color_stop_rgb(pat, .3, 252/255.0, 252/255.0, 251/255.0); + cairo_pattern_add_color_stop_rgb(pat, .8, 227/255.0, 222/255.0, 214/255.0); + //1cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); cairo_set_source (cr, pat); cairo_stroke(cr); cairo_close_path(cr); @@ -196,20 +229,21 @@ play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, cairo_pattern_t *pat; pat = cairo_pattern_create_linear (x, y, x, y+rect_height); - cairo_pattern_add_color_stop_rgb(pat, .7, 227/255.0, 222/255.0, 214/255.0); - cairo_pattern_add_color_stop_rgb(pat, .9, 183/255.0, 178/255.0, 172/255.0); + cairo_pattern_add_color_stop_rgb(pat, .5, 225/255.0, 218/255.0, 211/255.0); + cairo_pattern_add_color_stop_rgb(pat, .7, 197/255.0, 192/255.0, 185/255.0); + cairo_pattern_add_color_stop_rgb(pat, .9, 185/255.0, 179/255.0, 173/255.0); cairo_set_source (cr, pat); cairo_stroke (cr); cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); cairo_set_source (cr, pat); cairo_fill(cr); cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); + cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); - cairo_set_line_width (cr, 2); + cairo_set_line_width (cr, 0.75); cairo_stroke(cr); cairo_close_path(cr); cairo_pattern_destroy (pat); @@ -226,16 +260,16 @@ play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, d cairo_line_to(cr, x+rect_width, y+radius); cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (0, 0, 0, rect_height); - cairo_pattern_add_color_stop_rgb(pat, .2, 36/255.0, 35/255.0, 33/255.0); + pat = cairo_pattern_create_linear (x, y, x, y+rect_height); + cairo_pattern_add_color_stop_rgb(pat, .4, 36/255.0, 35/255.0, 33/255.0); cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); cairo_stroke (cr); cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); - pat = cairo_pattern_create_linear (0, 0, 0, rect_height+(p_radius-rect_height/2)); - cairo_pattern_add_color_stop_rgb(pat, .2, 36/255.0, 35/255.0, 33/255.0); + cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); + pat = cairo_pattern_create_linear ((rect_width/2 + radius/2 + x), rect_height/2 + y-p_radius, (rect_width/2 + radius/2 + x), rect_height+(p_radius-rect_height/2)); + cairo_pattern_add_color_stop_rgb(pat, .4, 36/255.0, 35/255.0, 33/255.0); cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); cairo_fill(cr); @@ -255,16 +289,16 @@ play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, d cairo_line_to(cr, x+rect_width, y+radius); cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (0, 0, 0, rect_height); - cairo_pattern_add_color_stop_rgb(pat, .2, 61/255.0, 60/255.0, 57/255.0); + pat = cairo_pattern_create_linear (x, y, x, y+rect_height); + cairo_pattern_add_color_stop_rgb(pat, .4, 61/255.0, 60/255.0, 57/255.0); cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); cairo_set_source (cr, pat); cairo_stroke (cr); cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x, rect_height/2 +y, p_radius, 0, 2*M_PI); - pat = cairo_pattern_create_linear (0, 0, 0, rect_height+(p_radius-rect_height/2)); - cairo_pattern_add_color_stop_rgb(pat, .2, 61/255.0, 60/255.0, 57/255.0); + cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); + pat = cairo_pattern_create_linear ((rect_width/2 + radius/2 + x), rect_height/2 + y-p_radius, (rect_width/2 + radius/2 + x), rect_height+(p_radius-rect_height/2)); + cairo_pattern_add_color_stop_rgb(pat, .4, 61/255.0, 60/255.0, 57/255.0); cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); cairo_set_source (cr, pat); -- cgit v1.2.3 From e830c3a70e7feaa761c006c9fcbce9183686dac7 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 5 Jul 2010 15:06:56 +0100 Subject: previous button coming along --- src/play-button.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 775ab53..76a8109 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -153,35 +153,39 @@ draw (GtkWidget* button, cairo_t *cr) play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x -1 + offset/2, rect_height/5 +y ); play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x + offset/2 + 10, rect_height/5 +y ); - play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset); + play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset+2); cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } static void play_button_draw_previous_symbol(cairo_t* cr, double x, double y) { - cairo_set_line_width (cr, 3); - cairo_move_to (cr, x, y); - gint shape_height = 17; + gint line_width = 2; + cairo_set_line_width (cr, line_width); + gint shape_height = 15; gint shape_width = 22; - cairo_move_to(x, y); - cairo_rel_line_to (cr, 0, shape_height); - cairo_move_to (cr, x, y+shape_height/2); - cairo_rel_line_to (cr, 15, -shape_height/2); - //cairo_move_to (cr, x, y+shape_height/2); - //cairo_rel_line_to (cr, 15, +shape_height/2); - //cairo_rel_line_to (cr, 15, shape_height/2); + gint single_arrow_width=16; cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+16); + pat = cairo_pattern_create_linear (x, y, x, y+shape_height); cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); - cairo_pattern_add_color_stop_rgb(pat, .6, 123/255.0, 123/255.0, 120/255.0); + cairo_pattern_add_color_stop_rgb(pat, .4, 123/255.0, 123/255.0, 120/255.0); cairo_set_source (cr, pat); + + cairo_move_to(cr, x, y); + cairo_rel_line_to (cr, 0, shape_height); + cairo_stroke(cr); + + cairo_move_to (cr, x+line_width, y+shape_height/2); + cairo_line_to (cr, x+single_arrow_width, y); + cairo_line_to (cr, x+single_arrow_width, y+shape_height); + cairo_line_to (cr, x+line_width, y+shape_height/2); cairo_fill(cr); - cairo_close_path(cr); - + + cairo_pattern_destroy (pat); + cairo_close_path(cr); } static void @@ -210,7 +214,7 @@ play_button_draw_pause_symbol(cairo_t* cr, double x, double y) pat = cairo_pattern_create_linear (x+1, y+1, x+1, y+16); cairo_pattern_add_color_stop_rgb(pat, .3, 252/255.0, 252/255.0, 251/255.0); cairo_pattern_add_color_stop_rgb(pat, .8, 227/255.0, 222/255.0, 214/255.0); - //1cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); + //cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); cairo_set_source (cr, pat); cairo_stroke(cr); cairo_close_path(cr); -- cgit v1.2.3 From f015c04d1e44c59ab650fe9f118bcf633833a150 Mon Sep 17 00:00:00 2001 From: Mirco Müller Date: Tue, 6 Jul 2010 13:47:31 +0200 Subject: added some internal helpers for blurring, added more precise button-background rendering --- src/play-button.c | 402 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 390 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 76a8109..347a0bc 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -15,6 +15,8 @@ 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, see . + +Uses code from ctk */ #ifdef HAVE_CONFIG_H @@ -58,6 +60,227 @@ static void play_button_draw_previous_symbol(cairo_t* cr, double x, double y); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); +/// internal helper functions ////////////////////////////////////////////////// + +static double +_align (double val) +{ + double fract = val - (int) val; + + if (fract != 0.5f) + return (double) ((int) val + 0.5f); + else + return val; +} + +static inline void +_blurinner (guchar* pixel, + gint* zR, + gint* zG, + gint* zB, + gint* zA, + gint alpha, + gint aprec, + gint zprec) +{ + gint R; + gint G; + gint B; + guchar A; + + R = *pixel; + G = *(pixel + 1); + B = *(pixel + 2); + A = *(pixel + 3); + + *zR += (alpha * ((R << zprec) - *zR)) >> aprec; + *zG += (alpha * ((G << zprec) - *zG)) >> aprec; + *zB += (alpha * ((B << zprec) - *zB)) >> aprec; + *zA += (alpha * ((A << zprec) - *zA)) >> aprec; + + *pixel = *zR >> zprec; + *(pixel + 1) = *zG >> zprec; + *(pixel + 2) = *zB >> zprec; + *(pixel + 3) = *zA >> zprec; +} + +static inline void +_blurrow (guchar* pixels, + gint width, + gint height, + gint channels, + gint line, + gint alpha, + gint aprec, + gint zprec) +{ + gint zR; + gint zG; + gint zB; + gint zA; + gint index; + guchar* scanline; + + scanline = &(pixels[line * width * channels]); + + zR = *scanline << zprec; + zG = *(scanline + 1) << zprec; + zB = *(scanline + 2) << zprec; + zA = *(scanline + 3) << zprec; + + for (index = 0; index < width; index ++) + _blurinner (&scanline[index * channels], + &zR, + &zG, + &zB, + &zA, + alpha, + aprec, + zprec); + + for (index = width - 2; index >= 0; index--) + _blurinner (&scanline[index * channels], + &zR, + &zG, + &zB, + &zA, + alpha, + aprec, + zprec); +} + +static inline void +_blurcol (guchar* pixels, + gint width, + gint height, + gint channels, + gint x, + gint alpha, + gint aprec, + gint zprec) +{ + gint zR; + gint zG; + gint zB; + gint zA; + gint index; + guchar* ptr; + + ptr = pixels; + + ptr += x * channels; + + zR = *((guchar*) ptr ) << zprec; + zG = *((guchar*) ptr + 1) << zprec; + zB = *((guchar*) ptr + 2) << zprec; + zA = *((guchar*) ptr + 3) << zprec; + + for (index = width; index < (height - 1) * width; index += width) + _blurinner ((guchar*) &ptr[index * channels], + &zR, + &zG, + &zB, + &zA, + alpha, + aprec, + zprec); + + for (index = (height - 2) * width; index >= 0; index -= width) + _blurinner ((guchar*) &ptr[index * channels], + &zR, + &zG, + &zB, + &zA, + alpha, + aprec, + zprec); +} + +void +_expblur (guchar* pixels, + gint width, + gint height, + gint channels, + gint radius, + gint aprec, + gint zprec) +{ + gint alpha; + gint row = 0; + gint col = 0; + + if (radius < 1) + return; + + // calculate the alpha such that 90% of + // the kernel is within the radius. + // (Kernel extends to infinity) + alpha = (gint) ((1 << aprec) * (1.0f - expf (-2.3f / (radius + 1.f)))); + + for (; row < height; row++) + _blurrow (pixels, + width, + height, + channels, + row, + alpha, + aprec, + zprec); + + for(; col < width; col++) + _blurcol (pixels, + width, + height, + channels, + col, + alpha, + aprec, + zprec); + + return; +} + +void +_surface_blur (cairo_surface_t* surface, + guint radius) +{ + guchar* pixels; + guint width; + guint height; + cairo_format_t format; + + // before we mess with the surface execute any pending drawing + cairo_surface_flush (surface); + + pixels = cairo_image_surface_get_data (surface); + width = cairo_image_surface_get_width (surface); + height = cairo_image_surface_get_height (surface); + format = cairo_image_surface_get_format (surface); + + switch (format) + { + case CAIRO_FORMAT_ARGB32: + _expblur (pixels, width, height, 4, radius, 16, 7); + break; + + case CAIRO_FORMAT_RGB24: + _expblur (pixels, width, height, 3, radius, 16, 7); + break; + + case CAIRO_FORMAT_A8: + _expblur (pixels, width, height, 1, radius, 16, 7); + break; + + default : + // do nothing + break; + } + + // inform cairo we altered the surfaces contents + cairo_surface_mark_dirty (surface); +} + +/// GObject functions ////////////////////////////////////////////////////////// static void play_button_class_init (PlayButtonClass *klass) @@ -97,7 +320,7 @@ static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event) { cairo_t *cr; - cr = gdk_cairo_create (button->window); + cr = gdk_cairo_create (button->window); g_debug("PlayButton::Draw - width = %i", button->allocation.width); g_debug("PlayButton::Draw - event->area.width = %i", event->area.width); @@ -109,7 +332,7 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) cairo_clip(cr); draw (button, cr); - cairo_destroy (cr); + cairo_destroy (cr); return FALSE; } @@ -126,34 +349,189 @@ play_button_set_style(GtkWidget* button, GtkStyle* style) } static void -draw (GtkWidget* button, cairo_t *cr) +draw_gradient (cairo_t* cr, + double x, + double y, + double w, + double r, + double* rgba_start, + double* rgba_end) { + cairo_pattern_t* pattern = NULL; + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + w - 2.0f * r, y); + cairo_arc (cr, + x + w - 2.0f * r, + y + r, + r, + -90.0f * G_PI / 180.0f, + 90.0f * G_PI / 180.0f); + cairo_line_to (cr, x, y + 2.0f * r); + cairo_arc (cr, + x, + y + r, + r, + 90.0f * G_PI / 180.0f, + 270.0f * G_PI / 180.0f); + cairo_close_path (cr); + + pattern = cairo_pattern_create_linear (x, y, x, y + 2.0f * r); + cairo_pattern_add_color_stop_rgba (pattern, + 0.0f, + rgba_start[0], + rgba_start[1], + rgba_start[2], + rgba_start[3]); + cairo_pattern_add_color_stop_rgba (pattern, + 1.0f, + rgba_end[0], + rgba_end[1], + rgba_end[2], + rgba_end[3]); + cairo_set_source (cr, pattern); + cairo_fill (cr); + cairo_pattern_destroy (pattern); +} + +static void +draw_circle (cairo_t* cr, + double x, + double y, + double r, + double* rgba_start, + double* rgba_end) +{ + cairo_pattern_t* pattern = NULL; + + cairo_move_to (cr, x, y); + cairo_arc (cr, + x + r, + y + r, + r, + 0.0f * G_PI / 180.0f, + 360.0f * G_PI / 180.0f); + + pattern = cairo_pattern_create_linear (x, y, x, y + 2.0f * r); + cairo_pattern_add_color_stop_rgba (pattern, + 0.0f, + rgba_start[0], + rgba_start[1], + rgba_start[2], + rgba_start[3]); + cairo_pattern_add_color_stop_rgba (pattern, + 1.0f, + rgba_end[0], + rgba_end[1], + rgba_end[2], + rgba_end[3]); + cairo_set_source (cr, pattern); + cairo_fill (cr); + cairo_pattern_destroy (pattern); +} + +static void +draw (GtkWidget* button, cairo_t *cr) +{ //PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); - double rect_width = 115; - double rect_height = 28; - double p_radius = 21; + double rect_width = 130; double y = 15; double x = 22; + double inner_height = 25.0f; + double inner_radius = 12.5f; + double inner_start[] = {229.0f / 255.0f, + 223.0f / 255.0f, + 215.0f / 255.0f, + 1.0f}; + double inner_end[] = {183.0f / 255.0f, + 178.0f / 255.0f, + 172.0f / 255.0f, + 1.0f}; + double middle_height = 27.0f; + double middle_radius = 13.5f; + double middle_start[] = {61.0f / 255.0f, + 60.0f / 255.0f, + 57.0f / 255.0f, + 1.0f}; + double middle_end[] = {94.0f / 255.0f, + 93.0f / 255.0f, + 90.0f / 255.0f, + 1.0f}; + double outter_height = 29.0f; + double outter_radius = 14.5f; + double outter_start[] = {36.0f / 255.0f, + 35.0f / 255.0f, + 33.0f / 255.0f, + 1.0f}; + double outter_end[] = {123.0f / 255.0f, + 123.0f / 255.0f, + 120.0f / 255.0f, + 1.0f}; + + double circle_radius = 19.0f; + //double radius=35; //double x= button->allocation.width/2 - rect_width/2; //double y= button->allocation.height/2 -rect_height/2; + // ffwd/back-background + draw_gradient (cr, + x, + y, + rect_width, + outter_radius, + outter_start, + outter_end); + draw_gradient (cr, + x, + y + 1, + rect_width - 2, + middle_radius, + middle_start, + middle_end); + draw_gradient (cr, + x, + y + 2, + rect_width - 4, + inner_radius, + inner_start, + inner_end); + + // play/pause-background + draw_circle (cr, + x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f, + y - ((circle_radius - outter_radius)), + circle_radius, + outter_start, + outter_end); + draw_circle (cr, + x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f + 1.0f, + y - ((circle_radius - outter_radius)) + 1.0f, + circle_radius - 1, + middle_start, + middle_end); + draw_circle (cr, + x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f + 2.0f, + y - ((circle_radius - outter_radius)) + 2.0f, + circle_radius - 2.0f, + inner_start, + inner_end); + // Draw the outside drop shadow background - play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); + //play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); // Draw the inside drop shadow background - gint offset = 4; - play_button_draw_background_shadow_2(button, cr, x + offset-1, y + offset/2, rect_width-offset, rect_height-offset, p_radius-(offset/2)); + /*gint offset = 4; + play_button_draw_background_shadow_2(button, cr, x + offset-1, y + offset/2, rect_width-offset, rect_height-offset, p_radius-(offset/2));*/ - offset = 5; + //offset = 5; // Draw the inside actual background - play_button_draw_background(button, cr, x+offset-1, y + offset/2+1, rect_width-offset, rect_height-offset, p_radius-offset/2); + /*play_button_draw_background(button, cr, x+offset-1, y + offset/2+1, rect_width-offset, rect_height-offset, p_radius-offset/2); play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x -1 + offset/2, rect_height/5 +y ); play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x + offset/2 + 10, rect_height/5 +y ); - play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset+2); + play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset+2);*/ cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); } -- cgit v1.2.3 From 9ec9e3fa570d0208c6409b13103bcd558f2b61a8 Mon Sep 17 00:00:00 2001 From: Mirco Müller Date: Wed, 7 Jul 2010 03:46:29 +0200 Subject: finished the rendering of the custom widget --- src/play-button.c | 467 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 288 insertions(+), 179 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 347a0bc..3c5b120 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -3,6 +3,7 @@ Copyright 2010 Canonical Ltd. Authors: Conor Curran + Mirco Müller This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published @@ -430,6 +431,147 @@ draw_circle (cairo_t* cr, cairo_pattern_destroy (pattern); } +static void +_setup (cairo_t** cr, + cairo_surface_t** surf, + gint width, + gint height) +{ + if (!cr || !surf) + return; + + *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + *cr = cairo_create (*surf); + cairo_scale (*cr, 1.0f, 1.0f); + cairo_set_operator (*cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (*cr); + cairo_set_operator (*cr, CAIRO_OPERATOR_OVER); +} + +static void +_mask_prev (cairo_t* cr, + double x, + double y, + double tri_width, + double tri_height, + double tri_offset) +{ + if (!cr) + return; + + cairo_move_to (cr, x, y + tri_height / 2.0f); + cairo_line_to (cr, x + tri_width, y); + cairo_line_to (cr, x + tri_width, y + tri_height); + x += tri_offset; + cairo_move_to (cr, x, y + tri_height / 2.0f); + cairo_line_to (cr, x + tri_width, y); + cairo_line_to (cr, x + tri_width, y + tri_height); + x -= tri_offset; + cairo_rectangle (cr, x, y, 2.5f, tri_height); + cairo_close_path (cr); +} + +static void +_mask_next (cairo_t* cr, + double x, + double y, + double tri_width, + double tri_height, + double tri_offset) +{ + if (!cr) + return; + + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + tri_width, y + tri_height / 2.0f); + cairo_line_to (cr, x, y + tri_height); + x += tri_offset; + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + tri_width, y + tri_height / 2.0f); + cairo_line_to (cr, x, y + tri_height); + x -= tri_offset; + x += 2.0f * tri_width - tri_offset - 1.0f; + cairo_rectangle (cr, x, y, 2.5f, tri_height); + + cairo_close_path (cr); +} + +static void +_mask_pause (cairo_t* cr, + double x, + double y, + double bar_width, + double bar_height, + double bar_offset) +{ + if (!cr) + return; + + cairo_set_line_width (cr, bar_width); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + + x += bar_width; + y += bar_width; + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + bar_height); + cairo_move_to (cr, x + bar_offset, y); + cairo_line_to (cr, x + bar_offset, y + bar_height); + + //cairo_close_path (cr); +} + +static void +_fill (cairo_t* cr, + double x_start, + double y_start, + double x_end, + double y_end, + double* rgba_start, + double* rgba_end, + gboolean stroke) +{ + cairo_pattern_t* pattern = NULL; + + if (!cr || !rgba_start || !rgba_end) + return; + + pattern = cairo_pattern_create_linear (x_start, y_start, x_end, y_end); + cairo_pattern_add_color_stop_rgba (pattern, + 0.0f, + rgba_start[0], + rgba_start[1], + rgba_start[2], + rgba_start[3]); + cairo_pattern_add_color_stop_rgba (pattern, + 1.0f, + rgba_end[0], + rgba_end[1], + rgba_end[2], + rgba_end[3]); + cairo_set_source (cr, pattern); + if (stroke) + cairo_stroke (cr); + else + cairo_fill (cr); + cairo_pattern_destroy (pattern); +} + +static void +_finalize (cairo_t* cr, + cairo_t** cr_surf, + cairo_surface_t** surf, + double x, + double y) +{ + if (!cr || !cr_surf || !surf) + return; + + cairo_set_source_surface (cr, *surf, x, y); + cairo_paint (cr); + cairo_surface_destroy (*surf); + cairo_destroy (*cr_surf); +} + static void draw (GtkWidget* button, cairo_t *cr) { @@ -470,11 +612,40 @@ draw (GtkWidget* button, cairo_t *cr) double circle_radius = 19.0f; - //double radius=35; - //double x= button->allocation.width/2 - rect_width/2; - //double y= button->allocation.height/2 -rect_height/2; - - // ffwd/back-background + double button_start[] = {252.0f / 255.0f, + 251.0f / 255.0f, + 251.0f / 255.0f, + 1.0f}; + double button_end[] = {186.0f / 255.0f, + 180.0f / 255.0f, + 170.0f / 255.0f, + 1.0f}; + double button_shadow[] = {0.0f / 255.0f, + 0.0f / 255.0f, + 0.0f / 255.0f, + 0.75f}; + double prev_width = 25.0f; + double prev_height = 17.0f; + double next_width = prev_width; + double next_height = prev_height; + cairo_surface_t* surf = NULL; + cairo_t* cr_surf = NULL; + double tri_width = 11.0f; + double tri_height = 13.0f; + double tri_offset = 6.0f; + double prev_x = 20.0f; + double prev_y = 21.0f; + double next_x = 98.0f; + double next_y = prev_y; + double pause_width = 21.0f; + double pause_height = 27.0f; + double bar_width = 4.5f; + double bar_height = 24.0f; + double bar_offset = 10.0f; + double pause_x = 62.0f; + double pause_y = 15.0f; + + // prev/next-background draw_gradient (cr, x, y, @@ -517,182 +688,120 @@ draw (GtkWidget* button, cairo_t *cr) inner_start, inner_end); - // Draw the outside drop shadow background - //play_button_draw_background_shadow_1(button, cr, x, y, rect_width, rect_height, p_radius); - - // Draw the inside drop shadow background - /*gint offset = 4; - play_button_draw_background_shadow_2(button, cr, x + offset-1, y + offset/2, rect_width-offset, rect_height-offset, p_radius-(offset/2));*/ - - //offset = 5; - // Draw the inside actual background - /*play_button_draw_background(button, cr, x+offset-1, y + offset/2+1, rect_width-offset, rect_height-offset, p_radius-offset/2); - - play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x -1 + offset/2, rect_height/5 +y ); - - play_button_draw_pause_symbol(cr, rect_width/2 + rect_height/10 + x + offset/2 + 10, rect_height/5 +y ); - play_button_draw_previous_symbol(cr, x+rect_height/2 + offset, y + offset+2);*/ - cairo_surface_write_to_png(cairo_get_target (cr), "/tmp/foobar.png"); -} - -static void -play_button_draw_previous_symbol(cairo_t* cr, double x, double y) -{ - gint line_width = 2; - cairo_set_line_width (cr, line_width); - gint shape_height = 15; - gint shape_width = 22; - gint single_arrow_width=16; - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+shape_height); - - cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); - cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); - cairo_pattern_add_color_stop_rgb(pat, .4, 123/255.0, 123/255.0, 120/255.0); - cairo_set_source (cr, pat); - - cairo_move_to(cr, x, y); - cairo_rel_line_to (cr, 0, shape_height); - cairo_stroke(cr); - - cairo_move_to (cr, x+line_width, y+shape_height/2); - cairo_line_to (cr, x+single_arrow_width, y); - cairo_line_to (cr, x+single_arrow_width, y+shape_height); - cairo_line_to (cr, x+line_width, y+shape_height/2); - cairo_fill(cr); - - cairo_pattern_destroy (pat); - cairo_close_path(cr); -} - -static void -play_button_draw_pause_symbol(cairo_t* cr, double x, double y) -{ - cairo_set_line_width (cr, 7); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to (cr, x, y); - cairo_rel_line_to (cr, 0, 18); - //cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+16); - cairo_pattern_add_color_stop_rgb(pat, 0, 227/255.0, 222/255.0, 214/255.0); - cairo_pattern_add_color_stop_rgb(pat, .1, 207/255.0, 201/255.0, 190/255.0); - cairo_pattern_add_color_stop_rgb(pat, .6, 123/255.0, 123/255.0, 120/255.0); - cairo_set_source (cr, pat); - cairo_stroke(cr); - cairo_close_path(cr); - - cairo_set_line_width (cr, 5.5); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to (cr, x, y+0.75); - cairo_rel_line_to (cr, 0, 16.5); - - pat = cairo_pattern_create_linear (x+1, y+1, x+1, y+16); - cairo_pattern_add_color_stop_rgb(pat, .3, 252/255.0, 252/255.0, 251/255.0); - cairo_pattern_add_color_stop_rgb(pat, .8, 227/255.0, 222/255.0, 214/255.0); - //cairo_pattern_add_color_stop_rgb(pat, .9, 207/255.0, 201/255.0, 190/255.0); - cairo_set_source (cr, pat); - cairo_stroke(cr); - cairo_close_path(cr); - - cairo_pattern_destroy (pat); -} - -static void -play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) -{ - double radius=rect_height/2; - cairo_set_line_width (cr, rect_height); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to(cr, x+radius, y+radius); - cairo_line_to(cr, x+rect_width, y+radius); - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+rect_height); - cairo_pattern_add_color_stop_rgb(pat, .5, 225/255.0, 218/255.0, 211/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 197/255.0, 192/255.0, 185/255.0); - cairo_pattern_add_color_stop_rgb(pat, .9, 185/255.0, 179/255.0, 173/255.0); - cairo_set_source (cr, pat); - cairo_stroke (cr); - - cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); - cairo_set_source (cr, pat); - cairo_fill(cr); - - cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); - cairo_set_source_rgb(cr, 94/255.0, 93/255.0, 90/255.0); - cairo_set_line_width (cr, 0.75); - cairo_stroke(cr); - cairo_close_path(cr); - cairo_pattern_destroy (pat); -} - -static void -play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) -{ - double radius=rect_height/2; - - cairo_set_line_width (cr, rect_height); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to(cr, x+radius, y+radius); - cairo_line_to(cr, x+rect_width, y+radius); - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+rect_height); - cairo_pattern_add_color_stop_rgb(pat, .4, 36/255.0, 35/255.0, 33/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); - cairo_set_source (cr, pat); - cairo_stroke (cr); - - cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); - pat = cairo_pattern_create_linear ((rect_width/2 + radius/2 + x), rect_height/2 + y-p_radius, (rect_width/2 + radius/2 + x), rect_height+(p_radius-rect_height/2)); - cairo_pattern_add_color_stop_rgb(pat, .4, 36/255.0, 35/255.0, 33/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 123/255.0, 123/255.0, 120/255.0); - cairo_set_source (cr, pat); - cairo_fill(cr); - cairo_close_path(cr); - cairo_pattern_destroy (pat); - -} - -static void -play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius) -{ - double radius=rect_height/2; - - cairo_set_line_width (cr, rect_height); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_move_to(cr, x+radius, y+radius); - cairo_line_to(cr, x+rect_width, y+radius); - - cairo_pattern_t *pat; - pat = cairo_pattern_create_linear (x, y, x, y+rect_height); - cairo_pattern_add_color_stop_rgb(pat, .4, 61/255.0, 60/255.0, 57/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); - cairo_set_source (cr, pat); - cairo_stroke (cr); - - cairo_close_path(cr); - cairo_arc(cr, rect_width/2 + radius/2 + x + 2, rect_height/2 +y, p_radius, 0, 2*M_PI); - pat = cairo_pattern_create_linear ((rect_width/2 + radius/2 + x), rect_height/2 + y-p_radius, (rect_width/2 + radius/2 + x), rect_height+(p_radius-rect_height/2)); - cairo_pattern_add_color_stop_rgb(pat, .4, 61/255.0, 60/255.0, 57/255.0); - cairo_pattern_add_color_stop_rgb(pat, .7, 94/255.0, 93/255.0, 90/255.0); - - cairo_set_source (cr, pat); - cairo_fill(cr); - cairo_close_path(cr); - cairo_pattern_destroy (pat); - + // draw previous-button drop-shadow + _setup (&cr_surf, &surf, prev_width, prev_height); + _mask_prev (cr_surf, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (prev_height - tri_height) / 2.0f, + tri_width, + tri_height, + tri_offset); + _fill (cr_surf, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (prev_height - tri_height) / 2.0f, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (double) tri_height, + button_shadow, + button_shadow, + FALSE); + _surface_blur (surf, 1); + _finalize (cr, &cr_surf, &surf, prev_x, prev_y + 1.0f); + + // draw previous-button + _setup (&cr_surf, &surf, prev_width, prev_height); + _mask_prev (cr_surf, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (prev_height - tri_height) / 2.0f, + tri_width, + tri_height, + tri_offset); + _fill (cr_surf, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (prev_height - tri_height) / 2.0f, + (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (double) tri_height, + button_start, + button_end, + FALSE); + _finalize (cr, &cr_surf, &surf, prev_x, prev_y); + + // draw next-button drop-shadow + _setup (&cr_surf, &surf, next_width, next_height); + _mask_next (cr_surf, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (next_height - tri_height) / 2.0f, + tri_width, + tri_height, + tri_offset); + _fill (cr_surf, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (next_height - tri_height) / 2.0f, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (double) tri_height, + button_shadow, + button_shadow, + FALSE); + _surface_blur (surf, 1); + _finalize (cr, &cr_surf, &surf, next_x, next_y + 1.0f); + + // draw next-button + _setup (&cr_surf, &surf, next_width, next_height); + _mask_next (cr_surf, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (next_height - tri_height) / 2.0f, + tri_width, + tri_height, + tri_offset); + _fill (cr_surf, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (next_height - tri_height) / 2.0f, + (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, + (double) tri_height, + button_start, + button_end, + FALSE); + _finalize (cr, &cr_surf, &surf, next_x, next_y); + + // draw pause-button drop-shadow + _setup (&cr_surf, &surf, pause_width, pause_height); + _mask_pause (cr_surf, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (pause_height - bar_height) / 2.0f, + bar_width, + bar_height - 2.0f * bar_width, + bar_offset); + _fill (cr_surf, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (pause_height - bar_height) / 2.0f, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (double) bar_height, + button_shadow, + button_shadow, + TRUE); + _surface_blur (surf, 1); + _finalize (cr, &cr_surf, &surf, pause_x, pause_y + 1.0f); + + // draw pause-button + _setup (&cr_surf, &surf, pause_width, pause_height); + _mask_pause (cr_surf, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (pause_height - bar_height) / 2.0f, + bar_width, + bar_height - 2.0f * bar_width, + bar_offset); + _fill (cr_surf, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (pause_height - bar_height) / 2.0f, + (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, + (double) bar_height, + button_start, + button_end, + TRUE); + _finalize (cr, &cr_surf, &surf, pause_x, pause_y); + + cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/foobar.png"); } - - - /** * play_button_new: * @returns: a new #PlayButton. -- cgit v1.2.3 From 5d8d12718e518a8bc695e57c071760720de4329e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 17:42:38 +0100 Subject: moved what I could to a #define and removed unused --- src/play-button.c | 349 +++++++++++++++++++++++------------------------------- 1 file changed, 151 insertions(+), 198 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 3c5b120..136f25d 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -27,6 +27,31 @@ Uses code from ctk #include #include "play-button.h" +#define RECT_WIDTH 130.0f +#define Y 15.0f +#define X 22.0f +#define INNER_RADIUS 12.5 +#define MIDDLE_RADIUS 13.5f +#define OUTER_RADIUS 14.5f +#define CIRCLE_RADIUS 19.0f +#define PREV_WIDTH 25.0f +#define PREV_HEIGHT 17.0f +#define NEXT_WIDTH 25.0f //PREV_WIDTH +#define NEXT_HEIGHT 17.0f //PREV_HEIGHT +#define TRI_WIDTH 11.0f +#define TRI_HEIGHT 13.0f +#define TRI_OFFSET 6.0f +#define PREV_X 20.0f +#define PREV_Y 21.0f +#define NEXT_X 98.0f +#define NEXT_Y 21.0f //prev_y +#define PAUSE_WIDTH 21.0f +#define PAUSE_HEIGHT 27.0f +#define BAR_WIDTH 4.5f +#define BAR_HEIGHT 24.0f +#define BAR_OFFSET 10.0f +#define PAUSE_X 62.0f +#define PAUSE_Y 15.0f typedef struct _PlayButtonPrivate PlayButtonPrivate; @@ -49,15 +74,6 @@ static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); static void draw (GtkWidget* button, cairo_t *cr); -static void play_button_draw_background(GtkWidget* button, cairo_t* cr, double x, double y, double width, double height, double p_radius); -static void play_button_draw_background_shadow_2(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius); -static void play_button_draw_background_shadow_1(GtkWidget* button, cairo_t* cr, double x, double y, double rect_width, double rect_height, double p_radius); - - -//static void play_button_draw_play_symbol(cairo_t* cr, double x, double y); -static void play_button_draw_pause_symbol(cairo_t* cr, double x, double y); -static void play_button_draw_previous_symbol(cairo_t* cr, double x, double y); - G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -301,7 +317,6 @@ play_button_class_init (PlayButtonClass *klass) static void play_button_init (PlayButton *self) { - g_debug("PlayButton::play_button_init"); gtk_widget_set_size_request(GTK_WIDGET(self), 200, 80); } @@ -323,10 +338,6 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) cairo_t *cr; cr = gdk_cairo_create (button->window); - g_debug("PlayButton::Draw - width = %i", button->allocation.width); - g_debug("PlayButton::Draw - event->area.width = %i", event->area.width); - g_debug("PlayButton::Draw - event->area.x = %i", event->area.x); - cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height); @@ -517,7 +528,6 @@ _mask_pause (cairo_t* cr, cairo_move_to (cr, x + bar_offset, y); cairo_line_to (cr, x + bar_offset, y + bar_height); - //cairo_close_path (cr); } static void @@ -575,233 +585,176 @@ _finalize (cairo_t* cr, static void draw (GtkWidget* button, cairo_t *cr) { - //PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); - double rect_width = 130; - double y = 15; - double x = 22; - double inner_height = 25.0f; - double inner_radius = 12.5f; - double inner_start[] = {229.0f / 255.0f, - 223.0f / 255.0f, - 215.0f / 255.0f, - 1.0f}; - double inner_end[] = {183.0f / 255.0f, - 178.0f / 255.0f, - 172.0f / 255.0f, - 1.0f}; - double middle_height = 27.0f; - double middle_radius = 13.5f; - double middle_start[] = {61.0f / 255.0f, - 60.0f / 255.0f, - 57.0f / 255.0f, - 1.0f}; - double middle_end[] = {94.0f / 255.0f, - 93.0f / 255.0f, - 90.0f / 255.0f, - 1.0f}; - double outter_height = 29.0f; - double outter_radius = 14.5f; - double outter_start[] = {36.0f / 255.0f, - 35.0f / 255.0f, - 33.0f / 255.0f, - 1.0f}; - double outter_end[] = {123.0f / 255.0f, - 123.0f / 255.0f, - 120.0f / 255.0f, - 1.0f}; - - double circle_radius = 19.0f; - - double button_start[] = {252.0f / 255.0f, - 251.0f / 255.0f, - 251.0f / 255.0f, - 1.0f}; - double button_end[] = {186.0f / 255.0f, - 180.0f / 255.0f, - 170.0f / 255.0f, - 1.0f}; - double button_shadow[] = {0.0f / 255.0f, - 0.0f / 255.0f, - 0.0f / 255.0f, - 0.75f}; - double prev_width = 25.0f; - double prev_height = 17.0f; - double next_width = prev_width; - double next_height = prev_height; cairo_surface_t* surf = NULL; cairo_t* cr_surf = NULL; - double tri_width = 11.0f; - double tri_height = 13.0f; - double tri_offset = 6.0f; - double prev_x = 20.0f; - double prev_y = 21.0f; - double next_x = 98.0f; - double next_y = prev_y; - double pause_width = 21.0f; - double pause_height = 27.0f; - double bar_width = 4.5f; - double bar_height = 24.0f; - double bar_offset = 10.0f; - double pause_x = 62.0f; - double pause_y = 15.0f; + double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f}; + double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f}; + double MIDDLE_START[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; + double MIDDLE_END[] = {94.0f / 255.0f,93.0f / 255.0f, 90.0f / 255.0f,1.0f}; + double OUTER_START[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; + double OUTER_END[] = {123.0f / 255.0f, 123.0f / 255.0f, 120.0f / 255.0f, 1.0f}; + double BUTTON_START[] = {252.0f / 255.0f, 251.0f / 255.0f, 251.0f / 255.0f,1.0f}; + double BUTTON_END[] = {186.0f / 255.0f,180.0f / 255.0f, 170.0f / 255.0f, 1.0f}; + double BUTTON_SHADOW[] = {0.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f, 0.75f}; + + // prev/next-background - draw_gradient (cr, - x, - y, - rect_width, - outter_radius, - outter_start, - outter_end); - draw_gradient (cr, - x, - y + 1, - rect_width - 2, - middle_radius, - middle_start, - middle_end); - draw_gradient (cr, - x, - y + 2, - rect_width - 4, - inner_radius, - inner_start, - inner_end); + draw_gradient (cr, + X, + Y, + RECT_WIDTH, + OUTER_RADIUS, + OUTER_START, + OUTER_END); + draw_gradient (cr, + X, + Y + 1, + RECT_WIDTH - 2, + MIDDLE_RADIUS, + MIDDLE_START, + MIDDLE_END); + draw_gradient (cr, + X, + Y + 2, + RECT_WIDTH - 4, + INNER_RADIUS, + INNER_START, + INNER_END); // play/pause-background draw_circle (cr, - x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f, - y - ((circle_radius - outter_radius)), - circle_radius, - outter_start, - outter_end); + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 4.5f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)), + CIRCLE_RADIUS, + OUTER_START, + OUTER_END); draw_circle (cr, - x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f + 1.0f, - y - ((circle_radius - outter_radius)) + 1.0f, - circle_radius - 1, - middle_start, - middle_end); + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 4.5f + 1.0f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.0f, + CIRCLE_RADIUS - 1, + MIDDLE_START, + MIDDLE_END); draw_circle (cr, - x + rect_width / 2.0f - 2.0f * outter_radius - 4.5f + 2.0f, - y - ((circle_radius - outter_radius)) + 2.0f, - circle_radius - 2.0f, - inner_start, - inner_end); + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 4.5f + 2.0f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 2.0f, + CIRCLE_RADIUS - 2.0f, + INNER_START, + INNER_END); // draw previous-button drop-shadow - _setup (&cr_surf, &surf, prev_width, prev_height); + _setup (&cr_surf, &surf, PREV_WIDTH, PREV_HEIGHT); _mask_prev (cr_surf, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (prev_height - tri_height) / 2.0f, - tri_width, - tri_height, - tri_offset); + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (PREV_HEIGHT - TRI_HEIGHT) / 2.0f, + TRI_WIDTH, + TRI_HEIGHT, + TRI_OFFSET); _fill (cr_surf, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (prev_height - tri_height) / 2.0f, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (double) tri_height, - button_shadow, - button_shadow, + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (PREV_HEIGHT - TRI_HEIGHT) / 2.0f, + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (double) TRI_HEIGHT, + BUTTON_SHADOW, + BUTTON_SHADOW, FALSE); _surface_blur (surf, 1); - _finalize (cr, &cr_surf, &surf, prev_x, prev_y + 1.0f); + _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y + 1.0f); // draw previous-button - _setup (&cr_surf, &surf, prev_width, prev_height); + _setup (&cr_surf, &surf, PREV_WIDTH, PREV_HEIGHT); _mask_prev (cr_surf, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (prev_height - tri_height) / 2.0f, - tri_width, - tri_height, - tri_offset); + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (PREV_HEIGHT - TRI_HEIGHT) / 2.0f, + TRI_WIDTH, + TRI_HEIGHT, + TRI_OFFSET); _fill (cr_surf, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (prev_height - tri_height) / 2.0f, - (prev_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (double) tri_height, - button_start, - button_end, + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (PREV_HEIGHT - TRI_HEIGHT) / 2.0f, + (PREV_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (double) TRI_HEIGHT, + BUTTON_START, + BUTTON_END, FALSE); - _finalize (cr, &cr_surf, &surf, prev_x, prev_y); + _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y); // draw next-button drop-shadow - _setup (&cr_surf, &surf, next_width, next_height); + _setup (&cr_surf, &surf, NEXT_WIDTH, NEXT_HEIGHT); _mask_next (cr_surf, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (next_height - tri_height) / 2.0f, - tri_width, - tri_height, - tri_offset); + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (NEXT_HEIGHT - TRI_HEIGHT) / 2.0f, + TRI_WIDTH, + TRI_HEIGHT, + TRI_OFFSET); _fill (cr_surf, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (next_height - tri_height) / 2.0f, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (double) tri_height, - button_shadow, - button_shadow, + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (NEXT_HEIGHT - TRI_HEIGHT) / 2.0f, + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (double) TRI_HEIGHT, + BUTTON_SHADOW, + BUTTON_SHADOW, FALSE); _surface_blur (surf, 1); - _finalize (cr, &cr_surf, &surf, next_x, next_y + 1.0f); + _finalize (cr, &cr_surf, &surf, NEXT_X, NEXT_Y + 1.0f); // draw next-button - _setup (&cr_surf, &surf, next_width, next_height); + _setup (&cr_surf, &surf, NEXT_WIDTH, NEXT_HEIGHT); _mask_next (cr_surf, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (next_height - tri_height) / 2.0f, - tri_width, - tri_height, - tri_offset); + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (NEXT_HEIGHT - TRI_HEIGHT) / 2.0f, + TRI_WIDTH, + TRI_HEIGHT, + TRI_OFFSET); _fill (cr_surf, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (next_height - tri_height) / 2.0f, - (next_width - (2.0f * tri_width - tri_offset)) / 2.0f, - (double) tri_height, - button_start, - button_end, + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (NEXT_HEIGHT - TRI_HEIGHT) / 2.0f, + (NEXT_WIDTH - (2.0f * TRI_WIDTH - TRI_OFFSET)) / 2.0f, + (double) TRI_HEIGHT, + BUTTON_START, + BUTTON_END, FALSE); - _finalize (cr, &cr_surf, &surf, next_x, next_y); + _finalize (cr, &cr_surf, &surf, NEXT_X, NEXT_Y); // draw pause-button drop-shadow - _setup (&cr_surf, &surf, pause_width, pause_height); + _setup (&cr_surf, &surf, PAUSE_WIDTH, PAUSE_HEIGHT); _mask_pause (cr_surf, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (pause_height - bar_height) / 2.0f, - bar_width, - bar_height - 2.0f * bar_width, - bar_offset); + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + BAR_WIDTH, + BAR_HEIGHT - 2.0f * BAR_WIDTH, + BAR_OFFSET); _fill (cr_surf, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (pause_height - bar_height) / 2.0f, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (double) bar_height, - button_shadow, - button_shadow, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (double) BAR_HEIGHT, + BUTTON_SHADOW, + BUTTON_SHADOW, TRUE); _surface_blur (surf, 1); - _finalize (cr, &cr_surf, &surf, pause_x, pause_y + 1.0f); + _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y + 1.0f); // draw pause-button - _setup (&cr_surf, &surf, pause_width, pause_height); + _setup (&cr_surf, &surf, PAUSE_WIDTH, PAUSE_HEIGHT); _mask_pause (cr_surf, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (pause_height - bar_height) / 2.0f, - bar_width, - bar_height - 2.0f * bar_width, - bar_offset); + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + BAR_WIDTH, + BAR_HEIGHT - 2.0f * BAR_WIDTH, + BAR_OFFSET); _fill (cr_surf, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (pause_height - bar_height) / 2.0f, - (pause_width - (2.0f * bar_width + bar_offset)) / 2.0f, - (double) bar_height, - button_start, - button_end, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (PAUSE_HEIGHT - BAR_HEIGHT) / 2.0f, + (PAUSE_WIDTH - (2.0f * BAR_WIDTH + BAR_OFFSET)) / 2.0f, + (double) BAR_HEIGHT, + BUTTON_START, + BUTTON_END, TRUE); - _finalize (cr, &cr_surf, &surf, pause_x, pause_y); - - cairo_surface_write_to_png (cairo_get_target (cr), "/tmp/foobar.png"); + _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y); } + /** * play_button_new: * @returns: a new #PlayButton. -- cgit v1.2.3