From 641b7f795c4748aca26156d1d1799ad78b3141c3 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 8 Apr 2023 21:17:36 +0300
Subject: [PATCH 41/41] gtk3.22/gtk4: Improve canvas.[ch] coding style

See osdn #47812

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-3.22/canvas.c | 78 +++++++++++++-----------------------
 client/gui-gtk-3.22/canvas.h |  5 ++-
 client/gui-gtk-4.0/canvas.c  | 70 ++++++++++++--------------------
 client/gui-gtk-4.0/canvas.h  |  5 ++-
 4 files changed, 60 insertions(+), 98 deletions(-)

diff --git a/client/gui-gtk-3.22/canvas.c b/client/gui-gtk-3.22/canvas.c
index b789e1df45..36f0e4e24d 100644
--- a/client/gui-gtk-3.22/canvas.c
+++ b/client/gui-gtk-3.22/canvas.c
@@ -74,8 +74,8 @@ void canvas_mapview_init(struct canvas *store)
   Copies an area from the source canvas to the destination canvas.
 ****************************************************************************/
 void canvas_copy(struct canvas *dest, struct canvas *src,
-		 int src_x, int src_y, int dest_x, int dest_y,
-		 int width, int height)
+                 int src_x, int src_y, int dest_x, int dest_y,
+                 int width, int height)
 {
   cairo_t *cr;
 
@@ -83,9 +83,6 @@ void canvas_copy(struct canvas *dest, struct canvas *src,
     cr = cairo_create(dest->surface);
   } else {
     cr = dest->drawable;
-  }
-
-  if (dest->drawable) {
     cairo_save(cr);
   }
 
@@ -106,10 +103,9 @@ void canvas_copy(struct canvas *dest, struct canvas *src,
   Draw some or all of a sprite onto the mapview or citydialog canvas.
   Supplied coordinates are prior to any canvas zoom.
 ****************************************************************************/
-void canvas_put_sprite(struct canvas *pcanvas,
-		       int canvas_x, int canvas_y,
-		       struct sprite *sprite,
-		       int offset_x, int offset_y, int width, int height)
+void canvas_put_sprite(struct canvas *pcanvas, int canvas_x, int canvas_y,
+                       struct sprite *sprite, int offset_x, int offset_y,
+                       int width, int height)
 {
   int sswidth, ssheight;
   cairo_t *cr;
@@ -145,15 +141,14 @@ void canvas_put_sprite(struct canvas *pcanvas,
   Draw a full sprite onto the mapview or citydialog canvas.
   Supplied canvas_x/y are prior to any canvas zoom.
 ****************************************************************************/
-void canvas_put_sprite_full(struct canvas *pcanvas,
-			    int canvas_x, int canvas_y,
-			    struct sprite *sprite)
+void canvas_put_sprite_full(struct canvas *pcanvas, int canvas_x, int canvas_y,
+                            struct sprite *sprite)
 {
   int width, height;
 
   get_sprite_dimensions(sprite, &width, &height);
   canvas_put_sprite(pcanvas, canvas_x, canvas_y, sprite,
-		    0, 0, width, height);
+                    0, 0, width, height);
 }
 
 /************************************************************************//**
@@ -170,25 +165,23 @@ void canvas_put_sprite_full_scaled(struct canvas *pcanvas,
 }
 
 /************************************************************************//**
-  Draw a full sprite onto the canvas.  If "fog" is specified draw it with
-  fog.
+  Draw a full sprite onto the canvas. If "fog" is specified draw it with fog.
 ****************************************************************************/
 void canvas_put_sprite_fogged(struct canvas *pcanvas,
-			      int canvas_x, int canvas_y,
-			      struct sprite *psprite,
-			      bool fog, int fog_x, int fog_y)
+                              int canvas_x, int canvas_y,
+                              struct sprite *psprite,
+                              bool fog, int fog_x, int fog_y)
 {
-    pixmap_put_overlay_tile_draw(pcanvas, canvas_x, canvas_y,
-				 psprite, fog);
+  pixmap_put_overlay_tile_draw(pcanvas, canvas_x, canvas_y,
+                               psprite, fog);
 }
 
 /************************************************************************//**
   Draw a filled-in colored rectangle onto the mapview or citydialog canvas.
   Supplied coordinates are prior to any canvas zoom.
 ****************************************************************************/
-void canvas_put_rectangle(struct canvas *pcanvas,
-			  struct color *pcolor,
-			  int canvas_x, int canvas_y, int width, int height)
+void canvas_put_rectangle(struct canvas *pcanvas, struct color *pcolor,
+                          int canvas_x, int canvas_y, int width, int height)
 {
   cairo_t *cr;
 
@@ -196,9 +189,6 @@ void canvas_put_rectangle(struct canvas *pcanvas,
     cr = cairo_create(pcanvas->surface);
   } else {
     cr = pcanvas->drawable;
-  }
-
-  if (pcanvas->drawable) {
     cairo_save(cr);
   }
 
@@ -218,12 +208,11 @@ void canvas_put_rectangle(struct canvas *pcanvas,
 /************************************************************************//**
   Fill the area covered by the sprite with the given color.
 ****************************************************************************/
-void canvas_fill_sprite_area(struct canvas *pcanvas,
-			     struct sprite *psprite,
-			     struct color *pcolor,
-			     int canvas_x, int canvas_y)
+void canvas_fill_sprite_area(struct canvas *pcanvas, struct sprite *psprite,
+                             struct color *pcolor, int canvas_x, int canvas_y)
 {
   int width, height;
+
   get_sprite_dimensions(psprite, &width, &height);
   canvas_put_rectangle(pcanvas, pcolor, canvas_x, canvas_y, width, height);
 }
@@ -233,10 +222,9 @@ void canvas_fill_sprite_area(struct canvas *pcanvas,
   XXX: unlike other canvas_put functions, supplied x/y are *not* prior to
   any canvas zoom.
 ****************************************************************************/
-void canvas_put_line(struct canvas *pcanvas,
-		     struct color *pcolor,
-		     enum line_type ltype, int start_x, int start_y,
-		     int dx, int dy)
+void canvas_put_line(struct canvas *pcanvas, struct color *pcolor,
+                     enum line_type ltype, int start_x, int start_y,
+                     int dx, int dy)
 {
   cairo_t *cr;
   double dashes[2] = {4.0, 4.0};
@@ -245,9 +233,6 @@ void canvas_put_line(struct canvas *pcanvas,
     cr = cairo_create(pcanvas->surface);
   } else {
     cr = pcanvas->drawable;
-  }
-
-  if (pcanvas->drawable) {
     cairo_save(cr);
   }
 
@@ -283,8 +268,7 @@ void canvas_put_line(struct canvas *pcanvas,
   Draw a colored curved line for the Technology Tree connectors
   A curved line is: 1 horizontal line, 2 arcs, 1 horizontal line
 ****************************************************************************/
-void canvas_put_curved_line(struct canvas *pcanvas,
-                            struct color *pcolor,
+void canvas_put_curved_line(struct canvas *pcanvas, struct color *pcolor,
                             enum line_type ltype, int start_x, int start_y,
                             int dx, int dy)
 {
@@ -297,9 +281,6 @@ void canvas_put_curved_line(struct canvas *pcanvas,
     cr = cairo_create(pcanvas->surface);
   } else {
     cr = pcanvas->drawable;
-  }
-
-  if (pcanvas->drawable) {
     cairo_save(cr);
   }
 
@@ -343,12 +324,12 @@ static struct {
 #define FONT(font) (*fonts[font].styles)
 
 /************************************************************************//**
-  Return the size of the given text in the given font.  This size should
-  include the ascent and descent of the text.  Either of width or height
+  Return the size of the given text in the given font. This size should
+  include the ascent and descent of the text. Either of width or height
   may be NULL in which case those values simply shouldn't be filled out.
 ****************************************************************************/
 void get_text_size(int *width, int *height,
-		   enum client_font font, const char *text)
+                   enum client_font font, const char *text)
 {
   PangoRectangle rect;
 
@@ -369,9 +350,9 @@ void get_text_size(int *width, int *height,
 }
 
 /************************************************************************//**
-  Draw the text onto the canvas in the given color and font.  The canvas
+  Draw the text onto the canvas in the given color and font. The canvas
   position does not account for the ascent of the text; this function must
-  take care of this manually.  The text will not be NULL but may be empty.
+  take care of this manually. The text will not be NULL but may be empty.
   Supplied canvas_x/y are prior to any canvas zoom.
 ****************************************************************************/
 void canvas_put_text(struct canvas *pcanvas, int canvas_x, int canvas_y,
@@ -384,9 +365,6 @@ void canvas_put_text(struct canvas *pcanvas, int canvas_x, int canvas_y,
     cr = cairo_create(pcanvas->surface);
   } else {
     cr = pcanvas->drawable;
-  }
-
-  if (pcanvas->drawable) {
     cairo_save(cr);
   }
 
diff --git a/client/gui-gtk-3.22/canvas.h b/client/gui-gtk-3.22/canvas.h
index 10b431c59b..e1bbe89dc7 100644
--- a/client/gui-gtk-3.22/canvas.h
+++ b/client/gui-gtk-3.22/canvas.h
@@ -25,10 +25,11 @@ struct canvas
   float zoom;
 };
 
-#define FC_STATIC_CANVAS_INIT { NULL, NULL, 1.0 }
+#define FC_STATIC_CANVAS_INIT \
+  { .surface = NULL, .drawable = NULL, .zoom = 1.0 }
 
 void surface_put_text(cairo_t *cr, int x, int y, float zoom,
                       enum client_font font, struct color *pcolor,
                       const char *text);
 
-#endif  /* FC__CANVAS_H */
+#endif /* FC__CANVAS_H */
diff --git a/client/gui-gtk-4.0/canvas.c b/client/gui-gtk-4.0/canvas.c
index 4c3beee9cb..7f8941f845 100644
--- a/client/gui-gtk-4.0/canvas.c
+++ b/client/gui-gtk-4.0/canvas.c
@@ -74,8 +74,8 @@ void canvas_mapview_init(struct canvas *store)
   Copies an area from the source canvas to the destination canvas.
 ****************************************************************************/
 void canvas_copy(struct canvas *dest, struct canvas *src,
-		 int src_x, int src_y, int dest_x, int dest_y,
-		 int width, int height)
+                 int src_x, int src_y, int dest_x, int dest_y,
+                 int width, int height)
 {
   cairo_t *cr;
 
@@ -106,10 +106,9 @@ void canvas_copy(struct canvas *dest, struct canvas *src,
   Draw some or all of a sprite onto the mapview or citydialog canvas.
   Supplied coordinates are prior to any canvas zoom.
 ****************************************************************************/
-void canvas_put_sprite(struct canvas *pcanvas,
-		       int canvas_x, int canvas_y,
-		       struct sprite *sprite,
-		       int offset_x, int offset_y, int width, int height)
+void canvas_put_sprite(struct canvas *pcanvas, int canvas_x, int canvas_y,
+                       struct sprite *sprite,
+                       int offset_x, int offset_y, int width, int height)
 {
   int sswidth, ssheight;
   cairo_t *cr;
@@ -120,9 +119,6 @@ void canvas_put_sprite(struct canvas *pcanvas,
     cr = cairo_create(pcanvas->surface);
   } else {
     cr = pcanvas->drawable;
-  }
-
-  if (pcanvas->drawable) {
     cairo_save(cr);
   }
 
@@ -145,15 +141,14 @@ void canvas_put_sprite(struct canvas *pcanvas,
   Draw a full sprite onto the mapview or citydialog canvas.
   Supplied canvas_x/y are prior to any canvas zoom.
 ****************************************************************************/
-void canvas_put_sprite_full(struct canvas *pcanvas,
-			    int canvas_x, int canvas_y,
-			    struct sprite *sprite)
+void canvas_put_sprite_full(struct canvas *pcanvas, int canvas_x, int canvas_y,
+                            struct sprite *sprite)
 {
   int width, height;
 
   get_sprite_dimensions(sprite, &width, &height);
   canvas_put_sprite(pcanvas, canvas_x, canvas_y, sprite,
-		    0, 0, width, height);
+                    0, 0, width, height);
 }
 
 /************************************************************************//**
@@ -170,25 +165,23 @@ void canvas_put_sprite_full_scaled(struct canvas *pcanvas,
 }
 
 /************************************************************************//**
-  Draw a full sprite onto the canvas.  If "fog" is specified draw it with
-  fog.
+  Draw a full sprite onto the canvas. If "fog" is specified draw it with fog.
 ****************************************************************************/
 void canvas_put_sprite_fogged(struct canvas *pcanvas,
-			      int canvas_x, int canvas_y,
-			      struct sprite *psprite,
-			      bool fog, int fog_x, int fog_y)
+                              int canvas_x, int canvas_y,
+                              struct sprite *psprite,
+                              bool fog, int fog_x, int fog_y)
 {
-    pixmap_put_overlay_tile_draw(pcanvas, canvas_x, canvas_y,
-				 psprite, fog);
+  pixmap_put_overlay_tile_draw(pcanvas, canvas_x, canvas_y,
+                               psprite, fog);
 }
 
 /************************************************************************//**
   Draw a filled-in colored rectangle onto the mapview or citydialog canvas.
   Supplied coordinates are prior to any canvas zoom.
 ****************************************************************************/
-void canvas_put_rectangle(struct canvas *pcanvas,
-			  struct color *pcolor,
-			  int canvas_x, int canvas_y, int width, int height)
+void canvas_put_rectangle(struct canvas *pcanvas, struct color *pcolor,
+                          int canvas_x, int canvas_y, int width, int height)
 {
   cairo_t *cr;
 
@@ -196,9 +189,6 @@ void canvas_put_rectangle(struct canvas *pcanvas,
     cr = cairo_create(pcanvas->surface);
   } else {
     cr = pcanvas->drawable;
-  }
-
-  if (pcanvas->drawable) {
     cairo_save(cr);
   }
 
@@ -218,12 +208,11 @@ void canvas_put_rectangle(struct canvas *pcanvas,
 /************************************************************************//**
   Fill the area covered by the sprite with the given color.
 ****************************************************************************/
-void canvas_fill_sprite_area(struct canvas *pcanvas,
-			     struct sprite *psprite,
-			     struct color *pcolor,
-			     int canvas_x, int canvas_y)
+void canvas_fill_sprite_area(struct canvas *pcanvas, struct sprite *psprite,
+                             struct color *pcolor, int canvas_x, int canvas_y)
 {
   int width, height;
+
   get_sprite_dimensions(psprite, &width, &height);
   canvas_put_rectangle(pcanvas, pcolor, canvas_x, canvas_y, width, height);
 }
@@ -233,10 +222,9 @@ void canvas_fill_sprite_area(struct canvas *pcanvas,
   XXX: unlike other canvas_put functions, supplied x/y are *not* prior to
   any canvas zoom.
 ****************************************************************************/
-void canvas_put_line(struct canvas *pcanvas,
-		     struct color *pcolor,
-		     enum line_type ltype, int start_x, int start_y,
-		     int dx, int dy)
+void canvas_put_line(struct canvas *pcanvas, struct color *pcolor,
+                     enum line_type ltype, int start_x, int start_y,
+                     int dx, int dy)
 {
   cairo_t *cr;
   double dashes[2] = {4.0, 4.0};
@@ -245,9 +233,6 @@ void canvas_put_line(struct canvas *pcanvas,
     cr = cairo_create(pcanvas->surface);
   } else {
     cr = pcanvas->drawable;
-  }
-
-  if (pcanvas->drawable) {
     cairo_save(cr);
   }
 
@@ -343,8 +328,8 @@ static struct {
 #define FONT(font) (*fonts[font].styles)
 
 /************************************************************************//**
-  Return the size of the given text in the given font.  This size should
-  include the ascent and descent of the text.  Either of width or height
+  Return the size of the given text in the given font. This size should
+  include the ascent and descent of the text. Either of width or height
   may be NULL in which case those values simply shouldn't be filled out.
 ****************************************************************************/
 void get_text_size(int *width, int *height,
@@ -369,9 +354,9 @@ void get_text_size(int *width, int *height,
 }
 
 /************************************************************************//**
-  Draw the text onto the canvas in the given color and font.  The canvas
+  Draw the text onto the canvas in the given color and font. The canvas
   position does not account for the ascent of the text; this function must
-  take care of this manually.  The text will not be NULL but may be empty.
+  take care of this manually. The text will not be NULL but may be empty.
   Supplied canvas_x/y are prior to any canvas zoom.
 ****************************************************************************/
 void canvas_put_text(struct canvas *pcanvas, int canvas_x, int canvas_y,
@@ -384,9 +369,6 @@ void canvas_put_text(struct canvas *pcanvas, int canvas_x, int canvas_y,
     cr = cairo_create(pcanvas->surface);
   } else {
     cr = pcanvas->drawable;
-  }
-
-  if (pcanvas->drawable) {
     cairo_save(cr);
   }
 
diff --git a/client/gui-gtk-4.0/canvas.h b/client/gui-gtk-4.0/canvas.h
index 10b431c59b..e1bbe89dc7 100644
--- a/client/gui-gtk-4.0/canvas.h
+++ b/client/gui-gtk-4.0/canvas.h
@@ -25,10 +25,11 @@ struct canvas
   float zoom;
 };
 
-#define FC_STATIC_CANVAS_INIT { NULL, NULL, 1.0 }
+#define FC_STATIC_CANVAS_INIT \
+  { .surface = NULL, .drawable = NULL, .zoom = 1.0 }
 
 void surface_put_text(cairo_t *cr, int x, int y, float zoom,
                       enum client_font font, struct color *pcolor,
                       const char *text);
 
-#endif  /* FC__CANVAS_H */
+#endif /* FC__CANVAS_H */
-- 
2.39.2