Skip to content

Commit

Permalink
Scrollwheel 607 - Add scrollwheel support to various controls (surge-…
Browse files Browse the repository at this point in the history
…synthesizer#650)

Scrollwheel support for most of the UI elements, but most importantly, for sliders when moused over allows quick editing with scroll gestures. 

Closes surge-synthesizer#605 flashing popups
Closes surge-synthesizer#607 scroll wheel support
  • Loading branch information
rghvdberg authored and baconpaul committed Feb 24, 2019
1 parent dc81bcb commit b46339e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/common/gui/CHSwitch2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,26 @@ CMouseEventResult CHSwitch2::onMouseMoved(CPoint& where, const CButtonState& but
}
return kMouseEventNotHandled;
}
bool CHSwitch2::onWheel(const CPoint& where, const float& distance, const CButtonState& buttons)
{
float newVal=value;
float rate = 1.0f;
float range = getRange();
if (columns >1)
{
rate = range / (float)columns;
newVal += rate * distance;
}
else
{
rate = range / (float)rows;
newVal += rate * -distance; // flip distance (==direction) because it makes more sense when wheeling
}
beginEdit();
value = newVal;
bounceValue();
if (listener)
listener->valueChanged(this);
setValue(value);
return true;
}
2 changes: 2 additions & 0 deletions src/common/gui/CHSwitch2.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ class CHSwitch2 : public VSTGUI::CHorizontalSwitch
virtual VSTGUI::CMouseEventResult
onMouseMoved(VSTGUI::CPoint& where,
const VSTGUI::CButtonState& buttons); ///< called when a mouse move event occurs
virtual bool
onWheel (const VSTGUI::CPoint& where, const float& distance, const VSTGUI::CButtonState& buttons); ///< called when scrollwheel events occurs
CLASS_METHODS(CHSwitch2, VSTGUI::CControl)
};
16 changes: 15 additions & 1 deletion src/common/gui/CNumberField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,21 @@ CMouseEventResult CNumberField::onMouseMoved(CPoint& where, const CButtonState&
}
return kMouseEventHandled;
}

bool CNumberField::onWheel(const CPoint& where, const float& distance, const CButtonState& buttons)
{
beginEdit();
i_value += int(distance);
int steps = i_max - i_min;
int offset = i_value - i_min;
float multiplier = 1.0f / (float) steps;
value = (float) offset * multiplier;
setIntValue(i_value); // also does bounceValue for i_value and value ..and setDirty
setValue(value);
if (isDirty() && listener)
listener->valueChanged(this);
endEdit();
return true;
}
//------------------------------------------------------------------------
/*void CParamEdit::mouse (CDrawContext *pContext, CPoint &where, long buttons)
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/gui/CNumberField.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class CNumberField : public VSTGUI::CControl
virtual VSTGUI::CMouseEventResult onMouseDown(VSTGUI::CPoint& where, const VSTGUI::CButtonState& buttons);
virtual VSTGUI::CMouseEventResult onMouseUp(VSTGUI::CPoint& where, const VSTGUI::CButtonState& buttons);
virtual VSTGUI::CMouseEventResult onMouseMoved(VSTGUI::CPoint& where, const VSTGUI::CButtonState& buttons);
// virtual bool onWheel (VSTGUI::CDrawContext *pContext, const VSTGUI::CPoint &where, float distance);
virtual bool onWheel(const VSTGUI::CPoint& where, const float& distance, const VSTGUI::CButtonState& buttons);
bool altlook;

private:
Expand Down
33 changes: 33 additions & 0 deletions src/common/gui/CSurgeSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,36 @@ void CSurgeSlider::setBipolar(bool b)

setDirty();
}
bool CSurgeSlider::onWheel(const VSTGUI::CPoint& where, const float &distance, const VSTGUI::CButtonState& buttons)
{
// shift + scrollwheel for fine control
double rate = 0.1 * moverate;
if (buttons & kShift)
rate *= 0.05;

edit_value = modmode ? &modval : &value;
oldVal = *edit_value;

beginEdit();
*edit_value += rate * distance;
bounceValue();
if (modmode)
{
setModValue(*edit_value);
}
else
{
setValue(value);
}
setDirty();
if (isDirty() && listener)
listener->valueChanged(this);
//endEdit();
/*
** No need to call endEdit since the timer in SurgeGUIEditor will close the
** info window, and SurgeGUIEditor will make sure a window
** doesn't appear twice
*/
edit_value = nullptr;
return true;
}
2 changes: 2 additions & 0 deletions src/common/gui/CSurgeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CSurgeSlider : public CCursorHidingControl
virtual void draw(VSTGUI::CDrawContext*);
// virtual void mouse (VSTGUI::CDrawContext *pContext, VSTGUI::CPoint &where, long buttons = -1);
// virtual bool onWheel (VSTGUI::CDrawContext *pContext, const VSTGUI::CPoint &where, float distance);
virtual bool
onWheel(const VSTGUI::CPoint& where, const float &distane, const VSTGUI::CButtonState& buttons);

virtual VSTGUI::CMouseEventResult
onMouseDown(VSTGUI::CPoint& where,
Expand Down
12 changes: 12 additions & 0 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2426,10 +2426,22 @@ void SurgeGUIEditor::draw_infowindow(int ptag, CControl* control, bool modulate,

if (buttons || forceMB)
{
// make sure an infowindow doesn't appear twice
if (((CParameterTooltip*)infowindow)->isVisible())
{
((CParameterTooltip*)infowindow)->Hide();
((CParameterTooltip*)infowindow)->invalid();
}

((CParameterTooltip*)infowindow)->setViewSize(r);
((CParameterTooltip*)infowindow)->Show();
infowindow->invalid();
// on Linux the infoview closes too soon
#if LINUX
clear_infoview_countdown = 100;
#else
clear_infoview_countdown = 40;
#endif
}
else
{
Expand Down

0 comments on commit b46339e

Please sign in to comment.