Update of /cvsroot/audacity/audacity-src/src/widgets
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv26629/widgets
Modified Files:
ASlider.cpp ASlider.h
Log Message:
Improved slider handling: the gain slider now moves twice as slow, clicking to
set the slider position is better, and the slider snaps back if you drag away
vertically.
Index: ASlider.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/widgets/ASlider.cpp,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- ASlider.cpp 30 Mar 2007 13:00:26 -0000 1.55
+++ ASlider.cpp 1 Apr 2007 07:41:06 -0000 1.56
@@ -292,7 +292,7 @@
)
{
Init(parent, name, pos, size, minValue, maxValue,
- stepValue, canUseShift, style, heavyweight, popup);
+ stepValue, canUseShift, style, heavyweight, popup, 1.0);
}
// Construct predefined slider
@@ -306,6 +306,7 @@
{
wxString leftLabel, rightLabel;
float minValue, maxValue, stepValue;
+ float speed = 1.0;
switch(style)
{
@@ -317,7 +318,8 @@
case DB_SLIDER:
minValue = -36.0f;
maxValue = 36.0f;
- stepValue = 3.0f;
+ stepValue = 1.0f;
+ speed = 0.5;
break;
case FRAC_SLIDER:
minValue = 0.0f;
@@ -338,20 +340,21 @@
}
Init(parent, name, pos, size, minValue, maxValue, stepValue,
- true, style, heavyweight, popup);
+ true, style, heavyweight, popup, speed);
}
void LWSlider::Init(wxWindow * parent,
- wxString name,
- const wxPoint &pos,
- const wxSize &size,
- float minValue,
- float maxValue,
- float stepValue,
- bool canUseShift,
- int style,
- bool heavyweight /* = false */,
- bool popup /* = true */
+ wxString name,
+ const wxPoint &pos,
+ const wxSize &size,
+ float minValue,
+ float maxValue,
+ float stepValue,
+ bool canUseShift,
+ int style,
+ bool heavyweight,
+ bool popup,
+ float speed
)
{
mName = name;
@@ -362,6 +365,7 @@
mParent = parent;
mHW = heavyweight;
mPopup = popup;
+ mSpeed = speed;
mID = wxID_ANY;
mMinValue = minValue;
mMaxValue = maxValue;
@@ -651,7 +655,18 @@
float prevValue = mCurrentValue;
- if( event.ButtonDClick() && mPopup ) // Should probably use a right click
instead
+ // Figure out the thumb position
+ wxRect r;
+ r.x = mLeft + ValueToPosition(mCurrentValue);
+ r.y = mTop + (mCenterY - (mThumbHeight / 2));
+ r.width = mThumbWidth;
+ r.height = mThumbHeight;
+
+ wxRect tolerantThumbRect = r;
+ tolerantThumbRect.Inflate(3, 3);
+
+ // Should probably use a right click instead/also
+ if( event.ButtonDClick() && mPopup )
{
//On a double-click, we should pop up a dialog.
DoShowDialog(mParent->ClientToScreen(wxPoint(event.m_x,event.m_y)));
@@ -660,36 +675,31 @@
{
mParent->SetFocus();
- // Figure out the thumb position
- wxRect r;
- r.x = mLeft + ValueToPosition(mCurrentValue);
- r.y = mTop + (mCenterY - (mThumbHeight / 2));
- r.width = mThumbWidth;
- r.height = mThumbHeight;
-
// Thumb clicked?
//
// Do not change position until first drag. This helps
// with unintended value changes.
- if( r.Inside( event.GetPosition() ) )
+ if( tolerantThumbRect.Inside( event.GetPosition() ) )
{
- // Remember mouse offset within thumb
- mClickX = event.m_x - r.x - mLeftX;
+ // Remember mouse position and current value
+ mClickX = event.m_x;
+ mClickValue = mCurrentValue;
mIsDragging = true;
- mParent->CaptureMouse();
-
- FormatPopWin();
- SetPopWinPosition();
- mPopWin->Show();
}
- // Left or right hand side clicked?
+ // Clicked to set location?
else
{
- mCurrentValue = PositionToValue(event.m_x, event.ShiftDown());
+ mCurrentValue = ClickPositionToValue(event.m_x, event.ShiftDown());
}
+
+ mParent->CaptureMouse();
+
+ FormatPopWin();
+ SetPopWinPosition();
+ mPopWin->Show();
}
- else if( event.ButtonUp() && mIsDragging )
+ else if( event.ButtonUp() )
{
mIsDragging = false;
mParent->ReleaseMouse();
@@ -698,7 +708,17 @@
}
else if( event.Dragging() && mIsDragging )
{
- mCurrentValue = PositionToValue(event.m_x - mClickX, event.ShiftDown());
+ if (event.m_y < (r.y - 2 * r.height) ||
+ event.m_y > (r.y + 3 * r.height)) {
+ // If the mouse y coordinate is relatively far from the slider,
+ // snap back to the original position
+ mCurrentValue = mClickValue;
+ }
+ else {
+ // Otherwise, move the slider to the right position based
+ // on the mouse position
+ mCurrentValue = DragPositionToValue(event.m_x, event.ShiftDown());
+ }
}
else if( event.m_wheelRotation != 0 )
{
@@ -814,20 +834,54 @@
return (int)rint((val - mMinValue) * mWidthX / (mMaxValue - mMinValue));
}
-float LWSlider::PositionToValue(int xPos, bool shiftDown)
+void LWSlider::SetSpeed(float speed)
{
- int pos = (xPos - mLeft) - mLeftX;
+ mSpeed = speed;
+}
+
+// Given the mouse x coordinate in xPos, compute the new value
+// of the slider when clicking to set a new position.
+float LWSlider::ClickPositionToValue(int xPos, bool shiftDown)
+{
+ int pos = (xPos - mLeft - (mThumbWidth / 2));
- // MM: Special cases: If position is at the very left or the
- // very right, set minimum/maximum value without other checks
if (pos <= 0)
return mMinValue;
if (pos >= mWidthX)
return mMaxValue;
-
- float val = ((float)pos/(float)mWidthX)
+
+ float val = (pos / (float)mWidthX)
* (mMaxValue - mMinValue) + mMinValue;
+ if (val < mMinValue)
+ val = mMinValue;
+ if (val > mMaxValue)
+ val = mMaxValue;
+
+ if (!(mCanUseShift && shiftDown) && mStepValue != STEP_CONTINUOUS)
+ {
+ // MM: If shift is not down, or we don't allow usage
+ // of shift key at all, trim value to steps of
+ // provided size.
+ val = (int)(val / mStepValue + 0.5 * (val>0?1.0f:-1.0f)) * mStepValue;
+ }
+
+ return val;
+}
+
+// Given the mouse x coordinate in xPos, compute the new value
+// of the slider during a drag.
+float LWSlider::DragPositionToValue(int xPos, bool shiftDown)
+{
+ int delta = (xPos - mClickX);
+ float val = mClickValue +
+ mSpeed * (delta / (float)mWidthX) * (mMaxValue - mMinValue);
+
+ if (val < mMinValue)
+ val = mMinValue;
+ if (val > mMaxValue)
+ val = mMaxValue;
+
if (!(mCanUseShift && shiftDown) && mStepValue != STEP_CONTINUOUS)
{
// MM: If shift is not down, or we don't allow usage
@@ -1055,6 +1109,11 @@
mLWSlider->Decrease(steps);
}
+void ASlider::SetSpeed(float speed)
+{
+ mLWSlider->SetSpeed(speed);
+}
+
#if wxUSE_ACCESSIBILITY
ASliderAx::ASliderAx( wxWindow * window ):
Index: ASlider.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/widgets/ASlider.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- ASlider.h 30 Mar 2007 13:00:26 -0000 1.25
+++ ASlider.h 1 Apr 2007 07:41:07 -0000 1.26
@@ -83,16 +83,17 @@
bool popup=true);
void Init(wxWindow * parent,
- wxString name,
- const wxPoint &pos,
- const wxSize &size,
- float minValue,
- float maxValue,
- float stepValue,
- bool canUseShift,
- int style,
- bool heavyweight=false,
- bool popup=true
+ wxString name,
+ const wxPoint &pos,
+ const wxSize &size,
+ float minValue,
+ float maxValue,
+ float stepValue,
+ bool canUseShift,
+ int style,
+ bool heavyweight,
+ bool popup,
+ float speed
);
virtual ~LWSlider();
@@ -106,6 +107,10 @@
void Increase(int steps);
void Decrease(int steps);
+ // If set to less than 1.0, moving the mouse one pixel will move
+ // the slider by less than 1 unit
+ void SetSpeed(float speed);
+
void Move(const wxPoint &newpos);
void OnPaint(wxDC &dc, bool selected);
@@ -130,7 +135,8 @@
void SendUpdate( float newValue );
int ValueToPosition(float val);
- float PositionToValue(int xPos, bool shiftDown);
+ float DragPositionToValue(int xPos, bool shiftDown);
+ float ClickPositionToValue(int xPos, bool shiftDown);
wxWindow* GetToolTipParent() const;
@@ -156,13 +162,14 @@
int mThumbWidth; //In pixels
int mThumbHeight; //In pixels
- int mClickValue;
+ float mClickValue;
int mClickX;
float mMinValue;
float mMaxValue;
float mStepValue;
-
+ float mSpeed;
+
float mCurrentValue;
bool mCanUseShift;
@@ -204,6 +211,8 @@
void Increase(int steps);
void Decrease(int steps);
+ void SetSpeed(float speed);
+
void OnErase(wxEraseEvent & event);
void OnPaint(wxPaintEvent & event);
void OnSize(wxSizeEvent & event);
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs