3 summary:: A gui object source for drag and drop
5 related:: Classes/DragSink, Classes/DragBoth
8 A gui object which acts as a source a source for drag and drop. See link::Classes/SCDragView:: for usage and examples, and link::Classes/View:: for a general description of the drag and drop mechanism.
17 An instance of link::Classes/Rect::, or a link::Classes/Point:: indicating code::width@height::.
24 s.waitForBoot({ // only needed if you are using sound
27 // store various kinds of objects in the drag source
30 a = DragSource(w, Rect(10, 10, 150, 20)).align_(\center);
31 a.object = "I am a string source";
34 b = DragSource(w, Rect(10, 40, 150, 20)).align_(\center);
38 c = DragSource(w, Rect(10, 70, 150, 20)).align_(\center);
39 c.object = Point(20, 30);
41 // A sound function source
42 // dragLabel_() is used for the label while dragging
43 d = DragSource(w, Rect(10, 100, 150, 20)).align_(\center);
44 d.object = { Synth(\default) };
45 d.dragLabel = " I am a sound function.\n My dragLabel_() is set \n to inform you about that ";
47 // A sound function source
48 // here the string label is independent of the content type (Function)
49 // dragLabel_() is used for the label while dragging
50 f = DragSource(w, Rect(10, 130, 150, 20)).align_(\center).setBoth_(false);
51 f.object = { { SinOsc.ar(440,0,0.4) }.play };
52 f.string = "My label is independent";
53 f.dragLabel = " My dragLabel_() says \n I am dragging a sound function ";
56 g = DragSink(w, Rect(170, 10, 200, 20)).align_(\center);
57 g.string = "recieve anything, do nothing";
59 // receive only floats
60 g = DragSink(w, Rect(170, 40, 200, 20)).align_(\center);
61 g.string = "I only like floats";
62 g.canReceiveDragHandler = { View.currentDrag.isFloat };
64 // receive only numbers and points, and convert them to rects
65 h = DragSink(w, Rect(170, 70, 200, 20)).align_(\center);
66 h.string = "I convert to Rect";
67 h.canReceiveDragHandler = { View.currentDrag.isKindOf(Number) || View.currentDrag.isKindOf(Point) };
68 h.receiveDragHandler = { arg v; h.object = View.currentDrag.asRect };
70 // receive only functions, and try to play them
71 i = DragSink(w, Rect(170, 100, 200, 20)).align_(\center);
72 i.string = "I evaluate a (sound) function";
73 i.canReceiveDragHandler = { View.currentDrag.isKindOf(Function) };
74 i.receiveDragHandler = { arg v;
75 i.object = View.currentDrag.value;
76 i.string = "click here for silence";
77 i.background_(Color.red)};
80 i.string = "I evaluate a (sound) function";
81 i.background_(Color.clear) });
83 StaticText(w, Rect(10, 200, 380, 50))
84 .stringColor_(Color.white)
85 .string_("Try dragging any item on the left -----> to any item on the right");