aboutsummaryrefslogtreecommitdiff
path: root/src/play-button.c
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-07-02 20:04:15 +0100
committerConor Curran <conor.curran@canonical.com>2010-07-02 20:04:15 +0100
commitd79472daaf580062397ef688766cbe48b2cbd992 (patch)
treea6532eb6497641e330c1a97438a1c5c890728d84 /src/play-button.c
parentb1d159ec617f067753cd3a012697e94c592e2b88 (diff)
downloadayatana-indicator-sound-d79472daaf580062397ef688766cbe48b2cbd992.tar.gz
ayatana-indicator-sound-d79472daaf580062397ef688766cbe48b2cbd992.tar.bz2
ayatana-indicator-sound-d79472daaf580062397ef688766cbe48b2cbd992.zip
cairo is taking some time
Diffstat (limited to 'src/play-button.c')
-rw-r--r--src/play-button.c201
1 files changed, 157 insertions, 44 deletions
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;