Browse Source

Added method MouseEvent::mouseWasDraggedSinceMouseDown()

tags/2021-05-28
jules 9 years ago
parent
commit
674c833c84
15 changed files with 51 additions and 40 deletions
  1. +10
    -10
      examples/audio plugin host/Source/GraphEditorPanel.cpp
  2. +1
    -1
      extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElement.cpp
  3. +1
    -1
      extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElementPath.cpp
  4. +1
    -1
      extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp
  5. +1
    -1
      extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentOverlayComponent.cpp
  6. +1
    -1
      extras/Introjucer/Source/ComponentEditor/ui/jucer_PaintRoutineEditor.cpp
  7. +6
    -1
      modules/juce_gui_basics/mouse/juce_MouseEvent.cpp
  8. +16
    -14
      modules/juce_gui_basics/mouse/juce_MouseEvent.h
  9. +1
    -1
      modules/juce_gui_basics/widgets/juce_ComboBox.cpp
  10. +1
    -2
      modules/juce_gui_basics/widgets/juce_Label.cpp
  11. +1
    -1
      modules/juce_gui_basics/widgets/juce_ListBox.cpp
  12. +2
    -2
      modules/juce_gui_basics/widgets/juce_Slider.cpp
  13. +4
    -2
      modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp
  14. +4
    -1
      modules/juce_gui_basics/widgets/juce_TableListBox.cpp
  15. +1
    -1
      modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp

+ 10
- 10
examples/audio plugin host/Source/GraphEditorPanel.cpp View File

@@ -408,16 +408,16 @@ public:
void mouseUp (const MouseEvent& e) override
{
if (e.mouseWasClicked() && e.getNumberOfClicks() == 2)
if (e.mouseWasDraggedSinceMouseDown())
{
graph.setChangedFlag (true);
}
else if (e.getNumberOfClicks() == 2)
{
if (const AudioProcessorGraph::Node::Ptr f = graph.getNodeForId (filterID))
if (PluginWindow* const w = PluginWindow::getWindowFor (f, PluginWindow::Normal))
w->toFront (true);
}
else if (! e.mouseWasClicked())
{
graph.setChangedFlag (true);
}
}
bool hitTest (int x, int y) override
@@ -699,7 +699,11 @@ public:
void mouseDrag (const MouseEvent& e)
{
if ((! dragging) && ! e.mouseWasClicked())
if (dragging)
{
getGraphPanel()->dragConnector (e);
}
else if (e.mouseWasDraggedSinceMouseDown())
{
dragging = true;
@@ -715,10 +719,6 @@ public:
destFilterChannel,
e);
}
else if (dragging)
{
getGraphPanel()->dragConnector (e);
}
}
void mouseUp (const MouseEvent& e)


+ 1
- 1
extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElement.cpp View File

@@ -296,7 +296,7 @@ void PaintElement::mouseDrag (const MouseEvent& e)
if (selected && ! dragging)
{
dragging = ! e.mouseWasClicked();
dragging = e.mouseWasDraggedSinceMouseDown();
if (dragging)
owner->startDragging (area);


+ 1
- 1
extras/Introjucer/Source/ComponentEditor/paintelements/jucer_PaintElementPath.cpp View File

@@ -1565,7 +1565,7 @@ void PathPointComponent::mouseDrag (const MouseEvent& e)
if (! e.mods.isPopupMenu())
{
if (selected && ! dragging)
dragging = ! e.mouseWasClicked();
dragging = e.mouseWasDraggedSinceMouseDown();
if (dragging)
{


+ 1
- 1
extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentLayoutEditor.cpp View File

@@ -298,7 +298,7 @@ void ComponentLayoutEditor::mouseUp (const MouseEvent& e)
lassoComp.endLasso();
removeChildComponent (&lassoComp);
if (e.mouseWasClicked() && ! e.mods.isAnyModifierKeyDown())
if (! (e.mouseWasDraggedSinceMouseDown() || e.mods.isAnyModifierKeyDown()))
layout.getSelectedSet().deselectAll();
}


+ 1
- 1
extras/Introjucer/Source/ComponentEditor/ui/jucer_ComponentOverlayComponent.cpp View File

@@ -113,7 +113,7 @@ void ComponentOverlayComponent::mouseDrag (const MouseEvent& e)
{
if (selected && ! dragging)
{
dragging = ! e.mouseWasClicked();
dragging = e.mouseWasDraggedSinceMouseDown();
if (dragging)
layout.startDragging();


+ 1
- 1
extras/Introjucer/Source/ComponentEditor/ui/jucer_PaintRoutineEditor.cpp View File

@@ -231,7 +231,7 @@ void PaintRoutineEditor::mouseUp (const MouseEvent& e)
{
lassoComp.endLasso();
if (e.mouseWasClicked() && ! e.mods.isAnyModifierKeyDown())
if (! (e.mouseWasDraggedSinceMouseDown() || e.mods.isAnyModifierKeyDown()))
{
graphics.getSelectedElements().deselectAll();
graphics.getSelectedPoints().deselectAll();


+ 6
- 1
modules/juce_gui_basics/mouse/juce_MouseEvent.cpp View File

@@ -79,9 +79,14 @@ MouseEvent MouseEvent::withNewPosition (Point<int> newPosition) const noexcept
}
//==============================================================================
bool MouseEvent::mouseWasDraggedSinceMouseDown() const noexcept
{
return wasMovedSinceMouseDown != 0;
}
bool MouseEvent::mouseWasClicked() const noexcept
{
return wasMovedSinceMouseDown == 0;
return ! mouseWasDraggedSinceMouseDown();
}
int MouseEvent::getLengthOfMousePress() const noexcept


+ 16
- 14
modules/juce_gui_basics/mouse/juce_MouseEvent.h View File

@@ -156,19 +156,19 @@ public:
//==============================================================================
/** Returns the x coordinate of the last place that a mouse was pressed.
The coordinate is relative to the component specified in MouseEvent::component.
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
*/
int getMouseDownX() const noexcept;
/** Returns the y coordinate of the last place that a mouse was pressed.
The coordinate is relative to the component specified in MouseEvent::component.
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
*/
int getMouseDownY() const noexcept;
/** Returns the coordinates of the last place that a mouse was pressed.
The coordinates are relative to the component specified in MouseEvent::component.
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
*/
Point<int> getMouseDownPosition() const noexcept;
@@ -203,25 +203,27 @@ public:
*/
Point<int> getOffsetFromDragStart() const noexcept;
/** Returns true if the mouse has just been clicked.
/** Returns true if the user seems to be performing a drag gesture.
Used in either your mouseUp() or mouseDrag() methods, this will tell you whether
the user has dragged the mouse more than a few pixels from the place where the
mouse-down occurred.
This is only meaningful if called in either a mouseUp() or mouseDrag() method.
Once they have dragged it far enough for this method to return false, it will continue
to return false until the mouse-up, even if they move the mouse back to the same
position where they originally pressed it. This means that it's very handy for
It will return true if the user has dragged the mouse more than a few pixels
from the place where the mouse-down occurred.
Once they have dragged it far enough for this method to return true, it will continue
to return true until the mouse-up, even if they move the mouse back to the same
location at which the mouse-down happened. This means that it's very handy for
objects that can either be clicked on or dragged, as you can use it in the mouseDrag()
callback to ignore any small movements they might make while clicking.
callback to ignore small movements they might make while trying to click.
*/
bool mouseWasDraggedSinceMouseDown() const noexcept;
@returns true if the mouse wasn't dragged by more than a few pixels between
the last time the button was pressed and released.
/** Returns true if the mouse event is part of a click gesture rather than a drag.
This is effectively the opposite of mouseWasDraggedSinceMouseDown()
*/
bool mouseWasClicked() const noexcept;
/** For a click event, the number of times the mouse was clicked in succession.
So for example a double-click event will return 2, a triple-click 3, etc.
*/
int getNumberOfClicks() const noexcept { return numberOfClicks; }


+ 1
- 1
modules/juce_gui_basics/widgets/juce_ComboBox.cpp View File

@@ -579,7 +579,7 @@ void ComboBox::mouseDrag (const MouseEvent& e)
{
beginDragAutoRepeat (50);
if (isButtonDown && ! e.mouseWasClicked())
if (isButtonDown && e.mouseWasDraggedSinceMouseDown())
showPopupIfNotActive();
}


+ 1
- 2
modules/juce_gui_basics/widgets/juce_Label.cpp View File

@@ -329,9 +329,8 @@ void Label::mouseUp (const MouseEvent& e)
{
if (editSingleClick
&& isEnabled()
&& e.mouseWasClicked()
&& contains (e.getPosition())
&& ! e.mods.isPopupMenu())
&& ! (e.mouseWasDraggedSinceMouseDown() || e.mods.isPopupMenu()))
{
showEditor();
}


+ 1
- 1
modules/juce_gui_basics/widgets/juce_ListBox.cpp View File

@@ -104,7 +104,7 @@ public:
{
if (ListBoxModel* m = owner.getModel())
{
if (isEnabled() && ! (e.mouseWasClicked() || isDragging))
if (isEnabled() && e.mouseWasDraggedSinceMouseDown() && ! isDragging)
{
SparseSet<int> rowsToDrag;


+ 2
- 2
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -693,7 +693,7 @@ public:
while (angle < 0.0)
angle += double_Pi * 2.0;
if (rotaryParams.stopAtEnd && ! e.mouseWasClicked())
if (rotaryParams.stopAtEnd && e.mouseWasDraggedSinceMouseDown())
{
if (std::abs (angle - lastAngle) > double_Pi)
{
@@ -883,7 +883,7 @@ public:
{
if (style == IncDecButtons && ! incDecDragged)
{
if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
if (e.getDistanceFromDragStart() < 10 || ! e.mouseWasDraggedSinceMouseDown())
return;
incDecDragged = true;


+ 4
- 2
modules/juce_gui_basics/widgets/juce_TableHeaderComponent.cpp View File

@@ -590,7 +590,8 @@ void TableHeaderComponent::mouseDrag (const MouseEvent& e)
{
if (columnIdBeingResized == 0
&& columnIdBeingDragged == 0
&& ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
&& e.mouseWasDraggedSinceMouseDown()
&& ! e.mods.isPopupMenu())
{
dragOverlayComp = nullptr;
@@ -599,6 +600,7 @@ void TableHeaderComponent::mouseDrag (const MouseEvent& e)
if (columnIdBeingResized != 0)
{
const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
jassert (ci != nullptr);
initialColumnWidth = ci->width;
}
else
@@ -767,7 +769,7 @@ void TableHeaderComponent::mouseUp (const MouseEvent& e)
updateColumnUnderMouse (e);
if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
if (columnIdUnderMouse != 0 && ! (e.mouseWasDraggedSinceMouseDown() || e.mods.isPopupMenu()))
columnClicked (columnIdUnderMouse, e.mods);
dragOverlayComp = nullptr;


+ 4
- 1
modules/juce_gui_basics/widgets/juce_TableListBox.cpp View File

@@ -153,7 +153,10 @@ public:
void mouseDrag (const MouseEvent& e) override
{
if (isEnabled() && owner.getModel() != nullptr && ! (e.mouseWasClicked() || isDragging))
if (isEnabled()
&& owner.getModel() != nullptr
&& e.mouseWasDraggedSinceMouseDown()
&& ! isDragging)
{
SparseSet<int> rowsToDrag;


+ 1
- 1
modules/juce_gui_basics/widgets/juce_ToolbarItemComponent.cpp View File

@@ -64,7 +64,7 @@ public:
void mouseDrag (const MouseEvent& e) override
{
if (! (isDragging || e.mouseWasClicked()))
if (e.mouseWasDraggedSinceMouseDown() && ! isDragging)
{
isDragging = true;


Loading…
Cancel
Save