Created
November 20, 2017 13:20
-
-
Save yairchu/e6dcfe5dab9004e64cbcb0a3f402f2fd to your computer and use it in GitHub Desktop.
AltClick class for JUCE (attempt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "AltClick.h" | |
using namespace juce; | |
AltClick::AltClick() | |
{ | |
coveredComponent_ = nullptr; | |
isAltClickEvent_ = false; | |
} | |
AltClick::AltClick (juce::Component* component, std::function<bool(juce::ModifierKeys)> func) | |
{ | |
attach (component, func); | |
isAltClickEvent_ = false; | |
} | |
void AltClick::attach (Component* component, std::function<bool(ModifierKeys)> func) | |
{ | |
coveredComponent_ = component; | |
func_ = func; | |
component->addAndMakeVisible (this); | |
parentSizeChanged(); | |
} | |
void AltClick::parentSizeChanged() | |
{ | |
jassert (coveredComponent_ != nullptr); | |
setBounds (coveredComponent_->getLocalBounds()); | |
} | |
void AltClick::mouseDown (const MouseEvent& event) | |
{ | |
jassert (coveredComponent_ != nullptr); | |
isAltClickEvent_ = event.mods.isAnyModifierKeyDown() && func_ (event.mods); | |
if (! isAltClickEvent_) | |
coveredComponent_->mouseDown (event); | |
} | |
void AltClick::mouseUp (const MouseEvent& event) | |
{ | |
jassert (coveredComponent_ != nullptr); | |
if (! isAltClickEvent_) | |
coveredComponent_->mouseUp (event); | |
} | |
void AltClick::mouseDrag (const MouseEvent& event) | |
{ | |
jassert (coveredComponent_ != nullptr); | |
if (! isAltClickEvent_) | |
coveredComponent_->mouseDrag (event); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "JuceHeader.h" | |
class AltClick : public Component | |
{ | |
public: | |
AltClick(); | |
AltClick (juce::Component*, std::function<bool(juce::ModifierKeys)>); | |
void attach (juce::Component*, std::function<bool(juce::ModifierKeys)>); | |
void parentSizeChanged() override; | |
void mouseDown (const juce::MouseEvent&) override; | |
void mouseUp (const juce::MouseEvent&) override; | |
void mouseDrag (const juce::MouseEvent&) override; | |
private: | |
Component* coveredComponent_; | |
std::function<bool(juce::ModifierKeys)> func_; | |
bool isAltClickEvent_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment