1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPlotWindow
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "plot.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/object.h"
26 #include "wx/colour.h"
27 #include "wx/settings.h"
31 #include "wx/dcclient.h"
34 #include "wx/plot/plot.h"
35 #include "wx/bmpbuttn.h"
36 #include "wx/module.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 #if !defined(__WXMSW__) && !defined(__WXPM__)
45 #include "wx/plot/plot_enl.xpm"
46 #include "wx/plot/plot_shr.xpm"
47 #include "wx/plot/plot_zin.xpm"
48 #include "wx/plot/plot_zot.xpm"
49 #include "wx/plot/plot_up.xpm"
50 #include "wx/plot/plot_dwn.xpm"
53 //----------------------------------------------------------------------------
55 //----------------------------------------------------------------------------
57 DEFINE_EVENT_TYPE(wxEVT_PLOT_SEL_CHANGING
);
58 DEFINE_EVENT_TYPE(wxEVT_PLOT_SEL_CHANGED
);
59 DEFINE_EVENT_TYPE(wxEVT_PLOT_CLICKED
);
60 DEFINE_EVENT_TYPE(wxEVT_PLOT_DOUBLECLICKED
);
61 DEFINE_EVENT_TYPE(wxEVT_PLOT_ZOOM_IN
);
62 DEFINE_EVENT_TYPE(wxEVT_PLOT_ZOOM_OUT
);
63 DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CREATING
);
64 DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CREATED
);
65 DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CHANGING
);
66 DEFINE_EVENT_TYPE(wxEVT_PLOT_VALUE_SEL_CHANGED
);
67 DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CREATING
);
68 DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CREATED
);
69 DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CHANGING
);
70 DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_SEL_CHANGED
);
71 DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_X_LABEL_EDIT
);
72 DEFINE_EVENT_TYPE(wxEVT_PLOT_END_X_LABEL_EDIT
);
73 DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_Y_LABEL_EDIT
);
74 DEFINE_EVENT_TYPE(wxEVT_PLOT_END_Y_LABEL_EDIT
);
75 DEFINE_EVENT_TYPE(wxEVT_PLOT_BEGIN_TITLE_EDIT
);
76 DEFINE_EVENT_TYPE(wxEVT_PLOT_END_TITLE_EDIT
);
77 DEFINE_EVENT_TYPE(wxEVT_PLOT_AREA_CREATE
);
79 //----------------------------------------------------------------------------
80 // accessor functions for the bitmaps (may return NULL, check for it!)
81 //----------------------------------------------------------------------------
83 static wxBitmap
*GetEnlargeBitmap();
84 static wxBitmap
*GetShrinkBitmap();
85 static wxBitmap
*GetZoomInBitmap();
86 static wxBitmap
*GetZoomOutBitmap();
87 static wxBitmap
*GetUpBitmap();
88 static wxBitmap
*GetDownBitmap();
90 //-----------------------------------------------------------------------------
92 //-----------------------------------------------------------------------------
94 #define wxPLOT_SCROLL_STEP 30
96 //-----------------------------------------------------------------------------
98 //-----------------------------------------------------------------------------
100 wxPlotEvent::wxPlotEvent( wxEventType commandType
, int id
)
101 : wxNotifyEvent( commandType
, id
)
103 m_curve
= (wxPlotCurve
*) NULL
;
108 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
112 IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve
, wxObject
)
114 wxPlotCurve::wxPlotCurve( int offsetY
, double startY
, double endY
)
121 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
125 IMPLEMENT_CLASS(wxPlotOnOffCurve
, wxObject
)
127 #include "wx/arrimpl.cpp"
128 WX_DEFINE_OBJARRAY(wxArrayPlotOnOff
);
130 wxPlotOnOffCurve::wxPlotOnOffCurve( int offsetY
)
137 void wxPlotOnOffCurve::Add( wxInt32 on
, wxInt32 off
, void *clientData
)
139 wxASSERT_MSG( on
> 0, _T("plot index < 0") );
140 wxASSERT( on
<= off
);
147 wxPlotOnOff
*v
= new wxPlotOnOff
;
150 v
->m_clientData
= clientData
;
154 size_t wxPlotOnOffCurve::GetCount()
156 return m_marks
.GetCount();
159 wxInt32
wxPlotOnOffCurve::GetOn( size_t index
)
161 wxPlotOnOff
*v
= &m_marks
.Item( index
);
165 wxInt32
wxPlotOnOffCurve::GetOff( size_t index
)
167 wxPlotOnOff
*v
= &m_marks
.Item( index
);
171 void* wxPlotOnOffCurve::GetClientData( size_t index
)
173 wxPlotOnOff
*v
= &m_marks
.Item( index
);
174 return v
->m_clientData
;
177 wxPlotOnOff
*wxPlotOnOffCurve::GetAt( size_t index
)
179 return &m_marks
.Item( index
);
182 void wxPlotOnOffCurve::DrawOnLine( wxDC
&dc
, wxCoord y
, wxCoord start
, wxCoord end
, void *WXUNUSED(clientData
) )
184 dc
.DrawLine( start
, y
, start
, y
-30 );
185 dc
.DrawLine( start
, y
-30, end
, y
-30 );
186 dc
.DrawLine( end
, y
-30, end
, y
);
189 void wxPlotOnOffCurve::DrawOffLine( wxDC
&dc
, wxCoord y
, wxCoord start
, wxCoord end
)
191 dc
.DrawLine( start
, y
, end
, y
);
194 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
198 IMPLEMENT_DYNAMIC_CLASS(wxPlotArea
, wxWindow
)
200 BEGIN_EVENT_TABLE(wxPlotArea
, wxWindow
)
201 EVT_PAINT( wxPlotArea::OnPaint
)
202 EVT_LEFT_DOWN( wxPlotArea::OnMouse
)
203 EVT_LEFT_DCLICK( wxPlotArea::OnMouse
)
206 wxPlotArea::wxPlotArea( wxPlotWindow
*parent
)
207 : wxWindow( parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxSIMPLE_BORDER
, _T("plotarea") )
213 SetBackgroundColour( *wxWHITE
);
216 void wxPlotArea::OnMouse( wxMouseEvent
&event
)
220 GetClientSize( &client_width
, &client_height
);
223 m_owner
->GetViewStart( &view_x
, &view_y
);
224 view_x
*= wxPLOT_SCROLL_STEP
;
225 view_y
*= wxPLOT_SCROLL_STEP
;
227 wxCoord x
= event
.GetX();
228 wxCoord y
= event
.GetY();
232 wxList::compatibility_iterator node
= m_owner
->m_curves
.GetFirst();
235 wxPlotCurve
*curve
= (wxPlotCurve
*)node
->GetData();
237 double double_client_height
= (double)client_height
;
238 double range
= curve
->GetEndY() - curve
->GetStartY();
239 double end
= curve
->GetEndY();
240 wxCoord offset_y
= curve
->GetOffsetY();
242 double dy
= (end
- curve
->GetY( (wxInt32
)(x
/m_owner
->GetZoom()) )) / range
;
243 wxCoord curve_y
= (wxCoord
)(dy
* double_client_height
) - offset_y
- 1;
245 if ((y
-curve_y
< 4) && (y
-curve_y
> -4))
247 wxPlotEvent
event1( event
.ButtonDClick() ? wxEVT_PLOT_DOUBLECLICKED
: wxEVT_PLOT_CLICKED
, m_owner
->GetId() );
248 event1
.SetEventObject( m_owner
);
249 event1
.SetZoom( m_owner
->GetZoom() );
250 event1
.SetCurve( curve
);
251 event1
.SetPosition( (int)floor(x
/m_owner
->GetZoom()) );
252 m_owner
->GetEventHandler()->ProcessEvent( event1
);
254 if (curve
!= m_owner
->GetCurrentCurve())
256 wxPlotEvent
event2( wxEVT_PLOT_SEL_CHANGING
, m_owner
->GetId() );
257 event2
.SetEventObject( m_owner
);
258 event2
.SetZoom( m_owner
->GetZoom() );
259 event2
.SetCurve( curve
);
260 if (!m_owner
->GetEventHandler()->ProcessEvent( event2
) || event2
.IsAllowed())
262 m_owner
->SetCurrentCurve( curve
);
268 node
= node
->GetNext();
272 void wxPlotArea::DeleteCurve( wxPlotCurve
*curve
, int from
, int to
)
275 m_owner
->PrepareDC( dc
);
276 dc
.SetPen( *wxWHITE_PEN
);
277 DrawCurve( &dc
, curve
, from
, to
);
280 void wxPlotArea::DrawCurve( wxDC
*dc
, wxPlotCurve
*curve
, int from
, int to
)
284 m_owner
->GetViewStart( &view_x
, &view_y
);
285 view_x
*= wxPLOT_SCROLL_STEP
;
292 GetClientSize( &client_width
, &client_height
);
295 to
= view_x
+ client_width
;
297 double zoom
= m_owner
->GetZoom();
299 int start_x
= wxMax( from
, (int)floor(curve
->GetStartX()*zoom
) );
300 int end_x
= wxMin( to
, (int)floor(curve
->GetEndX()*zoom
) );
302 start_x
= wxMax( view_x
, start_x
);
303 end_x
= wxMin( view_x
+ client_width
, end_x
);
307 double double_client_height
= (double)client_height
;
308 double range
= curve
->GetEndY() - curve
->GetStartY();
309 double end
= curve
->GetEndY();
310 wxCoord offset_y
= curve
->GetOffsetY();
313 for (int x
= start_x
; x
< end_x
; x
++)
315 double dy
= (end
- curve
->GetY( (wxInt32
)(x
/zoom
) )) / range
;
316 wxCoord y
= (wxCoord
)(dy
* double_client_height
) - offset_y
- 1;
319 dc
->DrawLine( x
-1, last_y
, x
, y
);
325 void wxPlotArea::DrawOnOffCurve( wxDC
*dc
, wxPlotOnOffCurve
*curve
, int from
, int to
)
329 m_owner
->GetViewStart( &view_x
, &view_y
);
330 view_x
*= wxPLOT_SCROLL_STEP
;
337 GetClientSize( &client_width
, &client_height
);
340 to
= view_x
+ client_width
;
342 double zoom
= m_owner
->GetZoom();
344 int start_x
= wxMax( from
, (int)floor(curve
->GetStartX()*zoom
) );
345 int end_x
= wxMin( to
, (int)floor(curve
->GetEndX()*zoom
) );
347 start_x
= wxMax( view_x
, start_x
);
348 end_x
= wxMin( view_x
+ client_width
, end_x
);
352 wxCoord offset_y
= curve
->GetOffsetY();
353 wxCoord last_off
= -5;
355 if (curve
->GetCount() == 0)
358 for (size_t index
= 0; index
< curve
->GetCount(); index
++)
360 wxPlotOnOff
*p
= curve
->GetAt( index
);
362 wxCoord on
= (wxCoord
)(p
->m_on
*zoom
);
363 wxCoord off
= (wxCoord
)(p
->m_off
*zoom
);
367 curve
->DrawOffLine( *dc
, client_height
-offset_y
, last_off
, on
);
373 curve
->DrawOffLine( *dc
, client_height
-offset_y
, last_off
, on
);
374 curve
->DrawOnLine( *dc
, client_height
-offset_y
, on
, off
, p
->m_clientData
);
379 wxPlotOnOff
*p
= curve
->GetAt( curve
->GetCount()-1 );
380 wxCoord off
= (wxCoord
)(p
->m_off
*zoom
);
382 curve
->DrawOffLine( *dc
, client_height
-offset_y
, off
, to
);
385 void wxPlotArea::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
389 m_owner
->GetViewStart( &view_x
, &view_y
);
390 view_x
*= wxPLOT_SCROLL_STEP
;
391 view_y
*= wxPLOT_SCROLL_STEP
;
393 wxPaintDC
dc( this );
394 m_owner
->PrepareDC( dc
);
396 wxRegionIterator
upd( GetUpdateRegion() );
400 int update_x
= upd
.GetX() + view_x
;
401 int update_width
= upd
.GetWidth();
404 if (m_owner->m_current)
406 dc.SetPen( *wxLIGHT_GREY_PEN );
407 int base_line = client_height - m_owner->m_current->GetOffsetY();
408 dc.DrawLine( update_x-1, base_line-1, update_x+update_width+2, base_line-1 );
412 wxList::compatibility_iterator node
= m_owner
->m_curves
.GetFirst();
415 wxPlotCurve
*curve
= (wxPlotCurve
*) node
->GetData();
417 if (curve
== m_owner
->GetCurrentCurve())
418 dc
.SetPen( *wxBLACK_PEN
);
420 dc
.SetPen( *wxGREY_PEN
);
422 DrawCurve( &dc
, curve
, update_x
-1, update_x
+update_width
+2 );
424 node
= node
->GetNext();
427 dc
.SetPen( *wxRED_PEN
);
429 node
= m_owner
->m_onOffCurves
.GetFirst();
432 wxPlotOnOffCurve
*curve
= (wxPlotOnOffCurve
*) node
->GetData();
434 DrawOnOffCurve( &dc
, curve
, update_x
-1, update_x
+update_width
+2 );
436 node
= node
->GetNext();
443 void wxPlotArea::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
445 wxWindow::ScrollWindow( dx
, dy
, rect
);
446 // m_owner->m_xaxis->ScrollWindow( dx, 0 );
449 //-----------------------------------------------------------------------------
451 //-----------------------------------------------------------------------------
453 IMPLEMENT_DYNAMIC_CLASS(wxPlotXAxisArea
, wxWindow
)
455 BEGIN_EVENT_TABLE(wxPlotXAxisArea
, wxWindow
)
456 EVT_PAINT( wxPlotXAxisArea::OnPaint
)
457 EVT_LEFT_DOWN( wxPlotXAxisArea::OnMouse
)
460 wxPlotXAxisArea::wxPlotXAxisArea( wxPlotWindow
*parent
)
461 : wxWindow( parent
, wxID_ANY
, wxDefaultPosition
, wxSize(wxDefaultCoord
,40), 0, _T("plotxaxisarea") )
465 SetBackgroundColour( *wxWHITE
);
466 SetFont( *wxSMALL_FONT
);
469 void wxPlotXAxisArea::OnMouse( wxMouseEvent
&event
)
473 GetClientSize( &client_width
, &client_height
);
476 m_owner
->GetViewStart( &view_x
, &view_y
);
477 view_x
*= wxPLOT_SCROLL_STEP
;
478 view_y
*= wxPLOT_SCROLL_STEP
;
480 wxCoord x
= event
.GetX() + view_x
;
481 wxCoord y
= event
.GetY() + view_y
;
483 /* TO DO: do something here */
488 void wxPlotXAxisArea::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
492 m_owner
->GetViewStart( &view_x
, &view_y
);
493 view_x
*= wxPLOT_SCROLL_STEP
;
494 view_y
*= wxPLOT_SCROLL_STEP
;
496 wxPaintDC
dc( this );
500 GetClientSize( &client_width
, &client_height
);
502 double zoom
= m_owner
->GetZoom();
504 double ups
= m_owner
->GetUnitsPerValue() / zoom
;
506 double start
= view_x
* ups
;
507 double end
= (view_x
+ client_width
) * ups
;
508 double range
= end
- start
;
510 int int_log_range
= (int)floor( log10( range
) );
512 if (int_log_range
> 0)
514 for (int i
= 0; i
< int_log_range
; i
++)
517 if (int_log_range
< 0)
519 for (int i
= 0; i
< -int_log_range
; i
++)
522 double lower
= ceil(start
/ step
) * step
;
523 double upper
= floor(end
/ step
) * step
;
525 // if too few values, shrink size
526 if ((range
/step
) < 4)
529 if (lower
-step
> start
) lower
-= step
;
530 if (upper
+step
< end
) upper
+= step
;
533 // if still too few, again
534 if ((range
/step
) < 4)
537 if (lower
-step
> start
) lower
-= step
;
538 if (upper
+step
< end
) upper
+= step
;
541 dc
.SetBrush( *wxWHITE_BRUSH
);
542 dc
.SetPen( *wxTRANSPARENT_PEN
);
543 dc
.DrawRectangle( 4, 5, client_width
-14, 10 );
544 dc
.DrawRectangle( 0, 20, client_width
, 20 );
545 dc
.SetPen( *wxBLACK_PEN
);
547 double current
= lower
;
548 while (current
< upper
+(step
/2))
550 int x
= (int)ceil((current
-start
) / range
* (double)client_width
) - 1;
551 if ((x
> 4) && (x
< client_width
-25))
553 dc
.DrawLine( x
, 5, x
, 15 );
557 label
.Printf( _T("%f"), current
);
558 while (label
.Last() == _T('0'))
560 if ((label
.Last() == _T('.')) || (label
.Last() == _T(',')))
561 label
.Append( _T('0') );
564 label
.Printf( _T("%d"), (int)floor(current
) );
565 dc
.DrawText( label
, x
-4, 20 );
571 dc
.DrawLine( 0, 15, client_width
-8, 15 );
572 dc
.DrawLine( client_width
-4, 15, client_width
-10, 10 );
573 dc
.DrawLine( client_width
-4, 15, client_width
-10, 20 );
576 //-----------------------------------------------------------------------------
578 //-----------------------------------------------------------------------------
580 IMPLEMENT_DYNAMIC_CLASS(wxPlotYAxisArea
, wxWindow
)
582 BEGIN_EVENT_TABLE(wxPlotYAxisArea
, wxWindow
)
583 EVT_PAINT( wxPlotYAxisArea::OnPaint
)
584 EVT_LEFT_DOWN( wxPlotYAxisArea::OnMouse
)
587 wxPlotYAxisArea::wxPlotYAxisArea( wxPlotWindow
*parent
)
588 : wxWindow( parent
, wxID_ANY
, wxDefaultPosition
, wxSize(60,wxDefaultCoord
), 0, _T("plotyaxisarea") )
592 SetBackgroundColour( *wxWHITE
);
593 SetFont( *wxSMALL_FONT
);
596 void wxPlotYAxisArea::OnMouse( wxMouseEvent
&WXUNUSED(event
) )
598 /* do something here */
601 void wxPlotYAxisArea::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
603 wxPaintDC
dc( this );
605 wxPlotCurve
*curve
= m_owner
->GetCurrentCurve();
611 GetClientSize( &client_width
, &client_height
);
614 double range
= curve
->GetEndY() - curve
->GetStartY();
615 double offset
= ((double) curve
->GetOffsetY() / (double)client_height
) * range
;
616 double start
= curve
->GetStartY() - offset
;
617 double end
= curve
->GetEndY() - offset
;
619 int int_log_range
= (int)floor( log10( range
) );
621 if (int_log_range
> 0)
623 for (int i
= 0; i
< int_log_range
; i
++)
626 if (int_log_range
< 0)
628 for (int i
= 0; i
< -int_log_range
; i
++)
631 double lower
= ceil(start
/ step
) * step
;
632 double upper
= floor(end
/ step
) * step
;
634 // if too few values, shrink size
635 if ((range
/step
) < 4)
638 if (lower
-step
> start
) lower
-= step
;
639 if (upper
+step
< end
) upper
+= step
;
642 // if still too few, again
643 if ((range
/step
) < 4)
646 if (lower
-step
> start
) lower
-= step
;
647 if (upper
+step
< end
) upper
+= step
;
650 dc
.SetPen( *wxBLACK_PEN
);
652 double current
= lower
;
653 while (current
< upper
+(step
/2))
655 int y
= (int)((curve
->GetEndY()-current
) / range
* (double)client_height
) - 1;
656 y
-= curve
->GetOffsetY();
657 if ((y
> 10) && (y
< client_height
-7))
659 dc
.DrawLine( client_width
-15, y
, client_width
-7, y
);
663 label
.Printf( _T("%f"), current
);
664 while (label
.Last() == _T('0'))
666 if ((label
.Last() == _T('.')) || (label
.Last() == _T(',')))
667 label
.Append( _T('0') );
670 label
.Printf( _T("%d"), (int)floor(current
) );
671 dc
.DrawText( label
, 5, y
-7 );
677 dc
.DrawLine( client_width
-15, 6, client_width
-15, client_height
);
678 dc
.DrawLine( client_width
-15, 2, client_width
-20, 8 );
679 dc
.DrawLine( client_width
-15, 2, client_width
-10, 8 );
682 //-----------------------------------------------------------------------------
684 //-----------------------------------------------------------------------------
686 #define ID_ENLARGE 1000
687 #define ID_SHRINK 1002
689 #define ID_MOVE_UP 1006
690 #define ID_MOVE_DOWN 1007
692 #define ID_ZOOM_IN 1010
693 #define ID_ZOOM_OUT 1011
696 IMPLEMENT_DYNAMIC_CLASS(wxPlotWindow
, wxScrolledWindow
)
698 BEGIN_EVENT_TABLE(wxPlotWindow
, wxScrolledWindow
)
699 EVT_BUTTON( ID_MOVE_UP
, wxPlotWindow::OnMoveUp
)
700 EVT_BUTTON( ID_MOVE_DOWN
, wxPlotWindow::OnMoveDown
)
702 EVT_BUTTON( ID_ENLARGE
, wxPlotWindow::OnEnlarge
)
703 EVT_BUTTON( ID_SHRINK
, wxPlotWindow::OnShrink
)
705 EVT_BUTTON( ID_ZOOM_IN
, wxPlotWindow::OnZoomIn
)
706 EVT_BUTTON( ID_ZOOM_OUT
, wxPlotWindow::OnZoomOut
)
708 EVT_SCROLLWIN( wxPlotWindow::OnScroll2
)
711 wxPlotWindow::wxPlotWindow( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
, int flag
)
712 : wxScrolledWindow( parent
, id
, pos
, size
, flag
, _T("plotcanvas") )
714 m_xUnitsPerValue
= 1.0;
717 m_enlargeAroundWindowCentre
= false;
718 m_scrollOnThumbRelease
= false;
720 m_area
= new wxPlotArea( this );
721 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxHORIZONTAL
);
723 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ALL
) != 0)
725 wxBoxSizer
*buttonlist
= new wxBoxSizer( wxVERTICAL
);
726 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ENLARGE
) != 0)
728 buttonlist
->Add( new wxBitmapButton( this, ID_ENLARGE
, *GetEnlargeBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
729 buttonlist
->Add( new wxBitmapButton( this, ID_SHRINK
, *GetShrinkBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
730 buttonlist
->Add( 20,10, 0 );
732 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_MOVE
) != 0)
734 buttonlist
->Add( new wxBitmapButton( this, ID_MOVE_UP
, *GetUpBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
735 buttonlist
->Add( new wxBitmapButton( this, ID_MOVE_DOWN
, *GetDownBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
736 buttonlist
->Add( 20,10, 0 );
738 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ZOOM
) != 0)
740 buttonlist
->Add( new wxBitmapButton( this, ID_ZOOM_IN
, *GetZoomInBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
741 buttonlist
->Add( new wxBitmapButton( this, ID_ZOOM_OUT
, *GetZoomOutBitmap() ), 0, wxEXPAND
|wxALL
, 2 );
743 mainsizer
->Add( buttonlist
, 0, wxEXPAND
|wxALL
, 4 );
746 wxBoxSizer
*plotsizer
= new wxBoxSizer( wxHORIZONTAL
);
748 if ((GetWindowStyleFlag() & wxPLOT_Y_AXIS
) != 0)
750 m_yaxis
= new wxPlotYAxisArea( this );
752 wxBoxSizer
*vert1
= new wxBoxSizer( wxVERTICAL
);
753 plotsizer
->Add( vert1
, 1, wxEXPAND
|wxTOP
,10 );
754 vert1
->Add( m_yaxis
, 1 );
755 if ((GetWindowStyleFlag() & wxPLOT_X_AXIS
) != 0)
756 vert1
->Add( 60, 40 );
760 m_yaxis
= (wxPlotYAxisArea
*) NULL
;
763 if ((GetWindowStyleFlag() & wxPLOT_X_AXIS
) != 0)
765 m_xaxis
= new wxPlotXAxisArea( this );
767 wxBoxSizer
*vert2
= new wxBoxSizer( wxVERTICAL
);
768 plotsizer
->Add( vert2
, 5, wxEXPAND
);
769 vert2
->Add( m_area
, 1, wxEXPAND
|wxTOP
,10 );
770 vert2
->Add( m_xaxis
, 0, wxEXPAND
);
774 plotsizer
->Add( m_area
, 1, wxEXPAND
);
775 m_xaxis
= (wxPlotXAxisArea
*) NULL
;
778 mainsizer
->Add( plotsizer
, 1, wxEXPAND
);
780 SetAutoLayout( true );
781 SetSizer( mainsizer
);
782 mainsizer
->Fit(this);
783 mainsizer
->SetSizeHints(this);
785 SetTargetWindow( m_area
);
787 SetBackgroundColour( *wxWHITE
);
789 m_current
= (wxPlotCurve
*) NULL
;
792 wxPlotWindow::~wxPlotWindow()
796 void wxPlotWindow::Add( wxPlotCurve
*curve
)
798 m_curves
.Append( curve
);
799 if (!m_current
) m_current
= curve
;
804 size_t wxPlotWindow::GetCount()
806 return m_curves
.GetCount();
809 wxPlotCurve
*wxPlotWindow::GetAt( size_t n
)
811 wxList::compatibility_iterator node
= m_curves
.Item( n
);
813 return (wxPlotCurve
*) NULL
;
815 return (wxPlotCurve
*) node
->GetData();
818 void wxPlotWindow::SetCurrentCurve( wxPlotCurve
* current
)
821 m_area
->Refresh( false );
825 wxPlotEvent
event( wxEVT_PLOT_SEL_CHANGED
, GetId() );
826 event
.SetEventObject( this );
827 event
.SetZoom( GetZoom() );
828 event
.SetCurve( m_current
);
829 GetEventHandler()->ProcessEvent( event
);
832 void wxPlotWindow::Delete( wxPlotCurve
* curve
)
834 wxList::compatibility_iterator node
= m_curves
.Find( curve
);
837 m_curves
.DeleteObject( curve
);
839 m_area
->DeleteCurve( curve
);
840 m_area
->Refresh( false );
842 if (curve
== m_current
) m_current
= (wxPlotCurve
*) NULL
;
845 wxPlotCurve
*wxPlotWindow::GetCurrentCurve()
850 void wxPlotWindow::Add( wxPlotOnOffCurve
*curve
)
852 m_onOffCurves
.Append( curve
);
855 void wxPlotWindow::Delete( wxPlotOnOffCurve
* curve
)
857 wxList::compatibility_iterator node
= m_onOffCurves
.Find( curve
);
860 m_onOffCurves
.DeleteObject( curve
);
863 size_t wxPlotWindow::GetOnOffCurveCount()
865 return m_onOffCurves
.GetCount();
868 wxPlotOnOffCurve
*wxPlotWindow::GetOnOffCurveAt( size_t n
)
870 wxList::compatibility_iterator node
= m_onOffCurves
.Item( n
);
872 return (wxPlotOnOffCurve
*) NULL
;
874 return (wxPlotOnOffCurve
*) node
->GetData();
877 void wxPlotWindow::Move( wxPlotCurve
* curve
, int pixels_up
)
879 m_area
->DeleteCurve( curve
);
881 curve
->SetOffsetY( curve
->GetOffsetY() + pixels_up
);
883 m_area
->Refresh( false );
888 void wxPlotWindow::OnMoveUp( wxCommandEvent
& WXUNUSED(event
) )
890 if (!m_current
) return;
892 Move( m_current
, 25 );
895 void wxPlotWindow::OnMoveDown( wxCommandEvent
& WXUNUSED(event
) )
897 if (!m_current
) return;
899 Move( m_current
, -25 );
902 void wxPlotWindow::Enlarge( wxPlotCurve
*curve
, double factor
)
904 m_area
->DeleteCurve( curve
);
908 m_area
->GetClientSize( &client_width
, &client_height
);
909 double offset
= (double)curve
->GetOffsetY() / (double)client_height
;
911 double range
= curve
->GetEndY() - curve
->GetStartY();
914 double new_range
= range
/ factor
;
915 double new_offset
= offset
/ factor
;
917 if (m_enlargeAroundWindowCentre
)
919 double middle
= curve
->GetStartY() - offset
+ range
/2;
921 curve
->SetStartY( middle
- new_range
/ 2 + new_offset
);
922 curve
->SetEndY( middle
+ new_range
/ 2 + new_offset
);
926 curve
->SetStartY( (curve
->GetStartY() - offset
)/factor
+ new_offset
);
927 curve
->SetEndY( (curve
->GetEndY() - offset
)/factor
+ new_offset
);
930 m_area
->Refresh( false );
934 void wxPlotWindow::SetUnitsPerValue( double upv
)
936 m_xUnitsPerValue
= upv
;
941 void wxPlotWindow::SetZoom( double zoom
)
943 double old_zoom
= m_xZoom
;
948 GetViewStart( &view_x
, &view_y
);
951 wxList::compatibility_iterator node
= m_curves
.GetFirst();
954 wxPlotCurve
*curve
= (wxPlotCurve
*) node
->GetData();
955 if (curve
->GetEndX() > max
)
956 max
= curve
->GetEndX();
957 node
= node
->GetNext();
959 SetScrollbars( wxPLOT_SCROLL_STEP
, wxPLOT_SCROLL_STEP
,
960 (int)((max
*m_xZoom
)/wxPLOT_SCROLL_STEP
)+1, 0,
961 (int)(view_x
*zoom
/old_zoom
), 0,
965 m_area
->Refresh( true );
968 void wxPlotWindow::ResetScrollbar()
971 wxList::compatibility_iterator node
= m_curves
.GetFirst();
974 wxPlotCurve
*curve
= (wxPlotCurve
*) node
->GetData();
975 if (curve
->GetEndX() > max
)
976 max
= curve
->GetEndX();
977 node
= node
->GetNext();
980 SetScrollbars( wxPLOT_SCROLL_STEP
, wxPLOT_SCROLL_STEP
,
981 (int)(((max
*m_xZoom
)/wxPLOT_SCROLL_STEP
)+1), 0 );
984 void wxPlotWindow::RedrawXAxis()
987 m_xaxis
->Refresh( false );
990 void wxPlotWindow::RedrawYAxis()
993 m_yaxis
->Refresh( true );
996 void wxPlotWindow::RedrawEverything()
999 m_xaxis
->Refresh( true );
1001 m_yaxis
->Refresh( true );
1002 m_area
->Refresh( true );
1005 void wxPlotWindow::OnZoomIn( wxCommandEvent
& WXUNUSED(event
) )
1007 SetZoom( m_xZoom
* 1.5 );
1010 void wxPlotWindow::OnZoomOut( wxCommandEvent
& WXUNUSED(event
) )
1012 SetZoom( m_xZoom
* 0.6666 );
1015 void wxPlotWindow::OnEnlarge( wxCommandEvent
& WXUNUSED(event
) )
1017 if (!m_current
) return;
1019 Enlarge( m_current
, 1.5 );
1022 void wxPlotWindow::OnShrink( wxCommandEvent
& WXUNUSED(event
) )
1024 if (!m_current
) return;
1026 Enlarge( m_current
, 0.6666666 );
1029 void wxPlotWindow::OnScroll2( wxScrollWinEvent
& event
)
1031 if ((!m_scrollOnThumbRelease
) || (event
.GetEventType() != wxEVT_SCROLLWIN_THUMBTRACK
))
1033 wxScrolledWindow::OnScroll( event
);
1038 // ----------------------------------------------------------------------------
1040 // ----------------------------------------------------------------------------
1043 static wxBitmap
*GetEnlargeBitmap()
1045 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1046 static bool s_loaded
= false;
1050 s_loaded
= true; // set it to true anyhow, we won't try again
1052 #if defined(__WXMSW__) || defined(__WXPM__)
1053 s_bitmap
= new wxBitmap(_T("plot_enl_bmp"), wxBITMAP_TYPE_RESOURCE
);
1055 s_bitmap
= new wxBitmap( plot_enl_xpm
);
1062 static wxBitmap
*GetShrinkBitmap()
1064 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1065 static bool s_loaded
= false;
1069 s_loaded
= true; // set it to true anyhow, we won't try again
1071 #if defined(__WXMSW__) || defined(__WXPM__)
1072 s_bitmap
= new wxBitmap(_T("plot_shr_bmp"), wxBITMAP_TYPE_RESOURCE
);
1074 s_bitmap
= new wxBitmap( plot_shr_xpm
);
1081 static wxBitmap
*GetZoomInBitmap()
1083 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1084 static bool s_loaded
= false;
1088 s_loaded
= true; // set it to true anyhow, we won't try again
1090 #if defined(__WXMSW__) || defined(__WXPM__)
1091 s_bitmap
= new wxBitmap(_T("plot_zin_bmp"), wxBITMAP_TYPE_RESOURCE
);
1093 s_bitmap
= new wxBitmap( plot_zin_xpm
);
1100 static wxBitmap
*GetZoomOutBitmap()
1102 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1103 static bool s_loaded
= false;
1107 s_loaded
= true; // set it to true anyhow, we won't try again
1109 #if defined(__WXMSW__) || defined(__WXPM__)
1110 s_bitmap
= new wxBitmap(_T("plot_zot_bmp"), wxBITMAP_TYPE_RESOURCE
);
1112 s_bitmap
= new wxBitmap( plot_zot_xpm
);
1119 static wxBitmap
*GetUpBitmap()
1121 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1122 static bool s_loaded
= false;
1126 s_loaded
= true; // set it to true anyhow, we won't try again
1128 #if defined(__WXMSW__) || defined(__WXPM__)
1129 s_bitmap
= new wxBitmap(_T("plot_up_bmp"), wxBITMAP_TYPE_RESOURCE
);
1131 s_bitmap
= new wxBitmap( plot_up_xpm
);
1138 static wxBitmap
*GetDownBitmap()
1140 static wxBitmap
* s_bitmap
= (wxBitmap
*) NULL
;
1141 static bool s_loaded
= false;
1145 s_loaded
= true; // set it to true anyhow, we won't try again
1147 #if defined(__WXMSW__) || defined(__WXPM__)
1148 s_bitmap
= new wxBitmap(_T("plot_dwn_bmp"), wxBITMAP_TYPE_RESOURCE
);
1150 s_bitmap
= new wxBitmap( plot_dwn_xpm
);