Many plot window gooddies.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6023 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
cb60902e04
commit
530a7383f2
@ -153,3 +153,21 @@ Helper function which redraws the X axis.
|
||||
|
||||
Helper function which redraws the Y axis.
|
||||
|
||||
\membersection{wxPlotWindow::SetScrollOnThumbRelease}\label{wxplotwindowsetscrollonthumbrelease}
|
||||
|
||||
\func{void}{SetScrollOnThumbRelease}{\param{bool}{ onrelease = TRUE}}
|
||||
|
||||
This function controls if the plot area will get scrolled only if the scrollbar thumb
|
||||
has been release or also if the thumb is being dragged. When displaying large amounts
|
||||
of data, it might become impossible to display the data fast enough to produce smooth
|
||||
scrolling and then this function should be called.
|
||||
|
||||
\membersection{wxPlotWindow::SetEnlargeAroundWindowCentre}\label{wxplotwindowsetenlargearoundwindowcentre}
|
||||
|
||||
\func{void}{SetEnlargeAroundWindowCentre}{\param{bool}{ aroundwindow = TRUE}}
|
||||
|
||||
Depending on the kind of data you display, the enlarging the individual curves might
|
||||
have different desired effects. Sometimes, the data will be supposed to get enlarged
|
||||
with the fixed point being the origin, sometimes the fixed point should be the centre
|
||||
of the current drawing area. This function controls this behaviour.
|
||||
|
||||
|
@ -20,14 +20,15 @@ for intercepting scroll window events from the receiving window.
|
||||
\twocolwidtha{7cm}
|
||||
\begin{twocollist}\itemsep=0pt
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN(func)}}{Process all scroll events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_TOP(func)}}{Process wxEVT\_SCROLL\_TOP scroll-to-top events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_BOTTOM(func)}}{Process wxEVT\_SCROLL\_TOP scroll-to-bottom events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_LINEUP(func)}}{Process wxEVT\_SCROLL\_LINEUP line up events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_LINEDOWN(func)}}{Process wxEVT\_SCROLL\_LINEDOWN line down events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_PAGEUP(func)}}{Process wxEVT\_SCROLL\_PAGEUP page up events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_PAGEDOWN(func)}}{Process wxEVT\_SCROLL\_PAGEDOWN page down events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_THUMBTRACK(func)}}{Process wxEVT\_SCROLL\_THUMBTRACK thumbtrack events (frequent events
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_TOP(func)}}{Process wxEVT\_SCROLLWIN\_TOP scroll-to-top events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_BOTTOM(func)}}{Process wxEVT\_SCROLLWIN\_TOP scroll-to-bottom events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_LINEUP(func)}}{Process wxEVT\_SCROLLWIN\_LINEUP line up events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_LINEDOWN(func)}}{Process wxEVT\_SCROLLWIN\_LINEDOWN line down events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_PAGEUP(func)}}{Process wxEVT\_SCROLLWIN\_PAGEUP page up events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_PAGEDOWN(func)}}{Process wxEVT\_SCROLLWIN\_PAGEDOWN page down events.}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_THUMBTRACK(func)}}{Process wxEVT\_SCROLLWIN\_THUMBTRACK thumbtrack events (frequent events
|
||||
sent as the user drags the thumtrack).}
|
||||
\twocolitem{{\bf EVT\_SCROLLWIN\_THUMBRELEASE(func)}}{Process wxEVT\_SCROLLWIN\_THUMBRELEASE thumb release events.}
|
||||
\end{twocollist}%
|
||||
|
||||
\wxheading{See also}
|
||||
|
@ -33,6 +33,7 @@ without window IDs for intercepting scroll events from the receiving window.
|
||||
\twocolitem{{\bf EVT\_SCROLL\_PAGEDOWN(func)}}{Process wxEVT\_SCROLL\_PAGEDOWN page down events.}
|
||||
\twocolitem{{\bf EVT\_SCROLL\_THUMBTRACK(func)}}{Process wxEVT\_SCROLL\_THUMBTRACK thumbtrack events (frequent events
|
||||
sent as the user drags the thumtrack).}
|
||||
\twocolitem{{\bf EVT\_SCROLL\_THUMBRELEASE(func)}}{Process wxEVT\_SCROLL\_THUMBRELEASE thumb release events.}
|
||||
\twocolitem{{\bf EVT\_COMMAND\_SCROLL(id, func)}}{Process all scroll events.}
|
||||
\twocolitem{{\bf EVT\_COMMAND\_SCROLL\_TOP(id, func)}}{Process wxEVT\_SCROLL\_TOP scroll-to-top events.}
|
||||
\twocolitem{{\bf EVT\_COMMAND\_SCROLL\_BOTTOM(id, func)}}{Process wxEVT\_SCROLL\_TOP scroll-to-bottom events.}
|
||||
|
@ -214,6 +214,19 @@ public:
|
||||
double GetZoom()
|
||||
{ return m_xZoom; }
|
||||
|
||||
// options
|
||||
// -------
|
||||
|
||||
void SetScrollOnThumbRelease( bool scrollOnThumbRelease = TRUE )
|
||||
{ m_scrollOnThumbRelease = scrollOnThumbRelease; }
|
||||
bool GetScrollOnThumbRelease()
|
||||
{ return m_scrollOnThumbRelease; }
|
||||
|
||||
void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre = TRUE )
|
||||
{ m_enlargeAroundWindowCentre = enlargeAroundWindowCentre; }
|
||||
bool GetEnlargeAroundWindowCentre()
|
||||
{ return m_enlargeAroundWindowCentre; }
|
||||
|
||||
// events (may be overridden)
|
||||
// --------------------------
|
||||
|
||||
@ -250,6 +263,9 @@ private:
|
||||
wxPlotYAxisArea *m_yaxis;
|
||||
wxPlotCurve *m_current;
|
||||
|
||||
bool m_scrollOnThumbRelease;
|
||||
bool m_enlargeAroundWindowCentre;
|
||||
|
||||
DECLARE_CLASS(wxPlotWindow)
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
@ -60,6 +60,12 @@ static wxBitmap *GetZoomOutBitmap();
|
||||
static wxBitmap *GetUpBitmap();
|
||||
static wxBitmap *GetDownBitmap();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// consts
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define wxPLOT_SCROLL_STEP 30
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxPlotEvent
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -115,8 +121,8 @@ void wxPlotArea::OnMouse( wxMouseEvent &event )
|
||||
int view_x;
|
||||
int view_y;
|
||||
m_owner->GetViewStart( &view_x, &view_y );
|
||||
view_x *= 10;
|
||||
view_y *= 10;
|
||||
view_x *= wxPLOT_SCROLL_STEP;
|
||||
view_y *= wxPLOT_SCROLL_STEP;
|
||||
|
||||
int x = event.GetX();
|
||||
int y = event.GetY();
|
||||
@ -176,7 +182,7 @@ void wxPlotArea::DrawCurve( wxDC *dc, wxPlotCurve *curve, int from, int to )
|
||||
int view_x;
|
||||
int view_y;
|
||||
m_owner->GetViewStart( &view_x, &view_y );
|
||||
view_x *= 10;
|
||||
view_x *= wxPLOT_SCROLL_STEP;
|
||||
|
||||
if (from == -1)
|
||||
from = view_x;
|
||||
@ -188,6 +194,8 @@ void wxPlotArea::DrawCurve( wxDC *dc, wxPlotCurve *curve, int from, int to )
|
||||
if (to == -1)
|
||||
to = view_x + client_width;
|
||||
|
||||
to += 2; // no idea why this is needed
|
||||
|
||||
double zoom = m_owner->GetZoom();
|
||||
|
||||
int start_x = wxMax( from, (int)floor(curve->GetStartX()*zoom) );
|
||||
@ -219,8 +227,8 @@ void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
int view_x;
|
||||
int view_y;
|
||||
m_owner->GetViewStart( &view_x, &view_y );
|
||||
view_x *= 10;
|
||||
view_y *= 10;
|
||||
view_x *= wxPLOT_SCROLL_STEP;
|
||||
view_y *= wxPLOT_SCROLL_STEP;
|
||||
|
||||
wxPaintDC dc( this );
|
||||
m_owner->PrepareDC( dc );
|
||||
@ -286,6 +294,7 @@ wxPlotXAxisArea::wxPlotXAxisArea( wxPlotWindow *parent )
|
||||
m_owner = parent;
|
||||
|
||||
SetBackgroundColour( *wxWHITE );
|
||||
SetFont( *wxSMALL_FONT );
|
||||
}
|
||||
|
||||
void wxPlotXAxisArea::OnMouse( wxMouseEvent &event )
|
||||
@ -296,8 +305,8 @@ void wxPlotXAxisArea::OnMouse( wxMouseEvent &event )
|
||||
int view_x;
|
||||
int view_y;
|
||||
m_owner->GetViewStart( &view_x, &view_y );
|
||||
view_x *= 10;
|
||||
view_y *= 10;
|
||||
view_x *= wxPLOT_SCROLL_STEP;
|
||||
view_y *= wxPLOT_SCROLL_STEP;
|
||||
|
||||
int x = event.GetX();
|
||||
int y = event.GetY();
|
||||
@ -312,8 +321,8 @@ void wxPlotXAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
int view_x;
|
||||
int view_y;
|
||||
m_owner->GetViewStart( &view_x, &view_y );
|
||||
view_x *= 10;
|
||||
view_y *= 10;
|
||||
view_x *= wxPLOT_SCROLL_STEP;
|
||||
view_y *= wxPLOT_SCROLL_STEP;
|
||||
|
||||
wxPaintDC dc( this );
|
||||
|
||||
@ -374,8 +383,14 @@ void wxPlotXAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
{
|
||||
dc.DrawLine( x, 5, x, 15 );
|
||||
wxString label;
|
||||
if (range < 10)
|
||||
label.Printf( wxT("%.1f"), current );
|
||||
if (range < 50)
|
||||
{
|
||||
label.Printf( wxT("%f"), current );
|
||||
while (label.Last() == wxT('0'))
|
||||
label.RemoveLast();
|
||||
if ((label.Last() == wxT('.')) || (label.Last() == wxT(',')))
|
||||
label.Append( wxT('0') );
|
||||
}
|
||||
else
|
||||
label.Printf( wxT("%d"), (int)floor(current) );
|
||||
dc.DrawText( label, x-4, 20 );
|
||||
@ -406,6 +421,7 @@ wxPlotYAxisArea::wxPlotYAxisArea( wxPlotWindow *parent )
|
||||
m_owner = parent;
|
||||
|
||||
SetBackgroundColour( *wxWHITE );
|
||||
SetFont( *wxSMALL_FONT );
|
||||
}
|
||||
|
||||
void wxPlotYAxisArea::OnMouse( wxMouseEvent &WXUNUSED(event) )
|
||||
@ -473,7 +489,16 @@ void wxPlotYAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
{
|
||||
dc.DrawLine( client_width-15, y, client_width-7, y );
|
||||
wxString label;
|
||||
label.Printf( wxT("%.1f"), current );
|
||||
if (range < 50)
|
||||
{
|
||||
label.Printf( wxT("%f"), current );
|
||||
while (label.Last() == wxT('0'))
|
||||
label.RemoveLast();
|
||||
if ((label.Last() == wxT('.')) || (label.Last() == wxT(',')))
|
||||
label.Append( wxT('0') );
|
||||
}
|
||||
else
|
||||
label.Printf( wxT("%d"), (int)floor(current) );
|
||||
dc.DrawText( label, 5, y-7 );
|
||||
}
|
||||
|
||||
@ -520,6 +545,9 @@ wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos,
|
||||
m_xUnitsPerValue = 1.0;
|
||||
m_xZoom = 1.0;
|
||||
|
||||
m_enlargeAroundWindowCentre = FALSE;
|
||||
m_scrollOnThumbRelease = FALSE;
|
||||
|
||||
m_area = new wxPlotArea( this );
|
||||
wxBoxSizer *mainsizer = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
@ -675,11 +703,29 @@ void wxPlotWindow::Enlarge( wxPlotCurve *curve, double factor )
|
||||
{
|
||||
m_area->DeleteCurve( curve );
|
||||
|
||||
int client_width;
|
||||
int client_height;
|
||||
m_area->GetClientSize( &client_width, &client_height);
|
||||
double offset = (double)curve->GetOffsetY() / (double)client_height;
|
||||
|
||||
double range = curve->GetEndY() - curve->GetStartY();
|
||||
offset *= range;
|
||||
|
||||
double new_range = range / factor;
|
||||
double middle = curve->GetEndY() - range/2;
|
||||
curve->SetStartY( middle - new_range / 2 );
|
||||
curve->SetEndY( middle + new_range / 2 );
|
||||
double new_offset = offset / factor;
|
||||
|
||||
if (m_enlargeAroundWindowCentre)
|
||||
{
|
||||
double middle = curve->GetStartY() - offset + range/2;
|
||||
|
||||
curve->SetStartY( middle - new_range / 2 + new_offset );
|
||||
curve->SetEndY( middle + new_range / 2 + new_offset );
|
||||
}
|
||||
else
|
||||
{
|
||||
curve->SetStartY( (curve->GetStartY() - offset)/factor + new_offset );
|
||||
curve->SetEndY( (curve->GetEndY() - offset)/factor + new_offset );
|
||||
}
|
||||
|
||||
m_area->Refresh( FALSE );
|
||||
RedrawYAxis();
|
||||
@ -710,7 +756,10 @@ void wxPlotWindow::SetZoom( double zoom )
|
||||
max = curve->GetEndX();
|
||||
node = node->Next();
|
||||
}
|
||||
SetScrollbars( 10, 10, (int)((max*m_xZoom)/10)+1, 0, (int)view_x*zoom/old_zoom, 0 );
|
||||
SetScrollbars( wxPLOT_SCROLL_STEP, wxPLOT_SCROLL_STEP,
|
||||
(int)((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1, 0,
|
||||
(int)view_x*zoom/old_zoom, 0,
|
||||
TRUE );
|
||||
|
||||
RedrawXAxis();
|
||||
m_area->Refresh( TRUE );
|
||||
@ -728,7 +777,8 @@ void wxPlotWindow::ResetScrollbar()
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
SetScrollbars( 10, 10, ((max*m_xZoom)/10)+1, 0 );
|
||||
SetScrollbars( wxPLOT_SCROLL_STEP, wxPLOT_SCROLL_STEP,
|
||||
((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1, 0 );
|
||||
}
|
||||
|
||||
void wxPlotWindow::RedrawXAxis()
|
||||
@ -778,9 +828,11 @@ void wxPlotWindow::OnShrink( wxCommandEvent& WXUNUSED(event) )
|
||||
|
||||
void wxPlotWindow::OnScroll2( wxScrollWinEvent& event )
|
||||
{
|
||||
wxScrolledWindow::OnScroll( event );
|
||||
|
||||
RedrawXAxis();
|
||||
if ((!m_scrollOnThumbRelease) || (event.GetEventType() != wxEVT_SCROLLWIN_THUMBTRACK))
|
||||
{
|
||||
wxScrolledWindow::OnScroll( event );
|
||||
RedrawXAxis();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -317,6 +317,7 @@ int wxScrolledWindow::CalcScrollInc(wxScrollWinEvent& event)
|
||||
break;
|
||||
}
|
||||
case wxEVT_SCROLLWIN_THUMBTRACK:
|
||||
case wxEVT_SCROLLWIN_THUMBRELEASE:
|
||||
{
|
||||
if (orient == wxHORIZONTAL)
|
||||
nScrollInc = pos - m_xScrollPosition;
|
||||
|
Loading…
Reference in New Issue
Block a user