Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / HelpSource / Classes / DragSink.schelp
bloba67106a83fd90b9c90b64f7c194f5f1c3a19ebde
1 class:: DragSink
2 redirect:: implClass
3 summary:: A simple drag-and-drop receiver.
4 categories:: GUI>Views
5 related:: Classes/DragBoth, Classes/DragSource
7 DESCRIPTION::
9 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::.
11 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::.
13 strong::DragSink::, specifically, strong::accepts any:: dropped data and stores it into the strong::-object:: variable, but allows strong::no dragging::.
15 See: link::Classes/View#drag_and_drop:: for a general description of the drag and drop mechanism.
20 CLASSMETHODS::
22 PRIVATE:: key
26 INSTANCEMETHODS::
28 METHOD:: defaultCanReceiveDrag
29         RETURNS:: Allways True.
31 METHOD:: defaultReceiveDrag
32         Sets the link::Classes/StaticText#-object#-object:: to the current drag data.
36 EXAMPLES::
37 code::
39 s.waitForBoot({ // only needed if you are using sound
40         w = Window.new.front;
42         // store various kinds of objects in the drag source
44         // a string source
45         a = DragSource(w, Rect(10, 10, 150, 20)).align_(\center);
46         a.object = "I am a string source";
48         // a Float source
49         b = DragSource(w, Rect(10, 40, 150, 20)).align_(\center);
50         b.object = 2.234;
52         // a Point source
53         c = DragSource(w, Rect(10, 70, 150, 20)).align_(\center);
54         c.object = Point(20, 30);
56         // A sound function source
57         // dragLabel_() is used for the label while dragging
58         d = DragSource(w, Rect(10, 100, 150, 20)).align_(\center);
59         d.object = { Synth(\default) };
60         d.dragLabel = " I am a sound function.\n My dragLabel_() is set \n to inform you about that ";
62         // A sound function source
63         // here the string label is independent of the content type (Function)
64         // dragLabel_() is used for the label while dragging
65         f = DragSource(w, Rect(10, 130, 150, 20)).align_(\center).setBoth_(false);
66         f.object = { { SinOsc.ar(440,0,0.4) }.play };
67         f.string = "My label is independent";
68         f.dragLabel = " My dragLabel_() says \n I am dragging a sound function ";
70         // receive anthing
71         g = DragSink(w, Rect(170, 10, 200, 20)).align_(\center);
72         g.string = "recieve anything, do nothing";
74         // receive only floats
75         g = DragSink(w, Rect(170, 40, 200, 20)).align_(\center);
76         g.string = "I only like floats";
77         g.canReceiveDragHandler = { View.currentDrag.isFloat };
79         // receive only numbers and points, and convert them to rects
80         h = DragSink(w, Rect(170, 70, 200, 20)).align_(\center);
81         h.string = "I convert to Rect";
82         h.canReceiveDragHandler = { View.currentDrag.isKindOf(Number) || View.currentDrag.isKindOf(Point) };
83         h.receiveDragHandler = { arg v; h.object = View.currentDrag.asRect };
85         // receive only functions, and try to play them
86         i = DragSink(w, Rect(170, 100, 200, 20)).align_(\center);
87         i.string = "I evaluate a (sound) function";
88         i.canReceiveDragHandler = { View.currentDrag.isKindOf(Function) };
89         i.receiveDragHandler = { arg v;
90                 i.object = View.currentDrag.value;
91                 i.string = "click here for silence";
92                 i.background_(Color.red) };
93         i.mouseDownAction_({
94                 i.object.free;
95                 i.string = "I evaluate a (sound) function";
96                 i.background_(Color.clear) });
98         StaticText(w, Rect(10, 200, 380, 50))
99                 .stringColor_(Color.white)
100                 .string_("Try dragging any item on the left -----> to any item on the right");