aboutsummaryrefslogtreecommitdiff
path: root/src/play-button.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/play-button.c')
-rw-r--r--src/play-button.c222
1 files changed, 163 insertions, 59 deletions
diff --git a/src/play-button.c b/src/play-button.c
index cac2bc3..539b2b2 100644
--- a/src/play-button.c
+++ b/src/play-button.c
@@ -52,13 +52,9 @@ Uses code from ctk
#define BAR_OFFSET 10.0f
#define PAUSE_X 77.0f
#define PAUSE_Y 15.0f
-
-
-// Transport updates
-enum{
- PAUSE,
- PLAY
-};
+#define PLAY_WIDTH 28.0f
+#define PLAY_HEIGHT 29.0f
+#define PLAY_PADDING 5.0f
typedef struct _PlayButtonPrivate PlayButtonPrivate;
@@ -70,6 +66,8 @@ struct _PlayButtonPrivate
GdkColor foreground_colour_fg;
GdkColor foreground_colour_bg;
PlayButtonEvent current_command;
+ PlayButtonState current_state;
+ GHashTable* command_coordinates;
};
#define PLAY_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAY_BUTTON_TYPE, PlayButtonPrivate))
@@ -87,7 +85,7 @@ G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA);
/// internal helper functions //////////////////////////////////////////////////
-static double
+/*static double
_align (double val)
{
double fract = val - (int) val;
@@ -96,7 +94,7 @@ _align (double val)
return (double) ((int) val + 0.5f);
else
return val;
-}
+}*/
static inline void
_blurinner (guchar* pixel,
@@ -309,8 +307,7 @@ _surface_blur (cairo_surface_t* surface,
static void
play_button_class_init (PlayButtonClass *klass)
-{
-
+{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass);
@@ -327,6 +324,41 @@ play_button_init (PlayButton *self)
{
PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(self);
priv->current_command = TRANSPORT_NADA;
+ priv->current_state = PAUSE;
+ priv->command_coordinates = g_hash_table_new_full(g_direct_hash,
+ g_direct_equal,
+ NULL,
+ g_list_free);
+ GList* previous_list = NULL;
+ previous_list = g_list_insert(previous_list, GINT_TO_POINTER(15), 0);
+ previous_list = g_list_insert(previous_list, GINT_TO_POINTER(10), 1);
+ previous_list = g_list_insert(previous_list, GINT_TO_POINTER(60), 2);
+ previous_list = g_list_insert(previous_list, GINT_TO_POINTER(34), 3);
+
+ g_hash_table_insert(priv->command_coordinates,
+ GINT_TO_POINTER(TRANSPORT_PREVIOUS),
+ previous_list);
+
+ GList* play_list = NULL;
+ play_list = g_list_insert(play_list, GINT_TO_POINTER(60), 0);
+ play_list = g_list_insert(play_list, GINT_TO_POINTER(10), 1);
+ play_list = g_list_insert(play_list, GINT_TO_POINTER(45), 2);
+ play_list = g_list_insert(play_list, GINT_TO_POINTER(40), 3);
+
+ g_hash_table_insert(priv->command_coordinates,
+ GINT_TO_POINTER(TRANSPORT_PLAY_PAUSE),
+ play_list);
+
+ GList* next_list = NULL;
+ next_list = g_list_insert(next_list, GINT_TO_POINTER(100), 0);
+ next_list = g_list_insert(next_list, GINT_TO_POINTER(10), 1);
+ next_list = g_list_insert(next_list, GINT_TO_POINTER(60), 2);
+ next_list = g_list_insert(next_list, GINT_TO_POINTER(34), 3);
+
+ g_hash_table_insert(priv->command_coordinates,
+ GINT_TO_POINTER(TRANSPORT_NEXT),
+ next_list);
+
gtk_widget_set_size_request(GTK_WIDGET(self), 200, 80);
}
@@ -391,12 +423,13 @@ play_button_react_to_button_press(GtkWidget* button, PlayButtonEvent 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);*/
+ GList* list = g_hash_table_lookup(priv->command_coordinates, GINT_TO_POINTER(command));
+ cairo_rectangle(cr,
+ GPOINTER_TO_INT(g_list_nth_data(list, 0)),
+ GPOINTER_TO_INT(g_list_nth_data(list, 1)),
+ GPOINTER_TO_INT(g_list_nth_data(list, 2)),
+ GPOINTER_TO_INT(g_list_nth_data(list, 3)));
+ cairo_clip(cr);
draw (button, cr);
cairo_destroy (cr);
}
@@ -407,22 +440,32 @@ 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 = TRANSPORT_NADA;
cairo_t *cr;
+
cr = gdk_cairo_create (button->window);
- /*cairo_rectangle (cr,
- event->area.x, event->area.y,
- event->area.width, event->area.height);
+ GList* list = g_hash_table_lookup(priv->command_coordinates,
+ GINT_TO_POINTER(priv->current_command));
+
+ priv->current_command = TRANSPORT_NADA;
+
+ cairo_rectangle(cr,
+ GPOINTER_TO_INT(g_list_nth_data(list, 0)),
+ GPOINTER_TO_INT(g_list_nth_data(list, 1)),
+ GPOINTER_TO_INT(g_list_nth_data(list, 2)),
+ GPOINTER_TO_INT(g_list_nth_data(list, 3)));
- cairo_clip(cr);*/
+ cairo_clip(cr);
draw (button, cr);
cairo_destroy (cr);
}
-void
-play_button_toggle_play_pause(GtkWidget* button, int update)
+void
+play_button_toggle_play_pause(GtkWidget* button, PlayButtonState update)
{
+ PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button);
+ priv->current_state = update;
+ g_debug("PlayButton::toggle play state : %i", priv->current_state);
}
@@ -608,6 +651,24 @@ _mask_pause (cairo_t* cr,
}
static void
+_mask_play (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);
+ cairo_close_path (cr);
+
+}
+
+static void
_fill (cairo_t* cr,
double x_start,
double y_start,
@@ -826,41 +887,84 @@ draw (GtkWidget* button, cairo_t *cr)
_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);
+ if(priv->current_state == PLAY){
+ _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);
+ }
+ else if(priv->current_state == PAUSE){
+ _setup (&cr_surf, &surf, PLAY_WIDTH, PLAY_HEIGHT);
+ _mask_play (cr_surf,
+ PLAY_PADDING,
+ PLAY_PADDING,
+ PLAY_WIDTH - (2*PLAY_PADDING),
+ PLAY_HEIGHT - (2*PLAY_PADDING));
+ _fill (cr_surf,
+ PLAY_PADDING,
+ PLAY_PADDING,
+ PLAY_WIDTH - (2*PLAY_PADDING),
+ PLAY_HEIGHT - (2*PLAY_PADDING),
+ BUTTON_SHADOW,
+ BUTTON_SHADOW,
+ FALSE);
+ cairo_surface_write_to_png(surf, "/tmp/drop_shadow.png");
+ _surface_blur (surf, 1);
+ _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y + 1.0f);
+ // draw play-button
+ _setup (&cr_surf, &surf, PLAY_WIDTH, PLAY_HEIGHT);
+ cairo_set_line_width (cr, 10.5);
+ cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
+ cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
+ _mask_play (cr_surf,
+ PLAY_PADDING,
+ PLAY_PADDING,
+ PLAY_WIDTH - (2*PLAY_PADDING),
+ PLAY_HEIGHT - (2*PLAY_PADDING));
+ _fill (cr_surf,
+ PLAY_PADDING,
+ PLAY_PADDING,
+ PLAY_WIDTH - (2*PLAY_PADDING),
+ PLAY_HEIGHT - (2*PLAY_PADDING),
+ BUTTON_START,
+ BUTTON_END,
+ FALSE);
+ cairo_surface_write_to_png(surf, "/tmp/play.png");
+
+ _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y);
+ }
+
}