4#ifndef INCLUDE_FIFECHAN_DRAGDROP_HPP
5#define INCLUDE_FIFECHAN_DRAGDROP_HPP
15#include "fifechan/platform.hpp"
18#include <fifechan/gui.hpp>
19#include <fifechan/widget.hpp>
93 explicit DragPayload(std::shared_ptr<void> data =
nullptr);
101 return std::static_pointer_cast<T>(m_data);
107 template <
typename T>
110 return static_cast<T*
>(m_data.get());
118 m_data = std::move(data);
125 return m_data !=
nullptr;
133 m_ghostRenderer = std::move(cb);
140 return m_ghostRenderer;
148 m_tooltip = std::move(tip);
162 std::shared_ptr<void> m_data;
167 RenderCallback m_ghostRenderer;
172 std::string m_tooltip;
247 bool beginDrag(
Widget* source, std::unique_ptr<DragPayload> payload,
int mouseX,
int mouseY);
257 void update(
int mouseX,
int mouseY);
298 Widget* root,
int x,
int y,
bool mustBeVisible =
true,
bool mustBeEnabled =
true);
304 void distributeDragLeave();
309 void distributeDragEnter(
Widget* candidate);
314 void updateActiveTarget();
329 std::unique_ptr<DragPayload> m_payload;
334 Widget* m_sourceWidget{
nullptr};
339 Widget* m_hoveredWidget{
nullptr};
344 Widget* m_activeTarget{
nullptr};
349 Widget* m_modalWidget{
nullptr};
DragPayload const * getPayload() const
Get the active payload.
DropResult drop(int mouseX, int mouseY)
Drop at the given position.
void render(Graphics &graphics)
Render drag related visuals.
Widget * getHoveredWidget() const
Get the widget currently hovered by the drag.
Widget * getModalWidget() const
Get the modal widget if any.
bool beginDrag(Widget *source, std::unique_ptr< DragPayload > payload, int mouseX, int mouseY)
Start a drag with the given payload.
Widget * getActiveDropTarget() const
Get the active drop target widget.
void update(int mouseX, int mouseY)
Update drag position.
DragRenderConfig const & getRenderConfig() const
Get the current render config.
void setModalWidget(Widget *modal)
Set a modal widget to ignore hits.
DragHandler(Gui *gui)
Create a drag handler for a GUI.
static Widget * findWidgetAt(Widget *root, int x, int y, bool mustBeVisible=true, bool mustBeEnabled=true)
Find a widget at the given coordinates.
void setRenderConfig(DragRenderConfig config)
Set how drag visuals are rendered.
DragState getState() const
Get the current drag state.
void cancel()
Cancel the current drag.
bool beginDragFromWidget(Widget *source, int mouseX, int mouseY)
Start a drag from a widget without explicit payload.
Container for arbitrary data carried during a drag operation.
DragPayload(std::shared_ptr< void > data=nullptr)
Construct a payload.
T * get() const
Get raw pointer to stored data.
bool hasData() const
True if payload stores data.
void setData(std::shared_ptr< void > data)
Set the stored data.
void setTooltip(std::string tip)
Set tooltip text for the payload.
std::shared_ptr< T > getShared() const
Get shared pointer to stored data.
std::string const & getTooltip() const
Get the tooltip text.
void setGhostRenderer(RenderCallback cb)
Set the ghost renderer callback.
RenderCallback getGhostRenderer() const
Get the ghost renderer callback.
std::function< void(Graphics &, DragPoint const &screenPos)> RenderCallback
Callback used to render a ghost image at a screen position.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Used replacement tokens by configure_file():
DropResult
Result returned after attempting to drop payload onto a target.
@ Accepted
Target accepted the drop.
@ Cancelled
Drop was cancelled before delivery.
@ Rejected
Target rejected the drop.
DragState
State of the drag controller.
@ Dragging
A drag operation is in progress.
Simple 2D integer point used for drag offsets and positions.
DragPoint(int x_=0, int y_=0)
Construct a point with optional coordinates.
Configuration for how drag visuals are rendered.
HighlightRenderer highlight
Renderer used to draw a highlight on targets.
static HighlightRenderer defaultHighlight()
Default highlight renderer.
GhostRenderer ghost
Renderer used to draw the ghost.
std::function< void(Graphics &, DragPayload const &, DragPoint const &)> GhostRenderer
Renderer used to draw the ghost image.
std::function< void(Graphics &, Widget *target, bool isValid)> HighlightRenderer
Renderer used to draw a highlight on candidate targets.