Esempio n. 1
0
void MLMultiSlider::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
{
	// filter out zero motions from trackpad
	if ((wheel.deltaX == 0.) && (wheel.deltaY == 0.)) return;
	
	if(mCurrDragSlider >= 0) return;
	
	bool doFineAdjust = e.mods.isShiftDown();
	float wheelSpeed = doFineAdjust ? 0.1f : 1.f;
	float wheelDirection = (wheel.isReversed) ? -1.f : 1.f;
	
    if (isEnabled())
	{
		int s = getSliderUnderPoint(Vec2(e.x, e.y));
		if ((s >= 0) && ! isMouseButtonDownAnywhere())
		{
			float currentVal = getFloatProperty(ml::textUtils::addFinalNumber(ml::Symbol("value"), s));
			float minPosDelta = 0.01f;
			float deltaDir = (wheel.deltaY > 0.f) ? 1.f : -1.f;
			float posDelta = (wheel.deltaY + deltaDir*minPosDelta)*wheelSpeed*wheelDirection; 			
			
			const float currentPos = valueToProportionOfLength (currentVal);
			const float newPos = ml::clamp (currentPos + posDelta, 0.f, 1.f);
			float newValue = proportionOfLengthToValue (newPos);

			if(newValue != currentVal)
			{
				if(!isMouseWheelMoving)
				{
					isMouseWheelMoving = true;
					beginGesture();
				}
				mpTimer->startTimer(kWheelTimeoutDuration);

				mCurrDragSlider = s;
				sendSliderAction(snapValue (newValue, false), s);
				mpTimer->startTimer(kWheelTimeoutDuration);
				mCurrDragSlider = -1;
			}
        }
    }
    else
    {
        Component::mouseWheelMove (e, wheel);
    }
}
Esempio n. 2
0
void MoveAwayForFineAdjustmentSlider::mouseDrag (const MouseEvent& e)
{
    DragMode dragMode = notDragging;
    
    const int indent = getLookAndFeel().getSliderThumbRadius(*this);
    int sliderRegionSize = jmax (1, getHeight() - indent * 2);
        
    if (isAbsoluteDragMode (e.mods) || (getMaximum() - getMinimum()) / sliderRegionSize < getInterval())
    {
        dragMode = absoluteDrag;
        // handleAbsoluteDrag (e);
        handleDragWithFineAdjustmentFurtherAway (e); // This sets the valueWhenLastDragged
        
        valueWhenLastDragged = jlimit (getMinimum(), getMaximum(), valueWhenLastDragged);
        
        setValue (snapValue (valueWhenLastDragged, dragMode),
                  sendChangeOnlyOnRelease ? dontSendNotification : sendNotificationSync);
            // This calls pimpl->setValue()
    }
    else
    {
        Slider::mouseDrag(e);
    }
}
Esempio n. 3
0
QPoint Grid::snapPoint(const QPoint &p) const
{
    const int sx = m_snapX ? snapValue(p.x(), m_deltaX) : p.x();
    const int sy = m_snapY ? snapValue(p.y(), m_deltaY) : p.y();
    return QPoint(sx, sy);
}
Esempio n. 4
0
void MLMultiSlider::mouseDrag(const MouseEvent& e)
{
	MLRect r = mPos.getLocalOutline();	
	float w = r.width();
	float h = r.height();
	
	int mx = ml::clamp(e.x, (int)r.left() + 1, (int)(r.left() + w));
	int my = ml::clamp(e.y, (int)r.top() + 1, (int)(r.top() + h));
	int dials = getNumSliders();
	int s = getSliderUnderPoint(Vec2(mx, my));
	
    if (isEnabled())
    {	
		if (ml::within(s, 0, dials))
		{
			const int mousePos = mVertical ? my : mx;
			float val;
			MLRange posRange;
			if (mVertical)
			{
				posRange.set(h, 1);
			}
			else
			{
				posRange.set(1, w);
			}
			posRange.convertTo(mRange);
			val = posRange(mousePos);
			
			// if dial changed in drag, interpolate, setting dials in between
			if((mCurrDragSlider >= 0) && (mCurrDragSlider != s)) 			
			{
				int span = (s - mCurrDragSlider);
				int dir = sign(span);
				float mix, mixedval;
				int startDrag = mCurrDragSlider + dir;
				int endDrag = s + dir;
				for(int i=startDrag; i != endDrag; i += dir)
				{
					mix = fabs(float(i - startDrag)/float(span));
					mixedval = lerp(mCurrDragValue, val, mix);
	
					// finish old drag and switch to dragging new dial
					if (i != mCurrDragSlider)
					{
						mCurrDragSlider = i;
					}
					sendSliderAction(snapValue (mixedval, false), i);
				}
			}
			else if (mCurrDragSlider == s) // set current drag dial
			{
				sendSliderAction(snapValue (val, false), s);
			}
			
			if (s != mSliderUnderMouse)
			{
				mSliderUnderMouse = s;
				repaint();
			}
			mCurrDragSlider = s;
			mCurrDragValue = val;
		}	
    }
}