[gegl/next-API: 5/7] fractal-explorer: use enum properties instead of integer



commit cfb065a3c4ee35853020760419222a47f9e1eeb0
Author: Michael Murà <mure michael gmail com>
Date:   Mon May 28 20:02:07 2012 +0900

    fractal-explorer: use enum properties instead of integer

 operations/common/fractal-explorer.c |   96 +++++++++++++++++----------------
 1 files changed, 49 insertions(+), 47 deletions(-)
---
diff --git a/operations/common/fractal-explorer.c b/operations/common/fractal-explorer.c
index ab3f5c7..8e6a5e4 100644
--- a/operations/common/fractal-explorer.c
+++ b/operations/common/fractal-explorer.c
@@ -32,7 +32,21 @@ gegl_chant_int_ui (width,  _("Width"),  1, 10000000, 400, 1, 2000, 1.5,
 gegl_chant_int_ui (height, _("Height"), 1, 10000000, 400, 1, 2000, 1.5,
                    _("Height"))
 
-gegl_chant_int (fractaltype, _("Fractal type"), 0, 8, 0, _("Type of a fractal"))
+gegl_chant_register_enum (gegl_fractal_explorer_type)
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_MANDELBROT,   "Mandelbrot")
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_JULIA,        "Julia")
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_BARNSLEY_1,   "Barnsley 1")
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_BARNSLEY_2,   "Barnsley 2")
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_BARNSLEY_3,   "Barnsley 3")
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_SPIDER,       "Spider")
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_MAN_O_WAR,    "Man O War")
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_LAMBDA,       "Lambda")
+  enum_value (GEGl_FRACTAL_EXPLORER_TYPE_SIERPINSKI,   "Sierpinski")
+gegl_chant_register_enum_end (GeglFractalExplorerType)
+
+gegl_chant_enum (fractaltype, _("Fractal type"), GeglFractalExplorerType,
+                 gegl_fractal_explorer_type, GEGl_FRACTAL_EXPLORER_TYPE_MANDELBROT,
+                 _("Type of a fractal"))
 
 gegl_chant_double (xmin, _("Left"),   -3.0, 3.0, -2.0, _("Left"))
 gegl_chant_double (xmax, _("Right"),  -3.0, 3.0,  2.0, _("Right"))
@@ -51,12 +65,21 @@ gegl_chant_double (greenstretch, _("Green stretch"), 0.0, 1.0, 1.0,
 gegl_chant_double (bluestretch,  _("Blue stretch"),  0.0, 1.0, 1.0,
                    _("Blue stretching factor"))
 
-gegl_chant_int (redmode,   _("Red mode"),   0, 2, 1,
-                _("Red application mode (0:SIN; 1:COS; 2:NONE)"))
-gegl_chant_int (greenmode, _("Green mode"), 0, 2, 1,
-                _("Green application mode (0:SIN; 1:COS; 2:NONE)"))
-gegl_chant_int (bluemode,  _("Blue mode"),  0, 2, 0,
-                _("Blue application mode (0:SIN; 1:COS; 2:NONE)"))
+gegl_chant_register_enum (gegl_fractal_explorer_mode)
+  enum_value (GEGl_FRACTAL_EXPLORER_MODE_SIN,       "Sine")
+  enum_value (GEGl_FRACTAL_EXPLORER_MODE_COS,       "Cosinus")
+  enum_value (GEGl_FRACTAL_EXPLORER_MODE_NONE,      "None")
+gegl_chant_register_enum_end (GeglFractalExplorerMode)
+
+gegl_chant_enum (redmode,   _("Red mode"),   GeglFractalExplorerMode,
+                 gegl_fractal_explorer_mode, GEGl_FRACTAL_EXPLORER_MODE_COS,
+                _("Red application mode"))
+gegl_chant_enum (greenmode,   _("Green mode"),   GeglFractalExplorerMode,
+                 gegl_fractal_explorer_mode, GEGl_FRACTAL_EXPLORER_MODE_COS,
+                _("Green application mode"))
+gegl_chant_enum (bluemode,   _("Blue mode"),   GeglFractalExplorerMode,
+                 gegl_fractal_explorer_mode, GEGl_FRACTAL_EXPLORER_MODE_SIN,
+                _("Blue application mode"))
 
 gegl_chant_boolean (redinvert,   _("Red inversion"),   FALSE,
                     _("Red inversion"))
@@ -80,27 +103,6 @@ gegl_chant_boolean (useloglog, _("Loglog smoothing"), FALSE,
 #include <math.h>
 #include <stdio.h>
 
-enum
-{
-  SINUS,
-  COSINUS,
-  NONE
-};
-
-enum
-{
-  TYPE_MANDELBROT,
-  TYPE_JULIA,
-  TYPE_BARNSLEY_1,
-  TYPE_BARNSLEY_2,
-  TYPE_BARNSLEY_3,
-  TYPE_SPIDER,
-  TYPE_MAN_O_WAR,
-  TYPE_LAMBDA,
-  TYPE_SIERPINSKI,
-  NUM_TYPES
-};
-
 typedef struct
 {
   guchar r, g, b;
@@ -149,7 +151,7 @@ explorer_render_row (GeglChantO *o,
     {
       a = o->xmin + (gdouble) col * xdiff;
       b = o->ymin + (gdouble) row * ydiff;
-      if (o->fractaltype != 0)
+      if (o->fractaltype != GEGl_FRACTAL_EXPLORER_TYPE_MANDELBROT)
         {
           tmpx = x = a;
           tmpy = y = b;
@@ -167,17 +169,17 @@ explorer_render_row (GeglChantO *o,
 
           switch (o->fractaltype)
             {
-            case TYPE_MANDELBROT:
+            case GEGl_FRACTAL_EXPLORER_TYPE_MANDELBROT:
               xx = x * x - y * y + a;
               y = 2.0 * x * y + b;
               break;
 
-            case TYPE_JULIA:
+            case GEGl_FRACTAL_EXPLORER_TYPE_JULIA:
               xx = x * x - y * y + o->cx;
               y = 2.0 * x * y + o->cy;
               break;
 
-            case TYPE_BARNSLEY_1:
+            case GEGl_FRACTAL_EXPLORER_TYPE_BARNSLEY_1:
               foldxinitx = oldx * o->cx;
               foldyinity = oldy * o->cy;
               foldxinity = oldx * o->cy;
@@ -195,7 +197,7 @@ explorer_render_row (GeglChantO *o,
                 }
               break;
 
-            case TYPE_BARNSLEY_2:
+            case GEGl_FRACTAL_EXPLORER_TYPE_BARNSLEY_2:
               foldxinitx = oldx * o->cx;
               foldyinity = oldy * o->cy;
               foldxinity = oldx * o->cy;
@@ -213,7 +215,7 @@ explorer_render_row (GeglChantO *o,
                 }
               break;
 
-            case TYPE_BARNSLEY_3:
+            case GEGl_FRACTAL_EXPLORER_TYPE_BARNSLEY_3:
               foldxinitx  = oldx * oldx;
               foldyinity  = oldy * oldy;
               foldxinity  = oldx * oldy;
@@ -231,7 +233,7 @@ explorer_render_row (GeglChantO *o,
                 }
               break;
 
-            case TYPE_SPIDER:
+            case GEGl_FRACTAL_EXPLORER_TYPE_SPIDER:
               /* { c=z=pixel: z=z*z+c; c=c/2+z, |z|<=4 } */
               xx = x*x - y*y + tmpx + o->cx;
               y = 2 * oldx * oldy + tmpy + o->cy;
@@ -239,14 +241,14 @@ explorer_render_row (GeglChantO *o,
               tmpy = tmpy/2 + y;
               break;
 
-            case TYPE_MAN_O_WAR:
+            case GEGl_FRACTAL_EXPLORER_TYPE_MAN_O_WAR:
               xx = x*x - y*y + tmpx + o->cx;
               y = 2.0 * x * y + tmpy + o->cy;
               tmpx = oldx;
               tmpy = oldy;
               break;
 
-            case TYPE_LAMBDA:
+            case GEGl_FRACTAL_EXPLORER_TYPE_LAMBDA:
               tempsqrx = x * x;
               tempsqry = y * y;
               tempsqrx = oldx - tempsqrx + tempsqry;
@@ -256,7 +258,7 @@ explorer_render_row (GeglChantO *o,
               y = o->cx * tempsqry + o->cy * tempsqrx;
               break;
 
-            case TYPE_SIERPINSKI:
+            case GEGl_FRACTAL_EXPLORER_TYPE_SIERPINSKI:
               xx = oldx + oldx;
               y = oldy + oldy;
               if (oldy > .5)
@@ -321,13 +323,13 @@ make_color_map (GeglChantO *o, clrmap colormap)
 
       switch (o->redmode)
         {
-        case SINUS:
+        case GEGl_FRACTAL_EXPLORER_MODE_SIN:
           r = (int) redstretch *(1.0 + sin((x - 1) * pi));
           break;
-        case COSINUS:
+        case GEGl_FRACTAL_EXPLORER_MODE_COS:
           r = (int) redstretch *(1.0 + cos((x - 1) * pi));
           break;
-        case NONE:
+        case GEGl_FRACTAL_EXPLORER_MODE_NONE:
           r = (int)(redstretch *(x));
           break;
         default:
@@ -336,13 +338,13 @@ make_color_map (GeglChantO *o, clrmap colormap)
 
       switch (o->greenmode)
         {
-        case SINUS:
+        case GEGl_FRACTAL_EXPLORER_MODE_SIN:
           gr = (int) greenstretch *(1.0 + sin((x - 1) * pi));
           break;
-        case COSINUS:
+        case GEGl_FRACTAL_EXPLORER_MODE_COS:
           gr = (int) greenstretch *(1.0 + cos((x - 1) * pi));
           break;
-        case NONE:
+        case GEGl_FRACTAL_EXPLORER_MODE_NONE:
           gr = (int)(greenstretch *(x));
           break;
         default:
@@ -351,13 +353,13 @@ make_color_map (GeglChantO *o, clrmap colormap)
 
       switch (o->bluemode)
         {
-        case SINUS:
+        case GEGl_FRACTAL_EXPLORER_MODE_SIN:
           bl = (int) bluestretch * (1.0 + sin ((x - 1) * pi));
           break;
-        case COSINUS:
+        case GEGl_FRACTAL_EXPLORER_MODE_COS:
           bl = (int) bluestretch * (1.0 + cos ((x - 1) * pi));
           break;
-        case NONE:
+        case GEGl_FRACTAL_EXPLORER_MODE_NONE:
           bl = (int) (bluestretch * x);
           break;
         default:



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