Skip to content

Commit

Permalink
futureMouseDrag is now default. Replaced by a legacyMouseDrag. BREAKING.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Piolat committed Dec 11, 2024
1 parent f85a728 commit f2fe7ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
8 changes: 6 additions & 2 deletions gui/dplug/gui/context.d
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ nothrow:
// Stop an existing dragging operation.
stopDragging();

version(futureMouseDrag)
version(legacyMouseDrag)
{}
else
{
setMouseOver(element);
assert(this.mouseOver is element);
Expand All @@ -303,7 +305,9 @@ nothrow:
{
if (dragged !is null)
{
version(futureMouseDrag)
version(legacyMouseDrag)
{}
else
{
assert(this.mouseOver is dragged);
}
Expand Down
36 changes: 23 additions & 13 deletions gui/dplug/gui/element.d
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ nothrow:
/// Called when mouse move over this Element.
/// This function is meant to be overriden.
///
/// Note: If "legacyMouseDrag" version identifier is used,
/// Note: If "legacyMouseDrag" version identifier is used,
/// this will be called even during a drag, beware.
void onMouseMove(int x, int y, int dx, int dy, MouseState mstate)
{
Expand All @@ -427,10 +427,10 @@ nothrow:
/// This function is meant to be overriden.
/// Between `onBeginDrag` and `onStopDrag`, `isDragged` will return `true`.
///
/// Note: When a widget is dragged, and "futureMouseDrag" version identifier is used,
/// Note: When a widget is dragged, and "legacyMouseDrag" version identifier is NOT used,
/// then a dragged widget is always also isMouseOver.
///
/// Example: you could call `beginParamEdit` from there or from `onMouseClick`. You probably
/// Example: you could call `beginParamEdit` from there or from `onMouseClick`. You probably
/// have more context in `onMouseClick`.
void onBeginDrag()
{
Expand All @@ -449,7 +449,7 @@ nothrow:
/// This function is meant to be overriden.
/// Between `onBeginDrag` and `onStopDrag`, `isDragged` will return `true`.
///
/// Note: When a widget is dragged, and "futureMouseDrag" version identifier is used,
/// Note: When a widget is dragged, and "legacyMouseDrag" version identifier is NOT used,
/// then a dragged widget is always also isMouseOver.
///
/// Example: if a mouse click started a modification of a plugin parameter, this will be a
Expand Down Expand Up @@ -570,14 +570,18 @@ nothrow:
// to be called at top-level when the mouse is released
final void mouseRelease(int x, int y, int button, MouseState mstate)
{
version(futureMouseDrag)
version(legacyMouseDrag)
{}
else
{
bool wasDragging = (_context.dragged !is null);
}

_context.stopDragging();

version(futureMouseDrag)
version(legacyMouseDrag)
{}
else
{
// Enter widget below mouse if a dragged operation was stopped.
if (wasDragging)
Expand Down Expand Up @@ -704,7 +708,9 @@ nothrow:
// Can't be mouse over if not visible.
bool canBeMouseOver = _visibilityStatus;

version(futureMouseDrag)
version(legacyMouseDrag)
{}
else
{
// If dragged, it already received `onMouseDrag`.
// if something else is dragged, it can be mouse over.
Expand All @@ -720,15 +726,15 @@ nothrow:
foundMouseOver = true;
_context.setMouseOver(this);

version(futureMouseDrag)
version(legacyMouseDrag)
{}
else
{
onMouseMove(x - _position.min.x, y - _position.min.y, dx, dy, mstate);
}
}

version(futureMouseDrag)
{}
else
version(legacyMouseDrag)
{
onMouseMove(x - _position.min.x, y - _position.min.y, dx, dy, mstate);
}
Expand Down Expand Up @@ -891,7 +897,9 @@ nothrow:
/// Returns: `true` is this element is hovered by the mouse, and
final bool isMouseOver() pure const
{
version(futureMouseDrag)
version(legacyMouseDrag)
{}
else
{
if (_context.mouseOver !is this)
{
Expand All @@ -904,7 +912,9 @@ nothrow:

final bool isDragged() pure const
{
version(futureMouseDrag)
version(legacyMouseDrag)
{}
else
{
if (_context.dragged is this)
assert(isMouseOver());
Expand Down
12 changes: 5 additions & 7 deletions gui/dplug/gui/graphics.d
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,7 @@ nothrow:
x -= outer._userArea.min.x;
y -= outer._userArea.min.y;
bool hitSomething = outer.mouseMove(x, y, dx, dy, mstate, false);
version(futureMouseDrag)
{}
else
version(legacyMouseDrag)
{
if (!hitSomething)
{
Expand Down Expand Up @@ -425,14 +423,14 @@ nothrow:
override void onMouseExitedWindow()
{
// Stop an eventual isMouseOver
version(futureMouseDrag)
version(legacyMouseDrag)
{
if (outer._uiContext.dragged is null)
outer._uiContext.setMouseOver(null);
outer._uiContext.setMouseOver(null);
}
else
{
outer._uiContext.setMouseOver(null);
if (outer._uiContext.dragged is null)
outer._uiContext.setMouseOver(null);
}
}

Expand Down

0 comments on commit f2fe7ed

Please sign in to comment.