1 /**
2  * Arc specific module.
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tkd.widget.common.canvas.arcspecific;
8 
9 /**
10  * These are common commands that apply to all widgets that have them injected.
11  */
12 mixin template ArcSpecific()
13 {
14 	import std.typecons : Nullable;
15 
16 	/**
17 	 * The style of the arc.
18 	 */
19 	private string _style;
20 
21 	/**
22 	 * The extent of the arc.
23 	 */
24 	private int _extent;
25 
26 	/**
27 	 * The start angle of the arc.
28 	 */
29 	private Nullable!(double) _startAngle;
30 
31 	/**
32 	 * Get the style of the arc.
33 	 *
34 	 * Returns:
35 	 *     The style of the arc;
36 	 */
37 	public string getStyle()
38 	{
39 		if (this._parent)
40 		{
41 			this._tk.eval("%s itemcget %s -style", this._parent.id, this.id);
42 			this._style = this._tk.getResult!(string);
43 		}
44 
45 		return this._style;
46 	}
47 
48 	/**
49 	 * Specifies how to draw the arc. If type is pie (the default) then the 
50 	 * arc's region is defined by a section of the oval's perimeter plus two 
51 	 * line segments, one between the center of the oval and each end of the 
52 	 * perimeter section. If type is chord then the arc's region is defined by 
53 	 * a section of the oval's perimeter plus a single line segment connecting 
54 	 * the two end points of the perimeter section. If type is arc then the 
55 	 * arc's region consists of a section of the perimeter alone. In this last 
56 	 * case the fill color is ignored.
57 	 *
58 	 * Params:
59 	 *    style = The style of the arc.
60 	 *
61 	 * Returns:
62 	 *     This item to aid method chaining.
63 	 *
64 	 * See_Also:
65 	 *     $(LINK2 ../../canvas.html#CanvasArcStyle, tkd.widget.canvas.CanvasArcStyle)
66 	 */
67 	public auto setStyle(this T)(string style)
68 	{
69 		this._style = style;
70 
71 		if (this._parent && this._style.length)
72 		{
73 			this._tk.eval("%s itemconfigure %s -style {%s}", this._parent.id, this.id, this._style);
74 		}
75 
76 		return cast(T) this;
77 	}
78 
79 	/**
80 	 * Get the extent of the arc.
81 	 *
82 	 * Returns:
83 	 *     The extent of the arc;
84 	 */
85 	public int getExtent()
86 	{
87 		if (this._parent)
88 		{
89 			this._tk.eval("%s itemcget %s -extent", this._parent.id, this.id);
90 			this._extent = this._tk.getResult!(int);
91 		}
92 
93 		return this._extent;
94 	}
95 
96 	/**
97 	 * Specifies the size of the angular range occupied by the arc. The arc's 
98 	 * range extends for degrees counter-clockwise from the starting angle. 
99 	 * Degrees may be negative. If it is greater than 360 or less than -360, 
100 	 * then degrees modulo 360 is used as the extent.
101 	 *
102 	 * Params:
103 	 *    extent = The extent of the arc.
104 	 *
105 	 * Returns:
106 	 *     This item to aid method chaining.
107 	 */
108 	public auto setExtent(this T)(int extent)
109 	{
110 		this._extent = extent;
111 
112 		if (this._parent && this._extent > 0)
113 		{
114 			this._tk.eval("%s itemconfigure %s -extent %s", this._parent.id, this.id, this._extent);
115 		}
116 
117 		return cast(T) this;
118 	}
119 
120 	/**
121 	 * Get the start angle of the arc.
122 	 *
123 	 * Returns:
124 	 *     The start angle of the arc;
125 	 */
126 	public double getStartAngle()
127 	{
128 		if (this._parent)
129 		{
130 			this._tk.eval("%s itemcget %s -start", this._parent.id, this.id);
131 			this._startAngle = this._tk.getResult!(double);
132 		}
133 
134 		return this._startAngle.isNull ? 0.0 : this._startAngle.get;
135 	}
136 
137 	/**
138 	 * Specifies the beginning of the angular range occupied by the arc. 
139 	 * Degrees is given in units of degrees measured counter-clockwise from the 
140 	 * 3-o'clock position; it may be either positive or negative.
141 	 *
142 	 * Params:
143 	 *    startAngle = The start angle of the arc.
144 	 *
145 	 * Returns:
146 	 *     This item to aid method chaining.
147 	 */
148 	public auto setStartAngle(this T, A)(A startAngle) if (is(A == double) || is(A == Nullable!(double)))
149 	{
150 		static if (is(A == Nullable!(double)))
151 		{
152 			if (startAngle.isNull)
153 			{
154 				return cast(T) this;
155 			}
156 		}
157 
158 		this._startAngle = startAngle;
159 
160 		if (this._parent)
161 		{
162 			this._tk.eval("%s itemconfigure %s -start %s", this._parent.id, this.id, this._startAngle);
163 		}
164 
165 		return cast(T) this;
166 	}
167 }