File: SCNSObject%20control%20actions.scd

package info (click to toggle)
supercollider 1%3A3.4.5-1wheezy1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,972 kB
  • sloc: cpp: 116,645; lisp: 64,914; ansic: 10,725; python: 3,548; perl: 766; ruby: 487; sh: 152; makefile: 117; xml: 13
file content (69 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download | duplicates (2)
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

// blackrain
// NSButton
w = SCNSObject("NSWindow", "initWithContentRect:styleMask:backing:defer:", [ Rect(100,600,500,200), 10, 2, 1]);

w.invoke("makeKeyAndOrderFront:", [nil], true);
w.invoke("setTitle:", [ "Hello, World!" ], true);


b = SCNSObject("NSButton", "initWithFrame:", [ Rect(10,10,75,22) ]);
b.invoke("setBezelStyle:", [10], true);

v = w.invoke("contentView");
v.invoke("addSubview:", [ b ], true);


w.setDelegate;
(
	// - (void)buttonAction:(id)sender;
	w.nsDelegate.addMethod("buttonAction:", "v", "@", { arg method, args;
		var btn = args.at(0).asNSReturn; // args.at(0) is the button
		
		btn.invoke("state").postln;
		
	});
)

b.invoke("setTarget:", [ w.nsDelegate ], false);
b.invoke("setAction:", [ "buttonAction:" ], false); // SEL are recognized now

//

w.release;

SCNSObject.dumpPool;

SCNSObject.freePool;

// NSSlider
w = SCNSObject("NSWindow", "initWithContentRect:styleMask:backing:defer:", [ Rect(100,650,500,40), 10, 2, 1]);

w.invoke("makeKeyAndOrderFront:", [nil], true);
w.invoke("setTitle:", [ "Hello, World!" ], true);


l = SCNSObject("NSSlider", "initWithFrame:", [ Rect(10,10,480,22) ]);

v = w.invoke("contentView");
v.invoke("addSubview:", [ l ], true);


w.setDelegate;
(
	w.nsDelegate.addMethod("sliderAction:", "v", "@", { arg method, args;
		var slider = args.at(0).asNSReturn;
		
		slider.invoke("doubleValue").postln;
		
	});
)

l.invoke("setTarget:", [ w.nsDelegate ], false);
l.invoke("setAction:", [ "sliderAction:" ], false);



SCNSObject.dumpPool;

SCNSObject.freePool;