X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/298a3f2ee8a54964a8ba79931a9a5b1d8be200b4..bae328c1ffa6005fbbdbbf862b3db6c648c2f004:/contrib/src/plot/plot.cpp?ds=sidebyside diff --git a/contrib/src/plot/plot.cpp b/contrib/src/plot/plot.cpp index e55237d0f6..8a52aa8be5 100644 --- a/contrib/src/plot/plot.cpp +++ b/contrib/src/plot/plot.cpp @@ -9,10 +9,6 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "plot.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -29,6 +25,7 @@ #include "wx/log.h" #include "wx/intl.h" #include "wx/dcclient.h" +#include "wx/stattext.h" #endif #include "wx/plot/plot.h" @@ -54,27 +51,27 @@ // event types //---------------------------------------------------------------------------- -DEFINE_EVENT_TYPE(wxEVT_PLOT_SEL_CHANGING); -DEFINE_EVENT_TYPE(wxEVT_PLOT_SEL_CHANGED); -DEFINE_EVENT_TYPE(wxEVT_PLOT_CLICKED); -DEFINE_EVENT_TYPE(wxEVT_PLOT_DOUBLECLICKED); -DEFINE_EVENT_TYPE(wxEVT_PLOT_ZOOM_IN); -DEFINE_EVENT_TYPE(wxEVT_PLOT_ZOOM_OUT); -DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CREATING); -DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CREATED); -DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CHANGING); -DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CHANGED); -DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CREATING); -DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CREATED); -DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CHANGING); -DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CHANGED); -DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_X_LABEL_EDIT); -DEFINE_EVENT_TYPE(wxEVT_PLOT_END_X_LABEL_EDIT); -DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_Y_LABEL_EDIT); -DEFINE_EVENT_TYPE(wxEVT_PLOT_END_Y_LABEL_EDIT); -DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_TITLE_EDIT); -DEFINE_EVENT_TYPE(wxEVT_PLOT_END_TITLE_EDIT); -DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_CREATE); +DEFINE_EVENT_TYPE(wxEVT_PLOT_SEL_CHANGING) +DEFINE_EVENT_TYPE(wxEVT_PLOT_SEL_CHANGED) +DEFINE_EVENT_TYPE(wxEVT_PLOT_CLICKED) +DEFINE_EVENT_TYPE(wxEVT_PLOT_DOUBLECLICKED) +DEFINE_EVENT_TYPE(wxEVT_PLOT_ZOOM_IN) +DEFINE_EVENT_TYPE(wxEVT_PLOT_ZOOM_OUT) +DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CREATING) +DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CREATED) +DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CHANGING) +DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CHANGED) +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CREATING) +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CREATED) +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CHANGING) +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CHANGED) +DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_X_LABEL_EDIT) +DEFINE_EVENT_TYPE(wxEVT_PLOT_END_X_LABEL_EDIT) +DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_Y_LABEL_EDIT) +DEFINE_EVENT_TYPE(wxEVT_PLOT_END_Y_LABEL_EDIT) +DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_TITLE_EDIT) +DEFINE_EVENT_TYPE(wxEVT_PLOT_END_TITLE_EDIT) +DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_CREATE) //---------------------------------------------------------------------------- // accessor functions for the bitmaps (may return NULL, check for it!) @@ -112,6 +109,7 @@ wxPlotEvent::wxPlotEvent( wxEventType commandType, int id ) IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve, wxObject) wxPlotCurve::wxPlotCurve( int offsetY, double startY, double endY ) +: m_penNormal(*wxGREY_PEN), m_penSelected(*wxBLACK_PEN) { m_offsetY = offsetY; m_startY = startY; @@ -415,9 +413,9 @@ void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxPlotCurve *curve = (wxPlotCurve*) node->GetData(); if (curve == m_owner->GetCurrentCurve()) - dc.SetPen( *wxBLACK_PEN ); + dc.SetPen( curve->GetPenSelected() ); else - dc.SetPen( *wxGREY_PEN ); + dc.SetPen( curve->GetPenNormal() ); DrawCurve( &dc, curve, update_x-1, update_x+update_width+2 ); @@ -709,7 +707,8 @@ BEGIN_EVENT_TABLE(wxPlotWindow, wxScrolledWindow) END_EVENT_TABLE() wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag ) - : wxScrolledWindow( parent, id, pos, size, flag, _T("plotcanvas") ) + : wxScrolledWindow( parent, id, pos, size, flag, _T("plotcanvas") ), + m_titleStaticText( NULL ) { m_xUnitsPerValue = 1.0; m_xZoom = 1.0; @@ -745,6 +744,11 @@ wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, wxBoxSizer *plotsizer = new wxBoxSizer( wxHORIZONTAL ); + //Add sizer to hold the title and plot. + //Title to be added later. + m_plotAndTitleSizer = new wxBoxSizer( wxVERTICAL ); + m_plotAndTitleSizer->Add( plotsizer, 1, wxEXPAND | wxTOP, 10 ); + if ((GetWindowStyleFlag() & wxPLOT_Y_AXIS) != 0) { m_yaxis = new wxPlotYAxisArea( this ); @@ -775,12 +779,9 @@ wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, m_xaxis = (wxPlotXAxisArea*) NULL; } - mainsizer->Add( plotsizer, 1, wxEXPAND ); + mainsizer->Add( m_plotAndTitleSizer, 1, wxEXPAND ); - SetAutoLayout( true ); - SetSizer( mainsizer ); - mainsizer->Fit(this); - mainsizer->SetSizeHints(this); + SetSizerAndFit( mainsizer ); SetTargetWindow( m_area ); @@ -981,10 +982,45 @@ void wxPlotWindow::ResetScrollbar() (int)(((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1), 0 ); } +void wxPlotWindow::AddChartTitle(const wxString& title, wxFont font, + wxColour colour) +{ + m_title = title; + m_titleFont = font; + m_titleColour = colour; + DrawChartTitle(); +} + +void wxPlotWindow::DrawChartTitle() +{ + if(m_title.size() != 0) + { + //If it is already added, remove child and delete + if(m_titleStaticText) + { + RemoveChild( m_titleStaticText ); + m_titleStaticText->Destroy(); + } + + //Create the text control and set the font, colour + m_titleStaticText = new wxStaticText( this, -1, m_title ); + m_titleStaticText->SetFont( m_titleFont ); + m_titleStaticText->SetForegroundColour( m_titleColour ); + + //Create a sizer for the title. Prepend it to the Plot + Title sizer. + wxBoxSizer* titleSizer = new wxBoxSizer( wxHORIZONTAL ); + titleSizer->Add( m_titleStaticText, 0, wxALIGN_CENTER | wxALL, 10 ); + m_plotAndTitleSizer->Prepend( titleSizer, 0, wxALIGN_CENTER_HORIZONTAL ); + + //Finally, force layout + m_plotAndTitleSizer->Layout(); + } +} + void wxPlotWindow::RedrawXAxis() { if (m_xaxis) - m_xaxis->Refresh( false ); + m_xaxis->Refresh( true ); } void wxPlotWindow::RedrawYAxis() @@ -1000,6 +1036,8 @@ void wxPlotWindow::RedrawEverything() if (m_yaxis) m_yaxis->Refresh( true ); m_area->Refresh( true ); + + DrawChartTitle(); } void wxPlotWindow::OnZoomIn( wxCommandEvent& WXUNUSED(event) )