| 732 | } |
| 733 | |
| 734 | void TrackPanel::OnMouseEvent(wxMouseEvent & event) |
| 735 | { |
| 736 | if (event.LeftDown()) { |
| 737 | // wxTimers seem to be a little unreliable, so this |
| 738 | // "primes" it to make sure it keeps going for a while... |
| 739 | |
| 740 | // When this timer fires, we call TrackPanel::OnTimer and |
| 741 | // possibly update the screen for offscreen scrolling. |
| 742 | mTimer.Stop(); |
| 743 | mTimer.Start(std::chrono::milliseconds{kTimerInterval}.count(), FALSE); |
| 744 | } |
| 745 | |
| 746 | if (event.MiddleDown()) { |
| 747 | mIsPanning = true; |
| 748 | mLastPanX = event.GetX(); |
| 749 | CaptureMouse(); |
| 750 | } |
| 751 | else if (event.MiddleUp()) { |
| 752 | mIsPanning = false; |
| 753 | ReleaseMouse(); |
| 754 | } |
| 755 | else if (event.Dragging() && mIsPanning) { |
| 756 | int dx = event.GetX() - mLastPanX; |
| 757 | mLastPanX = event.GetX(); |
| 758 | |
| 759 | Viewport::Get(*GetProject()).ScrollHorizontalByPixels(-dx); |
| 760 | } |
| 761 | |
| 762 | if (event.ButtonUp()) { |
| 763 | //ShowTrack should be called after processing the up-click. |
| 764 | this->CallAfter( [this, event]{ |
| 765 | const auto foundCell = FindCell(event.m_x, event.m_y); |
| 766 | const auto t = FindTrack( foundCell.pCell.get() ); |
| 767 | if (t) { |
| 768 | auto &focus = TrackFocus::Get(*GetProject()); |
| 769 | focus.Set(t.get()); |
| 770 | Viewport::Get(*GetProject()).ShowTrack(*t); |
| 771 | } |
| 772 | } ); |
| 773 | } |
| 774 | |
| 775 | // Must also fall through to base class handler |
| 776 | event.Skip(); |
| 777 | } |
| 778 | |
| 779 | double TrackPanel::GetMostRecentXPos() |
| 780 | { |