UnrealImGui/Source/ImGui/Private/SImGuiWidget.h
Sebastian 77bb73dbce Added Multi-PIE support:
- Added ImGui Context Manager to create and manage ImGui Context Proxies.
- Changed ImGui Context Proxy to dynamically create context and allow pairing with input state.
- Changed ImGui Module Manager to create one widget per context.
- Changed ImGui Widget to work in different input modes.
- Changed ImGui Input State to allow partial reset (only mouse or keyboard).
2017-08-28 20:29:07 +01:00

97 lines
3.1 KiB
C++

// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
#pragma once
#include "ImGuiInputState.h"
#include <Widgets/SLeafWidget.h>
class FImGuiModuleManager;
// Slate widget for rendering ImGui output and storing Slate inputs.
class SImGuiWidget : public SLeafWidget
{
typedef SLeafWidget Super;
public:
SLATE_BEGIN_ARGS(SImGuiWidget)
{}
SLATE_ARGUMENT(FImGuiModuleManager*, ModuleManager)
SLATE_ARGUMENT(int32, ContextIndex)
SLATE_END_ARGS()
void Construct(const FArguments& InArgs);
~SImGuiWidget();
// Get index of the context that this widget is targeting.
int32 GetContextIndex() const { return ContextIndex; }
// Get input state associated with this widget.
const FImGuiInputState& GetInputState() const { return InputState; }
//----------------------------------------------------------------------------------------------------
// SWidget overrides
//----------------------------------------------------------------------------------------------------
virtual bool SupportsKeyboardFocus() const override { return true; }
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;
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;
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;
private:
enum class EInputMode
{
None,
MouseOnly,
MouseAndKeyboard
};
FORCEINLINE void CopyModifierKeys(const FInputEvent& InputEvent);
FORCEINLINE void CopyModifierKeys(const FPointerEvent& MouseEvent);
// Determine new input mode based on requirement hints.
void UpdateInputMode(bool bNeedKeyboard, bool bNeedMouse);
void OnPostImGuiUpdate();
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;
FImGuiModuleManager* ModuleManager = nullptr;
mutable TArray<FSlateVertex> VertexBuffer;
mutable TArray<SlateIndex> IndexBuffer;
int32 ContextIndex = 0;
EInputMode InputMode = EInputMode::None;
FImGuiInputState InputState;
};