[dia] Provide convenience functions prop_list_add_<type>()



commit 65057673c67ad7ca1d9ee3bbf70d5b016a13e42d
Author: Hans Breuer <hans breuer org>
Date:   Fri Jun 17 16:59:05 2011 +0200

    Provide convenience functions prop_list_add_<type>()

 lib/libdia.def   |    7 ++++++
 lib/properties.h |   11 +++++++++
 lib/proplist.c   |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 78 insertions(+), 1 deletions(-)
---
diff --git a/lib/libdia.def b/lib/libdia.def
index 74894f4..1970471 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -661,6 +661,13 @@ EXPORTS
  prop_desc_list_free_handler_chain
  prop_desc_lists_intersection
  prop_list_add_list
+ prop_list_add_fill_colour
+ prop_list_add_line_colour
+ prop_list_add_line_style
+ prop_list_add_line_width
+ prop_list_add_point
+ prop_list_add_real
+ prop_list_add_show_background
  prop_list_free
  prop_list_from_descs
  prop_list_from_single
diff --git a/lib/properties.h b/lib/properties.h
index f5b3fab..a1127e2 100644
--- a/lib/properties.h
+++ b/lib/properties.h
@@ -357,6 +357,17 @@ GPtrArray *prop_list_from_descs(const PropDescription *plist,
    list. */
 GPtrArray *prop_list_from_single(Property *prop);
 
+/* Convenience functions to construct a prop list from standard properties */
+void prop_list_add_line_width  (GPtrArray *plist, real line_width);
+void prop_list_add_line_style  (GPtrArray *plist, LineStyle line_style, real dash);
+void prop_list_add_line_colour (GPtrArray *plist, const Color *color);
+void prop_list_add_fill_colour (GPtrArray *plist, const Color *color);
+void prop_list_add_show_background (GPtrArray *plist, gboolean fill);
+/* usually three variants: start_point, end_point, elem_corner */
+void prop_list_add_point (GPtrArray *plist, const char *name, const Point *point);
+/* quite generic, e.g. elem_width, elem_height, curve_distance */
+void prop_list_add_real (GPtrArray *plist, const char *name, real value);
+
 /* Some predicates: */
 gboolean pdtpp_true(const PropDescription *pdesc); /* always true */
 gboolean pdtpp_is_visible(const PropDescription *pdesc); 
diff --git a/lib/proplist.c b/lib/proplist.c
index 8bbe577..13a26c5 100644
--- a/lib/proplist.c
+++ b/lib/proplist.c
@@ -218,8 +218,67 @@ prop_list_add_list (GPtrArray *props, const GPtrArray *ptoadd)
 }
 
 GPtrArray *
-prop_list_from_single(Property *prop) {
+prop_list_from_single(Property *prop)
+{
   GPtrArray *plist = g_ptr_array_new();
   g_ptr_array_add(plist,prop);
   return plist;
 }
+
+void
+prop_list_add_line_width  (GPtrArray *plist, real line_width)
+{
+  Property *prop = make_new_prop (PROP_STDNAME_LINE_WIDTH, PROP_STDTYPE_LINE_WIDTH, 0);
+
+  ((RealProperty *)prop)->real_data = line_width;
+  g_ptr_array_add (plist, prop);
+}
+void
+prop_list_add_line_style  (GPtrArray *plist, LineStyle line_style, real dash)
+{
+  Property *prop = make_new_prop ("line_style", PROP_TYPE_LINESTYLE, 0);
+
+  ((LinestyleProperty *)prop)->style = line_style;
+  ((LinestyleProperty *)prop)->dash = dash;
+  g_ptr_array_add (plist, prop);
+}
+void
+prop_list_add_line_colour (GPtrArray *plist, const Color *color)
+{
+  Property *prop = make_new_prop ("line_colour", PROP_TYPE_COLOUR, 0);
+
+  ((ColorProperty *)prop)->color_data = *color;
+  g_ptr_array_add (plist, prop);
+}
+void
+prop_list_add_fill_colour (GPtrArray *plist, const Color *color)
+{
+  Property *prop = make_new_prop ("fill_colour", PROP_TYPE_COLOUR, 0);
+
+  ((ColorProperty *)prop)->color_data = *color;
+  g_ptr_array_add (plist, prop);
+}
+void
+prop_list_add_show_background (GPtrArray *plist, gboolean fill)
+{
+  Property *prop = make_new_prop ("show_background", PROP_TYPE_BOOL, 0);
+
+  ((BoolProperty *)prop)->bool_data = fill;
+  g_ptr_array_add (plist, prop);
+}
+void
+prop_list_add_point (GPtrArray *plist, const char *name, const Point *point)
+{
+  Property *prop = make_new_prop (name, PROP_TYPE_POINT, 0);
+
+  ((PointProperty *)prop)->point_data = *point;
+  g_ptr_array_add (plist, prop);
+}
+void
+prop_list_add_real (GPtrArray *plist, const char *name, real value)
+{
+  Property *prop = make_new_prop (name, PROP_TYPE_REAL, 0);
+
+  ((RealProperty *)prop)->real_data = value;
+  g_ptr_array_add (plist, prop);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]