libeek: share a single drawing context among each clutter elements

A new class EekClutterDrawingContext maintains the context used to draw actors. Single EekClutterDrawingContext instance is shared by EekClutterKeyboard, EekClutterSection, EekClutterKey, and EekClutterKeyActor.
This commit is contained in:
Daiki Ueno
2010-06-16 10:32:34 +09:00
parent 63b9fea27b
commit 473a9a9b2a
15 changed files with 349 additions and 145 deletions

View File

@ -56,6 +56,8 @@ libeek_clutter_la_SOURCES = \
eek-clutter-key.h \ eek-clutter-key.h \
eek-clutter-key-actor.c \ eek-clutter-key-actor.c \
eek-clutter-key-actor.h \ eek-clutter-key-actor.h \
eek-clutter-drawing-context.c \
eek-clutter-drawing-context.h \
eek-drawing.h \ eek-drawing.h \
eek-drawing.c \ eek-drawing.c \
eek-clutter.h eek-clutter.h

View File

@ -0,0 +1,137 @@
/*
* Copyright (C) 2010 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eek-clutter-drawing-context.h"
G_DEFINE_TYPE (EekClutterDrawingContext, eek_clutter_drawing_context,
G_TYPE_INITIALLY_UNOWNED);
#define EEK_CLUTTER_DRAWING_CONTEXT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEK_TYPE_CLUTTER_DRAWING_CONTEXT, EekClutterDrawingContextPrivate))
struct _EekClutterDrawingContextPrivate
{
/* outline pointer -> ClutterTexture */
GHashTable *outline_textures;
/* keysym category -> PangoFontDescription * */
PangoFontDescription *category_fonts[EEK_KEYSYM_CATEGORY_LAST];
};
static void
eek_clutter_drawing_context_dispose (GObject *object)
{
EekClutterDrawingContextPrivate *priv =
EEK_CLUTTER_DRAWING_CONTEXT_GET_PRIVATE(object);
if (priv->outline_textures) {
g_hash_table_unref (priv->outline_textures);
priv->outline_textures = NULL;
}
}
static void
eek_clutter_drawing_context_finalize (GObject *object)
{
EekClutterDrawingContextPrivate *priv =
EEK_CLUTTER_DRAWING_CONTEXT_GET_PRIVATE(object);
gint i;
for (i = 0; i < EEK_KEYSYM_CATEGORY_LAST; i++)
pango_font_description_free (priv->category_fonts[i]);
}
static void
eek_clutter_drawing_context_class_init (EekClutterDrawingContextClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (gobject_class,
sizeof (EekClutterDrawingContextPrivate));
gobject_class->finalize = eek_clutter_drawing_context_finalize;
}
static void
eek_clutter_drawing_context_init (EekClutterDrawingContext *self)
{
EekClutterDrawingContextPrivate *priv;
priv = self->priv = EEK_CLUTTER_DRAWING_CONTEXT_GET_PRIVATE(self);
priv->outline_textures = g_hash_table_new (g_direct_hash, g_direct_equal);
memset (priv->category_fonts, 0, sizeof *priv->category_fonts);
}
void
eek_clutter_drawing_context_set_outline_texture
(EekClutterDrawingContext *context,
EekOutline *outline,
ClutterActor *texture)
{
EekClutterDrawingContextPrivate *priv =
EEK_CLUTTER_DRAWING_CONTEXT_GET_PRIVATE(context);
g_return_if_fail (priv);
g_hash_table_insert (context->priv->outline_textures, outline, texture);
}
ClutterActor *
eek_clutter_drawing_context_get_outline_texture
(EekClutterDrawingContext *context,
EekOutline *outline)
{
EekClutterDrawingContextPrivate *priv =
EEK_CLUTTER_DRAWING_CONTEXT_GET_PRIVATE(context);
g_return_val_if_fail (priv, NULL);
return g_hash_table_lookup (context->priv->outline_textures, outline);
}
void
eek_clutter_drawing_context_set_category_font
(EekClutterDrawingContext *context,
EekKeysymCategory category,
PangoFontDescription *font)
{
EekClutterDrawingContextPrivate *priv =
EEK_CLUTTER_DRAWING_CONTEXT_GET_PRIVATE(context);
g_return_if_fail (priv);
priv->category_fonts[category] = pango_font_description_copy (font);
}
PangoFontDescription *
eek_clutter_drawing_context_get_category_font
(EekClutterDrawingContext *context,
EekKeysymCategory category)
{
EekClutterDrawingContextPrivate *priv =
EEK_CLUTTER_DRAWING_CONTEXT_GET_PRIVATE(context);
g_return_val_if_fail (priv, NULL);
return priv->category_fonts[category];
}
EekClutterDrawingContext *
eek_clutter_drawing_context_new (void)
{
return g_object_new (EEK_TYPE_CLUTTER_DRAWING_CONTEXT, NULL);
}

View File

@ -0,0 +1,78 @@
/*
* Copyright (C) 2010 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef EEK_CLUTTER_DRAWING_CONTEXT_H
#define EEK_CLUTTER_DRAWING_CONTEXT_H 1
#include <clutter/clutter.h>
#include <pango/pango.h>
#include "eek-keysym.h"
#include "eek-types.h"
G_BEGIN_DECLS
#define EEK_TYPE_CLUTTER_DRAWING_CONTEXT (eek_clutter_drawing_context_get_type())
#define EEK_CLUTTER_DRAWING_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEK_TYPE_CLUTTER_DRAWING_CONTEXT, EekClutterDrawingContext))
#define EEK_CLUTTER_DRAWING_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEK_TYPE_CLUTTER_DRAWING_CONTEXT, EekClutterDrawingContextClass))
#define EEK_IS_CLUTTER_DRAWING_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEK_TYPE_CLUTTER_DRAWING_CONTEXT))
#define EEK_IS_CLUTTER_DRAWING_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEK_TYPE_CLUTTER_DRAWING_CONTEXT))
#define EEK_CLUTTER_DRAWING_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEK_TYPE_CLUTTER_DRAWING_CONTEXT, EekClutterDrawingContextClass))
typedef struct _EekClutterDrawingContext EekClutterDrawingContext;
typedef struct _EekClutterDrawingContextClass EekClutterDrawingContextClass;
typedef struct _EekClutterDrawingContextPrivate EekClutterDrawingContextPrivate;
struct _EekClutterDrawingContext
{
/*< private >*/
GInitiallyUnowned parent;
/*< private >*/
EekClutterDrawingContextPrivate *priv;
};
struct _EekClutterDrawingContextClass
{
/*< private >*/
GInitiallyUnownedClass parent_class;
};
GType eek_clutter_drawing_context_get_type
(void) G_GNUC_CONST;
EekClutterDrawingContext *eek_clutter_drawing_context_new
(void);
void eek_clutter_drawing_context_set_outline_texture
(EekClutterDrawingContext *context,
EekOutline *outline,
ClutterActor *texture);
ClutterActor *eek_clutter_drawing_context_get_outline_texture
(EekClutterDrawingContext *context,
EekOutline *outline);
void eek_clutter_drawing_context_set_category_font
(EekClutterDrawingContext *context,
EekKeysymCategory category,
PangoFontDescription *fonts);
PangoFontDescription *eek_clutter_drawing_context_get_category_font
(EekClutterDrawingContext *context,
EekKeysymCategory category);
G_END_DECLS
#endif /* EEK_CLUTTER_DRAWING_CONTEXT_H */

View File

@ -54,29 +54,11 @@ G_DEFINE_TYPE (EekClutterKeyActor, eek_clutter_key_actor,
struct _EekClutterKeyActorPrivate struct _EekClutterKeyActorPrivate
{ {
EekClutterDrawingContext *context;
EekKey *key; EekKey *key;
ClutterActor *texture; ClutterActor *texture;
PangoFontDescription *font;
}; };
static struct {
/* outline pointer -> ClutterTexture */
GHashTable *outline_textures;
/* manually maintain the ref-count of outline_textures to set it
to NULL when all the EekClutterKeyActor are destroyed */
gint outline_textures_ref_count;
} texture_cache;
static struct {
/* keysym category -> PangoFontDescription * */
PangoFontDescription *category_fonts[EEK_KEYSYM_CATEGORY_LAST];
/* manually maintain the ref-count of category_fonts to set it to
NULL when all the EekClutterKeyActor are destroyed */
gint category_fonts_ref_count;
} font_cache;
static ClutterActor *get_texture (EekClutterKeyActor *actor); static ClutterActor *get_texture (EekClutterKeyActor *actor);
static void draw_key_on_layout (EekClutterKeyActor *actor, static void draw_key_on_layout (EekClutterKeyActor *actor,
PangoLayout *layout); PangoLayout *layout);
@ -183,30 +165,14 @@ eek_clutter_key_actor_dispose (GObject *object)
{ {
EekClutterKeyActorPrivate *priv = EEK_CLUTTER_KEY_ACTOR_GET_PRIVATE(object); EekClutterKeyActorPrivate *priv = EEK_CLUTTER_KEY_ACTOR_GET_PRIVATE(object);
if (priv->context) {
g_object_unref (priv->context);
priv->context = NULL;
}
if (priv->key) { if (priv->key) {
g_object_unref (priv->key); g_object_unref (priv->key);
priv->key = NULL; priv->key = NULL;
} }
if (priv->texture) {
/* no need to g_object_unref (priv->texture) */
priv->texture = NULL;
if (--texture_cache.outline_textures_ref_count == 0) {
g_hash_table_unref (texture_cache.outline_textures);
texture_cache.outline_textures = NULL;
}
}
if (priv->font) {
/* no need to pango_font_description_free (priv->font) */
priv->font = NULL;
if (--font_cache.category_fonts_ref_count == 0) {
gint i;
for (i = 0; i < EEK_KEYSYM_CATEGORY_LAST; i++) {
pango_font_description_free (font_cache.category_fonts[i]);
font_cache.category_fonts[i] = NULL;
}
}
}
G_OBJECT_CLASS (eek_clutter_key_actor_parent_class)->dispose (object); G_OBJECT_CLASS (eek_clutter_key_actor_parent_class)->dispose (object);
} }
@ -286,7 +252,6 @@ eek_clutter_key_actor_init (EekClutterKeyActor *self)
priv = self->priv = EEK_CLUTTER_KEY_ACTOR_GET_PRIVATE(self); priv = self->priv = EEK_CLUTTER_KEY_ACTOR_GET_PRIVATE(self);
priv->key = NULL; priv->key = NULL;
priv->texture = NULL; priv->texture = NULL;
priv->font = NULL;
clutter_actor_set_reactive (CLUTTER_ACTOR(self), TRUE); clutter_actor_set_reactive (CLUTTER_ACTOR(self), TRUE);
g_signal_connect (self, "button-press-event", g_signal_connect (self, "button-press-event",
@ -296,11 +261,13 @@ eek_clutter_key_actor_init (EekClutterKeyActor *self)
} }
ClutterActor * ClutterActor *
eek_clutter_key_actor_new (EekKey *key) eek_clutter_key_actor_new (EekClutterDrawingContext *context, EekKey *key)
{ {
EekClutterKeyActor *actor; EekClutterKeyActor *actor;
actor = g_object_new (EEK_TYPE_CLUTTER_KEY_ACTOR, NULL); actor = g_object_new (EEK_TYPE_CLUTTER_KEY_ACTOR, NULL);
actor->priv->context = context;
g_object_ref_sink (actor->priv->context);
actor->priv->key = key; actor->priv->key = key;
g_object_ref_sink (actor->priv->key); g_object_ref_sink (actor->priv->key);
return CLUTTER_ACTOR(actor); return CLUTTER_ACTOR(actor);
@ -387,17 +354,17 @@ get_texture (EekClutterKeyActor *actor)
ClutterActor *texture; ClutterActor *texture;
EekOutline *outline; EekOutline *outline;
if (!texture_cache.outline_textures)
texture_cache.outline_textures = g_hash_table_new (g_direct_hash,
g_direct_equal);
outline = eek_key_get_outline (actor->priv->key); outline = eek_key_get_outline (actor->priv->key);
texture = g_hash_table_lookup (texture_cache.outline_textures, outline); texture =
eek_clutter_drawing_context_get_outline_texture (actor->priv->context,
outline);
if (texture == NULL) { if (texture == NULL) {
texture = create_texture_for_key (actor->priv->key); texture = create_texture_for_key (actor->priv->key);
g_hash_table_insert (texture_cache.outline_textures, outline, texture); eek_clutter_drawing_context_set_outline_texture (actor->priv->context,
outline,
texture);
} else } else
texture = clutter_clone_new (texture); texture = clutter_clone_new (texture);
texture_cache.outline_textures_ref_count++;
return texture; return texture;
} }
@ -410,28 +377,7 @@ draw_key_on_layout (EekClutterKeyActor *self,
const gchar *label, *empty_label = ""; const gchar *label, *empty_label = "";
EekKeysymCategory category; EekKeysymCategory category;
EekBounds bounds; EekBounds bounds;
PangoFontDescription *font;
if (font_cache.category_fonts_ref_count == 0) {
EekContainer *keyboard, *section;
PangoFontDescription *font;
PangoLayout *copy;
section = EEK_ELEMENT_GET_CLASS(priv->key)->
get_parent (EEK_ELEMENT(priv->key));
g_return_if_fail (EEK_IS_SECTION(section));
keyboard = EEK_ELEMENT_GET_CLASS(section)->
get_parent (EEK_ELEMENT(section));
g_return_if_fail (EEK_IS_KEYBOARD(keyboard));
copy = pango_layout_copy (layout);
font = pango_font_description_from_string ("Sans");
pango_layout_set_font_description (copy, font);
eek_get_fonts (EEK_KEYBOARD(keyboard), copy,
font_cache.category_fonts);
g_object_unref (G_OBJECT(copy));
}
keysym = eek_key_get_keysym (priv->key); keysym = eek_key_get_keysym (priv->key);
if (keysym == EEK_INVALID_KEYSYM) if (keysym == EEK_INVALID_KEYSYM)
@ -439,11 +385,10 @@ draw_key_on_layout (EekClutterKeyActor *self,
category = eek_keysym_get_category (keysym); category = eek_keysym_get_category (keysym);
if (category == EEK_KEYSYM_CATEGORY_UNKNOWN) if (category == EEK_KEYSYM_CATEGORY_UNKNOWN)
return; return;
if (!priv->font) {
priv->font = font_cache.category_fonts[category]; font = eek_clutter_drawing_context_get_category_font (priv->context,
font_cache.category_fonts_ref_count++; category);
} pango_layout_set_font_description (layout, font);
pango_layout_set_font_description (layout, priv->font);
eek_element_get_bounds (EEK_ELEMENT(priv->key), &bounds); eek_element_get_bounds (EEK_ELEMENT(priv->key), &bounds);
pango_layout_set_width (layout, PANGO_SCALE * bounds.width); pango_layout_set_width (layout, PANGO_SCALE * bounds.width);

View File

@ -21,6 +21,7 @@
#define EEK_CLUTTER_KEY_ACTOR_H 1 #define EEK_CLUTTER_KEY_ACTOR_H 1
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "eek-clutter-drawing-context.h"
#include "eek-key.h" #include "eek-key.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -54,8 +55,10 @@ struct _EekClutterKeyActorClass
void (* released) (EekClutterKeyActor *self); void (* released) (EekClutterKeyActor *self);
}; };
GType eek_clutter_key_actor_get_type (void) G_GNUC_CONST; GType eek_clutter_key_actor_get_type
ClutterActor *eek_clutter_key_actor_new (EekKey *key); (void) G_GNUC_CONST;
ClutterActor *eek_clutter_key_actor_new (EekClutterDrawingContext *context,
EekKey *key);
G_END_DECLS G_END_DECLS
#endif /* EEK_CLUTTER_KEY_ACTOR_H */ #endif /* EEK_CLUTTER_KEY_ACTOR_H */

View File

@ -36,6 +36,7 @@ G_DEFINE_TYPE (EekClutterKey, eek_clutter_key, EEK_TYPE_KEY);
struct _EekClutterKeyPrivate struct _EekClutterKeyPrivate
{ {
EekClutterDrawingContext *context;
ClutterActor *actor; ClutterActor *actor;
}; };
@ -91,6 +92,10 @@ eek_clutter_key_dispose (GObject *object)
{ {
EekClutterKeyPrivate *priv = EEK_CLUTTER_KEY_GET_PRIVATE(object); EekClutterKeyPrivate *priv = EEK_CLUTTER_KEY_GET_PRIVATE(object);
if (priv->context) {
g_object_unref (priv->context);
priv->context = NULL;
}
if (priv->actor) { if (priv->actor) {
g_object_unref (priv->actor); g_object_unref (priv->actor);
priv->actor = NULL; priv->actor = NULL;
@ -129,9 +134,26 @@ ClutterActor *
eek_clutter_key_get_actor (EekClutterKey *key) eek_clutter_key_get_actor (EekClutterKey *key)
{ {
EekClutterKeyPrivate *priv = EEK_CLUTTER_KEY_GET_PRIVATE(key); EekClutterKeyPrivate *priv = EEK_CLUTTER_KEY_GET_PRIVATE(key);
if (!priv->actor) { if (!priv->actor) {
priv->actor = eek_clutter_key_actor_new (EEK_KEY(key)); g_return_val_if_fail (priv->context, NULL);
priv->actor = eek_clutter_key_actor_new (priv->context, EEK_KEY(key));
g_object_ref_sink (priv->actor); g_object_ref_sink (priv->actor);
} }
return priv->actor; return priv->actor;
} }
EekKey *
eek_clutter_key_new (EekClutterDrawingContext *context, gint column, gint row)
{
EekClutterKey *key;
g_return_val_if_fail (context, NULL);
key = g_object_new (EEK_TYPE_CLUTTER_KEY,
"column", column,
"row", row,
NULL);
key->priv->context = context;
g_object_ref_sink (key->priv->context);
return EEK_KEY(key);
}

View File

@ -21,6 +21,7 @@
#define EEK_CLUTTER_KEY_H 1 #define EEK_CLUTTER_KEY_H 1
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "eek-clutter-drawing-context.h"
#include "eek-key.h" #include "eek-key.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -50,8 +51,11 @@ struct _EekClutterKeyClass
EekKeyClass parent_class; EekKeyClass parent_class;
}; };
GType eek_clutter_key_get_type (void) G_GNUC_CONST; GType eek_clutter_key_get_type (void) G_GNUC_CONST;
ClutterActor *eek_clutter_key_get_actor (EekClutterKey *key); EekKey * eek_clutter_key_new (EekClutterDrawingContext *context,
gint column,
gint row);
ClutterActor *eek_clutter_key_get_actor (EekClutterKey *key);
G_END_DECLS G_END_DECLS
#endif /* EEK_CLUTTER_KEY_H */ #endif /* EEK_CLUTTER_KEY_H */

View File

@ -29,6 +29,7 @@
#endif /* HAVE_CONFIG_H */ #endif /* HAVE_CONFIG_H */
#include "eek-clutter-keyboard.h" #include "eek-clutter-keyboard.h"
#include "eek-clutter-drawing-context.h"
#include "eek-keyboard.h" #include "eek-keyboard.h"
G_DEFINE_TYPE (EekClutterKeyboard, eek_clutter_keyboard, EEK_TYPE_KEYBOARD); G_DEFINE_TYPE (EekClutterKeyboard, eek_clutter_keyboard, EEK_TYPE_KEYBOARD);
@ -39,7 +40,9 @@ G_DEFINE_TYPE (EekClutterKeyboard, eek_clutter_keyboard, EEK_TYPE_KEYBOARD);
struct _EekClutterKeyboardPrivate struct _EekClutterKeyboardPrivate
{ {
EekClutterDrawingContext *context;
ClutterActor *actor; ClutterActor *actor;
guint key_press_event_handler; guint key_press_event_handler;
guint key_release_event_handler; guint key_release_event_handler;
}; };
@ -92,10 +95,16 @@ key_released_event (EekSection *section,
static EekSection * static EekSection *
eek_clutter_keyboard_real_create_section (EekKeyboard *self) eek_clutter_keyboard_real_create_section (EekKeyboard *self)
{ {
EekClutterKeyboardPrivate *priv = EEK_CLUTTER_KEYBOARD_GET_PRIVATE(self);
EekSection *section; EekSection *section;
ClutterActor *actor; ClutterActor *actor;
section = g_object_new (EEK_TYPE_CLUTTER_SECTION, NULL); if (!priv->context) {
priv->context = eek_clutter_drawing_context_new ();
g_object_ref_sink (G_OBJECT(priv->context));
}
section = eek_clutter_section_new (priv->context);
g_return_val_if_fail (section, NULL); g_return_val_if_fail (section, NULL);
g_signal_connect (section, "key-pressed", g_signal_connect (section, "key-pressed",
@ -119,6 +128,10 @@ eek_clutter_keyboard_dispose (GObject *object)
{ {
EekClutterKeyboardPrivate *priv = EEK_CLUTTER_KEYBOARD_GET_PRIVATE(object); EekClutterKeyboardPrivate *priv = EEK_CLUTTER_KEYBOARD_GET_PRIVATE(object);
if (priv->context) {
g_object_unref (G_OBJECT(priv->context));
priv->context = NULL;
}
if (priv->actor) { if (priv->actor) {
ClutterActor *stage; ClutterActor *stage;
@ -238,6 +251,31 @@ on_clutter_realize (ClutterActor *actor, gpointer user_data)
G_CALLBACK (on_clutter_key_release_event), keyboard); G_CALLBACK (on_clutter_key_release_event), keyboard);
} }
static void
update_category_fonts (EekClutterKeyboard *keyboard)
{
EekClutterKeyboardPrivate *priv =
EEK_CLUTTER_KEYBOARD_GET_PRIVATE(keyboard);
PangoContext *context;
PangoLayout *layout;
PangoFontDescription *fonts[EEK_KEYSYM_CATEGORY_LAST], *base_font;
gint i;
context = clutter_actor_get_pango_context (priv->actor);
layout = pango_layout_new (context);
base_font = pango_font_description_from_string ("Sans");
pango_layout_set_font_description (layout, base_font);
pango_font_description_free (base_font);
eek_get_fonts (EEK_KEYBOARD(keyboard), layout, &fonts);
for (i = 0; i < EEK_KEYSYM_CATEGORY_LAST; i++) {
eek_clutter_drawing_context_set_category_font (priv->context,
i,
fonts[i]);
pango_font_description_free (fonts[i]);
}
g_object_unref (G_OBJECT(layout));
}
ClutterActor * ClutterActor *
eek_clutter_keyboard_get_actor (EekClutterKeyboard *keyboard) eek_clutter_keyboard_get_actor (EekClutterKeyboard *keyboard)
{ {
@ -249,7 +287,9 @@ eek_clutter_keyboard_get_actor (EekClutterKeyboard *keyboard)
g_signal_connect (priv->actor, "realize", g_signal_connect (priv->actor, "realize",
G_CALLBACK (on_clutter_realize), keyboard); G_CALLBACK (on_clutter_realize), keyboard);
g_return_val_if_fail (priv->actor, NULL); g_return_val_if_fail (priv->actor, NULL);
eek_keyboard_realize (EEK_KEYBOARD(keyboard)); eek_keyboard_realize (EEK_KEYBOARD(keyboard));
update_category_fonts (keyboard);
} }
return priv->actor; return priv->actor;
} }

View File

@ -35,6 +35,7 @@ G_DEFINE_TYPE (EekClutterSection, eek_clutter_section, EEK_TYPE_SECTION);
struct _EekClutterSectionPrivate struct _EekClutterSectionPrivate
{ {
EekClutterDrawingContext *context;
ClutterActor *actor; ClutterActor *actor;
}; };
@ -101,6 +102,7 @@ eek_clutter_section_real_create_key (EekSection *self,
gint column, gint column,
gint row) gint row)
{ {
EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(self);
EekKey *key; EekKey *key;
gint num_columns, num_rows; gint num_columns, num_rows;
EekOrientation orientation; EekOrientation orientation;
@ -111,10 +113,7 @@ eek_clutter_section_real_create_key (EekSection *self,
eek_section_get_row (self, row, &num_columns, &orientation); eek_section_get_row (self, row, &num_columns, &orientation);
g_return_val_if_fail (column < num_columns, NULL); g_return_val_if_fail (column < num_columns, NULL);
key = g_object_new (EEK_TYPE_CLUTTER_KEY, key = eek_clutter_key_new (priv->context, column, row);
"column", column,
"row", row,
NULL);
g_return_val_if_fail (key, NULL); g_return_val_if_fail (key, NULL);
g_signal_connect (key, "pressed", G_CALLBACK(pressed_event), self); g_signal_connect (key, "pressed", G_CALLBACK(pressed_event), self);
@ -136,6 +135,10 @@ eek_clutter_section_dispose (GObject *object)
{ {
EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(object); EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(object);
if (priv->context) {
g_object_unref (priv->context);
priv->context = NULL;
}
if (priv->actor) { if (priv->actor) {
g_object_unref (priv->actor); g_object_unref (priv->actor);
priv->actor = NULL; priv->actor = NULL;
@ -177,3 +180,16 @@ eek_clutter_section_get_actor (EekClutterSection *section)
} }
return priv->actor; return priv->actor;
} }
EekSection *
eek_clutter_section_new (EekClutterDrawingContext *context)
{
EekClutterSection *section;
g_return_val_if_fail (context, NULL);
section = g_object_new (EEK_TYPE_CLUTTER_SECTION, NULL);
section->priv->context = context;
g_object_ref_sink (G_OBJECT(section->priv->context));
return EEK_SECTION(section);
}

View File

@ -20,6 +20,7 @@
#ifndef EEK_CLUTTER_SECTION_H #ifndef EEK_CLUTTER_SECTION_H
#define EEK_CLUTTER_SECTION_H 1 #define EEK_CLUTTER_SECTION_H 1
#include "eek-clutter-drawing-context.h"
#include "eek-clutter-key.h" #include "eek-clutter-key.h"
#include "eek-section.h" #include "eek-section.h"
@ -49,8 +50,9 @@ struct _EekClutterSectionClass
EekSectionClass parent_class; EekSectionClass parent_class;
}; };
GType eek_clutter_section_get_type (void) G_GNUC_CONST; GType eek_clutter_section_get_type (void) G_GNUC_CONST;
ClutterActor *eek_clutter_section_get_actor (EekClutterSection *section); EekSection * eek_clutter_section_new (EekClutterDrawingContext *context);
ClutterActor *eek_clutter_section_get_actor (EekClutterSection *section);
G_END_DECLS G_END_DECLS
#endif /* EEK_CLUTTER_SECTION_H */ #endif /* EEK_CLUTTER_SECTION_H */

View File

@ -61,7 +61,6 @@ eek_container_real_add_child (EekContainer *self,
g_object_ref_sink (child); g_object_ref_sink (child);
priv->children = g_slist_prepend (priv->children, child); priv->children = g_slist_prepend (priv->children, child);
EEK_ELEMENT_GET_CLASS(child)->set_parent (child, self);
} }
static void static void
@ -76,7 +75,6 @@ eek_container_real_remove_child (EekContainer *self,
g_return_if_fail (head); g_return_if_fail (head);
g_object_unref (child); g_object_unref (child);
priv->children = g_slist_remove_link (priv->children, head); priv->children = g_slist_remove_link (priv->children, head);
EEK_ELEMENT_GET_CLASS(child)->set_parent (child, NULL);
} }
static void static void

View File

@ -87,26 +87,21 @@ egf_key_callback (EekElement *element,
{ {
EekKey *key = EEK_KEY(element); EekKey *key = EEK_KEY(element);
GetFontSizeCallbackData *data = user_data; GetFontSizeCallbackData *data = user_data;
guint *keysyms;
gint num_groups, num_levels, i;
gdouble font_size; gdouble font_size;
guint keysym;
EekBounds bounds;
const gchar *label;
eek_key_get_keysyms (key, &keysyms, &num_groups, &num_levels); keysym = eek_key_get_keysym (key);
for (i = 0; i < num_groups * num_levels; i++) { if (keysym == EEK_INVALID_KEYSYM ||
guint keysym = keysyms[i]; eek_keysym_get_category (keysym) != data->category)
EekBounds bounds; return;
const gchar *label;
if (keysym == EEK_INVALID_KEYSYM || eek_element_get_bounds (EEK_ELEMENT(key), &bounds);
eek_keysym_get_category (keysym) != data->category) label = eek_keysym_to_string (keysym);
continue; font_size = get_font_size (label, &bounds, data->layout);
if (font_size < data->font_size && font_size >= data->minimum_font_size)
eek_element_get_bounds (EEK_ELEMENT(key), &bounds); data->font_size = font_size;
label = eek_keysym_to_string (keysym);
font_size = get_font_size (label, &bounds, data->layout);
if (font_size < data->font_size && font_size >= data->minimum_font_size)
data->font_size = font_size;
}
} }
static void static void

View File

@ -33,7 +33,6 @@
#endif /* HAVE_CONFIG_H */ #endif /* HAVE_CONFIG_H */
#include "eek-element.h" #include "eek-element.h"
#include "eek-container.h"
enum { enum {
PROP_0, PROP_0,
@ -52,30 +51,8 @@ struct _EekElementPrivate
{ {
gchar *name; gchar *name;
EekBounds bounds; EekBounds bounds;
EekContainer *parent;
}; };
static void
eek_element_real_set_parent (EekElement *self,
EekContainer *parent)
{
EekElementPrivate *priv = EEK_ELEMENT_GET_PRIVATE(self);
if (parent) {
g_return_if_fail (EEK_IS_CONTAINER(parent));
g_object_ref_sink (G_OBJECT(parent));
} else if (priv->parent)
g_object_unref (G_OBJECT (priv->parent));
priv->parent = parent;
}
static EekContainer *
eek_element_real_get_parent (EekElement *self)
{
EekElementPrivate *priv = EEK_ELEMENT_GET_PRIVATE(self);
return priv->parent;
}
static void static void
eek_element_real_set_name (EekElement *self, eek_element_real_set_name (EekElement *self,
const gchar *name) const gchar *name)
@ -117,17 +94,6 @@ eek_element_real_get_bounds (EekElement *self,
g_object_notify (G_OBJECT(self), "bounds"); g_object_notify (G_OBJECT(self), "bounds");
} }
static void
eek_element_dispose (GObject *object)
{
EekElementPrivate *priv = EEK_ELEMENT_GET_PRIVATE(object);
if (priv->parent) {
g_object_unref (G_OBJECT(priv->parent));
priv->parent = NULL;
}
}
static void static void
eek_element_finalize (GObject *object) eek_element_finalize (GObject *object)
{ {
@ -190,8 +156,6 @@ eek_element_class_init (EekElementClass *klass)
g_type_class_add_private (gobject_class, g_type_class_add_private (gobject_class,
sizeof (EekElementPrivate)); sizeof (EekElementPrivate));
klass->set_parent = eek_element_real_set_parent;
klass->get_parent = eek_element_real_get_parent;
klass->set_name = eek_element_real_set_name; klass->set_name = eek_element_real_set_name;
klass->get_name = eek_element_real_get_name; klass->get_name = eek_element_real_get_name;
klass->set_bounds = eek_element_real_set_bounds; klass->set_bounds = eek_element_real_set_bounds;
@ -200,7 +164,6 @@ eek_element_class_init (EekElementClass *klass)
gobject_class->set_property = eek_element_set_property; gobject_class->set_property = eek_element_set_property;
gobject_class->get_property = eek_element_get_property; gobject_class->get_property = eek_element_get_property;
gobject_class->finalize = eek_element_finalize; gobject_class->finalize = eek_element_finalize;
gobject_class->dispose = eek_element_dispose;
/** /**
* EekElement:name: * EekElement:name:

View File

@ -47,9 +47,6 @@ struct _EekElementClass
/*< private >*/ /*< private >*/
GInitiallyUnownedClass parent_class; GInitiallyUnownedClass parent_class;
void (* set_parent) (EekElement *self,
EekContainer *parent);
EekContainer *(* get_parent) (EekElement *self);
void (* set_name) (EekElement *self, void (* set_name) (EekElement *self,
const gchar *name); const gchar *name);

View File

@ -20,6 +20,8 @@
#ifndef EEK_KEYSYM_H #ifndef EEK_KEYSYM_H
#define EEK_KEYSYM_H 1 #define EEK_KEYSYM_H 1
#include <glib-object.h>
#define EEK_INVALID_KEYSYM ((guint)(-1)) #define EEK_INVALID_KEYSYM ((guint)(-1))
#define EEK_INVALID_KEYCODE ((guint)(-1)) #define EEK_INVALID_KEYCODE ((guint)(-1))