1 /** 2 * Outline dash module. 3 * 4 * License: 5 * MIT. See LICENSE for full details. 6 */ 7 module tkd.widget.common.canvas.outlinedash; 8 9 /** 10 * These are common commands that apply to all widgets that have them injected. 11 */ 12 mixin template OutlineDash() 13 { 14 import std.algorithm; 15 import std.array; 16 import std.conv; 17 18 /** 19 * The dash pattern. 20 */ 21 private int[] _outlineDash; 22 23 /** 24 * The active dash pattern. 25 */ 26 private int[] _activeOutlineDash; 27 28 /** 29 * The disabled dash pattern. 30 */ 31 private int[] _disabledOutlineDash; 32 33 /** 34 * The dash offset. 35 */ 36 private int _outlineDashOffset; 37 38 /** 39 * Get the dash pattern. 40 * 41 * Returns: 42 * The dash pattern of the item. 43 */ 44 public int[] getOutlineDash() 45 { 46 if (this._parent) 47 { 48 this._tk.eval("%s itemcget %s -dash", this._parent.id, this.id); 49 this._outlineDash = this._tk.getResult!(string).split().map!(to!(int)).array; 50 } 51 52 return this._outlineDash; 53 } 54 55 /** 56 * Set the dash pattern of the outline. Each element represents the number 57 * of pixels of a line segment. Only the odd segments are drawn using the 58 * outline color. The other segments are drawn transparent. 59 * 60 * Params: 61 * dash = The dash pattern. 62 * 63 * Returns: 64 * This widget to aid method chaining. 65 */ 66 public auto setOutlineDash(this T)(int[] dash) 67 { 68 this._outlineDash = dash; 69 70 if (this._parent && this._outlineDash.length) 71 { 72 this._tk.eval("%s itemconfigure %s -dash [list %s]", this._parent.id, this.id, this._outlineDash.map!(to!(string)).join(" ")); 73 } 74 75 return cast(T) this; 76 } 77 78 /** 79 * Get the active dash pattern. 80 * An item's active state is triggered when the mouse rolls over the item. 81 * 82 * Returns: 83 * The active dash pattern of the item. 84 */ 85 public int[] getActiveOutlineDash() 86 { 87 if (this._parent) 88 { 89 this._tk.eval("%s itemcget %s -activedash", this._parent.id, this.id); 90 this._activeOutlineDash = this._tk.getResult!(string).split().map!(to!(int)).array; 91 } 92 93 return this._activeOutlineDash; 94 } 95 96 /** 97 * Set the active dash pattern of the outline. Each element represents the 98 * number of pixels of a line segment. Only the odd segments are drawn 99 * using the outline color. The other segments are drawn transparent. An 100 * item's active state is triggered when the mouse rolls over the item. 101 * 102 * Params: 103 * dash = The active dash pattern. 104 * 105 * Returns: 106 * This widget to aid method chaining. 107 */ 108 public auto setActiveOutlineDash(this T)(int[] dash) 109 { 110 this._activeOutlineDash = dash; 111 112 if (this._parent && this._activeOutlineDash.length) 113 { 114 this._tk.eval("%s itemconfigure %s -activedash [list %s]", this._parent.id, this.id, this._activeOutlineDash.map!(to!(string)).join(" ")); 115 } 116 117 return cast(T) this; 118 } 119 120 /** 121 * Get the disabled dash pattern. 122 * 123 * Returns: 124 * The disabled dash pattern of the item. 125 */ 126 public int[] getDisabledOutlineDash() 127 { 128 if (this._parent) 129 { 130 this._tk.eval("%s itemcget %s -disableddash", this._parent.id, this.id); 131 this._disabledOutlineDash = this._tk.getResult!(string).split().map!(to!(int)).array; 132 } 133 134 return this._disabledOutlineDash; 135 } 136 137 /** 138 * Set the disabled dash pattern of the outline. Each element represents the 139 * number of pixels of a line segment. Only the odd segments are drawn 140 * using the outline color. The other segments are drawn transparent. 141 * 142 * Params: 143 * dash = The disabled dash pattern. 144 * 145 * Returns: 146 * This widget to aid method chaining. 147 */ 148 public auto setDisabledOutlineDash(this T)(int[] dash) 149 { 150 this._disabledOutlineDash = dash; 151 152 if (this._parent && this._disabledOutlineDash.length) 153 { 154 this._tk.eval("%s itemconfigure %s -disableddash [list %s]", this._parent.id, this.id, this._disabledOutlineDash.map!(to!(string)).join(" ")); 155 } 156 157 return cast(T) this; 158 } 159 160 /** 161 * Get the dash offset. 162 * 163 * Returns: 164 * The dash offset. 165 */ 166 public int getOutlineDashOffset() 167 { 168 if (this._parent) 169 { 170 this._tk.eval("%s itemcget %s -dashoffset", this._parent.id, this.id); 171 this._outlineDashOffset = this._tk.getResult!(int); 172 } 173 174 return this._outlineDashOffset; 175 } 176 177 /** 178 * Set the dash offset. 179 * 180 * Params: 181 * offset = The dash offset. 182 * 183 * Returns: 184 * This widget to aid method chaining. 185 */ 186 public auto setOutlineDashOffset(this T)(int offset) 187 { 188 this._outlineDashOffset = offset; 189 190 if (this._parent && this._outlineDashOffset > 0) 191 { 192 this._tk.eval("%s itemconfigure %s -dashoffset %s", this._parent.id, this.id, this._outlineDashOffset); 193 } 194 195 return cast(T) this; 196 } 197 }