void ResizableEdgeComponent::mouseDrag (const MouseEvent& e)
{
    if (component == nullptr)
    {
        jassertfalse; // You've deleted the component that this resizer was supposed to be using!
        return;
    }

    Rectangle<int> newBounds (originalBounds);

    switch (edge)
    {
        case leftEdge:      newBounds.setLeft (jmin (newBounds.getRight(), newBounds.getX() + e.getDistanceFromDragStartX())); break;
        case rightEdge:     newBounds.setWidth (jmax (0, newBounds.getWidth() + e.getDistanceFromDragStartX())); break;
        case topEdge:       newBounds.setTop (jmin (newBounds.getBottom(), newBounds.getY() + e.getDistanceFromDragStartY())); break;
        case bottomEdge:    newBounds.setHeight (jmax (0, newBounds.getHeight() + e.getDistanceFromDragStartY())); break;
        default:            jassertfalse; break;
    }

    if (constrainer != nullptr)
    {
        constrainer->setBoundsForComponent (component, newBounds,
                                            edge == topEdge,
                                            edge == leftEdge,
                                            edge == bottomEdge,
                                            edge == rightEdge);
    }
    else
    {
        if (Component::Positioner* const pos = component->getPositioner())
            pos->applyNewBounds (newBounds);
        else
            component->setBounds (newBounds);
    }
}
Ejemplo n.º 2
0
void CommentComponent::mouseDrag (const MouseEvent& e)
{

    if (! e.mods.isPopupMenu())
    {
        jassert (dynamic_cast <ObjectsHolder*> (getParentComponent()) != 0);
//        const Rectangle<int> area (((ObjectsHolder*) getParentComponent())->getComponentArea());

        if (selected && ! dragging)
        {
            dragging = ! e.mouseWasClicked();

            if (dragging)
            {
                owner.startDragging ();
            }
        }

        if (dragging)
        {
            owner.dragSelectedComps (e.getDistanceFromDragStartX(),
                                      e.getDistanceFromDragStartY());
        }
        update();
    }
}
Ejemplo n.º 3
0
void GraphComponent::mouseDrag (const MouseEvent& e)
{
    if (e.mods.isLeftButtonDown())
    {
        lassoComponent->toFront (false);
        lassoComponent->dragLasso (e);
    }
    else if (e.mods.isMiddleButtonDown ())
    {
        Viewport* parent = findParentComponentOfClass ((Viewport*) 0);
        if (parent)
        {
            int x = dragStartX - e.getDistanceFromDragStartX ();
            int y = dragStartY - e.getDistanceFromDragStartY ();

            Component* comp = parent->getViewedComponent ();
            if (comp)
            {
                x = jmax (0, jmin (comp->getWidth () - parent->getViewWidth (), x));
                y = jmax (0, jmin (comp->getHeight () - parent->getViewHeight (), y));
            }
            
            parent->setViewPosition (x, y);
            
            setMouseCursor (MouseCursor::DraggingHandCursor);
        }
    }
    else if (e.mods.isRightButtonDown ())
    {
    }
}
void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
{
    if (component == nullptr)
    {
        jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
        return;
    }

    Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
                                               originalBounds.getHeight() + e.getDistanceFromDragStartY()));

    if (constrainer != nullptr)
    {
        constrainer->setBoundsForComponent (component, r, false, false, true, true);
    }
    else
    {
        Component::Positioner* const pos = component->getPositioner();

        if (pos != nullptr)
            pos->applyNewBounds (r);
        else
            component->setBounds (r);
    }
}
Ejemplo n.º 5
0
void LfpDisplayCanvas::mouseDragInCanvas(const MouseEvent& e)
{

    int ypos = e.getMouseDownY();

    if (ypos <= headerHeight/2) {

        float scaleFactor = (float) e.getDistanceFromDragStartY();

        if (scaleFactor < 60.0 && scaleFactor > -200.0f)
        {
            timebase = pow(10.0f, -scaleFactor/200.0f);
        }

        repaint();

    } else if (ypos > headerHeight/2 && ypos < headerHeight) {

        float scaleFactor = (float) e.getDistanceFromDragStartX();

        timeOffset = scaleFactor;

        repaint();

    }


}
Ejemplo n.º 6
0
void TrackComponent::mouseDrag(const MouseEvent &e)
{
    int posX;
    if(_regionComponents.size() != 0)
    {
        MouseEvent ev = e.getEventRelativeTo(this);
        posX = ev.x;
        for (std::size_t i = 0; i != _regionComponents.size(); ++i)
        {
            _regionComponents.at(i)->toFront(true);
            
            int distance = ev.getDistanceFromDragStartX();
            Rectangle<int> r = _regionComponents.at(i)->getBounds();
            if(_regionComponents.at(i)->getPositionX() < posX && posX < (_regionComponents.at(i)->getPositionX() + _regionComponents.at(i)->getRegionWidth()))
            {
                int newPos = r.getX() + distance;
                int newEnd = r.getX() + distance + r.getWidth();
                _posX.at(i) = newPos;
                _regionComponents.at(i)->setBounds(newPos, 0, newEnd - newPos, getHeight());
                resized();
                
                int64 samplesRange = secondsToSamples(static_cast<double>(_numberOfClips), _sampleRate);
                int64 positionSamples = pixelsToSamples(newPos - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
                int64 widthInSamples = pixelsToSamples(newEnd - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
                _track->setTotalLength(widthInSamples);
                _track->move(_regionComponents.at(i)->getRegion(), positionSamples);
                
                if(_posX.at(i) < _mixerOffset)
                {
                    _posX.at(i) = getX() + _mixerOffset ;
                    _track->move(_regionComponents.at(i)->getRegion(), 0);
                    resized();
                }
            }
            else if((getComponentAt(e.x, e.y ) == _regionComponents.at(i)))
            {
                if(ev.x > _mixerOffset)
                {
                    int newPos = r.getX() + distance;
                    int newEnd = r.getX() + distance + r.getWidth();
                    _posX.at(i) = newPos;
                    resized();
                    Region* region = _regionComponents.at(i)->getRegion();
                    region->setNextReadPosition(0);
                    int64 samplesRange = secondsToSamples((double)_numberOfClips, _sampleRate);
                    int64 positionSamples = pixelsToSamples(newPos - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
                    int64 widthInSamples = pixelsToSamples(newEnd - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
                    _track->setTotalLength(widthInSamples);
                    _track->move(region, positionSamples);
                    if(_posX.at(i) < _mixerOffset)
                    {
                        _posX.at(i) = getX() + _mixerOffset ;
                        _track->move(region, 0);
                        resized();
                    }
                 }
            }
        }
    }
}
Ejemplo n.º 7
0
void CabbageEnvelopeHandleComponent::mouseDrag (const MouseEvent& e)
{
    CabbageEnvelopeHandleComponent* previousHandle = getPreviousHandle();
    CabbageEnvelopeHandleComponent* nextHandle = getNextHandle();
    bool fixed = this->getProperties().getWithDefault("fixedPos", false);


    int leftLimit = previousHandle == 0 ? 0 : previousHandle->getX()+1;
    int rightLimit = nextHandle == 0 ? getParentWidth()-previousHandle->getHeight() : nextHandle->getX()-1;
    int topLimit = previousHandle == 0 ? 0 : previousHandle->getX()+1;
    int bottomLimit = nextHandle == 0 ? getParentWidth()-previousHandle->getHeight() : nextHandle->getX()-1;
    int dragX = x+e.getDistanceFromDragStartX();
    int dragY = y+e.getDistanceFromDragStartY();

    //dragger.dragComponent(this, e, &resizeLimits);
    if(dragX < leftLimit)
        dragX = leftLimit;
    if(dragX > rightLimit)
        dragX = rightLimit;
    if(dragY< 0)
        dragY = 0;
    if(dragY > height-5)
        dragY = height-5;
    if(fixed)
        dragX = x;

    this->setTopLeftPosition(dragX, dragY);

    getParentComponent()->repaint();
}
Ejemplo n.º 8
0
 void mouseDrag (const MouseEvent& e)
 {
     if (Viewport* viewport = findParentComponentOfClass<Viewport>())
         viewport->setViewPosition (jlimit (0, jmax (0, viewport->getViewedComponent()->getWidth() - viewport->getViewWidth()),
                                            startX - e.getDistanceFromDragStartX()),
                                    jlimit (0, jmax (0, viewport->getViewedComponent()->getHeight() - viewport->getViewHeight()),
                                            startY - e.getDistanceFromDragStartY()));
 }
void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
{
    const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
                                                      : e.getDistanceFromDragStartY());

    layout->setItemPosition (itemIndex, desiredPos);

    hasBeenMoved();
}
Ejemplo n.º 10
0
void Joystick::mouseDrag (const MouseEvent& e)  //Called continuously while moving mouse
{
    if (isEnabled() && ! menuShown)
    {
        // If shift is down, don't allow changes to the X value
        if (! e.mods.isShiftDown())
        {
            //Determine current X value based on mouse location
            int x = startPressX + e.getDistanceFromDragStartX ();
            if (x < 0)
                current_x = 0;
            else if (x >= getWidth())
                current_x = x_max - x_min;
            else
                current_x = x / x_ratio;
        }

        // If ctrl is down, don't allow changes to Y value
        if (! e.mods.isCtrlDown())
        {
            //Determine current Y value based on mouse location
            int y = startPressY + e.getDistanceFromDragStartY ();
            if (y < 0)
                current_y = 0;
            else if (y > getHeight())
                current_y = y_max - y_min;
            else
                current_y = y / y_ratio;
        }

        // If holding down control key, then set snapback values
        if (e.mods.isLeftButtonDown())
        {
            x_snap = current_x;
            y_snap = current_y;
        }

        // If right left is down, then hold
        if (e.mods.isLeftButtonDown())
            holdOnMouseRelease = true;
        else
            holdOnMouseRelease = false;

        // Send changes and repaint screen
        if (! sendChangeOnlyOnRelease)
        {
            valueChanged (current_x, current_y);
            sendChanges ();
        }

        // update drawing position
        calculateDrawingSpot();

        repaint ();
    }
}
Ejemplo n.º 11
0
void PianoRoll::mouseDrag (const MouseEvent& e)
{
	bool snap = snapToGrid != e.mods.isShiftDown();
	double x = pixelsToPpq((float)e.x,false);
	if (snap)
	{
		lastDragTime = snapPpqToGrid(lastDragTime);
	}
	int n = (int)((float)(getHeight()-e.y)*128.f/(float)getHeight());
	if(hoveringNoteIndex != No_Note)
	{
		double startTime = draggingNoteStartTime;
		double length = draggingNoteLength;
		double offset = lastDragTime-startTime;
		if (!e.mods.isAltDown())
		{
			int noteDelta = n-draggingNoteNumber;
			double timeDelta = jmax(0.0,snap ? snapPpqToGrid(x-offset) : x-offset) - draggingNoteStartTime;
			draggingNoteNumber += noteDelta;
			draggingNoteStartTime += timeDelta;
			draggingNoteTransposition = n-hoveringNote->message.getNoteNumber();
			draggingNoteTimeDelta = jmax(0.0,snap ? snapPpqToGrid(x-offset) : x-offset) - hoveringNote->message.getTimeStamp();
		}
		else
		{
			wasResizing=true;
			length = x - startTime + draggingNoteEndOffset;
			double lengthDelta = snap ? snapPpqToGrid(length-draggingNoteLength,true) : length-draggingNoteLength;
			int velocityDelta = jlimit(1,127,originalNoteVelocity + (getHeight()-e.y) - draggingNoteNumber*getHeight()/128) - draggingNoteVelocity;
			for (int i=0;i<selectedNotes.size();i++)
			{
				if (selectedNotes.getUnchecked(i)->noteOffObject) {
					//set length and velocity when Alt is down
					double minWidth = snap ? stepLengthInPpq : 1.0;
					//if (lengthDelta!=0) 
						selectedNotes.getUnchecked(i)->noteOffObject->message.setTimeStamp(jmax(selectedNotes.getUnchecked(i)->message.getTimeStamp()+minWidth,selectedNotes.getUnchecked(i)->message.getTimeStamp()+selectedNoteLengths.getUnchecked(i).length+lengthDelta));
					selectedNotes.getUnchecked(i)->message.setVelocity((jlimit(1,127,selectedNotes.getUnchecked(i)->message.getVelocity()+velocityDelta))*midiScaler);
				}
			}
			draggingNoteVelocity += velocityDelta;
		}
		lastDragTime=x;
		noteLayer->repaint();
	}
	else if (e.mods.isLeftButtonDown())
	{
		lasso.setBounds(jmin(e.x,e.getMouseDownX()),
			            jmin(e.y,e.getMouseDownY()),
						abs(e.getDistanceFromDragStartX()),
						abs(e.getDistanceFromDragStartY()));
		repaint();
	}
}
Ejemplo n.º 12
0
    void mouseDrag (const MouseEvent& e)
    {
        if (! e.mods.isPopupMenu())
        {
            Point<int> pos (originalPos + Point<int> (e.getDistanceFromDragStartX(), e.getDistanceFromDragStartY()));

            if (getParentComponent() != nullptr)
                pos = getParentComponent()->getLocalPoint (nullptr, pos);

            graph.setNodePosition (filterID,
                                   (pos.getX() + getWidth() / 2) / (double) getParentWidth(),
                                   (pos.getY() + getHeight() / 2) / (double) getParentHeight());

            getGraphPanel()->updateComponents();
        }
    }
Ejemplo n.º 13
0
void NodeComponent::mouseDrag (const MouseEvent& e)
{
  if (! e.mods.isPopupMenu())
  {
    Point<int> pos (originalPos + Point<int> (e.getDistanceFromDragStartX(), e.getDistanceFromDragStartY()));
    
    if (getParentComponent() != nullptr)
      pos = getParentComponent()->getLocalPoint (nullptr, pos);
    
    endPos.x = (pos.getX() + getWidth() / 2) / (double) getParentWidth();
    endPos.y = (pos.getY() + getHeight() / 2) / (double) getParentHeight();
    
    audioEngine.getDoc().setNodePosition (nodeID, endPos.x, endPos.y);
    
    getGraphEditor()->updateComponents();
  }
}
void ComponentOverlayComponent::mouseDrag (const MouseEvent& e)
{
    if (! e.mods.isPopupMenu())
    {
        if (selected && ! dragging)
        {
            dragging = ! e.mouseWasClicked();

            if (dragging)
                layout.startDragging();
        }

        if (dragging)
        {
            layout.dragSelectedComps (e.getDistanceFromDragStartX(),
                                      e.getDistanceFromDragStartY());
        }
    }
}
Ejemplo n.º 15
0
void PaintElement::mouseDrag (const MouseEvent& e)
{
    if (! e.mods.isPopupMenu())
    {
        jassert (dynamic_cast<PaintRoutineEditor*> (getParentComponent()) != nullptr);
        const Rectangle<int> area (((PaintRoutineEditor*) getParentComponent())->getComponentArea());

        if (selected && ! dragging)
        {
            dragging = e.mouseWasDraggedSinceMouseDown();

            if (dragging)
                owner->startDragging (area);
        }

        if (dragging)
            owner->dragSelectedComps (e.getDistanceFromDragStartX(),
                                      e.getDistanceFromDragStartY(),
                                      area);
    }
}
Ejemplo n.º 16
0
void PathPointComponent::mouseDrag (const MouseEvent& e)
{
    if (! e.mods.isPopupMenu())
    {
        if (selected && ! dragging)
            dragging = ! e.mouseWasClicked();

        if (dragging)
        {
            const Rectangle<int> area (((PaintRoutineEditor*) getParentComponent())->getComponentArea());
            int x = dragX + e.getDistanceFromDragStartX() - area.getX();
            int y = dragY + e.getDistanceFromDragStartY() - area.getY();

            if (JucerDocument* const document = owner->getDocument())
            {
                x = document->snapPosition (x);
                y = document->snapPosition (y);
            }

            owner->getDocument()->getUndoManager().undoCurrentTransactionOnly();
            path->movePoint (index, pointNumber, x + area.getX(), y + area.getY(), area, true);
        }
    }
}
Ejemplo n.º 17
0
void ComponentOverlay::mouseDrag (const MouseEvent& e)
{

    if (e.eventComponent != resizer)
    {
        bool multipleSelection = false;

        if (!e.mods.isPopupMenu())
        {
            for ( ComponentOverlay* child : layoutEditor->getLassoSelection() )
            {
                const int gridSize = 2;
                const int selectedCompsPosX = ((int (child->getProperties().getWithDefault ("originalX", 1)) + e.getDistanceFromDragStartX() ) / gridSize) * gridSize;
                const int selectedCompsPosY = ((int (child->getProperties().getWithDefault ("originalY", 1)) + e.getDistanceFromDragStartY() ) / gridSize) * gridSize;
                child->setTopLeftPosition (selectedCompsPosX, selectedCompsPosY);
                child->applyToTarget();
                multipleSelection = true;
            }

            if (multipleSelection == false)
            {
                dragger.dragComponent (this, e, constrainer);
                applyToTarget ();
            }

        }

    }
}
Ejemplo n.º 18
0
void SampleStripControl::mouseDrag(const MouseEvent &e)
{
    int mouseX = e.x;

    // Make sure we don't select outside the waveform
    if (mouseX > componentWidth) mouseX = componentWidth;
    else if (mouseX < 0) mouseX = 0;

    // CASE: traditional drag-to-select region of sample
    if (mouseDownMods == ModifierKeys::leftButtonModifier)
    {
        *selectionPointFixed = e.getMouseDownX();
        *selectionPointToChange = mouseX;
    }

    // CASE: just moving one end of an existing selection
    else if (mouseDownMods == (ModifierKeys::ctrlModifier + ModifierKeys::leftButtonModifier))
    {
        *selectionPointToChange = mouseX;
    }

    // CASE: RMB is held, see which hit zone it selects
    else if (e.mods == ModifierKeys::rightButtonModifier)
    {
        selectedHitZone = mouseX / (componentWidth / 4);
    }

    // CASE: ctrl-shift-LMB allows us to snap to specific intervals
    else if ((e.mods == (ModifierKeys::ctrlModifier +
        ModifierKeys::leftButtonModifier +
        ModifierKeys::shiftModifier)))
    {
        // TODO: have snapping interval as an option
        int eighth = componentWidth / 16;

        // round to the nearest snap point
        int newSeg = (int) floor(0.5 + mouseX / (float) eighth);

        // update the changing part of the selection to the snapped position
        *selectionPointToChange = (int)(newSeg * eighth);
    }

    // CASE: moving the entire selection (whilst retaining size)
    else if (mouseDownMods == ModifierKeys::middleButtonModifier)
    {
        int newStart = selectionStartBeforeDrag + e.getDistanceFromDragStartX();
        int newEnd = newStart + visualSelectionLength;

        if(newStart < 0)
        {
            newStart = 0;
            newEnd = visualSelectionLength;
        }
        else if (newEnd > componentWidth)
        {
            newEnd = componentWidth;
            newStart = newEnd - visualSelectionLength;
        }

        visualSelectionStart = newStart;
        visualSelectionEnd = newEnd;
    }

    // Swap selection positions if inverse selection is made
    if (visualSelectionEnd < visualSelectionStart)
    {
        int temp = visualSelectionStart;
        visualSelectionStart = visualSelectionEnd;
        visualSelectionEnd = temp;

        // same for the pointers
        int *tempPointer = selectionPointFixed;
        selectionPointFixed = selectionPointToChange;
        selectionPointToChange = tempPointer;
    }

    visualSelectionLength = (visualSelectionEnd - visualSelectionStart);
    visualChunkSize = (visualSelectionLength / (float) numChunks);

    // send the new selection to the SampleStrips
    dataStrip->setSampleStripParam(SampleStrip::pVisualStart, &visualSelectionStart);
    dataStrip->setSampleStripParam(SampleStrip::pVisualEnd, &visualSelectionEnd);

    // update the play speed to account for new selection,
    // of course this doesn't change if we are just moving the
    // selection (i.e. using the middle mouse button)
    if (mouseDownMods != ModifierKeys::middleButtonModifier)
        processor->calcPlaySpeedForSelectionChange(sampleStripID);

    // repaint when we next get a timed update
    stripChanged = true;
}