2017-03-26 20:32:57 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-22 15:38:04 +00:00
|
|
|
#include "ImGuiInputState.h"
|
2018-10-30 22:25:48 +00:00
|
|
|
#include "ImGuiModuleDebug.h"
|
2018-12-08 21:15:20 +00:00
|
|
|
#include "ImGuiModuleSettings.h"
|
2017-04-22 15:38:04 +00:00
|
|
|
|
2019-03-13 20:40:13 +00:00
|
|
|
#include <Widgets/SCompoundWidget.h>
|
2017-03-26 20:32:57 +00:00
|
|
|
|
2017-04-22 15:38:04 +00:00
|
|
|
|
2018-10-30 22:25:48 +00:00
|
|
|
// Hide ImGui Widget debug in non-developer mode.
|
|
|
|
#define IMGUI_WIDGET_DEBUG IMGUI_MODULE_DEVELOPER
|
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
class FImGuiModuleManager;
|
2019-03-13 20:40:13 +00:00
|
|
|
class SImGuiCanvasControl;
|
2018-07-10 16:40:57 +00:00
|
|
|
class UImGuiInputHandler;
|
2017-03-26 20:32:57 +00:00
|
|
|
|
2017-04-22 15:38:04 +00:00
|
|
|
// Slate widget for rendering ImGui output and storing Slate inputs.
|
2019-03-13 20:40:13 +00:00
|
|
|
class SImGuiWidget : public SCompoundWidget
|
2017-03-26 20:32:57 +00:00
|
|
|
{
|
2019-03-13 20:40:13 +00:00
|
|
|
typedef SCompoundWidget Super;
|
2017-08-19 20:19:38 +00:00
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
SLATE_BEGIN_ARGS(SImGuiWidget)
|
|
|
|
{}
|
|
|
|
SLATE_ARGUMENT(FImGuiModuleManager*, ModuleManager)
|
2017-09-27 20:16:54 +00:00
|
|
|
SLATE_ARGUMENT(UGameViewportClient*, GameViewport)
|
2017-08-28 19:29:07 +00:00
|
|
|
SLATE_ARGUMENT(int32, ContextIndex)
|
2017-03-26 20:32:57 +00:00
|
|
|
SLATE_END_ARGS()
|
|
|
|
|
|
|
|
void Construct(const FArguments& InArgs);
|
|
|
|
|
2017-04-22 15:38:04 +00:00
|
|
|
~SImGuiWidget();
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
// Get index of the context that this widget is targeting.
|
|
|
|
int32 GetContextIndex() const { return ContextIndex; }
|
|
|
|
|
|
|
|
// Get input state associated with this widget.
|
2017-04-22 15:38:04 +00:00
|
|
|
const FImGuiInputState& GetInputState() const { return InputState; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// SWidget overrides
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
|
2017-09-02 17:42:41 +00:00
|
|
|
virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
|
|
|
|
|
2018-07-10 16:40:57 +00:00
|
|
|
virtual bool SupportsKeyboardFocus() const override { return bInputEnabled && !IsConsoleOpened(); }
|
2017-04-22 15:38:04 +00:00
|
|
|
|
|
|
|
virtual FReply OnKeyChar(const FGeometry& MyGeometry, const FCharacterEvent& CharacterEvent) override;
|
|
|
|
|
|
|
|
virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) override;
|
|
|
|
|
|
|
|
virtual FReply OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) override;
|
|
|
|
|
2018-05-17 22:25:47 +00:00
|
|
|
virtual FReply OnAnalogValueChanged(const FGeometry& MyGeometry, const FAnalogInputEvent& AnalogInputEvent) override;
|
|
|
|
|
2017-04-22 15:38:04 +00:00
|
|
|
virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
|
|
|
|
|
|
|
virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
|
|
|
|
|
|
|
virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
|
|
|
|
|
|
|
virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
|
|
|
|
|
|
|
virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
virtual FReply OnFocusReceived(const FGeometry& MyGeometry, const FFocusEvent& FocusEvent) override;
|
|
|
|
|
|
|
|
virtual void OnFocusLost(const FFocusEvent& FocusEvent) override;
|
|
|
|
|
|
|
|
virtual void OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
|
|
|
|
|
|
|
virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
|
|
|
|
|
2018-07-10 16:40:57 +00:00
|
|
|
virtual FCursorReply OnCursorQuery(const FGeometry& MyGeometry, const FPointerEvent& CursorEvent) const override;
|
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
private:
|
|
|
|
|
2017-09-02 17:42:41 +00:00
|
|
|
enum class EInputMode : uint8
|
2017-08-28 19:29:07 +00:00
|
|
|
{
|
|
|
|
None,
|
2017-09-21 21:09:03 +00:00
|
|
|
// Mouse pointer only without user focus
|
|
|
|
MousePointerOnly,
|
2018-05-17 22:25:47 +00:00
|
|
|
// Full input with user focus (mouse, keyboard and depending on navigation mode gamepad)
|
|
|
|
Full
|
2017-08-28 19:29:07 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
void CreateInputHandler(const FStringClassReference& HandlerClassReference);
|
2018-07-10 16:40:57 +00:00
|
|
|
void ReleaseInputHandler();
|
|
|
|
|
2018-12-08 21:03:18 +00:00
|
|
|
void SetUseSoftwareCursor(bool bUse) { bUseSoftwareCursor = bUse; }
|
2018-10-28 21:15:02 +00:00
|
|
|
|
|
|
|
void RegisterImGuiSettingsDelegates();
|
|
|
|
void UnregisterImGuiSettingsDelegates();
|
2018-07-10 16:40:57 +00:00
|
|
|
|
2017-08-19 20:19:38 +00:00
|
|
|
FORCEINLINE void CopyModifierKeys(const FInputEvent& InputEvent);
|
2017-08-28 19:29:07 +00:00
|
|
|
|
2017-09-16 20:52:14 +00:00
|
|
|
bool IsConsoleOpened() const;
|
|
|
|
|
2017-09-02 17:42:41 +00:00
|
|
|
// Update visibility based on input enabled state.
|
2019-03-13 20:40:13 +00:00
|
|
|
void UpdateVisibility();
|
2017-09-02 17:42:41 +00:00
|
|
|
|
2019-02-05 20:48:19 +00:00
|
|
|
ULocalPlayer* GetLocalPlayer() const;
|
|
|
|
void TakeFocus();
|
|
|
|
void ReturnFocus();
|
|
|
|
|
2017-09-02 17:42:41 +00:00
|
|
|
void UpdateInputEnabled();
|
|
|
|
|
2017-09-21 21:09:03 +00:00
|
|
|
// Determine new input mode based on hints.
|
|
|
|
void UpdateInputMode(bool bHasKeyboardFocus, bool bHasMousePointer);
|
|
|
|
|
2019-03-13 20:40:13 +00:00
|
|
|
void UpdateCanvasControlMode(const FInputEvent& InputEvent);
|
2018-04-21 21:43:15 +00:00
|
|
|
|
2019-03-13 20:40:13 +00:00
|
|
|
void OnPostImGuiUpdate();
|
2018-04-21 21:43:15 +00:00
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& WidgetStyle, bool bParentEnabled) const override;
|
|
|
|
|
|
|
|
virtual FVector2D ComputeDesiredSize(float) const override;
|
|
|
|
|
2019-03-13 20:40:13 +00:00
|
|
|
void SetImGuiTransform(const FSlateRenderTransform& Transform) { ImGuiTransform = Transform; }
|
|
|
|
|
2018-10-30 22:25:48 +00:00
|
|
|
#if IMGUI_WIDGET_DEBUG
|
2017-09-09 10:40:44 +00:00
|
|
|
void OnDebugDraw();
|
2018-10-30 22:25:48 +00:00
|
|
|
#endif // IMGUI_WIDGET_DEBUG
|
2017-09-09 10:40:44 +00:00
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
FImGuiModuleManager* ModuleManager = nullptr;
|
2017-09-10 20:05:37 +00:00
|
|
|
TWeakObjectPtr<UGameViewportClient> GameViewport;
|
2018-07-10 16:40:57 +00:00
|
|
|
TWeakObjectPtr<UImGuiInputHandler> InputHandler;
|
2017-03-26 20:32:57 +00:00
|
|
|
|
2019-03-13 20:40:13 +00:00
|
|
|
FSlateRenderTransform ImGuiTransform;
|
|
|
|
FSlateRenderTransform ImGuiRenderTransform;
|
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
mutable TArray<FSlateVertex> VertexBuffer;
|
|
|
|
mutable TArray<SlateIndex> IndexBuffer;
|
2017-04-22 15:38:04 +00:00
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
int32 ContextIndex = 0;
|
|
|
|
|
2018-04-21 21:43:15 +00:00
|
|
|
FImGuiInputState InputState;
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
EInputMode InputMode = EInputMode::None;
|
2017-09-02 17:42:41 +00:00
|
|
|
bool bInputEnabled = false;
|
2017-08-28 19:29:07 +00:00
|
|
|
|
2018-10-28 21:15:02 +00:00
|
|
|
// Whether or not ImGui should draw its own cursor.
|
|
|
|
bool bUseSoftwareCursor = false;
|
|
|
|
|
2019-03-13 20:40:13 +00:00
|
|
|
TSharedPtr<SImGuiCanvasControl> CanvasControlWidget;
|
2017-09-10 20:05:37 +00:00
|
|
|
TWeakPtr<SWidget> PreviousUserFocusedWidget;
|
2017-03-26 20:32:57 +00:00
|
|
|
};
|