GESTimelineTextOverlay/TrackTextOverlay: add color setting

Color property of the text overlay can be set and get.
This commit is contained in:
Luis de Bethencourt 2011-08-03 12:20:27 +02:00
parent d8d93aad82
commit ba5babd474
5 changed files with 131 additions and 2 deletions

View file

@ -46,6 +46,7 @@ struct _GESTimelineTextOverlayPrivate
gchar *font_desc;
GESTextHAlign halign;
GESTextVAlign valign;
guint32 color;
};
enum
@ -55,6 +56,7 @@ enum
PROP_FONT_DESC,
PROP_HALIGNMENT,
PROP_VALIGNMENT,
PROP_COLOR,
};
static GESTrackObject
@ -81,6 +83,9 @@ ges_timeline_text_overlay_get_property (GObject * object, guint property_id,
case PROP_VALIGNMENT:
g_value_set_enum (value, priv->valign);
break;
case PROP_COLOR:
g_value_set_uint (value, priv->color);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@ -105,6 +110,9 @@ ges_timeline_text_overlay_set_property (GObject * object, guint property_id,
case PROP_VALIGNMENT:
ges_timeline_text_overlay_set_valign (tfs, g_value_get_enum (value));
break;
case PROP_COLOR:
ges_timeline_text_overlay_set_color (tfs, g_value_get_uint (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@ -183,6 +191,16 @@ ges_timeline_text_overlay_class_init (GESTimelineTextOverlayClass * klass)
timobj_class->create_track_object =
ges_timeline_text_overlay_create_track_object;
timobj_class->need_fill_track = FALSE;
/**
* GESTimelineTextOverlay:color
*
* The color of the text
*/
g_object_class_install_property (object_class, PROP_COLOR,
g_param_spec_uint ("color", "Color", "The color of the text",
0, G_MAXUINT32, G_MAXUINT32, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
@ -197,6 +215,7 @@ ges_timeline_text_overlay_init (GESTimelineTextOverlay * self)
self->priv->font_desc = NULL;
self->priv->halign = DEFAULT_PROP_HALIGNMENT;
self->priv->valign = DEFAULT_PROP_VALIGNMENT;
self->priv->color = G_MAXUINT32;
}
/**
@ -337,6 +356,38 @@ ges_timeline_text_overlay_set_valign (GESTimelineTextOverlay * self,
}
/**
* ges_timeline_text_overlay_set_color:
* @self: the #GESTimelineTextOverlay* to set
* @color: The color @self is being set to
*
* Sets the color of the text.
*
*/
void
ges_timeline_text_overlay_set_color (GESTimelineTextOverlay * self,
guint32 color)
{
GList *tmp, *trackobjects;
GESTimelineObject *object = (GESTimelineObject *) self;
GST_DEBUG ("self:%p, color:%d", self, color);
self->priv->color = color;
trackobjects = ges_timeline_object_get_track_objects (object);
for (tmp = trackobjects; tmp; tmp = tmp->next) {
GESTrackObject *trackobject = (GESTrackObject *) tmp->data;
if (ges_track_object_get_track (trackobject)->type == GES_TRACK_TYPE_VIDEO)
ges_track_text_overlay_set_color (GES_TRACK_TEXT_OVERLAY
(trackobject), self->priv->color);
g_object_unref (GES_TRACK_OBJECT (tmp->data));
}
g_list_free (trackobjects);
}
/**
* ges_timeline_text_overlay_get_text:
* @self: a #GESTimelineTextOverlay
@ -394,6 +445,22 @@ ges_timeline_text_overlay_get_valignment (GESTimelineTextOverlay * self)
return self->priv->valign;
}
/**
* ges_timeline_text_overlay_get_color:
* @self: a #GESTimelineTextOverlay
*
* Get the color used by @source.
*
* Returns: The color used by @source.
*/
const guint32
ges_timeline_text_overlay_get_color (GESTimelineTextOverlay * self)
{
return self->priv->color;
}
static GESTrackObject *
ges_timeline_text_overlay_create_track_object (GESTimelineObject * obj,
GESTrack * track)
@ -414,6 +481,7 @@ ges_timeline_text_overlay_create_track_object (GESTimelineObject * obj,
priv->halign);
ges_track_text_overlay_set_valignment ((GESTrackTextOverlay *) res,
priv->valign);
ges_track_text_overlay_set_color ((GESTrackTextOverlay *) res, priv->color);
}
return res;

View file

@ -93,6 +93,10 @@ void
ges_timeline_text_overlay_set_halign (GESTimelineTextOverlay * self,
GESTextHAlign halign);
void
ges_timeline_text_overlay_set_color (GESTimelineTextOverlay * self,
guint32 color);
const gchar* ges_timeline_text_overlay_get_text (GESTimelineTextOverlay * self);
const gchar*
@ -101,6 +105,9 @@ ges_timeline_text_overlay_get_font_desc (GESTimelineTextOverlay * self);
GESTextVAlign
ges_timeline_text_overlay_get_valignment (GESTimelineTextOverlay * self);
const guint32
ges_timeline_text_overlay_get_color (GESTimelineTextOverlay * self);
GESTextHAlign
ges_timeline_text_overlay_get_halignment (GESTimelineTextOverlay * self);

View file

@ -39,6 +39,7 @@ struct _GESTrackTextOverlayPrivate
gchar *font_desc;
GESTextHAlign halign;
GESTextVAlign valign;
guint32 color;
GstElement *text_el;
};
@ -87,6 +88,7 @@ ges_track_text_overlay_init (GESTrackTextOverlay * self)
self->priv->text_el = NULL;
self->priv->halign = DEFAULT_HALIGNMENT;
self->priv->valign = DEFAULT_VALIGNMENT;
self->priv->color = G_MAXUINT32;
}
static void
@ -156,6 +158,7 @@ ges_track_text_overlay_create_element (GESTrackObject * object)
g_object_set (text, "halignment", (gint) self->priv->halign, "valignment",
(gint) self->priv->valign, NULL);
g_object_set (text, "color", (guint32) self->priv->color, NULL);
ret = gst_bin_new ("overlay-bin");
gst_bin_add_many (GST_BIN (ret), text, iconv, oconv, NULL);
@ -187,6 +190,8 @@ ges_track_text_overlay_create_element (GESTrackObject * object)
void
ges_track_text_overlay_set_text (GESTrackTextOverlay * self, const gchar * text)
{
GST_DEBUG ("self:%p, text:%s", self, text);
if (self->priv->text)
g_free (self->priv->text);
@ -208,6 +213,8 @@ void
ges_track_text_overlay_set_font_desc (GESTrackTextOverlay * self,
const gchar * font_desc)
{
GST_DEBUG ("self:%p, font_desc:%s", self, font_desc);
if (self->priv->font_desc)
g_free (self->priv->font_desc);
@ -230,8 +237,9 @@ void
ges_track_text_overlay_set_valignment (GESTrackTextOverlay * self,
GESTextVAlign valign)
{
GST_DEBUG ("self:%p, halign:%d", self, valign);
self->priv->valign = valign;
GST_LOG ("set valignment to: %d", valign);
if (self->priv->text_el)
g_object_set (self->priv->text_el, "valignment", valign, NULL);
}
@ -249,12 +257,31 @@ void
ges_track_text_overlay_set_halignment (GESTrackTextOverlay * self,
GESTextHAlign halign)
{
GST_DEBUG ("self:%p, halign:%d", self, halign);
self->priv->halign = halign;
GST_LOG ("set halignment to: %d", halign);
if (self->priv->text_el)
g_object_set (self->priv->text_el, "halignment", halign, NULL);
}
/**
* ges_track_text_overlay_set_color:
* @self: the #GESTrackTextOverlay* to set
* @color: The color @self is being set to
*
* Sets the color of the text.
*
*/
void
ges_track_text_overlay_set_color (GESTrackTextOverlay * self, guint32 color)
{
GST_DEBUG ("self:%p, color:%d", self, color);
self->priv->color = color;
if (self->priv->text_el)
g_object_set (self->priv->text_el, "color", color, NULL);
}
/**
* ges_track_text_overlay_get_text:
* @self: a GESTrackTextOverlay
@ -311,6 +338,21 @@ ges_track_text_overlay_get_valignment (GESTrackTextOverlay * self)
return self->priv->valign;
}
/**
* ges_track_text_overlay_get_color:
* @self: a GESTrackTextOverlay
*
* Get the color used by @source.
*
* Returns: The color used by @source.
*/
const guint32
ges_track_text_overlay_get_color (GESTrackTextOverlay * self)
{
return self->priv->color;
}
/**
* ges_track_text_overlay_new:
*

View file

@ -81,11 +81,14 @@ void ges_track_text_overlay_set_halignment(GESTrackTextOverlay *self,
void ges_track_text_overlay_set_valignment(GESTrackTextOverlay *self,
GESTextVAlign valign);
void ges_track_text_overlay_set_color(GESTrackTextOverlay *self,
guint32 color);
const gchar *ges_track_text_overlay_get_text(GESTrackTextOverlay *self);
const char *ges_track_text_overlay_get_font_desc(GESTrackTextOverlay *self);
GESTextHAlign ges_track_text_overlay_get_halignment(GESTrackTextOverlay *self);
GESTextVAlign ges_track_text_overlay_get_valignment(GESTrackTextOverlay *self);
const guint32 ges_track_text_overlay_get_color (GESTrackTextOverlay *self);
GESTrackTextOverlay* ges_track_text_overlay_new (void);

View file

@ -112,6 +112,7 @@ GST_START_TEST (test_overlay_in_layer)
GESTimelineTextOverlay *source;
gchar *text;
gint halign, valign;
guint32 color;
ges_init ();
@ -164,6 +165,14 @@ GST_START_TEST (test_overlay_in_layer)
assert_equals_int (halign, GES_TEXT_HALIGN_LEFT);
assert_equals_int (valign, GES_TEXT_VALIGN_TOP);
/* test color */
g_object_set (source, "color", (gint) 2147483647, NULL);
g_object_get (source, "color", &color, NULL);
assert_equals_int (color, 2147483647);
color = ges_track_text_overlay_get_color (GES_TRACK_TEXT_OVERLAY (trobj));
assert_equals_int (color, 2147483647);
GST_DEBUG ("removing the source");
ges_timeline_layer_remove_object (layer, (GESTimelineObject *) source);