3 var <rangeSlider, <hiBox,<loBox, <unitView, <>controlSpec,
4 <>action,<lo, <hi, popUp=false, numSize,numberWidth,unitWidth;
7 *new { arg parent, bounds, label, controlSpec, action, initVal,
8 initAction=false, labelWidth=60, numberWidth=45,
9 unitWidth=0, labelHeight=20, layout=\horz, gap,margin;
11 ^super.new.init(parent, bounds, label, controlSpec, action,
12 initVal, initAction, labelWidth, numberWidth,
13 unitWidth, labelHeight, layout, gap, margin)
16 init { arg parentView, bounds, label, argControlSpec, argAction, initVal,
17 initAction, labelWidth, argNumberWidth,argUnitWidth,
18 labelHeight, argLayout, argGap,argMargin;
20 var labelBounds, hiBounds,loBounds, unitBounds,rangerBounds;
24 this.prMakeMarginGap(parentView, argMargin, argGap);
26 unitWidth = argUnitWidth;
27 numberWidth = argNumberWidth;
30 bounds.isNil.if{bounds = 350@20};
32 // if no parent, then pop up window
33 # view,bounds = this.prMakeView( parentView,bounds);
35 labelSize=labelWidth@labelHeight;
36 numSize = numberWidth@labelHeight;
39 # labelBounds,hiBounds,loBounds,rangerBounds, unitBounds
40 = this.prSubViewBounds(innerBounds, label.notNil, unitWidth>0);
42 label.notNil.if{ //only add a label if desired
43 labelView = GUI.staticText.new(view, labelBounds);
44 labelView.string = label;
47 (unitWidth>0).if{ //only add a unitLabel if desired
48 unitView = GUI.staticText.new(view, unitBounds);
52 loBox = GUI.numberBox.new(view, loBounds);
53 rangeSlider = GUI.rangeSlider.new(view, rangerBounds);
54 hiBox = GUI.numberBox.new(view, hiBounds);
56 controlSpec = argControlSpec.asSpec;
57 (unitWidth>0).if{unitView.string = " "++controlSpec.units.asString};
60 loBox.action_({ |box| this.lo_(box.value).doAction; });
61 rangeSlider.action_({ |sl|
62 this.lo_(controlSpec.map(sl.lo));
63 this.hi_(controlSpec.map(sl.hi));
66 hiBox.action_({ |box| this.hi_(box.value).doAction; });
68 if (initVal.notNil) { this.value_(initVal) };
69 if (initAction) { this.doAction };
72 // if (controlSpec.step != 0) {
73 // rangeSlider.step = (controlSpec.step / (controlSpec.maxval - controlSpec.minval));
76 numberStep = controlSpec.step;
77 if (numberStep == 0) {
78 numberStep = controlSpec.guessNumberStep;
80 // controlSpec wants a step, so zooming in with alt is disabled.
81 hiBox.alt_scale = 1.0;
82 loBox.alt_scale = 1.0;
83 rangeSlider.alt_scale = 1.0;
86 hiBox.step=numberStep;
87 loBox.step=numberStep;
88 hiBox.scroll_step=numberStep;
89 loBox.scroll_step=numberStep;
91 rangeSlider.receiveDragHandler = { arg slider;
92 slider.valueAction = controlSpec.unmap(GUI.view.currentDrag);
95 rangeSlider.beginDragAction = { arg slider;
96 controlSpec.map(slider.value)
103 doAction { action.value(this); }
105 set { arg label, spec, argAction, initVal, initAction = false;
106 labelView.notNil.if { labelView.string = label.asString };
107 spec.notNil.if { controlSpec = spec.asSpec };
108 argAction.notNil.if { action = argAction };
110 initVal = initVal ? this.value ? controlSpec.default.dup(2);
113 this.valueAction_(initVal);
115 this.value_(initVal);
120 value_ { |vals| this.lo_(vals[0]).hi_(vals[1]) }
121 valueAction_ { |vals| this.value_(vals).doAction }
124 lo = controlSpec.constrain(val);
125 loBox.value_(lo.round(round));
126 rangeSlider.lo_(controlSpec.unmap(lo));
130 hi = controlSpec.constrain(val);
131 hiBox.value_(hi.round(round));
132 rangeSlider.hi_(controlSpec.unmap(hi));
134 setColors{arg stringBackground, stringColor, sliderColor, numBackground,numStringColor,
135 numNormalColor, numTypingColor, knobColor,background ;
137 stringBackground.notNil.if{
138 labelView.notNil.if{labelView.background_(stringBackground)};
139 unitView.notNil.if{unitView.background_(stringBackground)};};
140 stringColor.notNil.if{
141 labelView.notNil.if{labelView.stringColor_(stringColor)};
142 unitView.notNil.if{unitView.stringColor_(stringColor)};};
143 sliderColor.notNil.if{
144 rangeSlider.background_(sliderColor);};
145 numBackground.notNil.if{
146 hiBox.background_(numBackground);
147 loBox.background_(numBackground);};
148 numNormalColor.notNil.if{
149 hiBox.normalColor_(numNormalColor);
150 loBox.normalColor_(numNormalColor);};
151 numTypingColor.notNil.if{
152 hiBox.typingColor_(numTypingColor);
153 loBox.typingColor_(numTypingColor);};
154 numStringColor.notNil.if{
155 hiBox.stringColor_(numStringColor);
156 loBox.stringColor_(numStringColor);};
158 rangeSlider.knobColor_(knobColor);};
159 background.notNil.if{
160 view.background=background;};
166 labelView.notNil.if{labelView.font=font};
167 unitView.notNil.if{unitView.font=font};
178 labelView.resize_(2);
179 unitView.notNil.if{unitView.resize_(3)};
184 unitView.resize_(2).align_(\left)};
188 rangeSlider.resize_(5);
189 popUp.if{view.resize_(2)};
192 labelView.notNil.if{labelView.resize_(2)};
193 unitView.notNil.if{unitView.resize_(8)};
196 rangeSlider.resize_(5);
197 popUp.if{view.resize_(4)};
200 labelView.notNil.if{labelView.resize_(4).align_(\right)};
201 unitView.notNil.if{unitView.resize_(6)};
204 rangeSlider.resize_(5);
205 popUp.if{view.resize_(2)};
208 prSubViewBounds{arg rect, hasLabel, hasUnit;
209 var hiBounds,loBounds,labelBounds,rangerBounds;
210 var unitBounds, gap1, gap2, gap3,gap4, tmp, labelH, unitH;
211 gap1 = gap.copy; // use copy to make sure these are unique
212 gap2 = gap.copy; // since you later set the .x or .y
215 labelH=labelSize.y;// needed for \vert
216 unitH=labelSize.y; // needed for \vert
220 hasLabel.not.if{ gap2 = 0@0; labelSize.x = 0 ;};
221 hasUnit.not.if{ gap4 = 0@0; unitWidth = 0};
222 hasLabel.if{ // with label
223 unitBounds = (unitWidth@labelSize.y)
224 .asRect.left_(rect.width-unitWidth);// view to right
225 hiBounds = (numSize.x@labelSize.y)
226 .asRect.left_(rect.width-unitBounds.width-numberWidth-gap4.x); // view to right
227 loBounds = (numSize.x@labelSize.y)
228 .asRect.left_(rect.width-unitBounds.width-numberWidth
229 -gap3.x-hiBounds.width-gap4.x); // view to right
230 labelBounds = (labelSize.x@labelSize.y)
231 .asRect.width_(loBounds.left-gap2.x); //adjust width
233 labelBounds = (0@labelSize.y).asRect; //just a dummy
234 loBounds = (numberWidth@labelSize.y).asRect; //view to left
235 hiBounds = (numberWidth@labelSize.y).asRect.moveTo(loBounds.width+gap3.x,0); //view to left
237 unitBounds = Rect.newSides (hiBounds.right+gap4.x,
238 0,rect.width, labelSize.y); //adjust width
240 unitBounds = Rect (0, 0,0,0); //no unitView
248 rect.height-numSize.y-gap1.y;
253 hasLabel.not.if{labelH=0; gap1.y=0};
254 labelBounds = (rect.width@labelH).asRect; // to top
255 hasUnit.not.if{unitH=0; gap4 = 0@0;};
256 unitBounds = (rect.width@unitH)
257 .asRect.top_(rect.height-unitH); // to bottom
258 hiBounds = (rect.width@labelSize.y)
259 .asRect.top_(labelBounds.height+gap1.y); // to bottom
260 loBounds = (rect.width@labelSize.y)
261 .asRect.top_(rect.height-unitBounds.height-numSize.y-gap4.y); // to bottom
262 rangerBounds = Rect.newSides(
264 hiBounds.bottom+gap2.y,
271 hasLabel.not.if{ gap1 = 0@0; labelSize.x = 0 ;};
272 hasUnit.not.if{ gap4 = 0@0; unitWidth = 0};
273 labelSize.y=rect.height;
274 labelBounds = (labelSize.x@labelSize.y).asRect;
275 unitBounds = (unitWidth@labelSize.y).asRect.left_(rect.width-unitWidth);
276 loBounds = (numSize.x@labelSize.y).asRect
277 .left_(labelBounds.width+gap1.x);
278 hiBounds = (numSize.x@labelSize.y).asRect
279 .left_(rect.width-unitBounds.width-numSize.x-gap4.x);
280 rangerBounds = Rect.newSides(
281 loBounds.right+gap2.x , 0,
282 rect.width-hiBounds.width-unitBounds.width
289 ^[labelBounds, hiBounds, loBounds, rangerBounds, unitBounds]
290 .collect{arg v; v.moveBy(margin.x,margin.y)}