From: Christophe CURIS <christophe.cu...@free.fr>

When defining enums as types instead of simple enums allows to use these
types at the places where the corresponding enum values are expected, then
allowing the compiler to check that, potentially reporting incorrect use
of values to the user.

This patch adds types for the configuration fields in the RContextAttributes
structure.

Signed-off-by: Christophe CURIS <christophe.cu...@free.fr>
---
 util/wmsetbg.c  |  3 ++-
 wrlib/scale.c   |  2 +-
 wrlib/scale.h   |  2 +-
 wrlib/wraster.h | 52 +++++++++++++++++++++++-----------------------------
 4 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/util/wmsetbg.c b/util/wmsetbg.c
index 6e74c53..9f862a2 100644
--- a/util/wmsetbg.c
+++ b/util/wmsetbg.c
@@ -1213,7 +1213,8 @@ int main(int argc, char **argv)
        char *back_color = "gray20";
        char *image_name = NULL;
        char *domain = "WindowMaker";
-       int update = 0, cpc = 4, render_mode = RDitheredRendering, obey_user = 
0;
+       int update = 0, cpc = 4, obey_user = 0;
+       RRenderingMode render_mode = RDitheredRendering;
        char *texture = NULL;
        int workspace = -1;
 
diff --git a/wrlib/scale.c b/wrlib/scale.c
index 3694be6..eafe40f 100644
--- a/wrlib/scale.c
+++ b/wrlib/scale.c
@@ -247,7 +247,7 @@ static double Mitchell_filter(double t)
 static double (*filterf)(double) = Mitchell_filter;
 static double fwidth = Mitchell_support;
 
-void wraster_change_filter(int type)
+void wraster_change_filter(RScalingFilter type)
 {
        switch (type) {
        case RBoxFilter:
diff --git a/wrlib/scale.h b/wrlib/scale.h
index 887b47d..4d2d738 100644
--- a/wrlib/scale.h
+++ b/wrlib/scale.h
@@ -24,7 +24,7 @@
 /*
  * Function to change the smoothing filter used for image scaling 
(RSmoothScaleImage)
  */
-void wraster_change_filter(int type);
+void wraster_change_filter(RScalingFilter type);
 
 
 #endif
diff --git a/wrlib/wraster.h b/wrlib/wraster.h
index 45cbcc6..66443e1 100644
--- a/wrlib/wraster.h
+++ b/wrlib/wraster.h
@@ -82,30 +82,43 @@ extern "C" {
 
 
 
-
+/* image display modes */
+typedef enum {
+       RDitheredRendering = 0,
+       RBestMatchRendering = 1
+} RRenderingMode;
 
 
 /* std colormap usage/creation modes */
-enum {
-    RUseStdColormap,                  /* default. fallbacks to RIgnore.. if
-    there is none defined */
-    RCreateStdColormap,
-    RIgnoreStdColormap
-};
+typedef enum {
+       RUseStdColormap,        /* default: fallbacks to RIgnore if there is 
none defined */
+       RCreateStdColormap,
+       RIgnoreStdColormap
+} RStdColormapMode;
 
 
+/* smoothed scaling filter types */
+typedef enum {
+       RBoxFilter,
+       RTriangleFilter,
+       RBellFilter,
+       RBSplineFilter,
+       RLanczos3Filter,
+       RMitchellFilter
+} RScalingFilter;
+
 
 typedef struct RContextAttributes {
     int flags;
-    int render_mode;
+    RRenderingMode render_mode;
     int colors_per_channel;           /* for PseudoColor */
     float rgamma;                     /* gamma correction for red, */
     float ggamma;                     /* green, */
     float bgamma;                     /* and blue */
     VisualID visualid;        /* visual ID to use */
     int use_shared_memory;            /* True of False */
-    int scaling_filter;
-    int standard_colormap_mode;    /* what to do with std cma */
+    RScalingFilter scaling_filter;
+    RStdColormapMode standard_colormap_mode;    /* what to do with std cma */
 } RContextAttributes;
 
 
@@ -211,24 +224,6 @@ typedef struct RXImage {
 } RXImage;
 
 
-/* image display modes */
-enum {
-    RDitheredRendering = 0,
-    RBestMatchRendering = 1
-};
-
-
-/* smoothed scaling filter types */
-enum {
-    RBoxFilter,
-    RTriangleFilter,
-    RBellFilter,
-    RBSplineFilter,
-    RLanczos3Filter,
-    RMitchellFilter
-};
-
-
 /* note that not all operations are supported in all functions */
 enum {
     RClearOperation,          /* clear with 0 */
@@ -481,4 +476,3 @@ extern int RErrorCode;
 #endif /* __cplusplus */
 
 #endif
-
-- 
1.9.2


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to