Audacity  3.2.0
Public Member Functions | Public Attributes | List of all members
anonymous_namespace{ProjectWindow.cpp}::MouseWheelHandler Struct Reference

Public Member Functions

 MouseWheelHandler ()
 
unsigned operator() (const TrackPanelMouseEvent &evt, AudacityProject *pProject) const
 

Public Attributes

double mVertScrollRemainder = 0.0
 

Detailed Description

Definition at line 359 of file ProjectWindow.cpp.

Constructor & Destructor Documentation

◆ MouseWheelHandler()

anonymous_namespace{ProjectWindow.cpp}::MouseWheelHandler::MouseWheelHandler ( )
inline

Definition at line 361 of file ProjectWindow.cpp.

362 {
364 }

References CommonTrackPanelCell::InstallMouseWheelHook().

Here is the call graph for this function:

Member Function Documentation

◆ operator()()

unsigned anonymous_namespace{ProjectWindow.cpp}::MouseWheelHandler::operator() ( const TrackPanelMouseEvent evt,
AudacityProject pProject 
) const
inline

Definition at line 369 of file ProjectWindow.cpp.

371 {
372  using namespace RefreshCode;
373 
374  if ( TrackList::Get( *pProject ).empty() )
375  // Scrolling and Zoom in and out commands are disabled when there are no tracks.
376  // This should be disabled too for consistency. Otherwise
377  // you do see changes in the time ruler.
378  return Cancelled;
379 
380  unsigned result = RefreshAll;
381  const wxMouseEvent &event = evt.event;
382  auto &viewInfo = ViewInfo::Get( *pProject );
383  Scrubber &scrubber = Scrubber::Get( *pProject );
384  auto &window = ProjectWindow::Get( *pProject );
385  const auto steps = evt.steps;
386 
387  if (event.ShiftDown()
388  // Don't pan during smooth scrolling. That would conflict with keeping
389  // the play indicator centered.
390  && !scrubber.IsScrollScrubbing()
391  )
392  {
393  // MM: Scroll left/right when used with Shift key down
394  window.TP_ScrollWindow(
395  viewInfo.OffsetTimeByPixels(
396  viewInfo.PositionToTime(0), 50.0 * -steps));
397  }
398  else if (event.CmdDown())
399  {
400 #if 0
401  // JKC: Alternative scroll wheel zooming code
402  // using AudacityProject zooming, which is smarter,
403  // it keeps selections on screen and centred if it can,
404  // also this ensures mousewheel and zoom buttons give same result.
405  double ZoomFactor = pow(2.0, steps);
406  AudacityProject *p = GetProject();
407  if( steps > 0 )
408  // PRL: Track panel refresh may be needed if you reenable this
409  // code, but we don't want this file dependent on TrackPanel.cpp
410  p->ZoomInByFactor( ZoomFactor );
411  else
412  p->ZoomOutByFactor( ZoomFactor );
413 #endif
414  // MM: Zoom in/out when used with Control key down
415  // We're converting pixel positions to times,
416  // counting pixels from the left edge of the track.
417  int trackLeftEdge = viewInfo.GetLeftOffset();
418 
419  // Time corresponding to mouse position
420  wxCoord xx;
421  double center_h;
422  double mouse_h = viewInfo.PositionToTime(event.m_x, trackLeftEdge);
423 
424  // Scrubbing? Expand or contract about the center, ignoring mouse position
425  if (scrubber.IsScrollScrubbing())
426  center_h = viewInfo.h +
427  (viewInfo.GetScreenEndTime() - viewInfo.h) / 2.0;
428  // Zooming out? Focus on mouse.
429  else if( steps <= 0 )
430  center_h = mouse_h;
431  // No Selection? Focus on mouse.
432  else if((viewInfo.selectedRegion.t1() - viewInfo.selectedRegion.t0() ) < 0.00001 )
433  center_h = mouse_h;
434  // Before Selection? Focus on left
435  else if( mouse_h < viewInfo.selectedRegion.t0() )
436  center_h = viewInfo.selectedRegion.t0();
437  // After Selection? Focus on right
438  else if( mouse_h > viewInfo.selectedRegion.t1() )
439  center_h = viewInfo.selectedRegion.t1();
440  // Inside Selection? Focus on mouse
441  else
442  center_h = mouse_h;
443 
444  xx = viewInfo.TimeToPosition(center_h, trackLeftEdge);
445 
446  // Time corresponding to last (most far right) audio.
447  double audioEndTime = TrackList::Get( *pProject ).GetEndTime();
448 
449 // Disabled this code to fix Bug 1923 (tricky to wheel-zoom right of waveform).
450 #if 0
451  // When zooming in empty space, it's easy to 'lose' the waveform.
452  // This prevents it.
453  // IF zooming in
454  if (steps > 0)
455  {
456  // IF mouse is to right of audio
457  if (center_h > audioEndTime)
458  // Zooming brings far right of audio to mouse.
459  center_h = audioEndTime;
460  }
461 #endif
462 
463  wxCoord xTrackEnd = viewInfo.TimeToPosition( audioEndTime );
464  viewInfo.ZoomBy(pow(2.0, steps));
465 
466  double new_center_h = viewInfo.PositionToTime(xx, trackLeftEdge);
467  viewInfo.h += (center_h - new_center_h);
468 
469  // If wave has gone off screen, bring it back.
470  // This means that the end of the track stays where it was.
471  if( viewInfo.h > audioEndTime )
472  viewInfo.h += audioEndTime - viewInfo.PositionToTime( xTrackEnd );
473 
474 
475  result |= FixScrollbars;
476  }
477  else
478  {
479 #ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL
480  if (scrubber.IsScrubbing()) {
481  scrubber.HandleScrollWheel(steps);
482  evt.event.Skip(false);
483  }
484  else
485 #endif
486  {
487  // MM: Scroll up/down when used without modifier keys
488  double lines = steps * 4 + mVertScrollRemainder;
489  mVertScrollRemainder = lines - floor(lines);
490  lines = floor(lines);
491  auto didSomething = window.TP_ScrollUpDown((int)-lines);
492  if (!didSomething)
493  result |= Cancelled;
494  }
495  }
496 
497  return result;
498 }

References RefreshCode::Cancelled, TrackList::empty(), RefreshCode::FixScrollbars, ViewInfo::Get(), TrackList::Get(), ProjectWindow::Get(), Scrubber::Get(), TrackList::GetEndTime(), Scrubber::HandleScrollWheel(), Scrubber::IsScrollScrubbing(), Scrubber::IsScrubbing(), and RefreshCode::RefreshAll.

Here is the call graph for this function:

Member Data Documentation

◆ mVertScrollRemainder

double anonymous_namespace{ProjectWindow.cpp}::MouseWheelHandler::mVertScrollRemainder = 0.0
mutable

Definition at line 367 of file ProjectWindow.cpp.


The documentation for this struct was generated from the following file:
RefreshCode::FixScrollbars
@ FixScrollbars
Definition: RefreshCode.h:27
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
Scrubber::Get
static Scrubber & Get(AudacityProject &project)
Definition: Scrubbing.cpp:202
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
ProjectWindow::Get
static ProjectWindow & Get(AudacityProject &project)
Definition: ProjectWindow.cpp:535
Scrubber
Definition: Scrubbing.h:45
CommonTrackPanelCell::InstallMouseWheelHook
static Hook InstallMouseWheelHook(const Hook &hook)
Definition: CommonTrackPanelCell.cpp:35
TrackList::GetEndTime
double GetEndTime() const
Definition: Track.cpp:897
Scrubber::IsScrollScrubbing
bool IsScrollScrubbing() const
Definition: Scrubbing.h:94
Scrubber::HandleScrollWheel
void HandleScrollWheel(int steps)
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:377
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
Scrubber::IsScrubbing
bool IsScrubbing() const
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
TrackList::empty
bool empty() const
Definition: Track.cpp:854
TrackPanelMouseEvent::event
wxMouseEvent & event
Definition: TrackPanelMouseEvent.h:58
TrackPanelMouseEvent::steps
double steps
Definition: TrackPanelMouseEvent.h:62
anonymous_namespace{ProjectWindow.cpp}::MouseWheelHandler::mVertScrollRemainder
double mVertScrollRemainder
Definition: ProjectWindow.cpp:367