changeset 7844:3d60445d3638

Add new double_radio_property class for alpha values.
author Michael Goffioul <michael.goffioul@gmail.com>
date Tue, 26 Feb 2008 22:06:47 +0100
parents d3dcfdfdc434
children 25f5d628bc8a
files src/ChangeLog src/genprops.awk src/graphics.cc src/graphics.h.in
diffstat 4 files changed, 139 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Feb 25 21:50:37 2008 +0200
+++ b/src/ChangeLog	Tue Feb 26 22:06:47 2008 +0100
@@ -27,6 +27,17 @@
 
 2008-06-04  Michael Goffioul <michael.goffioul@gmail.com>
 
+	* graphics.h.in (class double_radio_property): New property class for
+	holding face/edge alpha values.
+	(patch::properties::facealpha, patch::properties::edgealpha,
+	surface::properties::facealpha, surface::properties::edgealpha): Use
+	double_radio_property class.
+	* graphics.cc (double_radio_property::set): Implement new property
+	class.
+	* genprops.awk (emit_get_double_radio): New function to emit code for
+	double_radio_property.
+	(emit_declarations): Use it.
+
 	* graphics.h.in (array_property::array_property(void)): New default
 	constructor.
 	(array_property::xmin, array_property:xmax, array_property::xminp,
--- a/src/genprops.awk	Mon Feb 25 21:50:37 2008 +0200
+++ b/src/genprops.awk	Tue Feb 26 22:06:47 2008 +0100
@@ -187,6 +187,29 @@
   emit_get_accessor(i, "octave_value", "get");
 }
 
+## double_radio_property
+
+function emit_get_double_radio (i)
+{
+  printf ("  bool %s_is_double (void) const { return %s.is_double (); }\n", name[i], name[i]);
+
+  printf ("  bool %s_is (const std::string& v) const", name[i]);
+  
+  if (emit_get[i] == "definition")
+    printf (" { return %s.is (v); }\n", name[i]);
+  else
+    printf (";\n");
+  
+  printf ("  double get_%s_double (void) const", name[i]);
+  
+  if (emit_get[i] == "definition")
+    printf (" { return (%s.is_double () ? %s.double_value () : 0); }\n", name[i], name[i]);
+  else
+    printf (";\n");
+
+  emit_get_accessor(i, "octave_value", "get");
+}
+
 ## callback_property
 
 function emit_get_callback (i)
@@ -262,6 +285,8 @@
         emit_get_accessor(i, "std::string", "string_value");
       else if (type[i] == "double_property")
         emit_get_accessor(i, "double", "double_value");
+      else if (type[i] == "double_radio_property")
+        emit_get_double_radio(i);
       else if (type[i] == "data_property")
         emit_get_data(i);
       else if (type[i] == "array_property" \
--- a/src/graphics.cc	Mon Feb 25 21:50:37 2008 +0200
+++ b/src/graphics.cc	Tue Feb 26 22:06:47 2008 +0100
@@ -581,6 +581,32 @@
            get_name ().c_str ());
 }
 
+void
+double_radio_property::set (const octave_value& val)
+{
+  if (val.is_string ())
+    {
+      std::string s = val.string_value ();
+
+      if (! s.empty () && radio_val.contains (s))
+	{
+	  current_val = s;
+	  current_type = radio_t;
+	}
+      else
+	error ("invalid value for double_radio property \"%s\"",
+	       get_name ().c_str ());
+    }
+  else if (val.is_scalar_type () && val.is_real_type ())
+    {
+      dval = val.double_value ();
+      current_type = double_t;
+    }
+  else 
+    error ("invalid value for double_radio property \"%s\"",
+	   get_name ().c_str ());
+}
+
 bool
 array_property::validate (const octave_value& v)
 {
--- a/src/graphics.h.in	Mon Feb 25 21:50:37 2008 +0200
+++ b/src/graphics.h.in	Tue Feb 26 22:06:47 2008 +0100
@@ -714,6 +714,79 @@
 
 // ---------------------------------------------------------------------
 
+class double_radio_property : public base_property
+{
+public:
+  double_radio_property (double d, const radio_values& v)
+      : base_property ("", graphics_handle ()),
+        current_type (double_t), dval (d), radio_val (v),
+	current_val (v.default_value ())
+  { }
+
+  double_radio_property (const std::string& nm, const graphics_handle& h,
+			 const std::string& v)
+      : base_property (nm, h),
+        current_type (radio_t), dval (0), radio_val (v),
+	current_val (radio_val.default_value ())
+  { }
+
+  double_radio_property (const std::string& nm, const graphics_handle& h,
+			 const double_radio_property& v)
+      : base_property (nm, h),
+        current_type (v.current_type), dval (v.dval),
+	radio_val (v.radio_val), current_val (v.current_val)
+  { }
+
+  octave_value get (void) const
+  {
+    if (current_type == double_t)
+      return dval;
+
+    return current_val;
+  }
+
+  OCTINTERP_API void set (const octave_value& v);
+
+  bool is_double (void) const { return (current_type == double_t); }
+
+  bool is_radio (void) const { return (current_type == radio_t); }
+
+  bool is (const std::string& v) const
+    { return (is_radio () && current_val == v); }
+
+  double double_value (void) const
+  {
+    if (current_type != double_t)
+      error ("%s: property has no double", get_name ().c_str ());
+
+    return dval;
+  }
+
+  const std::string& current_value (void) const
+  {
+    if (current_type != radio_t)
+      error ("%s: property has no radio value");
+
+    return current_val;
+  }
+
+  double_radio_property& operator = (const octave_value& val)
+    {
+      set (val);
+      return *this;
+    }
+
+  operator octave_value (void) const { return get (); }
+
+private:
+  enum current_enum { double_t, radio_t } current_type;
+  double dval;
+  radio_values radio_val;
+  std::string current_val;
+};
+
+// ---------------------------------------------------------------------
+
 class array_property : public base_property
 {
 public:
@@ -2945,10 +3018,10 @@
       array_property vertexnormals , Matrix ()
       radio_property normalmode , "{auto}|manual"
       color_property facecolor , "{flat}|none|interp"
-      double_property facealpha , 1.0
+      double_radio_property facealpha , double_radio_property (1.0, radio_values ("flat|interp"))
       radio_property facelighting , "flat|{none}|gouraud|phong"
       color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp"))
-      double_property edgealpha , 1.0
+      double_radio_property edgeealpha , double_radio_property (1.0, radio_values ("flat|interp"))
       radio_property edgelighting , "{none}|flat|gouraud|phong"
       radio_property backfacelighting , "{reverselit}|unlit|lit"
       double_property ambientstrength , 0.3
@@ -3018,8 +3091,7 @@
       array_property cdata l , Matrix ()
       radio_property cdatamapping a , "{scaled}|direct"
       color_property facecolor , "{flat}|none|interp|texturemap"
-      // FIXME: should be a double-radio property
-      double_property facealpha , 1.0
+      double_radio_property faceealpha , double_radio_property (1.0, radio_values ("flat|interp"))
       color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp"))
       radio_property linestyle , "{-}|--|:|-.|none"
       double_property linewidth , 0.5
@@ -3034,8 +3106,7 @@
       double_property ambientstrength , 0.3
       radio_property backfacelighting , "unlit|lit|{reverselit}"
       double_property diffusestrength , 0.6
-      // FIXME: should be a double-radio property
-      double_property edgealpha , 1.0
+      double_radio_property edgeealpha , double_radio_property (1.0, radio_values ("flat|interp"))
       radio_property edgelighting , "{none}|flat|gouraud|phong"
       radio_property erasemode , "{normal}|none|xor|background"
       radio_property facelighting , "{none}|flat|gouraud|phong"