commit 1172a33c1199a916126ea49fe2bef32b04ce1de9
Author: phantomjinx <[email protected]>
Date: Sat Aug 27 17:21:16 2011 +0100
clarity labelling of covers
* clarity_canvas
* Adds text labels for the track title and artist onto stage
* Modify and implement text colour API for changing text colour.
plugins/clarity/clarity.xml | 2 +-
plugins/clarity/clarity_canvas.c | 96 +++++++++++++++++++++++++++++--
plugins/clarity/clarity_canvas.h | 6 ++-
plugins/clarity/clarity_cover.c | 102 ++++++++++++++++++--------------
plugins/clarity/clarity_cover.h | 4 +
plugins/clarity/clarity_preferences.c | 2 +-
plugins/clarity/clarity_widget.c | 34 +++++++----
plugins/clarity/clarity_widget.h | 2 +-
8 files changed, 182 insertions(+), 66 deletions(-)
---
diff --git a/plugins/clarity/clarity.xml b/plugins/clarity/clarity.xml
index 349fa82..cfcc9c5 100644
--- a/plugins/clarity/clarity.xml
+++ b/plugins/clarity/clarity.xml
@@ -66,7 +66,7 @@
<property name="receives_default">True</property>
<property
name="use_action_appearance">False</property>
<property name="use_alpha">True</property>
- <property name="title" translatable="yes">Choose a
Different Colour for the Clarity Foreground</property>
+ <property name="title" translatable="yes">Choose a
Different Colour for the Clarity Text</property>
<property name="color">#ffffffffffff</property>
<signal name="color-set"
handler="on_clarity_dialog_fg_color_set" swapped="no"/>
</object>
diff --git a/plugins/clarity/clarity_canvas.c b/plugins/clarity/clarity_canvas.c
index 970b876..fbce129 100644
--- a/plugins/clarity/clarity_canvas.c
+++ b/plugins/clarity/clarity_canvas.c
@@ -56,6 +56,8 @@ struct _ClarityCanvasPrivate {
ClutterActor *container;
ClutterTimeline *timeline;
ClutterAlpha *alpha;
+ ClutterActor *title_text;
+ ClutterActor *artist_text;
gint curr_index;
@@ -142,12 +144,19 @@ static void clarity_canvas_init(ClarityCanvas *self) {
priv = self->priv;
+ priv->title_text = clutter_text_new();
+ clutter_text_set_font_name(CLUTTER_TEXT(priv->title_text), "Sans");
+
+ priv->artist_text = clutter_text_new();
+ clutter_text_set_font_name(CLUTTER_TEXT(priv->title_text), "Sans");
+
priv->container = clutter_group_new();
clutter_actor_set_reactive(priv->container, TRUE);
priv->preview_signal = g_signal_connect (self,
"button-press-event",
G_CALLBACK (_preview_cover_cb),
priv);
+ clutter_container_add(CLUTTER_CONTAINER(priv->container),
priv->title_text, priv->artist_text, NULL);
priv->embed = gtk_clutter_embed_new();
/*
@@ -182,11 +191,11 @@ GtkWidget *clarity_canvas_new() {
}
/**
- * coverart_get_background_display_color:
+ * clarity_canvas_get_background_display_color:
*
* Returns the background color of the clarity canvas.
*
- * The return value is a hexstring in the form "rrggbbaa"
+ * The return value is a GdkRGBA
*
*/
GdkRGBA *clarity_canvas_get_background_color(ClarityCanvas *self) {
@@ -212,7 +221,36 @@ GdkRGBA *clarity_canvas_get_background_color(ClarityCanvas
*self) {
return rgba;
}
-void clarity_canvas_set_background(ClarityCanvas *self, const gchar
*color_string) {
+/**
+ * clarity_canvas_get_text_color:
+ *
+ * Returns the text color of the clarity text.
+ *
+ * The return value is a GdkRGBA
+ *
+ */
+GdkRGBA *clarity_canvas_get_text_color(ClarityCanvas *self) {
+ g_return_val_if_fail(CLARITY_IS_CANVAS(self), NULL);
+
+ ClarityCanvasPrivate *priv = CLARITY_CANVAS_GET_PRIVATE(self);
+
+ ClutterColor *ccolor;
+ ccolor = g_malloc(sizeof(ClutterColor));
+
+ clutter_text_get_color(CLUTTER_TEXT(priv->title_text), ccolor);
+ g_return_val_if_fail(ccolor, NULL);
+
+ GdkRGBA *rgba;
+ rgba = g_malloc(sizeof(GdkRGBA));
+ rgba->red = ((gdouble) ccolor->red) / 255;
+ rgba->green = ((gdouble) ccolor->green) / 255;
+ rgba->blue = ((gdouble) ccolor->blue) / 255;
+ rgba->alpha = ((gdouble) ccolor->alpha) / 255;
+
+ return rgba;
+}
+
+void clarity_canvas_set_background_color(ClarityCanvas *self, const gchar
*color_string) {
g_return_if_fail(self);
g_return_if_fail(color_string);
@@ -227,6 +265,21 @@ void clarity_canvas_set_background(ClarityCanvas *self,
const gchar *color_strin
clutter_stage_set_color(CLUTTER_STAGE(stage), ccolor);
}
+void clarity_canvas_set_text_color(ClarityCanvas *self, const gchar
*color_string) {
+ g_return_if_fail(self);
+ g_return_if_fail(color_string);
+
+ ClarityCanvasPrivate *priv = CLARITY_CANVAS_GET_PRIVATE(self);
+
+ ClutterColor *ccolor;
+ ccolor = g_malloc(sizeof(ClutterColor));
+
+ clutter_color_from_string(ccolor, color_string);
+
+ clutter_text_set_color(CLUTTER_TEXT(priv->title_text), ccolor);
+ clutter_text_set_color(CLUTTER_TEXT(priv->artist_text), ccolor);
+}
+
void clarity_canvas_clear(ClarityCanvas *self) {
g_return_if_fail(self);
ClarityCanvasPrivate *priv = CLARITY_CANVAS_GET_PRIVATE(self);
@@ -286,6 +339,37 @@ static gint _calculate_index_opacity (gint
dist_from_front) {
return CLAMP ( 255 * (VISIBLE_ITEMS - ABS(dist_from_front)) /
VISIBLE_ITEMS, 0, 255);
}
+static void _update_text(ClarityCanvasPrivate *priv) {
+ g_return_if_fail(priv);
+
+ if (g_list_length(priv->covers) == 0)
+ return;
+
+ ClarityCover *ccover = g_list_nth_data(priv->covers, priv->curr_index);
+
+ gchar *title = clarity_cover_get_title(ccover);
+ gchar *artist = clarity_cover_get_artist(ccover);
+
+ clutter_text_set_text(CLUTTER_TEXT(priv->title_text), title);
+ clutter_text_set_text(CLUTTER_TEXT(priv->artist_text), artist);
+
+ g_warning("%s",
clutter_text_get_font_name(CLUTTER_TEXT(priv->title_text)));
+
+ g_free(title);
+ g_free(artist);
+
+ clutter_actor_raise_top(priv->title_text);
+ clutter_actor_raise_top(priv->artist_text);
+
+ gfloat artistx = (clutter_actor_get_width(priv->artist_text) / 2) * -1;
+ gfloat artisty = ((clutter_actor_get_height(CLUTTER_ACTOR(ccover)) / 2) -
25) * -1;
+ clutter_actor_set_position(priv->artist_text, artistx, artisty);
+
+ gfloat titlex = (clutter_actor_get_width(priv->title_text) / 2) * -1;
+ gfloat titley = artisty - clutter_actor_get_height(priv->artist_text) - 2;
+ clutter_actor_set_position(priv->title_text, titlex, titley);
+}
+
static void _display_clarity_cover(ClarityCover *ccover, gint index) {
ClutterTimeline *timeline = clutter_timeline_new(1600 * 5);
ClutterAlpha *alpha = clutter_alpha_new_full (timeline,
CLUTTER_EASE_OUT_EXPO);
@@ -298,7 +382,8 @@ static void _display_clarity_cover(ClarityCover *ccover,
gint index) {
static gboolean _set_loading_complete(gpointer data) {
ClarityCanvasPrivate *priv = (ClarityCanvasPrivate *) data;
priv->loading_complete = TRUE;
- return TRUE;
+ _update_text(priv);
+ return FALSE;
}
static gboolean _create_cover_idle(gpointer data) {
@@ -460,6 +545,7 @@ static void _animate_indices(ClarityCanvasPrivate *priv,
enum DIRECTION directio
}
static void _restore_z_order(ClarityCanvasPrivate *priv) {
+ g_return_if_fail(priv);
if (g_list_length(priv->covers) == 0)
return;
@@ -497,7 +583,7 @@ static void _move(ClarityCanvasPrivate *priv, enum
DIRECTION direction, gint inc
priv->curr_index += ((direction * -1) * increment);
-// update_text ();
+ _update_text(priv);
_restore_z_order(priv);
}
diff --git a/plugins/clarity/clarity_canvas.h b/plugins/clarity/clarity_canvas.h
index 2a6df7d..346c8de 100644
--- a/plugins/clarity/clarity_canvas.h
+++ b/plugins/clarity/clarity_canvas.h
@@ -70,7 +70,11 @@ GtkWidget * clarity_canvas_new();
GdkRGBA *clarity_canvas_get_background_color(ClarityCanvas *self);
-void clarity_canvas_set_background(ClarityCanvas *self, const gchar
*color_string);
+GdkRGBA *clarity_canvas_get_text_color(ClarityCanvas *self);
+
+void clarity_canvas_set_background_color(ClarityCanvas *self, const gchar
*color_string);
+
+void clarity_canvas_set_text_color(ClarityCanvas *self, const gchar
*color_string);
void clarity_canvas_clear(ClarityCanvas *self);
diff --git a/plugins/clarity/clarity_cover.c b/plugins/clarity/clarity_cover.c
index 42a969f..074dc43 100644
--- a/plugins/clarity/clarity_cover.c
+++ b/plugins/clarity/clarity_cover.c
@@ -162,63 +162,62 @@ static void clarity_cover_init(ClarityCover *self) {
priv->reflection = NULL;
}
-static void _clone_paint_cb (ClutterActor *actor)
-{
+static void _clone_paint_cb (ClutterActor *actor) {
ClutterActor *source;
- ClutterActorBox box;
- CoglHandle material;
- gfloat width, height;
- guint8 opacity;
- CoglColor color_1, color_2;
- CoglTextureVertex vertices[4];
-
- /* if we don't have a source actor, don't paint */
- source = clutter_clone_get_source (CLUTTER_CLONE (actor));
- if (source == NULL)
+ ClutterActorBox box;
+ CoglHandle material;
+ gfloat width, height;
+ guint8 opacity;
+ CoglColor color_1, color_2;
+ CoglTextureVertex vertices[4];
+
+ /* if we don't have a source actor, don't paint */
+ source = clutter_clone_get_source (CLUTTER_CLONE (actor));
+ if (source == NULL)
goto out;
- /* if the source texture does not have any content, don't paint */
- material = clutter_texture_get_cogl_material (CLUTTER_TEXTURE (source));
- if (material == NULL)
+ /* if the source texture does not have any content, don't paint */
+ material = clutter_texture_get_cogl_material (CLUTTER_TEXTURE (source));
+ if (material == NULL)
goto out;
- /* get the size of the reflection */
- clutter_actor_get_allocation_box (actor, &box);
- clutter_actor_box_get_size (&box, &width, &height);
+ /* get the size of the reflection */
+ clutter_actor_get_allocation_box (actor, &box);
+ clutter_actor_box_get_size (&box, &width, &height);
- /* get the composite opacity of the actor */
- opacity = clutter_actor_get_paint_opacity (actor);
+ /* get the composite opacity of the actor */
+ opacity = clutter_actor_get_paint_opacity (actor);
- /* figure out the two colors for the reflection: the first is
- * full color and the second is the same, but at 0 opacity
- */
- cogl_color_init_from_4f (&color_1, 1.0, 1.0, 1.0, opacity / 255.0);
- cogl_color_premultiply (&color_1);
- cogl_color_init_from_4f (&color_2, 1.0, 1.0, 1.0, 0.0);
- cogl_color_premultiply (&color_2);
+ /* figure out the two colors for the reflection: the first is
+ * full color and the second is the same, but at 0 opacity
+ */
+ cogl_color_init_from_4f (&color_1, 1.0, 1.0, 1.0, opacity / 255.0);
+ cogl_color_premultiply (&color_1);
+ cogl_color_init_from_4f (&color_2, 1.0, 1.0, 1.0, 0.0);
+ cogl_color_premultiply (&color_2);
- /* now describe the four vertices of the quad; since it has
- * to be a reflection, we need to invert it as well
- */
- vertices[0].x = 0; vertices[0].y = 0; vertices[0].z = 0;
- vertices[0].tx = 0.0; vertices[0].ty = 1.0;
- vertices[0].color = color_1;
+ /* now describe the four vertices of the quad; since it has
+ * to be a reflection, we need to invert it as well
+ */
+ vertices[0].x = 0; vertices[0].y = 0; vertices[0].z = 0;
+ vertices[0].tx = 0.0; vertices[0].ty = 1.0;
+ vertices[0].color = color_1;
- vertices[1].x = width; vertices[1].y = 0; vertices[1].z = 0;
- vertices[1].tx = 1.0; vertices[1].ty = 1.0;
- vertices[1].color = color_1;
+ vertices[1].x = width; vertices[1].y = 0; vertices[1].z = 0;
+ vertices[1].tx = 1.0; vertices[1].ty = 1.0;
+ vertices[1].color = color_1;
- vertices[2].x = width; vertices[2].y = height; vertices[2].z = 0;
- vertices[2].tx = 1.0; vertices[2].ty = 0.0;
- vertices[2].color = color_2;
+ vertices[2].x = width; vertices[2].y = height; vertices[2].z = 0;
+ vertices[2].tx = 1.0; vertices[2].ty = 0.0;
+ vertices[2].color = color_2;
- vertices[3].x = 0; vertices[3].y = height; vertices[3].z = 0;
- vertices[3].tx = 0.0; vertices[3].ty = 0.0;
- vertices[3].color = color_2;
+ vertices[3].x = 0; vertices[3].y = height; vertices[3].z = 0;
+ vertices[3].tx = 0.0; vertices[3].ty = 0.0;
+ vertices[3].color = color_2;
- /* paint the same texture but with a different geometry */
- cogl_set_source (material);
- cogl_polygon (vertices, 4, TRUE);
+ /* paint the same texture but with a different geometry */
+ cogl_set_source (material);
+ cogl_polygon (vertices, 4, TRUE);
out:
/* prevent the default clone handler from running */
@@ -267,6 +266,10 @@ void clarity_cover_set_album_item (ClarityCover *self,
AlbumItem *item) {
gfloat temp = w * DEFAULT_IMG_SIZE / h;
clutter_actor_set_size(priv->texture, temp, DEFAULT_IMG_SIZE);
}
+
+ // Add title / artist data
+ priv->title = g_strdup(item->albumname);
+ priv->artist = g_strdup(item->artist);
}
void clarity_cover_clear_rotation_behaviour(ClarityCover *self) {
@@ -307,6 +310,15 @@ void clarity_cover_set_rotation_behaviour(ClarityCover
*self, ClutterAlpha *alph
}
}
+gchar *clarity_cover_get_title(ClarityCover *self) {
+ ClarityCoverPrivate *priv = self->priv;
+ return g_strdup(priv->title);
+}
+
+gchar *clarity_cover_get_artist(ClarityCover *self) {
+ ClarityCoverPrivate *priv = self->priv;
+ return g_strdup(priv->artist);
+}
/**
* clarity_cover_new:
diff --git a/plugins/clarity/clarity_cover.h b/plugins/clarity/clarity_cover.h
index a2d4928..ee6542b 100644
--- a/plugins/clarity/clarity_cover.h
+++ b/plugins/clarity/clarity_cover.h
@@ -101,6 +101,10 @@ void clarity_cover_clear_rotation_behaviour(ClarityCover
*self);
void clarity_cover_set_rotation_behaviour(ClarityCover *self, ClutterAlpha
*alpha, int final_angle, ClutterRotateDirection direction);
+gchar *clarity_cover_get_title(ClarityCover *self);
+
+gchar *clarity_cover_get_artist(ClarityCover *self);
+
/* constructor - note this returns a ClutterActor instance */
ClarityCover *clarity_cover_new (void);
diff --git a/plugins/clarity/clarity_preferences.c
b/plugins/clarity/clarity_preferences.c
index 7414568..35acd91 100644
--- a/plugins/clarity/clarity_preferences.c
+++ b/plugins/clarity/clarity_preferences.c
@@ -107,7 +107,7 @@ GtkWidget *init_clarity_preferences(const gchar *gladepath,
ClarityWidget *cw) {
gtk_color_button_set_rgba
(GTK_COLOR_BUTTON(coverart_bgcolorselect_button), color);
gdk_rgba_free(color);
- color = clarity_widget_get_foreground_display_color(cw);
+ color = clarity_widget_get_text_display_color(cw);
gtk_color_button_set_rgba
(GTK_COLOR_BUTTON(coverart_fgcolorselect_button), color);
gdk_rgba_free(color);
diff --git a/plugins/clarity/clarity_widget.c b/plugins/clarity/clarity_widget.c
index 8636761..c0ac143 100644
--- a/plugins/clarity/clarity_widget.c
+++ b/plugins/clarity/clarity_widget.c
@@ -70,11 +70,7 @@ enum {
* track added
* track removed
* track updated
- * change background
- * text
* set cover from file
- * sort
- * preferences
*/
static void clarity_widget_dispose(GObject *gobject) {
@@ -220,11 +216,9 @@ static void _init_slider_range(ClarityWidgetPrivate *priv)
{
g_signal_handler_unblock(G_OBJECT(priv->cdslider), priv->slider_signal_id);
}
-static void _set_background(ClarityWidget *self) {
+static void _set_background_color(ClarityWidget *self) {
gchar *hex_string;
- hex_string = "#FFFFFF";
-
if (!prefs_get_string_value("clarity_bg_color", NULL))
hex_string = "#000000";
else
@@ -232,7 +226,20 @@ static void _set_background(ClarityWidget *self) {
ClarityWidgetPrivate *priv = CLARITY_WIDGET_GET_PRIVATE(self);
- clarity_canvas_set_background(CLARITY_CANVAS(priv->draw_area), hex_string);
+ clarity_canvas_set_background_color(CLARITY_CANVAS(priv->draw_area),
hex_string);
+}
+
+static void _set_text_color(ClarityWidget *self) {
+ gchar *hex_string;
+
+ if (!prefs_get_string_value("clarity_fg_color", NULL))
+ hex_string = "#FFFFFF";
+ else
+ prefs_get_string_value("clarity_fg_color", &hex_string);
+
+ ClarityWidgetPrivate *priv = CLARITY_WIDGET_GET_PRIVATE(self);
+
+ clarity_canvas_set_text_color(CLARITY_CANVAS(priv->draw_area), hex_string);
}
static void clarity_widget_class_init (ClarityWidgetClass *klass) {
@@ -257,7 +264,8 @@ static void clarity_widget_init (ClarityWidget *self) {
G_CALLBACK(_on_scrolling_covers_cb),
priv);
- _set_background(self);
+ _set_background_color(self);
+ _set_text_color(self);
priv->leftbutton = gtk_button_new_with_label("<");
gtk_widget_set_name(priv->leftbutton, LEFT_BUTTON);
@@ -331,12 +339,12 @@ GdkRGBA
*clarity_widget_get_background_display_color(ClarityWidget *self) {
return
clarity_canvas_get_background_color(CLARITY_CANVAS(priv->draw_area));
}
-GdkRGBA *clarity_widget_get_foreground_display_color(ClarityWidget *self) {
+GdkRGBA *clarity_widget_get_text_display_color(ClarityWidget *self) {
g_return_val_if_fail(CLARITY_IS_WIDGET(self), NULL);
ClarityWidgetPrivate *priv = CLARITY_WIDGET_GET_PRIVATE(self);
- return
clarity_canvas_get_background_color(CLARITY_CANVAS(priv->draw_area));
+ return clarity_canvas_get_text_color(CLARITY_CANVAS(priv->draw_area));
}
static void _resort_albums(ClarityWidget *self) {
@@ -366,7 +374,9 @@ void clarity_widget_preference_changed_cb(GtkPodApp *app,
gpointer pfname, gpoin
gchar *pref_name = pfname;
if (g_str_equal(pref_name, "clarity_bg_color"))
- _set_background(cw);
+ _set_background_color(cw);
+ else if (g_str_equal(pref_name, "clarity_fg_color"))
+ _set_text_color(cw);
else if (g_str_equal(pref_name, "clarity_sort"))
_resort_albums(cw);
}
diff --git a/plugins/clarity/clarity_widget.h b/plugins/clarity/clarity_widget.h
index a6c216f..70afb0b 100644
--- a/plugins/clarity/clarity_widget.h
+++ b/plugins/clarity/clarity_widget.h
@@ -67,7 +67,7 @@ struct _ClarityWidgetClass {
GdkRGBA *clarity_widget_get_background_display_color(ClarityWidget *self);
-GdkRGBA *clarity_widget_get_foreground_display_color(ClarityWidget *self);
+GdkRGBA *clarity_widget_get_text_display_color(ClarityWidget *self);
GtkWidget * clarity_widget_new();
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2