Explicitly include a boost "windows" folder even on linux
[supercollider.git] / HelpSource / Classes / DragSource.schelp
blobddf72df0e073d188a4f4801406602548d4eb1153
1 class:: DragSource
2 redirect:: implClass
3 summary:: A simple drag-and-drop source.
4 categories:: GUI>Views
5 related:: Classes/DragSink, Classes/DragBoth
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::DragSource::, specifically, gives the strong::-object:: variable as the data strong::for dragging::, but strong::accepts no drop::.
15 See: link::Classes/View#drag_and_drop:: for a general description of the drag and drop mechanism.
20 CLASSMETHODS::
22 PRIVATE:: key
27 INSTANCEMETHODS::
29 METHOD:: defaultGetDrag
30         RETURNS:: The link::Classes/StaticText#-object#-object::.
35 EXAMPLES::
36 code::
38 s.waitForBoot({ // only needed if you are using sound
39         w = Window.new.front;
41         // store various kinds of objects in the drag source
43         // a string source
44         a = DragSource(w, Rect(10, 10, 150, 20)).align_(\center);
45         a.object = "I am a string source";
47         // a Float source
48         b = DragSource(w, Rect(10, 40, 150, 20)).align_(\center);
49         b.object = 2.234;
51         // a Point source
52         c = DragSource(w, Rect(10, 70, 150, 20)).align_(\center);
53         c.object = Point(20, 30);
55         // A sound function source
56         // dragLabel_() is used for the label while dragging
57         d = DragSource(w, Rect(10, 100, 150, 20)).align_(\center);
58         d.object = { Synth(\default) };
59         d.dragLabel = " I am a sound function.\n My dragLabel_() is set \n to inform you about that ";
61         // A sound function source
62         // here the string label is independent of the content type (Function)
63         // dragLabel_() is used for the label while dragging
64         f = DragSource(w, Rect(10, 130, 150, 20)).align_(\center).setBoth_(false);
65         f.object = { { SinOsc.ar(440,0,0.4) }.play };
66         f.string = "My label is independent";
67         f.dragLabel = " My dragLabel_() says \n I am dragging a sound function ";
69         // receive anthing
70         g = DragSink(w, Rect(170, 10, 200, 20)).align_(\center);
71         g.string = "recieve anything, do nothing";
73         // receive only floats
74         g = DragSink(w, Rect(170, 40, 200, 20)).align_(\center);
75         g.string = "I only like floats";
76         g.canReceiveDragHandler = { View.currentDrag.isFloat };
78         // receive only numbers and points, and convert them to rects
79         h = DragSink(w, Rect(170, 70, 200, 20)).align_(\center);
80         h.string = "I convert to Rect";
81         h.canReceiveDragHandler = { View.currentDrag.isKindOf(Number) || View.currentDrag.isKindOf(Point) };
82         h.receiveDragHandler = { arg v; h.object = View.currentDrag.asRect };
84         // receive only functions, and try to play them
85         i = DragSink(w, Rect(170, 100, 200, 20)).align_(\center);
86         i.string = "I evaluate a (sound) function";
87         i.canReceiveDragHandler = { View.currentDrag.isKindOf(Function) };
88         i.receiveDragHandler = { arg v;
89                 i.object = View.currentDrag.value;
90                 i.string = "click here for silence";
91                 i.background_(Color.red)};
92         i.mouseDownAction_({
93                 i.object.free;
94                 i.string = "I evaluate a (sound) function";
95                 i.background_(Color.clear) });
97         StaticText(w, Rect(10, 200, 380, 50))
98                 .stringColor_(Color.white)
99                 .string_("Try dragging any item on the left -----> to any item on the right");