1 /**
2  * Vertex module.
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tkd.widget.common.canvas.vertex;
8 
9 /**
10  * These are common commands that apply to all widgets that have them injected.
11  */
12 mixin template Vertex()
13 {
14 	/**
15 	 * The style of the joins.
16 	 */
17 	private string _joinStyle;
18 
19 	/**
20 	 * The smoothing method used for the line.
21 	 */
22 	private string _smoothMethod;
23 
24 	/**
25 	 * Defines how many splines to use for smoothing.
26 	 */
27 	private int _splineSteps;
28 
29 	/**
30 	 * Get the join style.
31 	 *
32 	 * Returns:
33 	 *     The join style.
34 	 */
35 	public string getJoinStyle()
36 	{
37 		if (this._parent)
38 		{
39 			this._tk.eval("%s itemcget %s -joinstyle", this._parent.id, this.id);
40 			this._joinStyle = this._tk.getResult!(string);
41 		}
42 
43 		return this._joinStyle;
44 	}
45 
46 	/**
47 	 * Specifies the ways in which joints are to be drawn at the vertices of 
48 	 * the line. If this option is not specified then it defaults to round. If 
49 	 * the line only contains two points then this option is irrelevant.
50 	 *
51 	 * Params:
52 	 *    joinStyle = The join style.
53 	 *
54 	 * Returns:
55 	 *     This item to aid method chaining.
56 	 *
57 	 * See_Also:
58 	 *     $(LINK2 ../../canvas.html#CanvasLineJoinStyle, tkd.widget.canvas.CanvasLineJoinStyle)
59 	 */
60 	public auto setJoinStyle(this T)(string joinStyle)
61 	{
62 		this._joinStyle = joinStyle;
63 
64 		if (this._parent && this._joinStyle.length)
65 		{
66 			this._tk.eval("%s itemconfigure %s -joinstyle {%s}", this._parent.id, this.id, this._joinStyle);
67 		}
68 
69 		return cast(T) this;
70 	}
71 
72 	/**
73 	 * Get the smooth method.
74 	 *
75 	 * Returns:
76 	 *     The smooth method.
77 	 */
78 	public string getSmoothMethod()
79 	{
80 		if (this._parent)
81 		{
82 			this._tk.eval("%s itemcget %s -smooth", this._parent.id, this.id);
83 			this._smoothMethod = this._tk.getResult!(string);
84 		}
85 
86 		return this._smoothMethod;
87 	}
88 
89 	/**
90 	 * If the smoothing method is bezier, this indicates that the line should 
91 	 * be drawn as a curve, rendered as a set of quadratic splines: one spline 
92 	 * is drawn for the first and second line segments, one for the second and 
93 	 * third, and so on. Straight-line segments can be generated within a curve 
94 	 * by duplicating the end-points of the desired line segment. If the 
95 	 * smoothing method is raw, this indicates that the line should also be 
96 	 * drawn as a curve but where the list of coordinates is such that the 
97 	 * first coordinate pair (and every third coordinate pair thereafter) is a 
98 	 * knot point on a cubic bezier curve, and the other coordinates are 
99 	 * control points on the cubic bezier curve. Straight line segments can be 
100 	 * generated within a curve by making control points equal to their 
101 	 * neighbouring knot points. If the last point is a control point and not a 
102 	 * knot point, the point is repeated (one or two times) so that it also 
103 	 * becomes a knot point.
104 	 *
105 	 * Params:
106 	 *    smoothMethod = The smooth method.
107 	 *
108 	 * Returns:
109 	 *     This item to aid method chaining.
110 	 *
111 	 * See_Also:
112 	 *     $(LINK2 ../../canvas.html#CanvasLineSmoothMethod, tkd.widget.canvas.CanvasLineSmoothMethod)
113 	 */
114 	public auto setSmoothMethod(this T)(string smoothMethod)
115 	{
116 		this._smoothMethod = smoothMethod;
117 
118 		if (this._parent && this._smoothMethod.length)
119 		{
120 			this._tk.eval("%s itemconfigure %s -smooth {%s}", this._parent.id, this.id, this._smoothMethod);
121 		}
122 
123 		return cast(T) this;
124 	}
125 
126 	/**
127 	 * Get smooth method spline steps.
128 	 *
129 	 * Returns:
130 	 *     The smooth method spline steps.
131 	 */
132 	public int getSmoothSplineSteps()
133 	{
134 		if (this._parent)
135 		{
136 			this._tk.eval("%s itemcget %s -splinesteps", this._parent.id, this.id);
137 			this._splineSteps = this._tk.getResult!(int);
138 		}
139 
140 		return this._splineSteps;
141 	}
142 
143 	/**
144 	 * Specifies the degree of smoothness desired for curves: each spline will 
145 	 * be approximated with number line segments.
146 	 *
147 	 * Params:
148 	 *    splineSteps = The smooth method spline steps.
149 	 *
150 	 * Returns:
151 	 *     This item to aid method chaining.
152 	 */
153 	public auto setSmoothSplineSteps(this T)(int splineSteps)
154 	{
155 		this._splineSteps = splineSteps;
156 
157 		if (this._parent && this._splineSteps > 0)
158 		{
159 			this._tk.eval("%s itemconfigure %s -splinesteps %s", this._parent.id, this.id, this._splineSteps);
160 		}
161 
162 		return cast(T) this;
163 	}
164 }