]> git.saurik.com Git - wxWidgets.git/blob - src/generic/plot.cpp
added an extremely simple cell attr cache (yet it catches 80% of acccesses)
[wxWidgets.git] / src / generic / plot.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: plot.cpp
3 // Purpose: wxPlotWindow
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 12/01/2000
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "plot.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/object.h"
25 #include "wx/font.h"
26 #include "wx/colour.h"
27 #include "wx/settings.h"
28 #include "wx/sizer.h"
29 #include "wx/log.h"
30 #include "wx/intl.h"
31 #include "wx/dcclient.h"
32 #endif
33
34 #include "wx/generic/plot.h"
35 #include "wx/bmpbuttn.h"
36
37 #include <math.h>
38
39 // ----------------------------------------------------------------------------
40 // XPMs
41 // ----------------------------------------------------------------------------
42
43 #if !defined(__WXMSW__) && !defined(__WXPM__)
44 #include "wx/generic/plot_enl.xpm"
45 #include "wx/generic/plot_shr.xpm"
46 #include "wx/generic/plot_zin.xpm"
47 #include "wx/generic/plot_zot.xpm"
48 #include "wx/generic/plot_up.xpm"
49 #include "wx/generic/plot_dwn.xpm"
50 #endif
51
52 // ----------------------------------------------------------------------------
53 // accessor functions for the bitmaps (may return NULL, check for it!)
54 // ----------------------------------------------------------------------------
55
56 static wxBitmap *GetEnlargeBitmap();
57 static wxBitmap *GetShrinkBitmap();
58 static wxBitmap *GetZoomInBitmap();
59 static wxBitmap *GetZoomOutBitmap();
60 static wxBitmap *GetUpBitmap();
61 static wxBitmap *GetDownBitmap();
62
63 //-----------------------------------------------------------------------------
64 // wxPlotEvent
65 //-----------------------------------------------------------------------------
66
67 wxPlotEvent::wxPlotEvent( wxEventType commandType, int id )
68 : wxNotifyEvent( commandType, id )
69 {
70 m_curve = (wxPlotCurve*) NULL;
71 m_zoom = 1.0;
72 m_position = 0;
73 }
74
75 //-----------------------------------------------------------------------------
76 // wxPlotCurve
77 //-----------------------------------------------------------------------------
78
79 IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve, wxObject)
80
81 wxPlotCurve::wxPlotCurve( int offsetY, double startY, double endY )
82 {
83 m_offsetY = offsetY;
84 m_startY = startY;
85 m_endY = endY;
86 }
87
88 //-----------------------------------------------------------------------------
89 // wxPlotArea
90 //-----------------------------------------------------------------------------
91
92 IMPLEMENT_DYNAMIC_CLASS(wxPlotArea, wxWindow)
93
94 BEGIN_EVENT_TABLE(wxPlotArea, wxWindow)
95 EVT_PAINT( wxPlotArea::OnPaint)
96 EVT_LEFT_DOWN( wxPlotArea::OnMouse)
97 EVT_LEFT_DCLICK( wxPlotArea::OnMouse)
98 END_EVENT_TABLE()
99
100 wxPlotArea::wxPlotArea( wxPlotWindow *parent )
101 : wxWindow( parent, -1, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER, "plotarea" )
102 {
103 m_owner = parent;
104
105 m_zooming = FALSE;
106
107 SetBackgroundColour( *wxWHITE );
108 }
109
110 void wxPlotArea::OnMouse( wxMouseEvent &event )
111 {
112 int client_width;
113 int client_height;
114 GetClientSize( &client_width, &client_height);
115 int view_x;
116 int view_y;
117 m_owner->GetViewStart( &view_x, &view_y );
118 view_x *= 10;
119 view_y *= 10;
120
121 int x = event.GetX();
122 int y = event.GetY();
123 x += view_x;
124 y += view_y;
125
126 wxNode *node = m_owner->m_curves.First();
127 while (node)
128 {
129 wxPlotCurve *curve = (wxPlotCurve*)node->Data();
130
131 double double_client_height = (double)client_height;
132 double range = curve->GetEndY() - curve->GetStartY();
133 double end = curve->GetEndY();
134 wxCoord offset_y = curve->GetOffsetY();
135
136 double dy = (end - curve->GetY( x/m_owner->GetZoom() )) / range;
137 wxCoord curve_y = (wxCoord)(dy * double_client_height) - offset_y - 1;
138
139 if ((y-curve_y < 4) && (y-curve_y > -4))
140 {
141 wxPlotEvent event1( event.ButtonDClick() ? wxEVT_PLOT_DOUBLECLICKED : wxEVT_PLOT_CLICKED, m_owner->GetId() );
142 event1.SetEventObject( m_owner );
143 event1.SetZoom( m_owner->GetZoom() );
144 event1.SetCurve( curve );
145 event1.SetPosition( (int)floor(x/m_owner->GetZoom()) );
146 m_owner->GetEventHandler()->ProcessEvent( event1 );
147
148 if (curve != m_owner->GetCurrent());
149 {
150 wxPlotEvent event2( wxEVT_PLOT_SEL_CHANGING, m_owner->GetId() );
151 event2.SetEventObject( m_owner );
152 event2.SetZoom( m_owner->GetZoom() );
153 event2.SetCurve( curve );
154 if (!m_owner->GetEventHandler()->ProcessEvent( event2 ) || event2.IsAllowed())
155 {
156 m_owner->SetCurrent( curve );
157 }
158 }
159 return;
160 }
161
162 node = node->Next();
163 }
164 }
165
166 void wxPlotArea::DeleteCurve( wxPlotCurve *curve, int from, int to )
167 {
168 wxClientDC dc(this);
169 m_owner->PrepareDC( dc );
170 dc.SetPen( *wxWHITE_PEN );
171 DrawCurve( &dc, curve, from, to );
172 }
173
174 void wxPlotArea::DrawCurve( wxDC *dc, wxPlotCurve *curve, int from, int to )
175 {
176 int view_x;
177 int view_y;
178 m_owner->GetViewStart( &view_x, &view_y );
179 view_x *= 10;
180
181 if (from == -1)
182 from = view_x;
183
184 int client_width;
185 int client_height;
186 GetClientSize( &client_width, &client_height);
187
188 if (to == -1)
189 to = view_x + client_width;
190
191 double zoom = m_owner->GetZoom();
192
193 int start_x = wxMax( from, (int)floor(curve->GetStartX()*zoom) );
194 int end_x = wxMin( to, (int)floor(curve->GetEndX()*zoom) );
195
196 start_x = wxMax( view_x, start_x );
197 end_x = wxMin( view_x + client_width, end_x );
198
199 double double_client_height = (double)client_height;
200 double range = curve->GetEndY() - curve->GetStartY();
201 double end = curve->GetEndY();
202 wxCoord offset_y = curve->GetOffsetY();
203
204 wxCoord y=0,last_y=0;
205 for (int x = start_x; x < end_x; x++)
206 {
207 double dy = (end - curve->GetY( x/zoom )) / range;
208 y = (wxCoord)(dy * double_client_height) - offset_y - 1;
209
210 if (x != start_x)
211 dc->DrawLine( x-1, last_y, x, y );
212
213 last_y = y;
214 }
215 }
216
217 void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
218 {
219 int view_x;
220 int view_y;
221 m_owner->GetViewStart( &view_x, &view_y );
222 view_x *= 10;
223 view_y *= 10;
224
225 wxPaintDC dc( this );
226 m_owner->PrepareDC( dc );
227
228 wxRegionIterator upd( GetUpdateRegion() );
229
230 while (upd)
231 {
232 int update_x = upd.GetX();
233 int update_y = upd.GetY();
234 int update_width = upd.GetWidth();
235
236 update_x += view_x;
237 update_y += view_y;
238
239 /*
240 if (m_owner->m_current)
241 {
242 dc.SetPen( *wxLIGHT_GREY_PEN );
243 int base_line = client_height - m_owner->m_current->GetOffsetY();
244 dc.DrawLine( update_x-1, base_line-1, update_x+update_width+2, base_line-1 );
245 }
246 */
247
248 wxNode *node = m_owner->m_curves.First();
249 while (node)
250 {
251 wxPlotCurve *curve = (wxPlotCurve*)node->Data();
252
253 if (curve == m_owner->GetCurrent())
254 dc.SetPen( *wxBLACK_PEN );
255 else
256 dc.SetPen( *wxGREY_PEN );
257
258 DrawCurve( &dc, curve, update_x-1, update_x+update_width+2 );
259
260 node = node->Next();
261 }
262 upd ++;
263 }
264 }
265
266 void wxPlotArea::ScrollWindow( int dx, int dy, const wxRect *rect )
267 {
268 wxWindow::ScrollWindow( dx, dy, rect );
269 // m_owner->m_xaxis->ScrollWindow( dx, 0 );
270 }
271
272 //-----------------------------------------------------------------------------
273 // wxPlotXAxisArea
274 //-----------------------------------------------------------------------------
275
276 IMPLEMENT_DYNAMIC_CLASS(wxPlotXAxisArea, wxWindow)
277
278 BEGIN_EVENT_TABLE(wxPlotXAxisArea, wxWindow)
279 EVT_PAINT( wxPlotXAxisArea::OnPaint)
280 EVT_LEFT_DOWN( wxPlotXAxisArea::OnMouse)
281 END_EVENT_TABLE()
282
283 wxPlotXAxisArea::wxPlotXAxisArea( wxPlotWindow *parent )
284 : wxWindow( parent, -1, wxDefaultPosition, wxSize(-1,40), 0, "plotxaxisarea" )
285 {
286 m_owner = parent;
287
288 SetBackgroundColour( *wxWHITE );
289 }
290
291 void wxPlotXAxisArea::OnMouse( wxMouseEvent &event )
292 {
293 int client_width;
294 int client_height;
295 GetClientSize( &client_width, &client_height);
296 int view_x;
297 int view_y;
298 m_owner->GetViewStart( &view_x, &view_y );
299 view_x *= 10;
300 view_y *= 10;
301
302 int x = event.GetX();
303 int y = event.GetY();
304 x += view_x;
305 y += view_y;
306
307 /* do something here */
308 }
309
310 void wxPlotXAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
311 {
312 int view_x;
313 int view_y;
314 m_owner->GetViewStart( &view_x, &view_y );
315 view_x *= 10;
316 view_y *= 10;
317
318 wxPaintDC dc( this );
319
320 int client_width;
321 int client_height;
322 GetClientSize( &client_width, &client_height);
323
324 double zoom = m_owner->GetZoom();
325
326 double ups = m_owner->GetUnitsPerValue() / zoom;
327
328 double start = view_x * ups;
329 double end = (view_x + client_width) * ups;
330 double range = end - start;
331
332 int int_log_range = (int)floor( log10( range ) );
333 double step = 1.0;
334 if (int_log_range > 0)
335 {
336 for (int i = 0; i < int_log_range; i++)
337 step *= 10;
338 }
339 if (int_log_range < 0)
340 {
341 for (int i = 0; i < -int_log_range; i++)
342 step /= 10;
343 }
344 double lower = ceil(start / step) * step;
345 double upper = floor(end / step) * step;
346
347 // if too few values, shrink size
348 if ((range/step) < 4)
349 {
350 step /= 2;
351 if (lower-step > start) lower -= step;
352 if (upper+step < end) upper += step;
353 }
354
355 // if still too few, again
356 if ((range/step) < 4)
357 {
358 step /= 2;
359 if (lower-step > start) lower -= step;
360 if (upper+step < end) upper += step;
361 }
362
363 dc.SetBrush( *wxWHITE_BRUSH );
364 dc.SetPen( *wxTRANSPARENT_PEN );
365 dc.DrawRectangle( 4, 5, client_width-14, 10 );
366 dc.DrawRectangle( 0, 20, client_width, 20 );
367 dc.SetPen( *wxBLACK_PEN );
368
369 double current = lower;
370 while (current < upper+(step/2))
371 {
372 int x = (int)ceil((current-start) / range * (double)client_width) - 1;
373 if ((x > 4) && (x < client_width-25))
374 {
375 dc.DrawLine( x, 5, x, 15 );
376 wxString label;
377 if (range < 10)
378 label.Printf( wxT("%.1f"), current );
379 else
380 label.Printf( wxT("%d"), (int)floor(current) );
381 dc.DrawText( label, x-4, 20 );
382 }
383
384 current += step;
385 }
386
387 dc.DrawLine( 0, 15, client_width-8, 15 );
388 dc.DrawLine( client_width-4, 15, client_width-10, 10 );
389 dc.DrawLine( client_width-4, 15, client_width-10, 20 );
390 }
391
392 //-----------------------------------------------------------------------------
393 // wxPlotYAxisArea
394 //-----------------------------------------------------------------------------
395
396 IMPLEMENT_DYNAMIC_CLASS(wxPlotYAxisArea, wxWindow)
397
398 BEGIN_EVENT_TABLE(wxPlotYAxisArea, wxWindow)
399 EVT_PAINT( wxPlotYAxisArea::OnPaint)
400 EVT_LEFT_DOWN( wxPlotYAxisArea::OnMouse)
401 END_EVENT_TABLE()
402
403 wxPlotYAxisArea::wxPlotYAxisArea( wxPlotWindow *parent )
404 : wxWindow( parent, -1, wxDefaultPosition, wxSize(60,-1), 0, "plotyaxisarea" )
405 {
406 m_owner = parent;
407
408 SetBackgroundColour( *wxWHITE );
409 }
410
411 void wxPlotYAxisArea::OnMouse( wxMouseEvent &WXUNUSED(event) )
412 {
413 /* do something here */
414 }
415
416 void wxPlotYAxisArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
417 {
418 wxPaintDC dc( this );
419
420 wxPlotCurve *curve = m_owner->GetCurrent();
421
422 if (!curve) return;
423
424 int client_width;
425 int client_height;
426 GetClientSize( &client_width, &client_height);
427
428
429 double range = curve->GetEndY() - curve->GetStartY();
430 double offset = ((double) curve->GetOffsetY() / (double)client_height ) * range;
431 double start = curve->GetStartY() - offset;
432 double end = curve->GetEndY() - offset;
433
434 int int_log_range = (int)floor( log10( range ) );
435 double step = 1.0;
436 if (int_log_range > 0)
437 {
438 for (int i = 0; i < int_log_range; i++)
439 step *= 10;
440 }
441 if (int_log_range < 0)
442 {
443 for (int i = 0; i < -int_log_range; i++)
444 step /= 10;
445 }
446 double lower = ceil(start / step) * step;
447 double upper = floor(end / step) * step;
448
449 // if too few values, shrink size
450 if ((range/step) < 4)
451 {
452 step /= 2;
453 if (lower-step > start) lower -= step;
454 if (upper+step < end) upper += step;
455 }
456
457 // if still too few, again
458 if ((range/step) < 4)
459 {
460 step /= 2;
461 if (lower-step > start) lower -= step;
462 if (upper+step < end) upper += step;
463 }
464
465 dc.SetPen( *wxBLACK_PEN );
466
467 double current = lower;
468 while (current < upper+(step/2))
469 {
470 int y = (int)((curve->GetEndY()-current) / range * (double)client_height) - 1;
471 y -= curve->GetOffsetY();
472 if ((y > 10) && (y < client_height-7))
473 {
474 dc.DrawLine( client_width-15, y, client_width-7, y );
475 wxString label;
476 label.Printf( wxT("%.1f"), current );
477 dc.DrawText( label, 5, y-7 );
478 }
479
480 current += step;
481 }
482
483 dc.DrawLine( client_width-15, 6, client_width-15, client_height );
484 dc.DrawLine( client_width-15, 2, client_width-20, 8 );
485 dc.DrawLine( client_width-15, 2, client_width-10, 8 );
486 }
487
488 //-----------------------------------------------------------------------------
489 // wxPlotWindow
490 //-----------------------------------------------------------------------------
491
492 #define ID_ENLARGE 1000
493 #define ID_SHRINK 1002
494
495 #define ID_MOVE_UP 1006
496 #define ID_MOVE_DOWN 1007
497
498 #define ID_ZOOM_IN 1010
499 #define ID_ZOOM_OUT 1011
500
501
502 IMPLEMENT_DYNAMIC_CLASS(wxPlotWindow, wxScrolledWindow)
503
504 BEGIN_EVENT_TABLE(wxPlotWindow, wxScrolledWindow)
505 EVT_BUTTON( ID_MOVE_UP, wxPlotWindow::OnMoveUp)
506 EVT_BUTTON( ID_MOVE_DOWN, wxPlotWindow::OnMoveDown)
507
508 EVT_BUTTON( ID_ENLARGE, wxPlotWindow::OnEnlarge)
509 EVT_BUTTON( ID_SHRINK, wxPlotWindow::OnShrink)
510
511 EVT_BUTTON( ID_ZOOM_IN, wxPlotWindow::OnZoomIn)
512 EVT_BUTTON( ID_ZOOM_OUT, wxPlotWindow::OnZoomOut)
513
514 EVT_SCROLLWIN( wxPlotWindow::OnScroll2)
515 END_EVENT_TABLE()
516
517 wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
518 : wxScrolledWindow( parent, id, pos, size, flag, "plotcanvas" )
519 {
520 m_xUnitsPerValue = 1.0;
521 m_xZoom = 1.0;
522
523 m_area = new wxPlotArea( this );
524 wxBoxSizer *mainsizer = new wxBoxSizer( wxHORIZONTAL );
525
526 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ALL) != 0)
527 {
528 wxBoxSizer *buttonlist = new wxBoxSizer( wxVERTICAL );
529 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ENLARGE) != 0)
530 {
531 buttonlist->Add( new wxBitmapButton( this, ID_ENLARGE, *GetEnlargeBitmap() ), 0, wxEXPAND|wxALL, 2 );
532 buttonlist->Add( new wxBitmapButton( this, ID_SHRINK, *GetShrinkBitmap() ), 0, wxEXPAND|wxALL, 2 );
533 buttonlist->Add( 20,10, 0 );
534 }
535 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_MOVE) != 0)
536 {
537 buttonlist->Add( new wxBitmapButton( this, ID_MOVE_UP, *GetUpBitmap() ), 0, wxEXPAND|wxALL, 2 );
538 buttonlist->Add( new wxBitmapButton( this, ID_MOVE_DOWN, *GetDownBitmap() ), 0, wxEXPAND|wxALL, 2 );
539 buttonlist->Add( 20,10, 0 );
540 }
541 if ((GetWindowStyleFlag() & wxPLOT_BUTTON_ZOOM) != 0)
542 {
543 buttonlist->Add( new wxBitmapButton( this, ID_ZOOM_IN, *GetZoomInBitmap() ), 0, wxEXPAND|wxALL, 2 );
544 buttonlist->Add( new wxBitmapButton( this, ID_ZOOM_OUT, *GetZoomOutBitmap() ), 0, wxEXPAND|wxALL, 2 );
545 }
546 mainsizer->Add( buttonlist, 0, wxEXPAND|wxALL, 4 );
547 }
548
549 wxBoxSizer *plotsizer = new wxBoxSizer( wxHORIZONTAL );
550
551 if ((GetWindowStyleFlag() & wxPLOT_Y_AXIS) != 0)
552 {
553 m_yaxis = new wxPlotYAxisArea( this );
554
555 wxBoxSizer *vert1 = new wxBoxSizer( wxVERTICAL );
556 plotsizer->Add( vert1, 0, wxEXPAND );
557 vert1->Add( m_yaxis, 1 );
558 if ((GetWindowStyleFlag() & wxPLOT_X_AXIS) != 0)
559 vert1->Add( 60, 40 );
560 }
561 else
562 {
563 m_yaxis = (wxPlotYAxisArea*) NULL;
564 }
565
566 if ((GetWindowStyleFlag() & wxPLOT_X_AXIS) != 0)
567 {
568 m_xaxis = new wxPlotXAxisArea( this );
569
570 wxBoxSizer *vert2 = new wxBoxSizer( wxVERTICAL );
571 plotsizer->Add( vert2, 1, wxEXPAND );
572 vert2->Add( m_area, 1, wxEXPAND );
573 vert2->Add( m_xaxis, 0, wxEXPAND );
574 }
575 else
576 {
577 plotsizer->Add( m_area, 1, wxEXPAND );
578 m_xaxis = (wxPlotXAxisArea*) NULL;
579 }
580
581 mainsizer->Add( plotsizer, 1, wxEXPAND );
582
583 SetAutoLayout( TRUE );
584 SetSizer( mainsizer );
585
586 SetTargetWindow( m_area );
587
588 SetBackgroundColour( *wxWHITE );
589
590 m_current = (wxPlotCurve*) NULL;
591 }
592
593 wxPlotWindow::~wxPlotWindow()
594 {
595 }
596
597 void wxPlotWindow::Add( wxPlotCurve *curve )
598 {
599 m_curves.Append( curve );
600 if (!m_current) m_current = curve;
601
602 ResetScrollbar();
603 }
604
605 size_t wxPlotWindow::GetCount()
606 {
607 return m_curves.GetCount();
608 }
609
610 wxPlotCurve *wxPlotWindow::GetAt( size_t n )
611 {
612 wxNode *node = m_curves.Nth( n );
613 if (!node)
614 return (wxPlotCurve*) NULL;
615
616 return (wxPlotCurve*) node->Data();
617 }
618
619 void wxPlotWindow::SetCurrent( wxPlotCurve* current )
620 {
621 m_current = current;
622 m_area->Refresh( FALSE );
623
624 RedrawYAxis();
625
626 wxPlotEvent event( wxEVT_PLOT_SEL_CHANGED, GetId() );
627 event.SetEventObject( this );
628 event.SetZoom( GetZoom() );
629 event.SetCurve( m_current );
630 GetEventHandler()->ProcessEvent( event );
631 }
632
633 void wxPlotWindow::Delete( wxPlotCurve* curve )
634 {
635 wxNode *node = m_curves.Find( curve );
636 if (!node) return;
637
638 m_curves.DeleteObject( curve );
639
640 m_area->DeleteCurve( curve );
641 m_area->Refresh( FALSE );
642 }
643
644 wxPlotCurve *wxPlotWindow::GetCurrent()
645 {
646 return m_current;
647 }
648
649 void wxPlotWindow::Move( wxPlotCurve* curve, int pixels_up )
650 {
651 m_area->DeleteCurve( curve );
652
653 curve->SetOffsetY( curve->GetOffsetY() + pixels_up );
654
655 m_area->Refresh( FALSE );
656
657 RedrawYAxis();
658 }
659
660 void wxPlotWindow::OnMoveUp( wxCommandEvent& WXUNUSED(event) )
661 {
662 if (!m_current) return;
663
664 Move( m_current, 25 );
665 }
666
667 void wxPlotWindow::OnMoveDown( wxCommandEvent& WXUNUSED(event) )
668 {
669 if (!m_current) return;
670
671 Move( m_current, -25 );
672 }
673
674 void wxPlotWindow::Enlarge( wxPlotCurve *curve, double factor )
675 {
676 m_area->DeleteCurve( curve );
677
678 double range = curve->GetEndY() - curve->GetStartY();
679 double new_range = range / factor;
680 double middle = curve->GetEndY() - range/2;
681 curve->SetStartY( middle - new_range / 2 );
682 curve->SetEndY( middle + new_range / 2 );
683
684 m_area->Refresh( FALSE );
685 RedrawYAxis();
686 }
687
688 void wxPlotWindow::SetUnitsPerValue( double upv )
689 {
690 m_xUnitsPerValue = upv;
691
692 RedrawXAxis();
693 }
694
695 void wxPlotWindow::SetZoom( double zoom )
696 {
697 double old_zoom = m_xZoom;
698 m_xZoom = zoom;
699
700 int view_x = 0;
701 int view_y = 0;
702 GetViewStart( &view_x, &view_y );
703
704 wxInt32 max = 0;
705 wxNode *node = m_curves.First();
706 while (node)
707 {
708 wxPlotCurve *curve = (wxPlotCurve*) node->Data();
709 if (curve->GetEndX() > max)
710 max = curve->GetEndX();
711 node = node->Next();
712 }
713 SetScrollbars( 10, 10, (int)((max*m_xZoom)/10)+1, 0, (int)view_x*zoom/old_zoom, 0 );
714
715 RedrawXAxis();
716 m_area->Refresh( TRUE );
717 }
718
719 void wxPlotWindow::ResetScrollbar()
720 {
721 wxInt32 max = 0;
722 wxNode *node = m_curves.First();
723 while (node)
724 {
725 wxPlotCurve *curve = (wxPlotCurve*) node->Data();
726 if (curve->GetEndX() > max)
727 max = curve->GetEndX();
728 node = node->Next();
729 }
730
731 SetScrollbars( 10, 10, ((max*m_xZoom)/10)+1, 0 );
732 }
733
734 void wxPlotWindow::RedrawXAxis()
735 {
736 if (m_xaxis)
737 m_xaxis->Refresh( FALSE );
738 }
739
740 void wxPlotWindow::RedrawYAxis()
741 {
742 if (m_yaxis)
743 m_yaxis->Refresh( TRUE );
744 }
745
746 void wxPlotWindow::RedrawEverything()
747 {
748 if (m_xaxis)
749 m_xaxis->Refresh( TRUE );
750 if (m_yaxis)
751 m_yaxis->Refresh( TRUE );
752 m_area->Refresh( TRUE );
753 }
754
755 void wxPlotWindow::OnZoomIn( wxCommandEvent& WXUNUSED(event) )
756 {
757 SetZoom( m_xZoom * 1.5 );
758 }
759
760 void wxPlotWindow::OnZoomOut( wxCommandEvent& WXUNUSED(event) )
761 {
762 SetZoom( m_xZoom * 0.6666 );
763 }
764
765 void wxPlotWindow::OnEnlarge( wxCommandEvent& WXUNUSED(event) )
766 {
767 if (!m_current) return;
768
769 Enlarge( m_current, 1.5 );
770 }
771
772 void wxPlotWindow::OnShrink( wxCommandEvent& WXUNUSED(event) )
773 {
774 if (!m_current) return;
775
776 Enlarge( m_current, 0.6666666 );
777 }
778
779 void wxPlotWindow::OnScroll2( wxScrollWinEvent& event )
780 {
781 wxScrolledWindow::OnScroll( event );
782
783 RedrawXAxis();
784 }
785
786 // ----------------------------------------------------------------------------
787 // global functions
788 // ----------------------------------------------------------------------------
789
790 // FIXME MT-UNSAFE
791 static wxBitmap *GetEnlargeBitmap()
792 {
793 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
794 static bool s_loaded = FALSE;
795
796 if ( !s_loaded )
797 {
798 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
799
800 #if defined(__WXMSW__) || defined(__WXPM__)
801 s_bitmap = new wxBitmap("plot_enl.bmp", wxBITMAP_TYPE_RESOURCE);
802 #else
803 s_bitmap = new wxBitmap( plot_enl_xpm );
804 #endif
805 }
806
807 return s_bitmap;
808 }
809
810 static wxBitmap *GetShrinkBitmap()
811 {
812 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
813 static bool s_loaded = FALSE;
814
815 if ( !s_loaded )
816 {
817 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
818
819 #if defined(__WXMSW__) || defined(__WXPM__)
820 s_bitmap = new wxBitmap("plot_shr.bmp", wxBITMAP_TYPE_RESOURCE);
821 #else
822 s_bitmap = new wxBitmap( plot_shr_xpm );
823 #endif
824 }
825
826 return s_bitmap;
827 }
828
829 static wxBitmap *GetZoomInBitmap()
830 {
831 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
832 static bool s_loaded = FALSE;
833
834 if ( !s_loaded )
835 {
836 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
837
838 #if defined(__WXMSW__) || defined(__WXPM__)
839 s_bitmap = new wxBitmap("plot_zin.bmp", wxBITMAP_TYPE_RESOURCE);
840 #else
841 s_bitmap = new wxBitmap( plot_zin_xpm );
842 #endif
843 }
844
845 return s_bitmap;
846 }
847
848 static wxBitmap *GetZoomOutBitmap()
849 {
850 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
851 static bool s_loaded = FALSE;
852
853 if ( !s_loaded )
854 {
855 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
856
857 #if defined(__WXMSW__) || defined(__WXPM__)
858 s_bitmap = new wxBitmap("plot_zot.bmp", wxBITMAP_TYPE_RESOURCE);
859 #else
860 s_bitmap = new wxBitmap( plot_zot_xpm );
861 #endif
862 }
863
864 return s_bitmap;
865 }
866
867 static wxBitmap *GetUpBitmap()
868 {
869 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
870 static bool s_loaded = FALSE;
871
872 if ( !s_loaded )
873 {
874 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
875
876 #if defined(__WXMSW__) || defined(__WXPM__)
877 s_bitmap = new wxBitmap("plot_up.bmp", wxBITMAP_TYPE_RESOURCE);
878 #else
879 s_bitmap = new wxBitmap( plot_up_xpm );
880 #endif
881 }
882
883 return s_bitmap;
884 }
885
886 static wxBitmap *GetDownBitmap()
887 {
888 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
889 static bool s_loaded = FALSE;
890
891 if ( !s_loaded )
892 {
893 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
894
895 #if defined(__WXMSW__) || defined(__WXPM__)
896 s_bitmap = new wxBitmap("plot_dwn.bmp", wxBITMAP_TYPE_RESOURCE);
897 #else
898 s_bitmap = new wxBitmap( plot_dwn_xpm );
899 #endif
900 }
901
902 return s_bitmap;
903 }