segross / UnrealImGui

Unreal plug-in that integrates Dear ImGui framework into Unreal Engine 4.
MIT License
666 stars 212 forks source link

Slate/Hardware cursor support #6

Closed Unit2Ed closed 6 years ago

Unit2Ed commented 6 years ago

Locally I've implemented hardware cursor support - simply translating ImGui's requested cursor to slate's SetCursor function.

Remove the IO.MouseDrawCursor = InputState.HasMousePointer(); from ImGuiInteroperability::CopyInput, and add this to SImGuiWidget::UpdateInputEnabled:

if (bInputEnabled)
{
    ImGuiMouseCursor CursorShape = ImGui::GetMouseCursor();
    EMouseCursor::Type SlateCursorShape;
    switch(CursorShape)
    {
    case ImGuiMouseCursor_None:
        SlateCursorShape = EMouseCursor::None;
        break;
    case ImGuiMouseCursor_Arrow:
        SlateCursorShape = EMouseCursor::Default;
        break;
    case ImGuiMouseCursor_TextInput:
        SlateCursorShape = EMouseCursor::TextEditBeam;
        break;
    case ImGuiMouseCursor_Move:
        SlateCursorShape = EMouseCursor::CardinalCross;
        break;
    case ImGuiMouseCursor_ResizeNS:
        SlateCursorShape = EMouseCursor::ResizeUpDown;
        break;
    case ImGuiMouseCursor_ResizeEW:
        SlateCursorShape = EMouseCursor::ResizeLeftRight;
        break;
    case ImGuiMouseCursor_ResizeNESW:
        SlateCursorShape = EMouseCursor::ResizeSouthWest;
        break;
    case ImGuiMouseCursor_ResizeNWSE:
        SlateCursorShape = EMouseCursor::ResizeSouthEast;
        break;
    default:
        unimplemented();
        break;
    }
    SetCursor(SlateCursorShape);
}
else
    SetCursor(EMouseCursor::None);
segross commented 6 years ago

I did use the hardware cursor at some point but resigned from it because of the visible lag. It is connected with the update order of various sub-systems and I’m afraid that it cannot be completely removed. Personally, I feel that this lag is the bigger issue, but it could be a configurable option if really needed.

What would be the gain, other than slightly more native look and the lag?

Additionally to the above, mocking mouse with the controller is easier when already drawing own cursor, might be important if using ImGui on consoles. While proper console support is on the ImGui roadmap and has its experimental branch, right now it is not yet there.

Unit2Ed commented 6 years ago

I switched us over to hardware cursor to reduce lag caused by the GPU pipeline - in a DebugGame build it was basically unusable for us; ~20fps x 3 frames latency is quite significant.

On console we can always switch back again if it improves controller support.

segross commented 6 years ago

Hey, thanks for more info. I didn’t see it at that bad frame-rate but at 10fps and I see your point. At higher fps I do prefer software cursor but at low fps this becomes very uncomfortable.

I’ll switch to use hardware cursor as a default one and maybe leave the other one as an option.

I will try to reduce that lag and while it most probably cannot be less than one frame I tried today and was able to reduce it to just that. It requires a bit messier implementation but overall should be worth it.