Allow dragging the flux viewer.

This commit is contained in:
David Given
2022-08-06 21:37:46 +02:00
parent 2d5e91b853
commit 8eb25a911d
2 changed files with 30 additions and 0 deletions

View File

@@ -30,6 +30,9 @@ FluxViewerControl::FluxViewerControl(wxWindow* parent,
wxBEGIN_EVENT_TABLE(FluxViewerControl, wxPanel)
EVT_PAINT(FluxViewerControl::OnPaint)
EVT_MOUSEWHEEL(FluxViewerControl::OnMouseWheel)
EVT_LEFT_DOWN(FluxViewerControl::OnMouseMotion)
EVT_LEFT_UP(FluxViewerControl::OnMouseMotion)
EVT_MOTION(FluxViewerControl::OnMouseMotion)
wxEND_EVENT_TABLE()
void FluxViewerControl::SetScrollbar(wxScrollBar* scrollbar)
@@ -300,3 +303,27 @@ void FluxViewerControl::OnScrollbarChanged(wxScrollEvent& event)
Refresh();
}
void FluxViewerControl::OnMouseMotion(wxMouseEvent& event)
{
wxClientDC dc(this);
event.Skip();
if (event.ButtonDown(wxMOUSE_BTN_LEFT))
{
_dragStartX = event.GetLogicalPosition(dc).x;
_dragStartPosition = _scrollPosition;
}
else if (event.ButtonUp(wxMOUSE_BTN_LEFT))
{
/* end drag, do nothing */
}
else if (event.Dragging())
{
int dx = _dragStartX - event.GetLogicalPosition(dc).x;
nanoseconds_t dt = dx * _nanosecondsPerPixel;
_scrollPosition = _dragStartPosition + dt;
UpdateScale();
Refresh();
}
}

View File

@@ -27,6 +27,7 @@ private:
void OnPaint(wxPaintEvent&);
void OnMouseWheel(wxMouseEvent&);
void OnScrollbarChanged(wxScrollEvent&);
void OnMouseMotion(wxMouseEvent&);
private:
wxScrollBar* _scrollbar;
@@ -35,6 +36,8 @@ private:
nanoseconds_t _totalDuration;
double _nanosecondsPerPixel;
std::vector<float> _densityMap;
int _dragStartX;
nanoseconds_t _dragStartPosition;
wxDECLARE_EVENT_TABLE();
};