From 3866f14c102eec187e6fddbb7cf470df148053a3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 13 Jul 2010 17:31:19 +0100 Subject: button press background done --- src/play-button.c | 114 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 95 insertions(+), 19 deletions(-) (limited to 'src/play-button.c') 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; -- cgit v1.2.3