<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40221 >

Updated patch for S2_1 and S2_2/trunk.

I also change a few things:
- Renamed canvas_put_bezier_line to canvas_put_curved_line.
- Fixed some formatting and removed purely whitespace changes.
- Removed body duplication of canvas_put_line in GUI front-ends
  where canvas_put_curved_line was not implemented.
- Added an option to enable curved line drawing (default off,
  since it only affects gui-gtk-2.0).


----------------------------------------------------------------------
その事を忘れるのはおろか、この私が生まれた日から全部思い出せるよ。

 client/gui-ftwl/canvas.c    |   12 ++++++
 client/gui-gtk-2.0/canvas.c |   89 +++++++++++++++++++++++++++++++++++++++++++
 client/gui-sdl/canvas.c     |   11 +++++
 client/gui-stub/canvas.c    |   10 +++++
 client/gui-win32/canvas.c   |   11 +++++
 client/gui-xaw/mapview.c    |   12 ++++++
 client/include/canvas_g.h   |    4 ++
 client/options.c            |    8 ++++
 client/options.h            |    1 +
 client/reqtree.c            |   15 +++++--
 10 files changed, 169 insertions(+), 4 deletions(-)

diff --git a/client/gui-ftwl/canvas.c b/client/gui-ftwl/canvas.c
index a352f43..50f88a1 100644
--- a/client/gui-ftwl/canvas.c
+++ b/client/gui-ftwl/canvas.c
@@ -183,6 +183,18 @@ void canvas_put_line(struct canvas *pcanvas, struct color *pcolor,
   }
 }
 
+/**************************************************************************
+  Draw a 1-pixel-width curved colored line onto the mapview or 
+  citydialog canvas.
+**************************************************************************/
+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)
+{
+  /* FIXME: Implement curved line drawing. */
+  canvas_put_line(pcanvas, pcolor, ltype, start_x, start_y, dx, dy);
+}
+
 /****************************************************************************
   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
diff --git a/client/gui-gtk-2.0/canvas.c b/client/gui-gtk-2.0/canvas.c
index ed1526c..06340b1 100644
--- a/client/gui-gtk-2.0/canvas.c
+++ b/client/gui-gtk-2.0/canvas.c
@@ -265,6 +265,95 @@ 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,
+                            enum line_type ltype, int start_x, int start_y,
+                            int dx, int dy)
+{
+  if (pcanvas->type == CANVAS_PIXMAP) {
+    GdkGC *gc = NULL;
+    
+    switch (ltype) {
+    case LINE_NORMAL:
+      gc = thin_line_gc;
+      break;
+    case LINE_BORDER:
+      gc = border_line_gc;
+      break;
+    case LINE_TILE_FRAME:
+      gc = thick_line_gc;
+      break;
+    case LINE_GOTO:
+      gc = thick_line_gc;
+      break;
+    }
+
+    gdk_gc_set_foreground(gc, &pcolor->color);
+
+    /* To begin, work out the endpoints of the curve */
+    /* and initial horizontal stroke */
+    int line1end_x = start_x + 10;
+    int end_x = start_x + dx;
+    int end_y = start_y + dy;
+    
+    int arcwidth = dx - 10;
+    /* draw a short horizontal line */
+    gdk_draw_line(pcanvas->v.pixmap, gc,
+                  start_x, start_y, line1end_x, start_y);
+
+    if (end_y < start_y) {
+      /* if end_y is above start_y then the first curve is rising */
+      int archeight = -dy + 1;
+
+      /* position the BB of the arc */
+      int arcstart_x = line1end_x-arcwidth/2 -1;
+      int arcstart_y = end_y-1;
+
+      /* Draw arc curving up */
+      gdk_draw_arc(pcanvas->v.pixmap, gc, FALSE,
+                   arcstart_x, arcstart_y, 
+                   arcwidth, archeight, 0, -90*64);
+
+      /* Shift BB to the right */
+      arcstart_x = arcstart_x + arcwidth;
+
+      /* draw arc curving across */
+      gdk_draw_arc(pcanvas->v.pixmap, gc, FALSE,
+                   arcstart_x, arcstart_y, 
+                   arcwidth, archeight, 180*64, -90*64);
+
+    } else { /* end_y is below start_y */
+
+      int archeight = dy + 1;
+
+      /* position BB */
+      int arcstart_x = line1end_x - arcwidth/2 -1;
+      int arcstart_y = start_y-1;
+
+      /* Draw arc curving down */
+      gdk_draw_arc(pcanvas->v.pixmap, gc, FALSE,
+                   arcstart_x, arcstart_y, 
+                   arcwidth, archeight, 0, 90*64);
+
+      /* shift BB right */
+      arcstart_x = arcstart_x + arcwidth;
+
+      /* Draw arc curving across */
+      gdk_draw_arc(pcanvas->v.pixmap, gc, FALSE,
+                   arcstart_x, arcstart_y, 
+                   arcwidth, archeight, 270*64, -90*64);
+
+    }
+    /* Draw short horizontal line */
+    gdk_draw_line(pcanvas->v.pixmap, gc,
+                  end_x - 10, start_y + dy, end_x, end_y);
+  }
+}
+
 static PangoLayout *layout;
 static struct {
   PangoFontDescription **font;
diff --git a/client/gui-sdl/canvas.c b/client/gui-sdl/canvas.c
index 63dc4f0..1d3f52d 100644
--- a/client/gui-sdl/canvas.c
+++ b/client/gui-sdl/canvas.c
@@ -193,6 +193,17 @@ void canvas_put_line(struct canvas *pcanvas, struct color *pcolor,
 }
 
 /****************************************************************************
+  Draw a 1-pixel-width colored curved line onto the canvas.
+****************************************************************************/
+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)
+{
+  /* FIXME: Implement curved line drawing. */
+  canvas_put_line(pcanvas, pcolor, ltype, start_x, start_y, dx, dy);
+}
+
+/****************************************************************************
   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.
diff --git a/client/gui-stub/canvas.c b/client/gui-stub/canvas.c
index 60a969b..be09402 100644
--- a/client/gui-stub/canvas.c
+++ b/client/gui-stub/canvas.c
@@ -118,6 +118,16 @@ void canvas_put_line(struct canvas *pcanvas, struct color *pcolor,
 }
 
 /****************************************************************************
+  Draw a 1-pixel-width colored curved line onto the canvas.
+****************************************************************************/
+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)
+{
+  /* PORTME */
+}
+
+/****************************************************************************
   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.
diff --git a/client/gui-win32/canvas.c b/client/gui-win32/canvas.c
index a4e1c25..f9011ee 100644
--- a/client/gui-win32/canvas.c
+++ b/client/gui-win32/canvas.c
@@ -344,3 +344,14 @@ void canvas_put_line(struct canvas *pcanvas, struct color *pcolor,
 
   canvas_release_hdc(pcanvas);
 }
+
+/**************************************************************************
+  Draw a 1-pixel-width colored curved line onto the canvas.
+**************************************************************************/
+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)
+{
+  /* FIXME: Implement curved line drawing. */
+  canvas_put_line(pcanvas, pcolor, ltype, start_x, start_y, dx, dy);
+}
diff --git a/client/gui-xaw/mapview.c b/client/gui-xaw/mapview.c
index 0e588ee..5d86b67 100644
--- a/client/gui-xaw/mapview.c
+++ b/client/gui-xaw/mapview.c
@@ -522,6 +522,18 @@ void canvas_put_line(struct canvas *pcanvas, struct color *pcolor,
 }
 
 /**************************************************************************
+  Draw a 1-pixel-width curved colored line onto the mapview or 
+  citydialog canvas.
+**************************************************************************/
+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)
+{
+  /* FIXME: Implement curved line drawing. */
+  canvas_put_line(pcanvas, pcolor, ltype, start_x, start_y, dx, dy);
+}
+
+/**************************************************************************
   Flush the given part of the canvas buffer (if there is one) to the
   screen.
 **************************************************************************/
diff --git a/client/include/canvas_g.h b/client/include/canvas_g.h
index 8b9ba44..5f01fe5 100644
--- a/client/include/canvas_g.h
+++ b/client/include/canvas_g.h
@@ -55,6 +55,10 @@ 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_curved_line(struct canvas *pcanvas,
+                            struct color *pcolor,
+                            enum line_type ltype, int start_x, int start_y,
+                            int dx, int dy);
 
 /* Text drawing functions */
 enum client_font {
diff --git a/client/options.c b/client/options.c
index aac4e31..c54cfef 100644
--- a/client/options.c
+++ b/client/options.c
@@ -194,6 +194,13 @@ static client_option common_options[] = {
 		        "this option off makes the technology tree "
 		        "more compact."),
 		     COC_GRAPHICS, reqtree_show_icons_callback),
+  GEN_BOOL_OPTION_CB(reqtree_curved_lines,
+                     N_("Use curved lines in the technology tree"),
+                     N_("Setting this option make the technology tree "
+                        "diagram use curved lines to show technology "
+                        "relations. Turning this option off causes "
+                        "the lines to be drawn straight."),
+		     COC_GRAPHICS, reqtree_show_icons_callback),
   GEN_BOOL_OPTION_CB(draw_unit_shields, N_("Draw shield graphics for units"),
 		     N_("Setting this option will draw a shield icon "
 			"as the flags on units.  If unset, the full flag will "
@@ -302,6 +309,7 @@ bool draw_full_citybar = TRUE;
 bool draw_unit_shields = TRUE;
 bool player_dlg_show_dead_players = TRUE;
 bool reqtree_show_icons = TRUE;
+bool reqtree_curved_lines = FALSE;
 
 #define VIEW_OPTION(name) { #name, &name }
 #define VIEW_OPTION_TERMINATOR { NULL, NULL }
diff --git a/client/options.h b/client/options.h
index da43be2..e6651b5 100644
--- a/client/options.h
+++ b/client/options.h
@@ -165,6 +165,7 @@ extern bool draw_unit_shields;
 
 extern bool player_dlg_show_dead_players;
 extern bool reqtree_show_icons;
+extern bool reqtree_curved_lines;
 
 typedef struct {
   const char *name;
diff --git a/client/reqtree.c b/client/reqtree.c
index 553efce..e2e2015 100644
--- a/client/reqtree.c
+++ b/client/reqtree.c
@@ -1011,6 +1011,7 @@ void draw_reqtree(struct reqtree *tree, struct canvas *pcanvas,
   int i, j, k;
   int swidth, sheight;
   struct sprite* sprite;
+  struct color *color;
 
   /* draw the diagram */
   for (i = 0; i < tree->num_layers; i++) {
@@ -1114,14 +1115,20 @@ void draw_reqtree(struct reqtree *tree, struct canvas *pcanvas,
       starty = node->node_y + node->node_height / 2;
       for (k = 0; k < node->nprovide; k++) {
 	struct tree_node *dest_node = node->provide[k];
+	color = get_color(tileset, edge_color(node, dest_node));
 
 	endx = dest_node->node_x;
 	endy = dest_node->node_y + dest_node->node_height / 2;
 	
-	canvas_put_line(pcanvas,
-		        get_color(tileset, edge_color(node, dest_node)),
-		        LINE_GOTO,
-		        startx, starty, endx - startx, endy - starty);
+        if (reqtree_curved_lines) {
+          canvas_put_curved_line(pcanvas, color, LINE_GOTO,
+                                 startx, starty, endx - startx,
+                                 endy - starty);
+        } else {
+          canvas_put_line(pcanvas, color, LINE_GOTO,
+                          startx, starty, endx - startx,
+                          endy - starty);
+        }
       }
     }
   }
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to