aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-07-13 17:31:19 +0100
committerConor Curran <conor.curran@canonical.com>2010-07-13 17:31:19 +0100
commit3866f14c102eec187e6fddbb7cf470df148053a3 (patch)
treec173145667204b1b2bcc53cb86e35d70dad6e18d
parentec287ed34db17df23ab16d9199fbbb48bd6b246f (diff)
downloadayatana-indicator-sound-3866f14c102eec187e6fddbb7cf470df148053a3.tar.gz
ayatana-indicator-sound-3866f14c102eec187e6fddbb7cf470df148053a3.tar.bz2
ayatana-indicator-sound-3866f14c102eec187e6fddbb7cf470df148053a3.zip
button press background done
-rw-r--r--src/play-button.c114
-rw-r--r--src/play-button.h2
-rw-r--r--src/transport-widget.c11
3 files changed, 102 insertions, 25 deletions
diff --git a/src/play-button.c b/src/play-button.c
index f712209..0d3b1f3 100644
--- a/src/play-button.c
+++ b/src/play-button.c
@@ -60,6 +60,8 @@ enum {
NEXT
};
+static const gint NO_COMMAND = -1;
+
typedef struct _PlayButtonPrivate PlayButtonPrivate;
struct _PlayButtonPrivate
@@ -69,6 +71,7 @@ struct _PlayButtonPrivate
GdkColor background_colour_bg_light;
GdkColor foreground_colour_fg;
GdkColor foreground_colour_bg;
+ gint current_command;
};
#define PLAY_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAY_BUTTON_TYPE, PlayButtonPrivate))
@@ -324,6 +327,8 @@ play_button_class_init (PlayButtonClass *klass)
static void
play_button_init (PlayButton *self)
{
+ PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(self);
+ priv->current_command = NO_COMMAND;
gtk_widget_set_size_request(GTK_WIDGET(self), 200, 80);
}
@@ -361,7 +366,8 @@ determine_button_event(GtkWidget* button, GdkEventButton* event)
{
g_debug("event x coordinate = %f", event->x);
g_debug("event y coordinate = %f", event->y);
- gint result = -1;
+ gint result = NO_COMMAND;
+
// For now very simple rectangular collision detection
if(event->x > 55 && event->x < 95
&& event->y > 22 && event->y < 46){
@@ -379,6 +385,45 @@ determine_button_event(GtkWidget* button, GdkEventButton* event)
return result;
}
+void
+play_button_react_to_button_press(GtkWidget* button, gint command)
+{
+ g_return_if_fail(IS_PLAY_BUTTON(button));
+ PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button);
+ priv->current_command = command;
+
+ 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);
+}
+
+
+void
+play_button_react_to_button_release(GtkWidget* button)
+{
+ g_return_if_fail(IS_PLAY_BUTTON(button));
+ PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button);
+ priv->current_command = NO_COMMAND;
+ 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);
+
+}
+
void
play_button_set_style(GtkWidget* button, GtkStyle* style)
{
@@ -615,6 +660,9 @@ _finalize (cairo_t* cr,
static void
draw (GtkWidget* button, cairo_t *cr)
{
+ g_return_if_fail(IS_PLAY_BUTTON(button));
+ PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button);
+
cairo_surface_t* surf = NULL;
cairo_t* cr_surf = NULL;
@@ -627,7 +675,8 @@ draw (GtkWidget* button, cairo_t *cr)
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 INNER_COMPRESSED_END[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f};
+ double INNER_COMPRESSED_START[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f};
// prev/next-background
draw_gradient (cr,
@@ -644,13 +693,32 @@ draw (GtkWidget* button, cairo_t *cr)
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 + 2,
+ RECT_WIDTH - 4,
+ INNER_RADIUS,
+ INNER_START,
+ INNER_END);
+
+ if(priv->current_command == PREVIOUS){
+ draw_gradient (cr,
+ X,
+ Y + 2,
+ RECT_WIDTH/2,
+ INNER_RADIUS,
+ INNER_COMPRESSED_START,
+ INNER_COMPRESSED_END);
+ }
+ else if(priv->current_command == NEXT){
+ draw_gradient (cr,
+ RECT_WIDTH / 2 + X,
+ Y + 2,
+ (RECT_WIDTH - 7)/2,
+ INNER_RADIUS,
+ INNER_COMPRESSED_START,
+ INNER_COMPRESSED_END);
+ }
// play/pause-background
draw_circle (cr,
@@ -670,7 +738,16 @@ draw (GtkWidget* button, cairo_t *cr)
Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 2.0f,
CIRCLE_RADIUS - 2.0f,
INNER_START,
- INNER_END);
+ INNER_END);
+ if(priv->current_command == PLAY_PAUSE){
+ draw_circle (cr,
+ 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_COMPRESSED_START,
+ INNER_COMPRESSED_END);
+ }
+
// draw previous-button drop-shadow
_setup (&cr_surf, &surf, PREV_WIDTH, PREV_HEIGHT);
@@ -700,13 +777,13 @@ draw (GtkWidget* button, cairo_t *cr)
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);
+ (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
@@ -791,8 +868,7 @@ draw (GtkWidget* button, cairo_t *cr)
**/
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 3eaabcc..37b3624 100644
--- a/src/play-button.h
+++ b/src/play-button.h
@@ -44,6 +44,8 @@ struct _PlayButton {
GType play_button_get_type (void);
void play_button_set_style(GtkWidget* button, GtkStyle* style);
gint determine_button_event(GtkWidget* button, GdkEventButton* event);
+void play_button_react_to_button_press(GtkWidget* button, gint command);
+void play_button_react_to_button_release(GtkWidget* button);
GtkWidget* play_button_new();
diff --git a/src/transport-widget.c b/src/transport-widget.c
index 9450ea5..da4f7ad 100644
--- a/src/transport-widget.c
+++ b/src/transport-widget.c
@@ -137,9 +137,7 @@ static gboolean
transport_widget_button_press_event (GtkWidget *menuitem,
GdkEventButton *event)
{
- if(IS_TRANSPORT_WIDGET(menuitem) == FALSE){
- return FALSE;
- }
+ g_return_val_if_fail(IS_TRANSPORT_WIDGET(menuitem), FALSE);
TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem));
@@ -155,6 +153,7 @@ transport_widget_button_press_event (GtkWidget *menuitem,
g_debug("TransportWidget::menu_press_event - going to send value %i", result);
g_value_set_int(&value, result);
dbusmenu_menuitem_handle_event (priv->twin_item, "Transport state change", &value, 0);
+ play_button_react_to_button_press(priv->play_button, result);
}
return TRUE;
}
@@ -165,9 +164,9 @@ transport_widget_button_release_event (GtkWidget *menuitem,
GdkEventButton *event)
{
g_debug("TransportWidget::menu_release_event");
- if(IS_TRANSPORT_WIDGET(menuitem) == FALSE){
- return FALSE;
- }
+ g_return_val_if_fail(IS_TRANSPORT_WIDGET(menuitem), FALSE);
+ TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem));
+ play_button_react_to_button_release(priv->play_button);
return TRUE;
}