3 summary:: A gui object for receiving drag and drop
5 related:: Classes/DragBoth, Classes/DragSource
8 A gui object for receiving drag and drop. See link::Classes/SCDragView:: for description and examples, and link::Classes/View:: for a general description of the drag and drop mechanism.
16 An instance of link::Classes/Rect::, or a link::Classes/Point:: indicating code::width@height::.
22 subsection:: Subclassing and Internal Methods
24 The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.
26 method:: defaultCanReceiveDrag
27 The method called by default when attempting to drop a drag in this object. By default, DragSink will respond to any drag.
29 method:: defaultReceiveDrag
30 The default method called when a drag has been recieved. By default, this sets the object to the currentDrag and performs the action.
36 s.waitForBoot({ // only needed if you are using sound
39 // store various kinds of objects in the drag source
42 a = DragSource(w, Rect(10, 10, 150, 20)).align_(\center);
43 a.object = "I am a string source";
46 b = DragSource(w, Rect(10, 40, 150, 20)).align_(\center);
50 c = DragSource(w, Rect(10, 70, 150, 20)).align_(\center);
51 c.object = Point(20, 30);
53 // A sound function source
54 // dragLabel_() is used for the label while dragging
55 d = DragSource(w, Rect(10, 100, 150, 20)).align_(\center);
56 d.object = { Synth(\default) };
57 d.dragLabel = " I am a sound function.\n My dragLabel_() is set \n to inform you about that ";
59 // A sound function source
60 // here the string label is independent of the content type (Function)
61 // dragLabel_() is used for the label while dragging
62 f = DragSource(w, Rect(10, 130, 150, 20)).align_(\center).setBoth_(false);
63 f.object = { { SinOsc.ar(440,0,0.4) }.play };
64 f.string = "My label is independent";
65 f.dragLabel = " My dragLabel_() says \n I am dragging a sound function ";
68 g = DragSink(w, Rect(170, 10, 200, 20)).align_(\center);
69 g.string = "recieve anything, do nothing";
71 // receive only floats
72 g = DragSink(w, Rect(170, 40, 200, 20)).align_(\center);
73 g.string = "I only like floats";
74 g.canReceiveDragHandler = { View.currentDrag.isFloat };
76 // receive only numbers and points, and convert them to rects
77 h = DragSink(w, Rect(170, 70, 200, 20)).align_(\center);
78 h.string = "I convert to Rect";
79 h.canReceiveDragHandler = { View.currentDrag.isKindOf(Number) || View.currentDrag.isKindOf(Point) };
80 h.receiveDragHandler = { arg v; h.object = View.currentDrag.asRect };
82 // receive only functions, and try to play them
83 i = DragSink(w, Rect(170, 100, 200, 20)).align_(\center);
84 i.string = "I evaluate a (sound) function";
85 i.canReceiveDragHandler = { View.currentDrag.isKindOf(Function) };
86 i.receiveDragHandler = { arg v;
87 i.object = View.currentDrag.value;
88 i.string = "click here for silence";
89 i.background_(Color.red) };
92 i.string = "I evaluate a (sound) function";
93 i.background_(Color.clear) });
95 StaticText(w, Rect(10, 200, 380, 50))
96 .stringColor_(Color.white)
97 .string_("Try dragging any item on the left -----> to any item on the right");