Getting the LOCAL MOUSE POSITION in a custom widget V2

Hello gurus!

this time I feel very lazy, and I’m gonna ask for a fast solution (from you!)…

All my Draggable displays aren’t working because something is changed in the coordinate system

I used to have a working xform

sequence is/was this:

a) entering in onDragStart
b) getting current mouse position VEC (APP->scene->getMousePos())
c) convert to PARENT coord with a global2parent(), something like in_global_vec.minus(this->parent->box.pos);
d) convert to LOCAL coor with a parent2local, something like in_parent_vec.minus(this->box.pos)

now this sequence is not working anymore

Do you know how to get the local position of the mouse in a human way (I’m still using stuff I created in 0.5 and maybe I’ve missed something “new” )

grazie mille! Anto

I get the mouse position from event::Button and from event::DragHover with mousePos = new Vec(e.pos.x, e.pos.y);

This worked in Rack V1 and luckily works in V2 too.


void KnobWheel::onDragHover(const event::DragHover& e) {
	if (module && e.button == GLFW_MOUSE_BUTTON_LEFT) {
		mousePos = new Vec(e.pos.x, e.pos.y);
		Vec* center = new Vec(box.size.x * 0.5f, box.size.y * 0.5f);
		int mods = APP->window->getMods();
		module->touchedWheelForce = calcTouchedWheelForce(distance(mousePos, center), center->x, mods);
1 Like

Hi Antonio, I had problems with dragging, too. I needed to change it to APP->scene->rack->getMousePos() to fix it.

1 Like

bingo! :slight_smile:

now I have only check the 2 thousand displays…

1 Like

I can help if you shoot me a windows build, which is built against current Rack v2.git.042a9ce0 :wink:

I have to remove all the visible bugs before

the bigger one is Sevenseas not reading the base tables

no worries, ping me if you need test on win10

That seems like the “proper” way to do it, since a) it works and is portable and b) if there is a difference between the coordinates in the mouse event and the current mouse position, you would typically want the former. i.e. “where did the user click” vs. “where is the mouse right now”.

Your (a-d) sequence seems very complicated and britle. Just override Widget::onDragHover(const DragHoverEvent& e). The vector e.pos contains the pixel coordinate of the mouse cursor, relative to the widget.

1 Like

I did not use the

  • onDragHover

because was introduced in 1.0 and I had too many changes to do to support coordinates from the onDragHover and as my xfrom was correctly working (and I know that is the same xform in the “recurse” inner methods in VCVRack) I decided to leave in place my global2local method

but I’ll change immediately if you extend the

  • const event::DragStart& e

event to contains also the Mouse VEC local position (that you already have, because is precomputed for Button) ! :smiley:

thanks Antonio