DragBoth that can draw

Hi everybody.
can you tell me how to subclass DragBoth in order to add the drawing functionality of UserView , (or the other way round, a UserView that implements DragBoth) ?

I am sure you can !!

cheers
Hairi

Maybe put a transparent DragBoth inside and over the UserView like this:

// amended DragBoth help example
(
var func;
func = {|me|
	Pen.use{
		10.do{
			Color.red(rrand(0.0, 1), rrand(0.0, 0.5)).set;
			Pen.addArc((400.exprand(2))@(100.rand), rrand(10, 100), 2pi.rand, pi);
			Pen.perform([\stroke, \fill].choose);
		}
	}
};
w = Window.new.front;
w.addFlowLayout;
// store various kinds of objects in the drag source

// a string source
a = DragBoth(w, Rect(10, 10, 150, 20)).align_(\center).background_(Color.rand);
a.object = "drag us around";

a = DragBoth(w, Rect(10, 10, 150, 20)).align_(\center).background_(Color.rand);
a.object="SUPERCOLLIDER";

8.do{ var v, a;
	v = UserView(w, Rect(10, 10, 150, 20)).drawFunc_(func);
	v.resize=3; // the func coordinates ar valid even though the view move on resize
	v.background_(Color.rand);	
	a = DragBoth(v, Rect(0, 0, 150, 20)).align_(\center).background_(Color.clear);
	a.receiveDragHandler = { arg obj; obj.object = View.currentDrag.scramble };
};
)

Best,
Paul

I tried that too. It would do it if:

  • one could get rid of the ugly border the DragBoth is drawing
  • there would be a way to forward mouseDown etc to the UserView.
    DragBoth does not seem to react to mouseDown and does not forward events to the view below.

thanks
Hairi

But I suppose it is reacting to mouse down - by initiating the drag.
Do you need it to take other actions at the same time as dragging?

Yes. It is (i use a touchscreen):

  • tapping on the view for triggering
  • long tap (right click on mouse) for editing
  • drag and drop for making connections

I have it up and running without using views at all, scanning all items on the screen and using ny own dragdrop system. It would be nicer to use the standard way (UserViews as graphic elements).

I tried after your help, to use a UserView inside a DragBoth. That does it somehow as the UserView can forward mouseDown to the underlying DragBoth.

I will make a demo to see how that feels.

I see. Glad you found a solution.
Best,
Paul