[dia] [substitute] Implement create_standard_zigzagline()
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] [substitute] Implement create_standard_zigzagline()
- Date: Sun, 16 Sep 2012 18:11:44 +0000 (UTC)
commit 9016e53945bc2c25c340d17375738a881a4cab3f
Author: Hans Breuer <hans breuer org>
Date: Sun Sep 16 14:21:52 2012 +0200
[substitute] Implement create_standard_zigzagline()
Soon to be used by the Line Upgrade facility.
Also cleanup unnecessary heap allocations while on it.
lib/create.c | 84 ++++++++++++++++++++++++++++++++++---------------------
lib/create.h | 3 ++
lib/libdia.def | 1 +
3 files changed, 56 insertions(+), 32 deletions(-)
---
diff --git a/lib/create.c b/lib/create.c
index 4acab7a..c2fa63d 100644
--- a/lib/create.c
+++ b/lib/create.c
@@ -147,14 +147,49 @@ static PropDescription create_line_prop_descs[] = {
PROP_DESC_END};
DiaObject *
+create_standard_zigzagline(int num_points, const Point *points,
+ const Arrow *end_arrow, const Arrow *start_arrow)
+{
+ DiaObjectType *otype = object_get_type("Standard - ZigZagLine");
+ DiaObject *new_obj;
+ Handle *h1, *h2;
+ MultipointCreateData pcd;
+ GPtrArray *props;
+
+ if (otype == NULL){
+ message_error(_("Can't find standard object"));
+ return NULL;
+ }
+
+ pcd.num_points = num_points;
+ pcd.points = points;
+
+ new_obj = otype->ops->create(NULL, &pcd, &h1, &h2);
+
+ props = prop_list_from_descs(create_line_prop_descs,pdtpp_true);
+ g_assert(props->len == 2);
+
+ if (start_arrow != NULL)
+ ((ArrowProperty *)g_ptr_array_index(props, 0))->arrow_data = *start_arrow;
+ if (end_arrow != NULL)
+ ((ArrowProperty *)g_ptr_array_index(props, 1))->arrow_data = *end_arrow;
+
+ new_obj->ops->set_props(new_obj, props);
+ prop_list_free(props);
+
+ return new_obj;
+}
+
+DiaObject *
create_standard_polyline(int num_points,
Point *points,
Arrow *end_arrow,
- Arrow *start_arrow) {
+ Arrow *start_arrow)
+{
DiaObjectType *otype = object_get_type("Standard - PolyLine");
DiaObject *new_obj;
Handle *h1, *h2;
- MultipointCreateData *pcd;
+ MultipointCreateData pcd;
GPtrArray *props;
if (otype == NULL){
@@ -162,14 +197,10 @@ create_standard_polyline(int num_points,
return NULL;
}
- pcd = g_new(MultipointCreateData, 1);
- pcd->num_points = num_points;
- pcd->points = points;
-
- new_obj = otype->ops->create(NULL, pcd,
- &h1, &h2);
+ pcd.num_points = num_points;
+ pcd.points = points;
- g_free(pcd);
+ new_obj = otype->ops->create(NULL, &pcd, &h1, &h2);
props = prop_list_from_descs(create_line_prop_descs,pdtpp_true);
g_assert(props->len == 2);
@@ -191,20 +222,17 @@ create_standard_polygon(int num_points,
DiaObjectType *otype = object_get_type("Standard - Polygon");
DiaObject *new_obj;
Handle *h1, *h2;
- MultipointCreateData *pcd;
+ MultipointCreateData pcd;
if (otype == NULL){
message_error(_("Can't find standard object"));
return NULL;
}
- pcd = g_new(MultipointCreateData, 1);
- pcd->num_points = num_points;
- pcd->points = points;
-
- new_obj = otype->ops->create(NULL, pcd, &h1, &h2);
+ pcd.num_points = num_points;
+ pcd.points = points;
- g_free(pcd);
+ new_obj = otype->ops->create(NULL, &pcd, &h1, &h2);
return new_obj;
}
@@ -217,7 +245,7 @@ create_standard_bezierline(int num_points,
DiaObjectType *otype = object_get_type("Standard - BezierLine");
DiaObject *new_obj;
Handle *h1, *h2;
- BezierCreateData *bcd;
+ BezierCreateData bcd;
GPtrArray *props;
if (otype == NULL){
@@ -225,15 +253,11 @@ create_standard_bezierline(int num_points,
return NULL;
}
- bcd = g_new(BezierCreateData, 1);
- bcd->num_points = num_points;
- bcd->points = points;
+ bcd.num_points = num_points;
+ bcd.points = points;
- new_obj = otype->ops->create(NULL, bcd,
- &h1, &h2);
+ new_obj = otype->ops->create(NULL, &bcd, &h1, &h2);
- g_free(bcd);
-
props = prop_list_from_descs(create_line_prop_descs,pdtpp_true);
g_assert(props->len == 2);
@@ -254,21 +278,17 @@ create_standard_beziergon(int num_points,
DiaObjectType *otype = object_get_type("Standard - Beziergon");
DiaObject *new_obj;
Handle *h1, *h2;
- BezierCreateData *bcd;
+ BezierCreateData bcd;
if (otype == NULL){
message_error(_("Can't find standard object"));
return NULL;
}
- bcd = g_new(BezierCreateData, 1);
- bcd->num_points = num_points;
- bcd->points = points;
-
- new_obj = otype->ops->create(NULL, bcd,
- &h1, &h2);
+ bcd.num_points = num_points;
+ bcd.points = points;
- g_free(bcd);
+ new_obj = otype->ops->create(NULL, &bcd, &h1, &h2);
return new_obj;
}
diff --git a/lib/create.h b/lib/create.h
index a3e5d3c..10ea5fb 100644
--- a/lib/create.h
+++ b/lib/create.h
@@ -62,6 +62,9 @@ DiaObject *create_standard_box(real xpos, real ypos, real width, real height);
/*! Create a _Polyline with arrows */
DiaObject *create_standard_polyline(int num_points, Point *points,
Arrow *end_arrow, Arrow *start_arrow);
+/*! Create an _OrthConn with arrows */
+DiaObject *create_standard_zigzagline(int num_points, const Point *points,
+ const Arrow *end_arrow, const Arrow *start_arrow);
DiaObject *create_standard_polygon(int num_points, Point *points);
/*! Create a _Bezierline with arrows */
DiaObject *create_standard_bezierline(int num_points, BezPoint *points,
diff --git a/lib/libdia.def b/lib/libdia.def
index 02117c6..5ec813d 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -129,6 +129,7 @@ EXPORTS
create_standard_polygon
create_standard_polyline
create_standard_text
+ create_standard_zigzagline
data_add_boolean
data_add_color
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]