서의 공간

[UMG] Drag & Drop 본문

Unreal Engine

[UMG] Drag & Drop

홍서의 2021. 10. 29. 02:51
	UserWidget.h
    
    ...
    
    /**
	 * The system calls this method to notify the widget that a mouse button was pressed within it. This event is bubbled.
	 *
	 * @param MyGeometry The Geometry of the widget receiving the event
	 * @param MouseEvent Information about the input event
	 * @return Whether the event was handled along with possible requests for the system to take action.
	 */
	UFUNCTION(BlueprintImplementableEvent, BlueprintCosmetic, Category="Mouse")
	FEventReply OnMouseButtonDown(FGeometry MyGeometry, const FPointerEvent& MouseEvent);

	/**
	 * Just like OnMouseButtonDown, but tunnels instead of bubbling.
	 * If this even is handled, OnMouseButtonDown will not be sent.
	 * 
	 * Use this event sparingly as preview events generally make UIs more
	 * difficult to reason about.
	 *
	 * @param MyGeometry The Geometry of the widget receiving the event
	 * @param MouseEvent Information about the input event
	 * @return Whether the event was handled along with possible requests for the system to take action.
	 */
	UFUNCTION(BlueprintImplementableEvent, BlueprintCosmetic, Category="Mouse")
	FEventReply OnPreviewMouseButtonDown(FGeometry MyGeometry, const FPointerEvent& MouseEvent);
    
    /**
	 * Called when Slate detects that a widget started to be dragged.
	 *
	 * @param  InMyGeometry  Widget geometry
	 * @param  PointerEvent  MouseMove that triggered the drag
	 * @param  Operation     The drag operation that was detected.
	 */
	UFUNCTION(BlueprintImplementableEvent, BlueprintCosmetic, Category="Drag and Drop")
	void OnDragDetected(FGeometry MyGeometry, const FPointerEvent& PointerEvent, UDragDropOperation*& Operation);
    
    /**
	 * Called when the user is dropping something onto a widget.  Ends the drag and drop operation, even if no widget handles this.
	 *
	 * @param MyGeometry     The geometry of the widget receiving the event.
	 * @param PointerEvent   The mouse event from when the drag occurred over the widget.
	 * @param Operation      The drag operation over the widget.
	 * 
	 * @return 'true' to indicate you handled the drop operation.
	 */
	UFUNCTION(BlueprintImplementableEvent, BlueprintCosmetic, Category="Drag and Drop")
	bool OnDrop(FGeometry MyGeometry, FPointerEvent PointerEvent, UDragDropOperation* Operation);

 

  • FGeometry: Slate에서 위젯의 위치, 크기 및 절대위치를 나타낸다. Geometry의 절대위치는 일반적으로 geometry가 시작된 위치에 따른 화면 공간 또는 window 공간이다. Geometry들은 일반적으로 특정 위젯에 대한 정보를 제공하기 위해 SWidget 포인터와 쌍을 이룬다(FArrangedWidget 참고). Geometry의 부모는 일반적으로 해당 부모 위젯의 Geometry로 간주된다.
  • FPointerEvent: FPointerEvent는 마우스 또는 터치 동작(예: 누르기, 떼기, 이동 등)을 설명한다. 포인터 기반 입력을 처리하는 이벤트 핸들러에 전달된다.
  • FEventReply: 사용자가 이벤트를 처리하고 기본 UI 계층에 정보를 반환할 수 있다. 그 반환할 정보를 담은 구조체이다.

 

  • Bubbling: UI 계층 트리를 따라 최하위 계층 위젯에서 시작해 이벤트를 처리한다. 이벤트 처리가 되지 않으면, 한 단계씩 상위 계층 위젯으로 이벤트를 전달하여 처리한다.
  • Tunneling: UI 계층 트리를 따라 최상위 계층 위젯에서 시작해 이벤트를 처리한다. 이벤트 처리가 되지 않으면, 한 단계씩 하위 계층 위젯으로 이벤트를 전달하여 처리한다.

 

  • Drag 이벤트를 탐지하려면, Drag하기 위해 버튼을 클릭 했을 때(떼지 않고 누르고 있어야 한다), 버튼의 OnClicked 이벤트가 발생하지 않도록 OnPreviewMouseButtonDown을 사용한다.

 

 

'Unreal Engine' 카테고리의 다른 글

컨트롤러 방향  (2) 2021.12.16
AIController에서 BehaviorTreeComponent  (2) 2021.12.12
Set Timer 사용법  (0) 2021.12.12
속도, MakeFromX, MakeRotFromX  (0) 2021.11.09
Pawn  (0) 2021.11.09
Comments