Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add a way to determine if anything is visible (See comment) #213

Closed
midnite8177 opened this issue May 9, 2015 · 5 comments

Comments

@midnite8177
Copy link

This may be a very specialized request, so I can understand if you don't want to implement it (I maintain a small change for the feature locally). But at the same time, I can see this useful for some others. If there is a way to do it with existing API, please let me know.

In our engine I decide if mouse input should go to imgui or to move the camera, depending if there is any visible UI*. Since I need to use a software mouse cursor in many situations, something is always visible (the cursor), so I can't just make this determination in the render function (there is always something to draw, so something is visible). What I did is add a bool to the ImDrawList struct that is something like "is_mouse_cursor" which is initialized to false, but set to true for the draw list of the mouse cursor.

With that information I am able to see if there is non-mouse draw lists in the render function. With that I can then make a determination if mouse movement should be fed to imgui, or sent to the camera.

*There is a situation that I'd like to handle that I haven't thought of a quick solution for, which is if a user wants to display a non-interactable window (for informational display) -- no need for a mouse cursor, so mouse input could go to the camera.

@midnite8177 midnite8177 changed the title Add a way to determine if anything is visible (See comment) Feature request: Add a way to determine if anything is visible (See comment) May 9, 2015
@extrawurst
Copy link
Contributor

if i understand your question correctly this is already implemented in form of ImGuiIO::WantCaptureMouse see #52 (comment)

@ocornut
Copy link
Owner

ocornut commented May 9, 2015

Yes this will work and probably what you want. It tells you essentially if you are hovering an ImGui window (it is a little more stateful than this internally. For example: if you click outside a window and hold-drag over an window it consider that the mouse is owned by your application and doesn't request capture until the button is released).

Let me know if you actually need to know about the window visibility.
For your first version of the "hack", testing if the number of draw list is > 1 might work as well without adding an 'is_mouse_cursor" field.

@ocornut ocornut closed this as completed May 9, 2015
@ocornut ocornut reopened this May 9, 2015
@midnite8177
Copy link
Author

While I definitely see a good use for WantMouseCapture, there is still an issue for me that simply moving the mouse cursor to get it over an imgui window (to get WantMouseCapture to true) is going to cause the camera (normally controlled by mouse input) to orient as I move until I am over UI.

Yes, this is something I could control by doing things like 'hold down CTRL to [not] move the camera", but what is best is if I could just check to see if there is any UI windows up, and if so, mouse control doesn't go to camera.

@ocornut
Copy link
Owner

ocornut commented May 9, 2015

It looks it should be part of your application code to track that then, but counting the number of draw lists will be enough of a workaround since you'll only get 1 for the mouse.

I can add a call or a value to retrieve the number of active windows, you can use that but you'll have the same result as comparing the number of draw lists with >= 1.

*There is a situation that I'd like to handle that I haven't thought of a quick solution for, which is if a user wants to display a non-interactable window (for informational display) -- no need for a mouse cursor, so mouse input could go to the camera.

I don't really now how to express that from the library point of view. The distinction is arbitrary so it's probably easier if you keep track of them. Say you have two counters, increment one each time you begin a window that you aim to be interactive and require mouse, and increment another for non-interactive windows, etc.

@ocornut
Copy link
Owner

ocornut commented May 12, 2015

I added a window counter. If you want to differentiate certain windows you'd have to count them yourself (you can count the "non-interactive windows" and subtract that from the total counter). Hope it helps!

@ocornut ocornut closed this as completed May 12, 2015
ocornut added a commit that referenced this issue Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants