Store the default font name inside ClutterBackend
authorEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 23 Dec 2008 15:03:11 +0000 (15:03 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 23 Dec 2008 15:03:11 +0000 (15:03 +0000)
The default backend stores some of the global defaults, like the
font options, text resolution, double click settings. It should also
store the default font name, to allow various text-based actors to
share the same settings.

When the font name changes, the ::font-changed signal is emitted,
to allow actors to pick up the change.

clutter/clutter-backend.c
clutter/clutter-backend.h

index 086f274..597558b 100644 (file)
@@ -49,6 +49,8 @@
 
 G_DEFINE_ABSTRACT_TYPE (ClutterBackend, clutter_backend, G_TYPE_OBJECT);
 
+#define DEFAULT_FONT_NAME       "Sans 10"
+
 #define CLUTTER_BACKEND_GET_PRIVATE(obj) \
 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_BACKEND, ClutterBackendPrivate))
 
@@ -61,6 +63,8 @@ struct _ClutterBackendPrivate
   ClutterFixed resolution;
 
   cairo_font_options_t *font_options;
+
+  gchar *font_name;
 };
 
 enum
@@ -76,6 +80,7 @@ static guint backend_signals[LAST_SIGNAL] = { 0, };
 static void
 clutter_backend_dispose (GObject *gobject)
 {
+  ClutterBackendPrivate *priv = CLUTTER_BACKEND (gobject)->priv;
   ClutterMainContext *clutter_context;
 
   clutter_context = clutter_context_get_default ();
@@ -87,6 +92,8 @@ clutter_backend_dispose (GObject *gobject)
       clutter_context->events_queue = NULL;
     }
 
+  g_free (priv->font_name);
+
   clutter_backend_set_font_options (CLUTTER_BACKEND (gobject), NULL);
 
   G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
@@ -514,3 +521,30 @@ clutter_backend_get_font_options (ClutterBackend *backend)
   return priv->font_options;
 }
 
+void
+clutter_backend_set_font_name (ClutterBackend *backend,
+                               const gchar    *font_name)
+{
+  ClutterBackendPrivate *priv;
+
+  g_return_if_fail (CLUTTER_IS_BACKEND (backend));
+
+  priv = backend->priv;
+
+  g_free (priv->font_name);
+
+  if (font_name == NULL || *font_name == '\0')
+    priv->font_name = g_strdup (DEFAULT_FONT_NAME);
+  else
+    priv->font_name = g_strdup (font_name);
+
+  g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
+}
+
+G_CONST_RETURN gchar *
+clutter_backend_get_font_name (ClutterBackend *backend)
+{
+  g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
+
+  return backend->priv->font_name;
+}
index 0669d4f..fda1d34 100644 (file)
@@ -30,6 +30,8 @@
 
 #include <cairo.h>
 #include <glib-object.h>
+#include <pango/pango.h>
+
 #include <clutter/clutter-actor.h>
 #include <clutter/clutter-stage.h>
 #include <clutter/clutter-event.h>
@@ -99,6 +101,9 @@ guint                 clutter_backend_get_double_click_distance (ClutterBackend
 void                  clutter_backend_set_font_options          (ClutterBackend       *backend,
                                                                  cairo_font_options_t *options);
 cairo_font_options_t *clutter_backend_get_font_options          (ClutterBackend       *backend);
+void                  clutter_backend_set_font_name             (ClutterBackend       *backend,
+                                                                 const gchar          *font_name);
+G_CONST_RETURN gchar *clutter_backend_get_font_name             (ClutterBackend       *backend);
 
 G_END_DECLS