From 89b0b00dd14cde4f2a7d6bfab5bbdc78bc21f315 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 27 Jan 2009 16:47:20 +0000 Subject: [PATCH] Listen for the font-changed signal on the backend in ClutterText Whenever a ClutterText is created it now connects to the font-changed signal. When it is emitted the layout cache is dirtied and a relayout is queued. That way changes to the font options or resolution will cause an immediate update to the labels in the scene. --- clutter/clutter-text.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index 94229694d..5a0851bcd 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -155,6 +155,9 @@ struct _ClutterTextPrivate gint max_length; gunichar password_char; + + /* Signal handler for when the backend changes its font settings */ + guint font_changed_id; }; enum @@ -196,6 +199,8 @@ enum static guint text_signals[LAST_SIGNAL] = { 0, }; +static void clutter_text_font_changed_cb (ClutterText *text); + #define offset_real(t,p) ((p) == -1 ? g_utf8_strlen ((t), -1) : (p)) static gint @@ -337,6 +342,13 @@ clutter_text_dirty_cache (ClutterText *text) } } +static void +clutter_text_font_changed_cb (ClutterText *text) +{ + clutter_text_dirty_cache (text); + clutter_actor_queue_relayout (CLUTTER_ACTOR (text)); +} + /* * clutter_text_create_layout: * @text: a #ClutterText @@ -737,10 +749,18 @@ static void clutter_text_dispose (GObject *gobject) { ClutterText *self = CLUTTER_TEXT (gobject); + ClutterTextPrivate *priv = self->priv; /* get rid of the entire cache */ clutter_text_dirty_cache (self); + if (priv->font_changed_id) + { + g_signal_handler_disconnect (clutter_get_default_backend (), + priv->font_changed_id); + priv->font_changed_id = 0; + } + G_OBJECT_CLASS (clutter_text_parent_class)->dispose (gobject); } @@ -2092,6 +2112,12 @@ clutter_text_init (ClutterText *self) priv->max_length = 0; priv->cursor_size = DEFAULT_CURSOR_SIZE; + + priv->font_changed_id + = g_signal_connect_swapped (clutter_get_default_backend (), + "font-changed", + G_CALLBACK (clutter_text_font_changed_cb), + self); } /**