Implement part of LdLuaSymbol.

The "new" method requires to be passed a parameter that
makes it possible to call the appropriate render function.

Stub-plemented the "draw" method.
This commit is contained in:
Přemysl Eric Janouch 2010-09-29 09:13:26 +02:00
parent 9fc354e066
commit 0c9b297e50
5 changed files with 41 additions and 14 deletions

View File

@ -29,17 +29,21 @@
/* /*
* LdLuaSymbolPrivate: * LdLuaSymbolPrivate:
* @lua: Parent Lua object. * @lua: Parent #LdLua object.
* @ident: Identifier for the symbol.
*/ */
struct _LdLuaSymbolPrivate struct _LdLuaSymbolPrivate
{ {
LdLua *lua; LdLua *lua;
gchar *ident;
}; };
G_DEFINE_TYPE (LdLuaSymbol, ld_lua_symbol, LD_TYPE_SYMBOL); G_DEFINE_TYPE (LdLuaSymbol, ld_lua_symbol, LD_TYPE_SYMBOL);
static void ld_lua_symbol_finalize (GObject *gobject); static void ld_lua_symbol_finalize (GObject *gobject);
static void ld_lua_symbol_draw (LdSymbol *self, cairo_t *cr);
static void static void
ld_lua_symbol_class_init (LdLuaSymbolClass *klass) ld_lua_symbol_class_init (LdLuaSymbolClass *klass)
@ -49,7 +53,7 @@ ld_lua_symbol_class_init (LdLuaSymbolClass *klass)
object_class = G_OBJECT_CLASS (klass); object_class = G_OBJECT_CLASS (klass);
object_class->finalize = ld_lua_symbol_finalize; object_class->finalize = ld_lua_symbol_finalize;
/* TODO: Override the "draw" method of LdSymbol. */ klass->parent_class.draw = ld_lua_symbol_draw;
g_type_class_add_private (klass, sizeof (LdLuaSymbolPrivate)); g_type_class_add_private (klass, sizeof (LdLuaSymbolPrivate));
} }
@ -69,6 +73,8 @@ ld_lua_symbol_finalize (GObject *gobject)
self = LD_LUA_SYMBOL (gobject); self = LD_LUA_SYMBOL (gobject);
g_object_unref (self->priv->lua); g_object_unref (self->priv->lua);
g_free (self->priv->ident);
/* Chain up to the parent class. */ /* Chain up to the parent class. */
G_OBJECT_CLASS (ld_lua_symbol_parent_class)->finalize (gobject); G_OBJECT_CLASS (ld_lua_symbol_parent_class)->finalize (gobject);
} }
@ -76,23 +82,37 @@ ld_lua_symbol_finalize (GObject *gobject)
/** /**
* ld_symbol_new: * ld_symbol_new:
* @library: A library object. * @lua: An #LdLua object.
* @filename: The file from which the symbol will be loaded. * @ident: Identifier for the symbol.
* *
* Load a symbol from a file into the library. * Load a symbol from a file into the library.
*/ */
LdSymbol * LdSymbol *
ld_lua_symbol_new (LdSymbolCategory *parent, LdLua *lua) ld_lua_symbol_new (LdLua *lua, const gchar *ident)
{ {
LdLuaSymbol *symbol; LdLuaSymbol *self;
symbol = g_object_new (LD_TYPE_LUA_SYMBOL, NULL); g_return_val_if_fail (LD_IS_LUA (lua), NULL);
g_return_val_if_fail (ident != NULL, NULL);
/* TODO: Create a separate ld-symbol-private.h, include it in this file self = g_object_new (LD_TYPE_LUA_SYMBOL, NULL);
* and then assign and ref the parent category here.
*/
symbol->priv->lua = lua; self->priv->lua = lua;
g_object_ref (lua); g_object_ref (lua);
self->priv->ident = g_strdup (ident);
return LD_SYMBOL (self);
}
static void
ld_lua_symbol_draw (LdSymbol *self, cairo_t *cr)
{
g_return_if_fail (LD_IS_SYMBOL (self));
g_return_if_fail (cr != NULL);
/* TODO: Implement. */
/* Retrieve the function for rendering from the registry or wherever
* it's going to end up, and call it.
*/
} }

View File

@ -33,7 +33,6 @@ typedef struct _LdLuaSymbolClass LdLuaSymbolClass;
/** /**
* LdLuaSymbol: * LdLuaSymbol:
* @name: The name of this symbol.
*/ */
struct _LdLuaSymbol struct _LdLuaSymbol
{ {
@ -54,7 +53,7 @@ struct _LdLuaSymbolClass
GType ld_lua_symbol_get_type (void) G_GNUC_CONST; GType ld_lua_symbol_get_type (void) G_GNUC_CONST;
LdSymbol *ld_lua_symbol_new (LdSymbolCategory *parent, LdLua *lua); LdSymbol *ld_lua_symbol_new (LdLua *lua, const gchar *ident);
G_END_DECLS G_END_DECLS

View File

@ -269,7 +269,7 @@ ld_lua_logdiag_register (lua_State *L)
*/ */
/* /*
symbol = ld_lua_symbol_new (ud->category, ud->self); symbol = ld_lua_symbol_new (ud->self);
ld_symbol_category_insert (ud->category, symbol, -1); ld_symbol_category_insert (ud->category, symbol, -1);
g_object_unref (symbol); g_object_unref (symbol);
*/ */

View File

@ -65,6 +65,11 @@ GType ld_symbol_category_get_type (void) G_GNUC_CONST;
LdSymbolCategory * LdSymbolCategory *
ld_symbol_category_new (LdLibrary *parent); ld_symbol_category_new (LdLibrary *parent);
/* TODO: Methods for inserting and removing children. */
/* TODO: Create a separate ld-symbol-private.h, include it in this ld-s-c.c
* and then assign and ref the parent category here.
*/
G_END_DECLS G_END_DECLS

View File

@ -65,6 +65,9 @@ gchar *ld_symbol_build_identifier (LdSymbol *self);
void ld_symbol_draw (LdSymbol *self, cairo_t *cr); void ld_symbol_draw (LdSymbol *self, cairo_t *cr);
/* TODO: An interface for symbol terminals etc. */ /* TODO: An interface for symbol terminals etc. */
/* TODO: Store a pointer to the parent, probably as a property,
* using g_object_add_weak_pointer/remove_weak_pointer.
*/
G_END_DECLS G_END_DECLS