summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2010-10-27 15:52:36 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2010-10-27 16:52:00 +0200
commit9156953cc95cd4d814ea0ad0e9407efc9a6a0a7d (patch)
tree9bb740c24230eb0d4c5d79fa6ad684ca1f328eb3 /src
parentaa33db342b4fc194cdb4966381ac1e5f44b73465 (diff)
downloadlogdiag-9156953cc95cd4d814ea0ad0e9407efc9a6a0a7d.tar.gz
logdiag-9156953cc95cd4d814ea0ad0e9407efc9a6a0a7d.tar.xz
logdiag-9156953cc95cd4d814ea0ad0e9407efc9a6a0a7d.zip
Add more properties to LdSymbol.
Also move the actual storage of symbol properties to implementations of the abstract LdSymbol class. All the properties are read only.
Diffstat (limited to 'src')
-rw-r--r--src/ld-lua-symbol-private.h6
-rw-r--r--src/ld-lua-symbol.c39
-rw-r--r--src/ld-lua.c16
-rw-r--r--src/ld-symbol.c107
-rw-r--r--src/ld-symbol.h32
5 files changed, 134 insertions, 66 deletions
diff --git a/src/ld-lua-symbol-private.h b/src/ld-lua-symbol-private.h
index 53ef1ac..73bed20 100644
--- a/src/ld-lua-symbol-private.h
+++ b/src/ld-lua-symbol-private.h
@@ -19,10 +19,16 @@ G_BEGIN_DECLS
/*
* LdLuaSymbolPrivate:
* @lua: Parent #LdLua object.
+ * @name: Name of this symbol.
+ * @human_name: Localized human name of this symbol.
+ * @area: Area of this symbol.
*/
struct _LdLuaSymbolPrivate
{
LdLua *lua;
+ gchar *name;
+ gchar *human_name;
+ LdSymbolArea area;
};
diff --git a/src/ld-lua-symbol.c b/src/ld-lua-symbol.c
index cfbdeac..cdc512f 100644
--- a/src/ld-lua-symbol.c
+++ b/src/ld-lua-symbol.c
@@ -34,6 +34,9 @@ G_DEFINE_TYPE (LdLuaSymbol, ld_lua_symbol, LD_TYPE_SYMBOL);
static void ld_lua_symbol_finalize (GObject *gobject);
+static const gchar *ld_lua_symbol_get_name (LdSymbol *symbol);
+static const gchar *ld_lua_symbol_get_human_name (LdSymbol *symbol);
+static void ld_lua_symbol_get_area (LdSymbol *symbol, LdSymbolArea *area);
static void ld_lua_symbol_draw (LdSymbol *symbol, cairo_t *cr);
@@ -45,6 +48,9 @@ ld_lua_symbol_class_init (LdLuaSymbolClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = ld_lua_symbol_finalize;
+ klass->parent_class.get_name = ld_lua_symbol_get_name;
+ klass->parent_class.get_human_name = ld_lua_symbol_get_human_name;
+ klass->parent_class.get_area = ld_lua_symbol_get_area;
klass->parent_class.draw = ld_lua_symbol_draw;
g_type_class_add_private (klass, sizeof (LdLuaSymbolPrivate));
@@ -67,18 +73,49 @@ ld_lua_symbol_finalize (GObject *gobject)
ld_lua_private_unregister (self->priv->lua, self);
g_object_unref (self->priv->lua);
+ if (self->priv->name)
+ g_free (self->priv->name);
+ if (self->priv->human_name)
+ g_free (self->priv->human_name);
+
/* Chain up to the parent class. */
G_OBJECT_CLASS (ld_lua_symbol_parent_class)->finalize (gobject);
}
+const gchar *
+ld_lua_symbol_get_name (LdSymbol *symbol)
+{
+ g_return_val_if_fail (LD_IS_LUA_SYMBOL (symbol), NULL);
+ return LD_LUA_SYMBOL (symbol)->priv->name;
+}
+
+const gchar *
+ld_lua_symbol_get_human_name (LdSymbol *symbol)
+{
+ g_return_val_if_fail (LD_IS_LUA_SYMBOL (symbol), NULL);
+ return LD_LUA_SYMBOL (symbol)->priv->human_name;
+}
+
+void
+ld_lua_symbol_get_area (LdSymbol *symbol, LdSymbolArea *area)
+{
+ LdLuaSymbol *self;
+
+ g_return_if_fail (LD_IS_LUA_SYMBOL (symbol));
+ g_return_if_fail (area != NULL);
+
+ self = LD_LUA_SYMBOL (symbol);
+ *area = self->priv->area;
+}
+
static void
ld_lua_symbol_draw (LdSymbol *symbol, cairo_t *cr)
{
LdLuaSymbol *self;
+ g_return_if_fail (LD_IS_LUA_SYMBOL (symbol));
g_return_if_fail (cr != NULL);
- g_return_if_fail (LD_IS_SYMBOL (symbol));
self = LD_LUA_SYMBOL (symbol);
ld_lua_private_draw (self->priv->lua, self, cr);
diff --git a/src/ld-lua.c b/src/ld-lua.c
index 1e1dd30..3a6a5af 100644
--- a/src/ld-lua.c
+++ b/src/ld-lua.c
@@ -363,14 +363,6 @@ ld_lua_logdiag_register (lua_State *L)
lua_pop (L, 1);
g_return_val_if_fail (ud != NULL, 0);
- /* TODO: Create a symbol using the given parameters:
- * 1. name
- * 2. names (table) -> use g_get_language_names ()
- * 3. area (table)
- * 4. terminals (table)
- * 5. render function
- */
-
/* Check and retrieve arguments. */
name = lua_tostring (L, 1);
if (!name)
@@ -378,12 +370,16 @@ ld_lua_logdiag_register (lua_State *L)
if (!lua_isfunction (L, 5))
luaL_error (L, "register: bad or missing argument #%d", 5);
- /* Create a symbol object. */
+ /* TODO: Create a symbol using the given parameters:
+ * 2. names (table) -> use g_get_language_names ()
+ * 3. area (table)
+ * 4. terminals (table)
+ */
symbol = g_object_new (LD_TYPE_LUA_SYMBOL, NULL);
symbol->priv->lua = ud->self;
g_object_ref (ud->self);
- ld_symbol_set_name (LD_SYMBOL (symbol), name);
+ symbol->priv->name = g_strdup (name);
/* Create an entry in the symbol table. */
lua_getfield (L, LUA_REGISTRYINDEX, LD_LUA_SYMBOLS_INDEX);
diff --git a/src/ld-symbol.c b/src/ld-symbol.c
index c1d9abf..92e0baa 100644
--- a/src/ld-symbol.c
+++ b/src/ld-symbol.c
@@ -26,21 +26,14 @@
* drawn onto the #LdCanvas.
*/
-/*
- * LdSymbolPrivate:
- * @name: The name of this symbol.
- */
-struct _LdSymbolPrivate
-{
- gchar *name;
-};
-
G_DEFINE_ABSTRACT_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT);
enum
{
PROP_0,
- PROP_NAME
+ PROP_NAME,
+ PROP_HUMAN_NAME,
+ /* TODO: Property for the area. */
};
static void
@@ -63,7 +56,6 @@ ld_symbol_class_init (LdSymbolClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->get_property = ld_symbol_get_property;
object_class->set_property = ld_symbol_set_property;
- object_class->finalize = ld_symbol_finalize;
/**
* LdSymbol:name:
@@ -72,17 +64,23 @@ ld_symbol_class_init (LdSymbolClass *klass)
*/
pspec = g_param_spec_string ("name", "Name",
"The name of this symbol.",
- "", G_PARAM_READWRITE);
+ "", G_PARAM_READABLE);
g_object_class_install_property (object_class, PROP_NAME, pspec);
- g_type_class_add_private (klass, sizeof (LdSymbolPrivate));
+/**
+ * LdSymbol:human-name:
+ *
+ * The localized human name of this symbol.
+ */
+ pspec = g_param_spec_string ("human-name", "Human name",
+ "The localized human name of this symbol.",
+ "", G_PARAM_READABLE);
+ g_object_class_install_property (object_class, PROP_HUMAN_NAME, pspec);
}
static void
ld_symbol_init (LdSymbol *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE
- (self, LD_TYPE_SYMBOL, LdSymbolPrivate);
}
static void
@@ -97,6 +95,9 @@ ld_symbol_get_property (GObject *object, guint property_id,
case PROP_NAME:
g_value_set_string (value, ld_symbol_get_name (self));
break;
+ case PROP_HUMAN_NAME:
+ g_value_set_string (value, ld_symbol_get_human_name (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -106,62 +107,64 @@ static void
ld_symbol_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
- LdSymbol *self;
-
- self = LD_SYMBOL (object);
- switch (property_id)
- {
- case PROP_NAME:
- ld_symbol_set_name (self, g_value_get_string (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
-static void
-ld_symbol_finalize (GObject *gobject)
-{
- LdSymbol *self;
- self = LD_SYMBOL (gobject);
+/**
+ * ld_symbol_get_name:
+ * @self: An #LdSymbol object.
+ *
+ * Return value: The name of the symbol.
+ */
+const gchar *
+ld_symbol_get_name (LdSymbol *self)
+{
+ LdSymbolClass *klass;
- if (self->priv->name)
- g_free (self->priv->name);
+ g_return_if_fail (LD_IS_SYMBOL (self));
- /* Chain up to the parent class. */
- G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject);
+ klass = LD_SYMBOL_GET_CLASS (self);
+ g_return_val_if_fail (klass->get_name != NULL, NULL);
+ return klass->get_name (self);
}
/**
- * ld_symbol_set_name:
+ * ld_symbol_get_human_name:
* @self: An #LdSymbol object.
- * @name: A new name for the symbol.
*
- * Set the name of a symbol.
+ * Return value: The localised human name of the symbol.
*/
-void
-ld_symbol_set_name (LdSymbol *self, const gchar *name)
+const gchar *
+ld_symbol_get_human_name (LdSymbol *self)
{
+ LdSymbolClass *klass;
+
g_return_if_fail (LD_IS_SYMBOL (self));
- g_return_if_fail (name != NULL);
- if (self->priv->name)
- g_free (self->priv->name);
- self->priv->name = g_strdup (name);
+ klass = LD_SYMBOL_GET_CLASS (self);
+ g_return_val_if_fail (klass->get_human_name != NULL, NULL);
+ return klass->get_human_name (self);
}
/**
- * ld_symbol_get_name:
- * @self: An #LdSymbol object.
+ * ld_symbol_get_area:
+ * @self: A symbol object.
+ * @area: Where the area of the symbol will be returned.
*
- * Return value: The name of the symbol.
+ * Get the area of the symbol.
*/
-const gchar *
-ld_symbol_get_name (LdSymbol *self)
+void
+ld_symbol_get_area (LdSymbol *self, LdSymbolArea *area)
{
+ LdSymbolClass *klass;
+
g_return_if_fail (LD_IS_SYMBOL (self));
- return self->priv->name;
+ g_return_if_fail (area != NULL);
+
+ klass = LD_SYMBOL_GET_CLASS (self);
+ g_return_if_fail (klass->get_area != NULL);
+ klass->get_area (self, area);
}
/**
@@ -180,6 +183,6 @@ ld_symbol_draw (LdSymbol *self, cairo_t *cr)
g_return_if_fail (cr != NULL);
klass = LD_SYMBOL_GET_CLASS (self);
- if (klass->draw)
- klass->draw (self, cr);
+ g_return_if_fail (klass->draw != NULL);
+ klass->draw (self, cr);
}
diff --git a/src/ld-symbol.h b/src/ld-symbol.h
index 4010107..92d7d82 100644
--- a/src/ld-symbol.h
+++ b/src/ld-symbol.h
@@ -30,6 +30,8 @@ typedef struct _LdSymbol LdSymbol;
typedef struct _LdSymbolPrivate LdSymbolPrivate;
typedef struct _LdSymbolClass LdSymbolClass;
+typedef struct _LdSymbolArea LdSymbolArea;
+
/**
* LdSymbol:
@@ -43,26 +45,50 @@ struct _LdSymbol
};
/**
+ * LdSymbolArea:
+ * @x1: Left-top X coordinate.
+ * @y1: Left-top Y coordinate.
+ * @x2: Right-bottom X coordinate.
+ * @y2: Right-bottom Y coordinate.
+ *
+ * Defines the area of the symbol relative to the center of the symbol,
+ * which is at the (0, 0) coordinates.
+ */
+struct _LdSymbolArea
+{
+ gdouble x1, y1;
+ gdouble x2, y2;
+};
+
+/**
* LdSymbolClass:
* @parent_class: The parent class.
+ * @get_name: Get the name of the symbol.
+ * @get_human_name: Get the localized human name of the symbol.
+ * @get_area: Get the area of the symbol.
* @draw: Draw the symbol on a Cairo surface.
*/
struct _LdSymbolClass
{
GObjectClass parent_class;
+ const gchar *(*get_name) (LdSymbol *self);
+ const gchar *(*get_human_name) (LdSymbol *self);
+ void (*get_area) (LdSymbol *self, LdSymbolArea *area);
void (*draw) (LdSymbol *self, cairo_t *cr);
};
GType ld_symbol_get_type (void) G_GNUC_CONST;
-void ld_symbol_set_name (LdSymbol *self, const gchar *name);
const gchar *ld_symbol_get_name (LdSymbol *self);
-
+const gchar *ld_symbol_get_human_name (LdSymbol *self);
+void ld_symbol_get_area (LdSymbol *self, LdSymbolArea *area);
void ld_symbol_draw (LdSymbol *self, cairo_t *cr);
-/* TODO: Interface for symbol terminals. */
+/* TODO: Interface for terminals.
+ * Something like a list of gdouble pairs (-> a new structure).
+ */
G_END_DECLS