2

I have some ImGui DragFloats that are close to the right edge of the window, so if you try to drag the float to the right you hit the edge of your screen soon. Is there a way to replicate something similar like in Unity (when you are dragging something the cursor warps to the opposite side of the screen if it gets too close to the edge) ? I'm using ImGui and GLFW at the moment and I was not able to find out how to make this, I tried searching it up but found examples that use DX11 or completely different language and scenario.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
JacobDev
  • 65
  • 6

1 Answers1

0

I believe you could do this with some mouse monitoring, then setting the position if it goes over the edge of the window:

void checkMousePos() {
    double mxpos, mypos; // Get mouse position, relative to window
    glfwGetCursorPos(window, &xpos, &ypos);

    int width, height;   // Get dimensions of window
    glfwGetWindowSize(window, &width, &height);

    if( mxpos > width ) {
        glfwSetCursorPos( window, 0, mypos );
    } else if( mxpos < 0 ) {
        glfwSetCursorPos( window, width, mypos );
    }
    if( mypos > height ) {
        glfwSetCursorPos( window, mxpos, 0 );
    } else if( mypos < 0 ) {
        glfwSetCursorPos( window, mxpos, height );
    }
}

Note that I have not been able to test this, so I cannot guarantee it works.

cs1349459
  • 911
  • 9
  • 27