-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEZFancySlider.sc
122 lines (96 loc) · 3.44 KB
/
EZFancySlider.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
EZFancySlider : EZSlider {
init { arg parentView, bounds, label, argControlSpec, argAction, initVal,
initAction, labelWidth, argNumberWidth,argUnitWidth,
labelHeight, argLayout, argGap, argMargin;
var labelBounds, numBounds, unitBounds,sliderBounds;
var numberStep;
//try{SwingGUI.put(\fancySlider, JSCFancySlider);};
// Set Margin and Gap
this.prMakeMarginGap(parentView, argMargin, argGap);
unitWidth = argUnitWidth;
numberWidth = argNumberWidth;
layout=argLayout;
bounds.isNil.if{bounds = 350@20};
// if no parent, then pop up window
# view,bounds = this.prMakeView( parentView,bounds);
labelSize=labelWidth@labelHeight;
numSize = numberWidth@labelHeight;
// calculate bounds of all subviews
# labelBounds,numBounds,sliderBounds, unitBounds
= this.prSubViewBounds(innerBounds, label.notNil, unitWidth>0);
// instert the views
label.notNil.if{ //only add a label if desired
labelView = GUI.staticText.new(view, labelBounds);
labelView.string = label;
};
(unitWidth>0).if{ //only add a unitLabel if desired
unitView = GUI.staticText.new(view, unitBounds);
};
sliderView = FancySlider.new(view, sliderBounds);
numberView = GUI.numberBox.new(view, numBounds);
// set view parameters and actions
controlSpec = argControlSpec.asSpec;
controlSpec.addDependant(this);
this.onClose = { controlSpec.removeDependant(this) };
(unitWidth>0).if{unitView.string = " "++controlSpec.units.asString};
initVal = initVal ? controlSpec.default;
action = argAction;
sliderView.action = {
this.valueAction_(controlSpec.map(sliderView.value));
};
sliderView.receiveDragHandler = { arg slider;
sliderView.valueAction = controlSpec.unmap(GUI.view.currentDrag);
};
sliderView.beginDragAction = { arg slider;
controlSpec.map(sliderView.value);
};
numberView.action = { this.valueAction_(numberView.value) };
numberStep = controlSpec.step;
if (numberStep == 0) {
numberStep = controlSpec.guessNumberStep
}{
// controlSpec wants a step, so zooming in with alt is disabled.
numberView.alt_scale = 1.0;
sliderView.alt_scale = 1.0;
};
numberView.step = numberStep;
numberView.scroll_step = numberStep;
//numberView.scroll=true;
if (initAction) {
this.valueAction_(initVal);
}{
this.value_(initVal);
};
if (labelView.notNil) {
labelView.mouseDownAction = {|view, x, y, modifiers, buttonNumber, clickCount|
if(clickCount == 2, {this.editSpec});
}
};
this.prSetViewParams;
}
setColors{arg stringBackground,stringColor,sliderBackground,numBackground,
numStringColor,numNormalColor,numTypingColor,knobColor,background;
stringBackground.notNil.if{
labelView.notNil.if{labelView.background_(stringBackground)};
unitView.notNil.if{unitView.background_(stringBackground)};};
stringColor.notNil.if{
labelView.notNil.if{labelView.stringColor_(stringColor)};
unitView.notNil.if{unitView.stringColor_(stringColor)};};
numBackground.notNil.if{
numberView.background_(numBackground);};
numNormalColor.notNil.if{
numberView.normalColor_(numNormalColor);};
numTypingColor.notNil.if{
numberView.typingColor_(numTypingColor);};
numStringColor.notNil.if{
numberView.stringColor_(numStringColor);};
sliderBackground.notNil.if{
sliderView.background_(sliderBackground);};
knobColor.notNil.if{
sliderView.knobColor_(knobColor);
};
background.notNil.if{
view.background=background;};
numberView.refresh;
}
}