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 LinkTypeSquared : Object, LinkType { 23 24 /* Default constructor */ 25 public LinkTypeSquared() {} 26 27 /* Returns the search name */ 28 public string name() { 29 return( "squared" ); 30 } 31 32 /* Returns the name of the link type */ 33 public string display_name() { 34 return( _( "Squared" ) ); 35 } 36 37 /* Returns the name of the icon */ 38 public string icon_name() { 39 return( "minder-link-squared-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 52 tipx = tipy = 0; 53 54 switch( side ) { 55 case NodeSide.LEFT : to_x += adj_a; tipx = to_x - adj_t; tipy = to_y; break; 56 case NodeSide.RIGHT : to_x -= adj_a; tipx = to_x + adj_t; tipy = to_y; break; 57 case NodeSide.TOP : to_y += adj_a; tipy = to_y - adj_t; tipx = to_x; break; 58 case NodeSide.BOTTOM : to_y -= adj_a; tipy = to_y + adj_t; tipx = to_x; break; 59 } 60 61 ctx.move_to( from_x, from_y ); 62 if( (side & NodeSide.horizontal()) != 0 ) { 63 var mid_x = ((from_x + to_x) / 2) + adjust_mid_by( from_node, side ); 64 tailx = mid_x; 65 taily = to_y; 66 ctx.line_to( mid_x, from_y ); 67 ctx.line_to( mid_x, to_y ); 68 ctx.line_to( to_x, to_y ); 69 } else { 70 var mid_y = ((from_y + to_y) / 2) + adjust_mid_by( from_node, side ); 71 tailx = to_x; 72 taily = mid_y; 73 ctx.line_to( from_x, mid_y ); 74 ctx.line_to( to_x, mid_y ); 75 ctx.line_to( to_x, to_y ); 76 } 77 ctx.stroke(); 78 79 } 80 81} 82 83