File: DragSink.schelp

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 (102 lines) | stat: -rw-r--r-- 3,756 bytes parent folder | download | duplicates (4)
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
class:: DragSink
summary:: A simple drag-and-drop receiver.
categories:: GUI>Views
related:: Classes/DragBoth, Classes/DragSource

DESCRIPTION::

link::Classes/DragSource::, link::Classes/DragSink:: and link::Classes/DragBoth:: are a set of view classes intended as simple-to-use drag-and-drop sources and destinations. They are graphically represented as a simple rectangle, and their specialty is that they emphasis::do not require the Cmd/Ctrl key to be held down to initiate dragging::.

Akin to link::Classes/StaticText:: they can store arbitrary content in the link::Classes/StaticText#-object#-object:: variable, and display it using link::Classes/Object#-asString::. You can set the displayed text separately using link::Classes/StaticText#-string#-string::, and keep it independent of the content if you set link::Classes/StaticText#-setBoth#-setBoth:: to code::false::.

strong::DragSink::, specifically, strong::accepts any:: dropped data and stores it into the strong::-object:: variable, but allows strong::no dragging::.

See: link::Classes/View#Drag and drop:: for a general description of the drag and drop mechanism.




CLASSMETHODS::

PRIVATE:: key



INSTANCEMETHODS::

METHOD:: defaultCanReceiveDrag
	RETURNS:: Always True.

METHOD:: defaultReceiveDrag
	Sets the link::Classes/StaticText#-object#-object:: to the current drag data.



EXAMPLES::
code::
(
s.waitForBoot({	// only needed if you are using sound
	w = Window.new.front;

	// store various kinds of objects in the drag source

	// a string source
	a = DragSource(w, Rect(10, 10, 150, 20)).align_(\center);
	a.object = "I am a string source";

	// a Float source
	b = DragSource(w, Rect(10, 40, 150, 20)).align_(\center);
	b.object = 2.234;

	// a Point source
	c = DragSource(w, Rect(10, 70, 150, 20)).align_(\center);
	c.object = Point(20, 30);

	// A sound function source
	// dragLabel_() is used for the label while dragging
	d = DragSource(w, Rect(10, 100, 150, 20)).align_(\center);
	d.object = { Synth(\default) };
	d.dragLabel = " I am a sound function.\n My dragLabel_() is set \n to inform you about that ";

	// A sound function source
	// here the string label is independent of the content type (Function)
	// dragLabel_() is used for the label while dragging
	f = DragSource(w, Rect(10, 130, 150, 20)).align_(\center).setBoth_(false);
	f.object = { { SinOsc.ar(440,0,0.4) }.play };
	f.string = "My label is independent";
	f.dragLabel = " My dragLabel_() says \n I am dragging a sound function ";

	// receive anything
	g = DragSink(w, Rect(170, 10, 200, 20)).align_(\center);
	g.string = "receive anything, do nothing";

	// receive only floats
	g = DragSink(w, Rect(170, 40, 200, 20)).align_(\center);
	g.string = "I only like floats";
	g.canReceiveDragHandler = { View.currentDrag.isFloat };

	// receive only numbers and points, and convert them to rects
	h = DragSink(w, Rect(170, 70, 200, 20)).align_(\center);
	h.string = "I convert to Rect";
	h.canReceiveDragHandler = { View.currentDrag.isKindOf(Number) || View.currentDrag.isKindOf(Point) };
	h.receiveDragHandler = { arg v; h.object = View.currentDrag.asRect };

	// receive only functions, and try to play them
	i = DragSink(w, Rect(170, 100, 200, 20)).align_(\center);
	i.string = "I evaluate a (sound) function";
	i.canReceiveDragHandler = { View.currentDrag.isKindOf(Function) };
	i.receiveDragHandler = { arg v;
		i.object = View.currentDrag.value;
		i.string = "click here for silence";
		i.background_(Color.red) };
	i.mouseDownAction_({
		i.object.free;
		i.string = "I evaluate a (sound) function";
		i.background_(Color.clear) });

	StaticText(w, Rect(10, 200, 380, 50))
		.stringColor_(Color.white)
		.string_("Try dragging any item on the left -----> to any item on the right");
});
)
::