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

Mouse cursor types #155

Closed
ocornut opened this issue Mar 7, 2015 · 10 comments
Closed

Mouse cursor types #155

ocornut opened this issue Mar 7, 2015 · 10 comments

Comments

@ocornut
Copy link
Owner

ocornut commented Mar 7, 2015

Add a way for tell the application of which type of mouse cursor to display.
Applications can handle it or not.
The windows examples can support this.

Proposed enumeration

  • normal cursor
  • text input cursor
  • resize horizontal
  • resize vertical
  • resize upper-left <> lower-right
  • resize lower-left <> upper-right
  • move

Extra (can't think of where imgui can send this, but nice to have so the cursor can "set" it themselves)

  • disabled
  • pen

Applications are free to handle all the "resize" cursor the same way.

( Suggested here: #154 )

@ocornut
Copy link
Owner Author

ocornut commented Mar 21, 2015

That's done. The hardest part was embedding the cursors in code (imgui can draw cursors for you which is convenient on an embedded system/console) and then reducing the code space, first version took 200 lines. Ended up with this beauty:

ImGui::GetMouseCursor()
ImGui::SetMouseCursor()

// Enumeration for GetMouseCursor()
enum ImGuiMouseCursor_
{
    ImGuiMouseCursor_Arrow = 0,
    ImGuiMouseCursor_TextInput,
    ImGuiMouseCursor_Move,                  // Unused by ImGui
    ImGuiMouseCursor_ResizeNS,              // Unused by ImGui
    ImGuiMouseCursor_ResizeEW,              // Unused by ImGui
    ImGuiMouseCursor_ResizeNESW,            // Unused by ImGui
    ImGuiMouseCursor_ResizeNWSE,
    ImGuiMouseCursor_Count_
};
    const char texture_data[TEX_DATA_W*TEX_DATA_H+1] =
    {
        "..-         -XXXXXXX-    X    -           X           -XXXXXXX          -          XXXXXXX"
        "..-         -X.....X-   X.X   -          X.X          -X.....X          -          X.....X"
        "---         -XXX.XXX-  X...X  -         X...X         -X....X           -           X....X"
        "X           -  X.X  - X.....X -        X.....X        -X...X            -            X...X"
        "XX          -  X.X  -X.......X-       X.......X       -X..X.X           -           X.X..X"
        "X.X         -  X.X  -XXXX.XXXX-       XXXX.XXXX       -X.X X.X          -          X.X X.X"
        "X..X        -  X.X  -   X.X   -          X.X          -XX   X.X         -         X.X   XX"
        "X...X       -  X.X  -   X.X   -    XX    X.X    XX    -      X.X        -        X.X      "
        "X....X      -  X.X  -   X.X   -   X.X    X.X    X.X   -       X.X       -       X.X       "
        "X.....X     -  X.X  -   X.X   -  X..X    X.X    X..X  -        X.X      -      X.X        "
        "X......X    -  X.X  -   X.X   - X...XXXXXX.XXXXXX...X -         X.X   XX-XX   X.X         "
        "X.......X   -  X.X  -   X.X   -X.....................X-          X.X X.X-X.X X.X          "
        "X........X  -  X.X  -   X.X   - X...XXXXXX.XXXXXX...X -           X.X..X-X..X.X           "
        "X.........X -XXX.XXX-   X.X   -  X..X    X.X    X..X  -            X...X-X...X            "
        "X..........X-X.....X-   X.X   -   X.X    X.X    X.X   -           X....X-X....X           "
        "X......XXXXX-XXXXXXX-   X.X   -    XX    X.X    XX    -          X.....X-X.....X          "
        "X...X..X    ---------   X.X   -          X.X          -          XXXXXXX-XXXXXXX          "
        "X..X X..X   -       -XXXX.XXXX-       XXXX.XXXX       ------------------------------------"
        "X.X  X..X   -       -X.......X-       X.......X       -    XX           XX    -           "
        "XX    X..X  -       - X.....X -        X.....X        -   X.X           X.X   -           "
        "      X..X          -  X...X  -         X...X         -  X..X           X..X  -           "
        "       XX           -   X.X   -          X.X          - X...XXXXXXXXXXXXX...X -           "
        "------------        -    X    -           X           -X.....................X-           "
        "                    ----------------------------------- X...XXXXXXXXXXXXX...X -           "
        "                                                      -  X..X           X..X  -           "
        "                                                      -   X.X           X.X   -           "
        "                                                      -    XX           XX    -           "
    };

I have yet to make the example honor the cursor type at the OS level.

@ocornut
Copy link
Owner Author

ocornut commented May 1, 2015

I initially intended to have the example apps honor the cursor shapes using OS cursor facilities but it's too much work to consider portability and without straying off standard OS cursor shapes. So this is the user responsibility to decide how they want to handle that. The "software" cursor rendering is always available and useful on console or embedded platforms. I don't expect people to use it on computers because it'll be tied to the application framerate where the OS one isn't.
Potentially we could expose a facility to retrieve the imgui cursor texture data in some form that the user can pass to their OS/library.

Closing now because it's really low priority and hasn't been requested.

@ocornut ocornut closed this as completed May 1, 2015
@emoon
Copy link
Contributor

emoon commented May 1, 2015

Thanks :) I will use this when my target OS doesn't support it (as you stated as one of the use-cases above)

@colesnicov
Copy link

Hi Omar.
Implementation of cursor pointer will not? :)

@ocornut
Copy link
Owner Author

ocornut commented Feb 13, 2017

@colesnicov

Implementation of cursor pointer will not? :)

ImGui can already render a software mouse cursor, but those don't refresh as smoothly as a hardware cursor. Prefer to use OS cursor facilities if you can.

@aeris170
Copy link

@ocornut is ImGuiMouseCursor_Move removed in the latest version? Can't seem to find it.

@ocornut
Copy link
Owner Author

ocornut commented Jan 4, 2021

@aeris170 There was never a ImGuiMouseCursor_Move. You may be referring to ImGuiMouseCursor_Hand (from 1.63) or ImGuiMouseCursor_ResizeAll.

@aeris170
Copy link

aeris170 commented Jan 5, 2021

@ocornut forgive me if I'm not getting something here. In your second post, the one with the code, I see the enum "ImGuiMouseCursor_Move", but now you say it was never there to begin with. Can you explain why this is the case? Also, if there is not a move cursor (something like ✊, not 👆), how can I render it?

@ocornut
Copy link
Owner Author

ocornut commented Jan 5, 2021

You are correct
In 7c75835 it was renamed to _ResizeAll (see #1626), pre 1.60.
Somehow it wasn't added to the changelog (which was a mistake).

The way cursor look depend on the OS and Back-end, I don't think we ever see a ✊ in Windows, I don't think it has an explicit Move cursor.
In Demo->Inputs->Mouse cursors you can see them.

Win32:
ImGuiMouseCursor_ResizeAll -> IDC_SIZEALL
ImGuiMouseCursor_Hand -> IDC_HAND

SDL:
ImGuiMouseCursor_ResizeAll -> SDL_SYSTEM_CURSOR_SIZEALL
ImGuiMouseCursor_Hand -> SDL_SYSTEM_CURSOR_HAND

GLFW:
ImGuiMouseCursor_ResizeAll -> GLFW_RESIZE_ALL_CURSOR
ImGuiMouseCursor_Hand -> GLFW_HAND_CURSOR

Neither SDL, GLFW or Win32 api have a "Move" cursor.

@aeris170
Copy link

aeris170 commented Jan 6, 2021

OK, now I see. I was looking for "ResizeAll". Thank you for your help! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants