From a772f2797d75e4ac7fa7ce6f7fb984db32b63ece Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 14 Jun 2014 19:34:09 +0200 Subject: [PATCH] wrlib: add explicit type definition in API to allow compiler Type Checks (3/3) 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 the type for the gradient style for RRender*Gradient. Signed-off-by: Christophe CURIS --- WPrefs.app/Appearance.c | 6 +++--- util/wmsetbg.c | 6 +++--- wrlib/gradient.c | 4 ++-- wrlib/wraster.h | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c index 8d5020c5..b372ceac 100644 --- a/WPrefs.app/Appearance.c +++ b/WPrefs.app/Appearance.c @@ -556,7 +556,7 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2); } else if (strcasecmp(&type[1], "gradient") == 0) { - int style; + RGradientStyle style; RColor rcolor2; switch (toupper(type[0])) { @@ -580,7 +580,7 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int image = RRenderGradient(width, height, &rcolor, &rcolor2, style); } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') { - int style; + RGradientStyle style; RColor rcolor2; int i; RImage *grad = NULL; @@ -615,7 +615,7 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int RReleaseImage(grad); } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') { - int style; + RGradientStyle style; RColor **colors; int i, j; diff --git a/util/wmsetbg.c b/util/wmsetbg.c index 9f862a24..785aa1ba 100644 --- a/util/wmsetbg.c +++ b/util/wmsetbg.c @@ -326,7 +326,7 @@ static BackgroundTexture *parseTexture(RContext * rc, char *text) RColor color1, color2; RImage *image; Pixmap pixmap; - int gtype; + RGradientStyle gtype; int iwidth, iheight; GETSTRORGOTO(val, tmp, 1, error); @@ -396,7 +396,7 @@ static BackgroundTexture *parseTexture(RContext * rc, char *text) RImage *image; Pixmap pixmap; int i, j; - int gtype; + RGradientStyle gtype; int iwidth, iheight; colors = malloc(sizeof(RColor *) * (count - 1)); @@ -587,7 +587,7 @@ static BackgroundTexture *parseTexture(RContext * rc, char *text) Pixmap pixmap; int opaq; char *file; - int gtype; + RGradientStyle gtype; int twidth, theight; GETSTRORGOTO(val, file, 1, error); diff --git a/wrlib/gradient.c b/wrlib/gradient.c index 930d1225..7a07fe33 100644 --- a/wrlib/gradient.c +++ b/wrlib/gradient.c @@ -39,7 +39,7 @@ static RImage *renderMHGradient(unsigned width, unsigned height, RColor ** color static RImage *renderMVGradient(unsigned width, unsigned height, RColor ** colors, int count); static RImage *renderMDGradient(unsigned width, unsigned height, RColor ** colors, int count); -RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor ** colors, int style) +RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, RGradientStyle style) { int count; @@ -65,7 +65,7 @@ RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor ** colors, return NULL; } -RImage *RRenderGradient(unsigned width, unsigned height, const RColor * from, const RColor * to, int style) +RImage *RRenderGradient(unsigned width, unsigned height, const RColor *from, const RColor *to, RGradientStyle style) { switch (style) { case RHorizontalGradient: diff --git a/wrlib/wraster.h b/wrlib/wraster.h index 4bb1056a..974688d1 100644 --- a/wrlib/wraster.h +++ b/wrlib/wraster.h @@ -254,11 +254,11 @@ enum { /* 2 pixel width */ #define RBEV_RAISED3 3 -enum { +typedef enum { RHorizontalGradient = 2, RVerticalGradient = 3, RDiagonalGradient = 4 -}; +} RGradientStyle; /* for backwards compatibility */ #define RGRD_HORIZONTAL RHorizontalGradient #define RGRD_VERTICAL RVerticalGradient @@ -426,11 +426,11 @@ void RFillImage(RImage *image, const RColor *color); void RBevelImage(RImage *image, int bevel_type); RImage *RRenderGradient(unsigned width, unsigned height, const RColor *from, - const RColor *to, int style); + const RColor *to, RGradientStyle style); RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, - int style); + RGradientStyle style); RImage *RRenderInterwovenGradient(unsigned width, unsigned height,