2 summary:: An abstract superclass for drag views
3 categories:: GUI>Kits>Cocoa
4 related:: Classes/DragSource, Classes/DragSink, Classes/DragBoth
7 Users will not normally directly create instances of SCDragView, but only use it through its subclasses. The three subclasses, link::Classes/DragSource::, link::Classes/DragSink::, link::Classes/DragBoth::, all function basically the same way: they are simple, graphically represented rectangles, which act as a drag-source, a drag target, or both. Their dragging behavior only differs from other GUI views, in that they do not require the cmd key to be held down for dragging. All other dragging functions are those defined by link::Classes/View::. They inherit from SCStaticTextBase, and thus store their content in object and by default display their content using code::asString::. You can keep their string independent of the content, if you set code::setBoth = false::. You can also set a label to be displayed while dragging by using code::dragLabel_()::.
13 subsection:: Subclassing and Internal Methods
15 The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.
17 method:: defaultGetDrag
18 The method called by default when initiating a drag. Returns object.
25 s.waitForBoot({ // only needed if you are using sound
28 // store various kinds of objects in the drag source
31 a = DragSource(w, Rect(10, 10, 150, 20)).align_(\center);
32 a.object = "I am a string source";
35 b = DragSource(w, Rect(10, 40, 150, 20)).align_(\center);
39 c = DragSource(w, Rect(10, 70, 150, 20)).align_(\center);
40 c.object = Point(20, 30);
42 // A sound function source
43 // dragLabel_() is used for the label while dragging
44 d = DragSource(w, Rect(10, 100, 150, 20)).align_(\center);
45 d.object = { Synth(\default) };
46 d.dragLabel = " I am a sound function.\n My dragLabel_() is set \n to inform you about that ";
48 // A sound function source
49 // here the string label is independent of the content type (Function)
50 // dragLabel_() is used for the label while dragging
51 f = DragSource(w, Rect(10, 130, 150, 20)).align_(\center).setBoth_(false);
52 f.object = { { SinOsc.ar(440,0,0.4) }.play };
53 f.string = "My label is independent";
54 f.dragLabel = " My dragLabel_() says \n I am dragging a sound function ";
57 g = DragSink(w, Rect(170, 10, 200, 20)).align_(\center);
58 g.string = "recieve anything, do nothing";
60 // receive only floats
61 g = DragSink(w, Rect(170, 40, 200, 20)).align_(\center);
62 g.string = "I only like floats";
63 g.canReceiveDragHandler = { View.currentDrag.isFloat };
65 // receive only numbers and points, and convert them to rects
66 h = DragSink(w, Rect(170, 70, 200, 20)).align_(\center);
67 h.string = "I convert to Rect";
68 h.canReceiveDragHandler = { View.currentDrag.isKindOf(Number) || View.currentDrag.isKindOf(Point) };
69 h.receiveDragHandler = { arg v; h.object = View.currentDrag.asRect };
71 // receive only functions, and try to play them
72 i = DragSink(w, Rect(170, 100, 200, 20)).align_(\center);
73 i.string = "I evaluate a (sound) function";
74 i.canReceiveDragHandler = { View.currentDrag.isKindOf(Function) };
75 i.receiveDragHandler = { arg v;
76 i.object = View.currentDrag.value;
77 i.string = "click here for silence";
78 i.background_(Color.red)};
81 i.string = "I evaluate a (sound) function";
82 i.background_(Color.clear) });
84 StaticText(w, Rect(10, 200, 380, 50))
85 .stringColor_(Color.white)
86 .string_("Try dragging any item on the left -----> to any item on the right");