SCDragView an abstract superclass for drag views


Inherits from: Object : SCView : SCStaticTextBase


See also: SCDragSource, SCDragSink, SCDragBoth


Users will not normally directly create instances of SCDragView, but only use it through its subclasses. The three subclasses, SCDragSource, SCDragSink, SCDragBoth, 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 SCView. They inherit from SCStaticTextBase, and thus store their content in object and by default display their content using asString. You can keep their string independent of the content, if you set setBoth=false. You can also set a label to be displayed while dragging by using dragLabel_().


Subclassing and Internal Methods

The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.

defaultGetDrag

The method called by default when initiating a drag. Returns object .


Examples


(

s.waitForBoot({ //only needed if you are using sound

w=Window.new.front;

// store various kinds of objects in the drag source

// a string source

a=DragSource(w,Rect(10,10,150,20)).align_(\center);

a.object="I am a string source";

// a Float source

b=DragSource(w,Rect(10,40,150,20)).align_(\center);

b.object=2.234;

// a Point source

c=DragSource(w,Rect(10,70,150,20)).align_(\center);

c.object=Point(20,30);

// A sound function source

// dragLabel_() is used for the label while dragging

d=DragSource(w,Rect(10,100,150,20)).align_(\center);

d.object={Synth(\default)};

d.dragLabel=" I am a sound function.\n My dragLabel_() is set \n to inform you about that ";

// A sound function source

//here the string label is independent of the content type (Function)

// dragLabel_() is used for the label while dragging

f=DragSource(w,Rect(10,130,150,20)).align_(\center).setBoth_(false);

f.object={{SinOsc.ar(440,0,0.4)}.play};

f.string="My label is independent";

f.dragLabel=" My dragLabel_() says \n I am dragging a sound function ";

// receive anthing

g=DragSink(w,Rect(170,10,200,20)).align_(\center);

g.string="recieve anything, do nothing";

// receive only floats

g=DragSink(w,Rect(170,40,200,20)).align_(\center);

g.string="I only like floats";

g.canReceiveDragHandler = { View.currentDrag.isFloat };

// receive only numbers and points, and convert them to rects

h=DragSink(w,Rect(170,70,200,20)).align_(\center);

h.string="I convert to Rect";

h.canReceiveDragHandler = {View.currentDrag.isKindOf(Number)||View.currentDrag.isKindOf(Point)};

h.receiveDragHandler={arg v; h.object=View.currentDrag.asRect};

// receive only functions, and try to play them

i=DragSink(w,Rect(170,100,200,20)).align_(\center);

i.string="I evaluate a (sound) function";

i.canReceiveDragHandler = {View.currentDrag.isKindOf(Function)};

i.receiveDragHandler={arg v;

i.object=View.currentDrag.value;

i.string="click here for silence";

i.background_(Color.red)};

i.mouseDownAction_({i.object.free;i.string="I evaluate a (sound) function";i.background_(Color.clear)});

StaticText(w,Rect(10,200,380,50))

.stringColor_(Color.white)

.string_("Try dragging any item on the left -----> to any item on the right");

});

)