Skip to content

Commit

Permalink
Add and use SjWheelHelper class.
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Jan 12, 2016
1 parent 35dd64e commit 6927d7c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 71 deletions.
57 changes: 35 additions & 22 deletions src/sjbase/browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,6 @@ void SjBrowserWindow::OnMouseMotion(wxMouseEvent& event)
}


static void simulateSlider(long rotation, long wheelDelta, int targetUp, int targetDown)
{
SjSkinValue dummy;
long i, cnt = (rotation>0? rotation : (rotation*-1))/wheelDelta;
if( cnt<1 ) cnt = 1; if( cnt > 3 ) cnt = 3;
for( i = 0; i < cnt; i++ )
{
g_mainFrame->OnSkinTargetEvent(rotation>0?targetUp:targetDown, dummy, 0);
}
}


void SjBrowserWindow::OnMouseWheel(wxMouseEvent& event)
{
if( g_accelModule == NULL || m_mouseAction == SJ_ACTION_DRAGNDROP
Expand All @@ -203,8 +191,6 @@ void SjBrowserWindow::OnMouseWheel(wxMouseEvent& event)

// get information about the mouse wheel event

long rotation = event.GetWheelRotation();
long wheelDelta = event.GetWheelDelta();
bool scrollVert = event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL? false : true;
if( ((event.AltDown() || event.ShiftDown() || event.CmdDown() || event.ControlDown()) && g_accelModule->m_flags&SJ_ACCEL_WHEEL_MODIFIER_AXIS_TOGGLE)
|| (event.RightIsDown() && g_accelModule->m_flags&SJ_ACCEL_WHEEL_RMOUSE_AXIS_TOGGLE) )
Expand Down Expand Up @@ -232,7 +218,13 @@ void SjBrowserWindow::OnMouseWheel(wxMouseEvent& event)
{
if( scrollVert )
{
simulateSlider(rotation, wheelDelta, IDT_DISPLAY_UP, IDT_DISPLAY_DOWN);
static SjWheelHelper s_dispWheelHelper;
long actions, dir; s_dispWheelHelper.PushRotationNPopAction(event, actions, dir);
while( actions-- )
{
SjSkinValue dummy;
g_mainFrame->OnSkinTargetEvent(dir>0?IDT_DISPLAY_UP:IDT_DISPLAY_DOWN, dummy, 0);
}
}
return;
}
Expand All @@ -245,7 +237,13 @@ void SjBrowserWindow::OnMouseWheel(wxMouseEvent& event)
{
if( scrollVert )
{
simulateSlider(rotation, wheelDelta, IDT_MAIN_VOL_UP, IDT_MAIN_VOL_DOWN);
static SjWheelHelper s_volWheelHelper;
long actions, dir; s_volWheelHelper.PushRotationNPopAction(event, actions, dir);
while( actions-- )
{
SjSkinValue dummy;
g_mainFrame->OnSkinTargetEvent(dir>0?IDT_MAIN_VOL_UP:IDT_MAIN_VOL_DOWN, dummy, 0);
}
}
return;
}
Expand All @@ -255,8 +253,13 @@ void SjBrowserWindow::OnMouseWheel(wxMouseEvent& event)
{
if( scrollVert )
{
SjSkinValue dummy;
g_mainFrame->OnSkinTargetEvent(rotation>0?IDT_WORKSPACE_GOTO_PREV_AZ:IDT_WORKSPACE_GOTO_NEXT_AZ, dummy, 0);
static SjWheelHelper s_azWheelHelper;
long actions, dir; s_azWheelHelper.PushRotationNPopAction(event, actions, dir);
while( actions-- )
{
SjSkinValue dummy;
g_mainFrame->OnSkinTargetEvent(dir>0?IDT_WORKSPACE_GOTO_PREV_AZ:IDT_WORKSPACE_GOTO_NEXT_AZ, dummy, 0);
}
}
return;
}
Expand All @@ -268,8 +271,13 @@ void SjBrowserWindow::OnMouseWheel(wxMouseEvent& event)
{
if( scrollVert )
{
SjSkinValue dummy;
g_mainFrame->OnSkinTargetEvent(rotation>0?IDT_WORKSPACE_LINE_LEFT:IDT_WORKSPACE_LINE_RIGHT, dummy, 0);
static SjWheelHelper s_hscrollWheelHelper;
long actions, dir; s_hscrollWheelHelper.PushRotationNPopAction(event, actions, dir);
while( actions-- )
{
SjSkinValue dummy;
g_mainFrame->OnSkinTargetEvent(dir>0?IDT_WORKSPACE_LINE_LEFT:IDT_WORKSPACE_LINE_RIGHT, dummy, 0);
}
return;
}
}
Expand All @@ -281,8 +289,13 @@ void SjBrowserWindow::OnMouseWheel(wxMouseEvent& event)
{
if( scrollVert )
{
SjSkinValue dummy;
g_mainFrame->OnSkinTargetEvent(rotation>0?IDT_WORKSPACE_LINE_UP:IDT_WORKSPACE_LINE_DOWN, dummy, 0); // needed to allow vertical scrolling if SJ_ACCEL_WHEEL_HORZ_IN_ALBUMVIEW is set
static SjWheelHelper s_vscrollWheelHelper;
long actions, dir; s_vscrollWheelHelper.PushRotationNPopAction(event, actions, dir);
while( actions-- )
{
SjSkinValue dummy;
g_mainFrame->OnSkinTargetEvent(dir>0?IDT_WORKSPACE_LINE_UP:IDT_WORKSPACE_LINE_DOWN, dummy, 0); // needed to allow vertical scrolling if SJ_ACCEL_WHEEL_HORZ_IN_ALBUMVIEW is set
}
return;
}
}
Expand Down
24 changes: 8 additions & 16 deletions src/sjbase/browser_album.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,12 @@ void SjAlbumBrowser::OnMouseMotion(wxMouseEvent& event)
void SjAlbumBrowser::OnMouseWheel(wxMouseEvent& event, bool scrollVert)
{
long rotation = event.GetWheelRotation();
long delta = event.GetWheelDelta();

if( rotation != 0 && delta > 0 )
if( rotation != 0 )
{
if( g_accelModule->m_flags&SJ_ACCEL_WHEEL_HORZ_IN_ALBUMVIEW )
{
scrollVert = !scrollVert;
if( !scrollVert )
{
rotation *= -1; // simulate the old behaviour of Silverjuke 2.x - not compatible with modern scroll whells with more than one axis!
}
}

if( scrollVert )
Expand All @@ -494,18 +489,15 @@ void SjAlbumBrowser::OnMouseWheel(wxMouseEvent& event, bool scrollVert)
else
{
// add multiple small rotations (smaller than the delta to take action) to bigger ones
static long s_addedRotation = 0;
if( (rotation < 0 && s_addedRotation > 0) || (rotation > 0 && s_addedRotation < 0) )
{
s_addedRotation = 0; // discard saved scrolling for the wrong direction
}
s_addedRotation += rotation;

long rotateCols = s_addedRotation/delta;
static SjWheelHelper s_albumWheelHelper;
long rotateCols, dir; s_albumWheelHelper.PushRotationNPopAction(event, rotateCols, dir);
if( rotateCols != 0 )
{
s_addedRotation -= rotateCols*delta;
OnHScroll(IDT_WORKSPACE_H_SCROLL, m_applColIndex + rotateCols, TRUE/*redraw*/); // TOCHEK: Maybe we should use fine scrolling here
if( g_accelModule->m_flags&SJ_ACCEL_WHEEL_HORZ_IN_ALBUMVIEW )
{
dir *= -1; // simulate the old behaviour of Silverjuke 2.x - not compatible with modern scroll wheels with more than one axis!
}
OnHScroll(IDT_WORKSPACE_H_SCROLL, m_applColIndex + rotateCols*dir, TRUE/*redraw*/);
}
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/sjbase/browser_cover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,24 +459,14 @@ void SjCoverBrowser::OnMouseMotion(wxMouseEvent& event)

void SjCoverBrowser::OnMouseWheel(wxMouseEvent& event, bool scrollVert)
{
long rotation = event.GetWheelRotation();
long delta = event.GetWheelDelta();

if( scrollVert && rotation!=0 && delta>0 )
if( scrollVert )
{
// add multiple small rotations (smaller than the delta to take action) to bigger ones
static long s_addedRotation = 0;
if( (rotation < 0 && s_addedRotation > 0) || (rotation > 0 && s_addedRotation < 0) )
{
s_addedRotation = 0; // discard saved scrolling for the wrong direction
}
s_addedRotation += rotation;

long rotateCovers = s_addedRotation/delta;
static SjWheelHelper s_coverBrowserWheelHelper;
long rotateCovers, dir; s_coverBrowserWheelHelper.PushRotationNPopAction(event, rotateCovers, dir);
if( rotateCovers != 0 )
{
s_addedRotation -= rotateCovers*delta;
OnVScroll(IDT_WORKSPACE_V_SCROLL, m_applRowIndex + rotateCovers*-1, TRUE/*redraw*/);
OnVScroll(IDT_WORKSPACE_V_SCROLL, m_applRowIndex + rotateCovers*dir*-1, TRUE/*redraw*/);
}
}
}
Expand Down
27 changes: 11 additions & 16 deletions src/sjbase/browser_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,29 +1032,24 @@ void SjListBrowser::OnMouseMotion(wxMouseEvent& event)
void SjListBrowser::OnMouseWheel(wxMouseEvent& event, bool scrollVert)
{
long rotation = event.GetWheelRotation();
long delta = event.GetWheelDelta();

if( rotation != 0 && delta > 0 )
if( rotation != 0 )
{
if( scrollVert )
{
// We take action 4 times faster as normal to make things more comparable with
// the scrolling in the album view (line-by-line scrolling is too slow and page scrolling is too fast)
delta /= 4;

// add multiple small rotations (smaller than the delta to take action) to bigger ones
static long s_addedRotation = 0;
if( (rotation < 0 && s_addedRotation > 0) || (rotation > 0 && s_addedRotation < 0) )
{
s_addedRotation = 0; // discard saved scrolling for the wrong direction
}
s_addedRotation += rotation;

long rotateLines = s_addedRotation/delta;
static SjWheelHelper s_coverViewWheelHelper;
long rotateLines, dir; s_coverViewWheelHelper.PushRotationNPopAction(event, rotateLines, dir);
if( rotateLines != 0 )
{
s_addedRotation -= rotateLines*delta;
OnVScroll(IDT_WORKSPACE_V_SCROLL, m_scrollPos + rotateLines*-1, TRUE/*redraw*/);
// We take action 4 times faster as normal to make things more comparable with
// the scrolling in the album view (line-by-line scrolling is too slow and page scrolling is too fast)
float multiplier = m_fontHeight > 0? (event.GetWheelDelta()/m_fontHeight) : 1;
if( multiplier < 1 ) multiplier = 1;
if( multiplier > 8 ) multiplier = 8;
rotateLines = (long)((float)rotateLines * multiplier);

OnVScroll(IDT_WORKSPACE_V_SCROLL, m_scrollPos + rotateLines*dir*-1, TRUE/*redraw*/);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/sjmodules/accel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ void SjAccelModule::GetLittleOptions(SjArrayLittleOption& lo)
&m_flags, 0L, SJ_ACCEL_WHEEL_MODIFIER_AXIS_TOGGLE, "main/accelFlags"));
lo.Add(new SjLittleBit (_("Right mouse button toggles axis"), "yn",
&m_flags, 0L, SJ_ACCEL_WHEEL_RMOUSE_AXIS_TOGGLE, "main/accelFlags"));
lo.Add(new SjLittleBit (_("Value input"), "oo",
lo.Add(new SjLittleBit (_("Modify volume, scrollbars, letters etc."), "yn",
&m_flags, 0L, SJ_ACCEL_WHEEL_VALUE_INPUT, "main/accelFlags"));

// find out the extra menu items
Expand Down
42 changes: 41 additions & 1 deletion src/sjtools/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4155,7 +4155,7 @@ bool SjTrackInfoMatcher::GotMatch(const wxString& placeholder, const wxString& t


/*******************************************************************************
* SjProp Class
* SjProp Class
******************************************************************************/


Expand Down Expand Up @@ -4207,6 +4207,46 @@ void SjProp::AddBytes(const wxString& name, long value, long flags)
}


/*******************************************************************************
* SjWheelHelper Class
******************************************************************************/


SjWheelHelper::SjWheelHelper()
{
m_availRotation = 0;
}


void SjWheelHelper::PushRotationNPopAction(wxMouseEvent& e, long& actions, long& dir)
{
// collect rotations ...
long rotation = e.GetWheelRotation();
if( (rotation < 0 && m_availRotation > 0) || (rotation > 0 && m_availRotation < 0) )
{
m_availRotation = 0; // discard saved scrolling for the wrong direction
}
m_availRotation += rotation;

// ... use rotation, return the number of actions to perform
long delta = e.GetWheelDelta();
if( delta <= 0 ) delta = 120;

actions = m_availRotation/delta;
m_availRotation -= actions*delta;

// separate sign from action
dir = 1;
if( actions < 0 )
{
actions *= -1;
dir = -1;
}

if( actions > 2000 ) { actions = 2000; } // shdould not happen, added for safety
}


/*******************************************************************************
* SjLLHash - Hash long => long
******************************************************************************/
Expand Down
20 changes: 19 additions & 1 deletion src/sjtools/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,25 @@ class SjProp


/*******************************************************************************
* Hardware Graphic Stuff, Misc.
* SjWheelHelper Class
******************************************************************************/


class SjWheelHelper
{
public:
// the wheel helper class collects mouse wheel events and pop actions based on
// delta and the collected rotations. use a static/persistent object for this to work.
SjWheelHelper ();
void PushRotationNPopAction (wxMouseEvent& e, long& actions, long& dir);

private:
long m_availRotation;
};


/*******************************************************************************
* Hardware Graphic Stuff, Misc.
******************************************************************************/


Expand Down

0 comments on commit 6927d7c

Please sign in to comment.