File: EZScroller.sc

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (56 lines) | stat: -rw-r--r-- 1,785 bytes parent folder | download | duplicates (6)
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
EZScroller {
	var <maxItems=1, <numItems=1, <>action, <spec;
	var <value, <slider;

	*new { |w, bounds, maxItems, numItems, action, initVal=0|
		^super.newCopyArgs(maxItems, numItems, action)
			.init(w, bounds, initVal);
	}
	init { |w, bounds, initVal|
		slider = Slider.new(w, bounds);
		slider.action = { |sl|
			this.valueAction_(spec.map(sl.value));
		};
		slider.keyDownAction { arg char, modifiers, unicode,keycode;
			if (unicode == 16rF700, { this.increment; ^this });
			if (unicode == 16rF703, { this.increment; ^this });
			if (unicode == 16rF701, { this.decrement; ^this });
			if (unicode == 16rF702, { this.decrement; ^this });
		};
		spec = [0, 0, \lin, 1].asSpec;
		this.adjust;
		this.value_(initVal);
	}
	increment { this.valueAction = this.value + this.spec.step }
	decrement { this.valueAction = this.value + this.spec.step }

	adjust {
		var slBounds = slider.bounds;
		var maxLength = slBounds.width max: slBounds.height + 2;
		var numTooMany = (numItems - maxItems).max(1);
		var fractionToShow = (maxItems / numItems).min(1);

		slider.thumbSize = fractionToShow * maxLength; // CHECK: does this work with qt?
	//	slider.step_(1 / numTooMany.max(1));		// this does the action - it should not.
		slider.setProperty(\step, 1 / numTooMany.max(1));
		spec.minval_(numTooMany);	// minval to invert spec
	}

	value_ { |val|
		value = spec.constrain(val);
		slider.value_(spec.unmap(value));
	}

	maxItems_ { |val| maxItems = val.max(1); this.adjust }
	numItems_ { |val| numItems = val.max(1); this.adjust }

	valueAction_ { |val| this.value_(val).doAction; }
	doAction { action.value(this) }

	enabled { ^slider.enabled }
	enabled_ { |flag| slider.enabled_(flag) }
	visible { ^slider.visible }
	visible_ { |flag| slider.visible_(flag) }

	remove { slider.remove }
}