1/*
2* Copyright (c) 2018 (https://github.com/phase1geo/Minder)
3*
4* This program is free software; you can redistribute it and/or
5* modify it under the terms of the GNU General Public
6* License as published by the Free Software Foundation; either
7* version 2 of the License, or (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12* General Public License for more details.
13*
14* You should have received a copy of the GNU General Public
15* License along with this program; if not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17* Boston, MA 02110-1301 USA
18*
19* Authored by: Trevor Williams <phase1geo@gmail.com>
20*/
21
22public class LinkTypeCurved : Object, LinkType {
23
24  /* Default constructor */
25  public LinkTypeCurved() {}
26
27  /* Returns the search name */
28  public string name() {
29    return( "curved" );
30  }
31
32  /* Returns the name of the link type */
33  public string display_name() {
34    return( _( "Curved" ) );
35  }
36
37  /* Returns the name of the icon */
38  public string icon_name() {
39    return( "minder-link-curved-symbolic" );
40  }
41
42  /* Draw method for the link */
43  public void draw( Cairo.Context ctx, Node from_node, Node to_node,
44                    double from_x, double from_y, double to_x, double to_y,
45                    out double tailx, out double taily, out double tipx, out double tipy ) {
46
47    var side  = to_node.side;
48    var style = to_node.style;
49    var adj_a = adjust_a( style );
50    var adj_t = adjust_tip( style );
51    var x_adj = (to_x - from_x) * 0.5;
52    var y_adj = (to_y - from_y) * 0.5;
53
54    tipx = tipy = 0;
55
56    switch( side ) {
57      case NodeSide.LEFT   :  to_x += adj_a;  tipx = to_x - adj_t;  tipy = to_y;  break;
58      case NodeSide.RIGHT  :  to_x -= adj_a;  tipx = to_x + adj_t;  tipy = to_y;  break;
59      case NodeSide.TOP    :  to_y += adj_a;  tipx = to_x;  tipy = to_y - adj_t;  break;
60      case NodeSide.BOTTOM :  to_y -= adj_a;  tipx = to_x;  tipy = to_y + adj_t;  break;
61    }
62
63    ctx.move_to( from_x, from_y );
64    if( (side & NodeSide.horizontal()) != 0 ) {
65      tailx = from_x + x_adj;
66      taily = from_y + ((to_y - from_y) * 0.95);
67      ctx.curve_to( (to_x - x_adj), from_y, (from_x + x_adj), to_y, to_x, to_y );
68    } else {
69      tailx = from_x + ((to_x - from_x) * 0.95);
70      taily = from_y + y_adj;
71      ctx.curve_to( from_x, (to_y - y_adj), to_x, (from_y + y_adj), to_x, to_y );
72    }
73    ctx.stroke();
74
75  }
76
77}
78
79