Skip to content

Commit

Permalink
Add LambdaMouseListener
Browse files Browse the repository at this point in the history
  • Loading branch information
FigBug committed Jan 31, 2024
1 parent 47310fa commit 33905c3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion modules/gin_gui/utilities/gin_asyncutilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,37 @@ class LambdaAsyncUpdater : public juce::AsyncUpdater
}
};

void callOnMainThreadBlocking ( std::function<void ()> func );
void callOnMainThreadBlocking (std::function<void ()> func);

/**
If you add a mouse listener to yourself to get nested mouse messages, then you get
them all twice, so use a lambda mouse listener instead
*/
class LambdaMouseListener : public juce::MouseListener
{
public:
LambdaMouseListener() = default;

std::function<void (const juce::MouseEvent&)> onMouseMove;
std::function<void (const juce::MouseEvent&)> onMouseEnter;
std::function<void (const juce::MouseEvent&)> onMouseExit;
std::function<void (const juce::MouseEvent&)> onMouseDown;
std::function<void (const juce::MouseEvent&)> onMouseDrag;
std::function<void (const juce::MouseEvent&)> onMouseUp;
std::function<void (const juce::MouseEvent&)> onMouseDoubleClick;
std::function<void (const juce::MouseEvent&, const juce::MouseWheelDetails&)> onMouseWheelMove;
std::function<void (const juce::MouseEvent&, float)> onMouseMagnify;

private:
void mouseMove (const juce::MouseEvent& e) override { if (onMouseMove) onMouseMove (e); }
void mouseEnter (const juce::MouseEvent& e) override { if (onMouseEnter) onMouseEnter (e); }
void mouseExit (const juce::MouseEvent& e) override { if (onMouseExit) onMouseExit (e); }
void mouseDown (const juce::MouseEvent& e) override { if (onMouseDown) onMouseDown (e); }
void mouseDrag (const juce::MouseEvent& e) override { if (onMouseDrag) onMouseDrag (e); }
void mouseUp (const juce::MouseEvent& e) override { if (onMouseUp) onMouseUp (e); }
void mouseDoubleClick (const juce::MouseEvent& e) override { if (onMouseDoubleClick) onMouseDoubleClick (e); }
void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& w) override { if (onMouseWheelMove) onMouseWheelMove (e, w);}
void mouseMagnify (const juce::MouseEvent& e, float s) override { if (onMouseMagnify) onMouseMagnify (e, s); }

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LambdaMouseListener)
};

0 comments on commit 33905c3

Please sign in to comment.