void mouseUp (const MouseEvent& e)
    {
        if (e.originalComponent != this)
        {
            if (mouseDragSource != nullptr)
                mouseDragSource->removeMouseListener (this);

            // (note: use a local copy of this in case the callback runs
            // a modal loop and deletes this object before the method completes)
            DragAndDropTarget::SourceDetails details (sourceDetails);
            DragAndDropTarget* finalTarget = nullptr;

            const bool wasVisible = isVisible();
            setVisible (false);
            Component* unused;
            finalTarget = findTarget (e.getScreenPosition(), details.localPosition, unused);

            if (wasVisible) // fade the component and remove it - it'll be deleted later by the timer callback
                dismissWithAnimation (finalTarget == nullptr);

            if (getParentComponent() != nullptr)
                getParentComponent()->removeChildComponent (this);

            if (finalTarget != nullptr)
            {
                currentlyOverComp = nullptr;
                finalTarget->itemDropped (details);
            }

            // careful - this object could now be deleted..
        }
    }
Ejemplo n.º 2
0
void SynthSlider::mouseDown(const MouseEvent& e) {
  SynthGuiInterface* parent = findParentComponentOfClass<SynthGuiInterface>();

  if (e.mods.isPopupMenu()) {
    PopupMenu m;

    if (isDoubleClickReturnEnabled())
      m.addItem(kDefaultValue, "Set to Default Value");

    std::vector<mopo::ModulationConnection*> connections;
    if (parent) {
      m.addItem(kArmMidiLearn, "Learn MIDI Assignment");
      if (parent->isMidiMapped(getName().toStdString()))
        m.addItem(kClearMidiLearn, "Clear MIDI Assignment");

      connections = parent->getDestinationConnections(getName().toStdString());

      String disconnect("Disconnect from ");
      for (int i = 0; i < connections.size(); ++i)
        m.addItem(kModulationList + i, disconnect + connections[i]->source);

      if (connections.size() > 1)
        m.addItem(kClearModulations, "Disconnect all modulations");
    }

    int result = m.show();
    if (result == kArmMidiLearn) {
      parent->armMidiLearn(getName().toStdString(), getMinimum(), getMaximum());
    }
    else if (result == kClearMidiLearn) {
      parent->clearMidiLearn(getName().toStdString());
    }
    else if (result == kDefaultValue) {
      setValue(getDoubleClickReturnValue());
    }
    else if (result == kClearModulations) {
      for (mopo::ModulationConnection* connection : connections) {
        std::string source = connection->source;
        parent->disconnectModulation(connection);
      }
    }
    else if (result >= kModulationList) {
      int connection_index = result - kModulationList;
      std::string source = connections[connection_index]->source;
      parent->disconnectModulation(connections[connection_index]);
    }
  }
  else {
    Slider::mouseDown(e);

    if (parent)
      parent->beginChangeGesture(getName().toStdString());
    if (isRotary()) {
      click_position_ = e.getScreenPosition().toFloat();
      setMouseCursor(MouseCursor::NoCursor);
    }
  }
}
    void mouseUp (const MouseEvent& e)
    {
        if (e.originalComponent != this)
        {
            if (mouseDragSource != nullptr)
                mouseDragSource->removeMouseListener (this);

            bool dropAccepted = false;
            DragAndDropTarget* ddt = nullptr;
            Point<int> relPos;

            if (isVisible())
            {
                setVisible (false);
                ddt = findTarget (e.getScreenPosition(), relPos);

                // fade this component and remove it - it'll be deleted later by the timer callback

                dropAccepted = ddt != nullptr;

                setVisible (true);

                if (dropAccepted || sourceDetails.sourceComponent == nullptr)
                {
                    Desktop::getInstance().getAnimator().fadeOut (this, 120);
                }
                else
                {
                    const Point<int> target (sourceDetails.sourceComponent->localPointToGlobal (sourceDetails.sourceComponent->getLocalBounds().getCentre()));
                    const Point<int> ourCentre (localPointToGlobal (getLocalBounds().getCentre()));

                    Desktop::getInstance().getAnimator().animateComponent (this,
                                                                           getBounds() + (target - ourCentre),
                                                                           0.0f, 120,
                                                                           true, 1.0, 1.0);
                }
            }

            if (getParentComponent() != nullptr)
                getParentComponent()->removeChildComponent (this);

            if (dropAccepted && ddt != nullptr)
            {
                // (note: use a local copy of this in case the callback runs
                // a modal loop and deletes this object before the method completes)
                DragAndDropTarget::SourceDetails details (sourceDetails);
                details.localPosition = relPos;

                currentlyOverComp = nullptr;

                ddt->itemDropped (details);
            }

            // careful - this object could now be deleted..
        }
    }
 void mouseDrag (const MouseEvent& e)
 {
     if (e.originalComponent != this)
         updateLocation (true, e.getScreenPosition());
 }