X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/279ababf7baa0655a58074b868da222db7cc5a4b..ffae916f44b271928c3ab7d734a2e9fd89a59e94:/src/generic/plot.cpp?ds=inline diff --git a/src/generic/plot.cpp b/src/generic/plot.cpp index 0da3f4ec79..825f5fbbb6 100644 --- a/src/generic/plot.cpp +++ b/src/generic/plot.cpp @@ -20,6 +20,8 @@ #pragma hdrstop #endif +#if wxUSE_PLOT + #ifndef WX_PRECOMP #include "wx/object.h" #include "wx/font.h" @@ -60,6 +62,12 @@ static wxBitmap *GetZoomOutBitmap(); static wxBitmap *GetUpBitmap(); static wxBitmap *GetDownBitmap(); +//----------------------------------------------------------------------------- +// consts +//----------------------------------------------------------------------------- + +#define wxPLOT_SCROLL_STEP 30 + //----------------------------------------------------------------------------- // wxPlotEvent //----------------------------------------------------------------------------- @@ -115,8 +123,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 +184,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; @@ -187,6 +195,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(); @@ -219,8 +229,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 +296,7 @@ wxPlotXAxisArea::wxPlotXAxisArea( wxPlotWindow *parent ) m_owner = parent; SetBackgroundColour( *wxWHITE ); + SetFont( *wxSMALL_FONT ); } void wxPlotXAxisArea::OnMouse( wxMouseEvent &event ) @@ -296,8 +307,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 +323,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 +385,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 +423,7 @@ wxPlotYAxisArea::wxPlotYAxisArea( wxPlotWindow *parent ) m_owner = parent; SetBackgroundColour( *wxWHITE ); + SetFont( *wxSMALL_FONT ); } void wxPlotYAxisArea::OnMouse( wxMouseEvent &WXUNUSED(event) ) @@ -473,7 +491,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 ); } @@ -519,6 +546,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 ); @@ -630,6 +660,17 @@ void wxPlotWindow::SetCurrent( wxPlotCurve* current ) GetEventHandler()->ProcessEvent( event ); } +void wxPlotWindow::Delete( wxPlotCurve* curve ) +{ + wxNode *node = m_curves.Find( curve ); + if (!node) return; + + m_curves.DeleteObject( curve ); + + m_area->DeleteCurve( curve ); + m_area->Refresh( FALSE ); +} + wxPlotCurve *wxPlotWindow::GetCurrent() { return m_current; @@ -664,11 +705,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(); @@ -699,7 +758,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 ); @@ -717,7 +779,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() @@ -767,9 +830,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(); + } } // ---------------------------------------------------------------------------- @@ -787,7 +852,7 @@ static wxBitmap *GetEnlargeBitmap() s_loaded = TRUE; // set it to TRUE anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_enl.bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap("plot_enl_bmp", wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_enl_xpm ); #endif @@ -806,7 +871,7 @@ static wxBitmap *GetShrinkBitmap() s_loaded = TRUE; // set it to TRUE anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_shr.bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap("plot_shr_bmp", wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_shr_xpm ); #endif @@ -825,7 +890,7 @@ static wxBitmap *GetZoomInBitmap() s_loaded = TRUE; // set it to TRUE anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_zin.bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap("plot_zin_bmp", wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_zin_xpm ); #endif @@ -844,7 +909,7 @@ static wxBitmap *GetZoomOutBitmap() s_loaded = TRUE; // set it to TRUE anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_zot.bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap("plot_zot_bmp", wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_zot_xpm ); #endif @@ -863,7 +928,7 @@ static wxBitmap *GetUpBitmap() s_loaded = TRUE; // set it to TRUE anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_up.bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap("plot_up_bmp", wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_up_xpm ); #endif @@ -882,7 +947,7 @@ static wxBitmap *GetDownBitmap() s_loaded = TRUE; // set it to TRUE anyhow, we won't try again #if defined(__WXMSW__) || defined(__WXPM__) - s_bitmap = new wxBitmap("plot_dwn.bmp", wxBITMAP_TYPE_RESOURCE); + s_bitmap = new wxBitmap("plot_dwn_bmp", wxBITMAP_TYPE_RESOURCE); #else s_bitmap = new wxBitmap( plot_dwn_xpm ); #endif @@ -890,3 +955,5 @@ static wxBitmap *GetDownBitmap() return s_bitmap; } + +#endif // wxUSE_PLOT