summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2013-01-31 13:47:57 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2013-01-31 13:47:57 +0000
commitcf0e75b670de03aae7d3660c9d8f8396ede3b9f8 (patch)
tree3ba514aaf5b62da2daafeb6cfa4980f1973f786f
parent29998cf55524394fce52b44997371ae0a100feda (diff)
downloadnavit-cf0e75b670de03aae7d3660c9d8f8396ede3b9f8.tar.gz
Add:Core:Converted osd to new object scheme
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5360 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/osd.c47
-rw-r--r--navit/osd.h1
-rw-r--r--navit/xmlconfig.c10
-rw-r--r--navit/xmlconfig.h5
4 files changed, 49 insertions, 14 deletions
diff --git a/navit/osd.c b/navit/osd.c
index 7374f9dee..10cc6ea68 100644
--- a/navit/osd.c
+++ b/navit/osd.c
@@ -21,6 +21,7 @@
#include "debug.h"
#include "plugin.h"
#include "item.h"
+#include "xmlconfig.h"
#include "color.h"
#include "point.h"
#include "navit.h"
@@ -31,9 +32,9 @@
struct osd {
+ NAVIT_OBJECT
struct osd_methods meth;
struct osd_priv *priv;
- struct attr** osd_attrs;
};
struct osd *
@@ -50,23 +51,22 @@ osd_new(struct attr *parent, struct attr **attrs)
return NULL;
o=g_new0(struct osd, 1);
o->priv=new(parent->u.navit, &o->meth, attrs);
-
- o->osd_attrs = attr_list_dup(attrs);
-
+ if (o->priv) {
+ o->func=&osd_func;
+ navit_object_ref((struct navit_object *)o);
+ o->attrs=attr_list_dup(attrs);
+ } else {
+ g_free(o);
+ o=NULL;
+ }
return o;
}
int
-osd_get_attr(struct osd *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
-{
- return attr_generic_get_attr(this_->osd_attrs, NULL, type, attr, NULL);
-}
-
-int
osd_set_attr(struct osd *osd, struct attr* attr)
{
- osd->osd_attrs=attr_generic_set_attr(osd->osd_attrs,attr);
if(osd && osd->meth.set_attr) {
+ navit_object_set_attr((struct navit_object *)osd, attr);
osd->meth.set_attr(osd->priv, attr);
return 1;
}
@@ -74,6 +74,15 @@ osd_set_attr(struct osd *osd, struct attr* attr)
}
void
+osd_destroy(struct osd *osd)
+{
+ if (osd && osd->meth.destroy) {
+ osd->meth.destroy(osd->priv);
+ }
+ g_free(osd);
+}
+
+void
osd_wrap_point(struct point *p, struct navit *nav)
{
if (p->x < 0)
@@ -368,3 +377,19 @@ osd_std_draw(struct osd_item *item)
if (flags & 8)
graphics_draw_lines(item->gr, item->graphic_fg_text, p, 2);
}
+
+struct object_func osd_func = {
+ attr_osd,
+ (object_func_new)osd_new,
+ (object_func_get_attr)navit_object_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)osd_set_attr,
+ (object_func_add_attr)NULL,
+ (object_func_remove_attr)NULL,
+ (object_func_init)NULL,
+ (object_func_destroy)osd_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
+};
diff --git a/navit/osd.h b/navit/osd.h
index 45eabd7a1..57219a06f 100644
--- a/navit/osd.h
+++ b/navit/osd.h
@@ -26,6 +26,7 @@ struct attr;
struct osd_methods {
void (*osd_destroy)(struct osd_priv *osd);
void (*set_attr)(struct osd_priv *osd, struct attr* attr);
+ void (*destroy)(struct osd_priv *osd);
};
#define osd_draw_cast(x) (void (*)(struct osd_priv *osd, struct navit *navit, struct vehicle *v))(x)
diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c
index b6571d85c..8acf5e07a 100644
--- a/navit/xmlconfig.c
+++ b/navit/xmlconfig.c
@@ -257,7 +257,6 @@ static struct object_func object_funcs[] = {
{ attr_itemgra, NEW(itemgra_new), NULL, NULL, NULL, NULL, ADD(itemgra_add_attr)},
{ attr_log, NEW(log_new)},
{ attr_navigation, NEW(navigation_new), GET(navigation_get_attr)},
- { attr_osd, NEW(osd_new), GET(osd_get_attr), NULL, NULL, SET(osd_set_attr) },
{ attr_plugins, NEW(plugins_new), NULL, NULL, NULL, NULL, NULL, NULL, INIT(plugins_init)},
{ attr_plugin, NEW(plugin_new)},
{ attr_polygon, NEW(polygon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
@@ -287,6 +286,8 @@ object_func_lookup(enum attr_type type)
return &mapset_func;
case attr_navit:
return &navit_func;
+ case attr_osd:
+ return &osd_func;
case attr_trackingo:
return &tracking_func;
case attr_vehicle:
@@ -1317,3 +1318,10 @@ navit_object_remove_attr(struct navit_object *obj, struct attr *attr)
callback_list_call_attr_2(obj->attrs[0]->u.callback_list, attr->type, attr->u.data, -1);
return 1;
}
+
+void
+navit_object_destroy(struct navit_object *obj)
+{
+ attr_list_free(obj->attrs);
+ g_free(obj);
+}
diff --git a/navit/xmlconfig.h b/navit/xmlconfig.h
index bfb7c65ee..94cae7c86 100644
--- a/navit/xmlconfig.h
+++ b/navit/xmlconfig.h
@@ -54,9 +54,9 @@ struct object_func {
void *(*unref)(void *);
};
-extern struct object_func map_func, mapset_func, navit_func, tracking_func, vehicle_func, maps_func, layout_func, vehicleprofile_func, layer_func, config_func;
+extern struct object_func map_func, mapset_func, navit_func, osd_func, tracking_func, vehicle_func, maps_func, layout_func, vehicleprofile_func, layer_func, config_func;
-#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config)
+#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config)
#define NAVIT_OBJECT struct object_func *func; int refcount; struct attr **attrs;
struct navit_object {
@@ -71,6 +71,7 @@ int navit_object_get_attr(struct navit_object *obj, enum attr_type type, struct
int navit_object_set_attr(struct navit_object *obj, struct attr *attr);
int navit_object_add_attr(struct navit_object *obj, struct attr *attr);
int navit_object_remove_attr(struct navit_object *obj, struct attr *attr);
+void navit_object_destroy(struct navit_object *obj);
typedef GError xmlerror;