]> git.saurik.com Git - wxWidgets.git/blame - src/generic/plot.cpp
Applied colour reduction and changes to use
[wxWidgets.git] / src / generic / plot.cpp
CommitLineData
981b2508
RR
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"
279ababf 35#include "wx/bmpbuttn.h"
981b2508 36
846e1424
RR
37#include <math.h>
38
279ababf
RR
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
56static wxBitmap *GetEnlargeBitmap();
57static wxBitmap *GetShrinkBitmap();
58static wxBitmap *GetZoomInBitmap();
59static wxBitmap *GetZoomOutBitmap();
60static wxBitmap *GetUpBitmap();
61static wxBitmap *GetDownBitmap();
62
63//-----------------------------------------------------------------------------
64// wxPlotEvent
65//-----------------------------------------------------------------------------
66
67wxPlotEvent::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
981b2508
RR
75//-----------------------------------------------------------------------------
76// wxPlotCurve
77//-----------------------------------------------------------------------------
78
79IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve, wxObject)
80
846e1424 81wxPlotCurve::wxPlotCurve( int offsetY, double startY, double endY )
981b2508
RR
82{
83 m_offsetY = offsetY;
846e1424
RR
84 m_startY = startY;
85 m_endY = endY;
981b2508
RR
86}
87
88//-----------------------------------------------------------------------------
89// wxPlotArea
90//-----------------------------------------------------------------------------
91
92IMPLEMENT_DYNAMIC_CLASS(wxPlotArea, wxWindow)
93
94BEGIN_EVENT_TABLE(wxPlotArea, wxWindow)
95 EVT_PAINT( wxPlotArea::OnPaint)
96 EVT_LEFT_DOWN( wxPlotArea::OnMouse)
279ababf 97 EVT_LEFT_DCLICK( wxPlotArea::OnMouse)
981b2508
RR
98END_EVENT_TABLE()
99
100wxPlotArea::wxPlotArea( wxPlotWindow *parent )
101 : wxWindow( parent, -1, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER, "plotarea" )
102{
103 m_owner = parent;
279ababf
RR
104
105 m_zooming = FALSE;
981b2508
RR
106
107 SetBackgroundColour( *wxWHITE );
108}
109
110void 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;
279ababf
RR
120
121 int x = event.GetX();
122 int y = event.GetY();
981b2508
RR
123 x += view_x;
124 y += view_y;
279ababf 125
981b2508
RR
126 wxNode *node = m_owner->m_curves.First();
127 while (node)
128 {
129 wxPlotCurve *curve = (wxPlotCurve*)node->Data();
279ababf 130
846e1424
RR
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();
279ababf
RR
135
136 double dy = (end - curve->GetY( x/m_owner->GetZoom() )) / range;
846e1424 137 wxCoord curve_y = (wxCoord)(dy * double_client_height) - offset_y - 1;
279ababf 138
981b2508
RR
139 if ((y-curve_y < 4) && (y-curve_y > -4))
140 {
279ababf
RR
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 }
981b2508
RR
159 return;
160 }
279ababf 161
981b2508
RR
162 node = node->Next();
163 }
164}
165
d3a809c7
RR
166void 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
174void wxPlotArea::DrawCurve( wxDC *dc, wxPlotCurve *curve, int from, int to )
981b2508 175{
d3a809c7
RR
176 int view_x;
177 int view_y;
178 m_owner->GetViewStart( &view_x, &view_y );
179 view_x *= 10;
279ababf 180
d3a809c7
RR
181 if (from == -1)
182 from = view_x;
183
981b2508
RR
184 int client_width;
185 int client_height;
186 GetClientSize( &client_width, &client_height);
279ababf 187
d3a809c7
RR
188 if (to == -1)
189 to = view_x + client_width;
06b466c7 190
279ababf
RR
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) );
d3a809c7
RR
195
196 start_x = wxMax( view_x, start_x );
197 end_x = wxMin( view_x + client_width, end_x );
279ababf 198
d3a809c7
RR
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();
279ababf 203
d3a809c7
RR
204 wxCoord y=0,last_y=0;
205 for (int x = start_x; x < end_x; x++)
206 {
279ababf 207 double dy = (end - curve->GetY( x/zoom )) / range;
d3a809c7 208 y = (wxCoord)(dy * double_client_height) - offset_y - 1;
279ababf 209
d3a809c7
RR
210 if (x != start_x)
211 dc->DrawLine( x-1, last_y, x, y );
279ababf 212
d3a809c7
RR
213 last_y = y;
214 }
215}
216
217void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) )
218{
981b2508
RR
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() );
279ababf 229
981b2508
RR
230 while (upd)
231 {
232 int update_x = upd.GetX();
233 int update_y = upd.GetY();
234 int update_width = upd.GetWidth();
279ababf 235
981b2508
RR
236 update_x += view_x;
237 update_y += view_y;
279ababf 238
846e1424 239/*
981b2508
RR
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 }
846e1424 246*/
279ababf 247
981b2508
RR
248 wxNode *node = m_owner->m_curves.First();
249 while (node)
250 {
251 wxPlotCurve *curve = (wxPlotCurve*)node->Data();
279ababf 252
981b2508
RR
253 if (curve == m_owner->GetCurrent())
254 dc.SetPen( *wxBLACK_PEN );
255 else
279ababf
RR
256 dc.SetPen( *wxGREY_PEN );
257
d3a809c7 258 DrawCurve( &dc, curve, update_x-1, update_x+update_width+2 );
981b2508 259
981b2508
RR
260 node = node->Next();
261 }
262 upd ++;
263 }
264}
265
279ababf
RR
266void 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
276IMPLEMENT_DYNAMIC_CLASS(wxPlotXAxisArea, wxWindow)
277
278BEGIN_EVENT_TABLE(wxPlotXAxisArea, wxWindow)
279 EVT_PAINT( wxPlotXAxisArea::OnPaint)
280 EVT_LEFT_DOWN( wxPlotXAxisArea::OnMouse)
281END_EVENT_TABLE()
282
283wxPlotXAxisArea::wxPlotXAxisArea( wxPlotWindow *parent )
284 : wxWindow( parent, -1, wxDefaultPosition, wxSize(-1,40), 0, "plotxaxisarea" )
285{
286 m_owner = parent;
287
288 SetBackgroundColour( *wxWHITE );
289}
290
291void 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
310void 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
396IMPLEMENT_DYNAMIC_CLASS(wxPlotYAxisArea, wxWindow)
397
398BEGIN_EVENT_TABLE(wxPlotYAxisArea, wxWindow)
399 EVT_PAINT( wxPlotYAxisArea::OnPaint)
400 EVT_LEFT_DOWN( wxPlotYAxisArea::OnMouse)
401END_EVENT_TABLE()
402
403wxPlotYAxisArea::wxPlotYAxisArea( wxPlotWindow *parent )
404 : wxWindow( parent, -1, wxDefaultPosition, wxSize(60,-1), 0, "plotyaxisarea" )
405{
406 m_owner = parent;
407
408 SetBackgroundColour( *wxWHITE );
409}
410
411void wxPlotYAxisArea::OnMouse( wxMouseEvent &WXUNUSED(event) )
412{
413 /* do something here */
414}
415
416void 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
981b2508
RR
488//-----------------------------------------------------------------------------
489// wxPlotWindow
490//-----------------------------------------------------------------------------
491
279ababf
RR
492#define ID_ENLARGE 1000
493#define ID_SHRINK 1002
981b2508
RR
494
495#define ID_MOVE_UP 1006
496#define ID_MOVE_DOWN 1007
497
279ababf
RR
498#define ID_ZOOM_IN 1010
499#define ID_ZOOM_OUT 1011
500
981b2508
RR
501
502IMPLEMENT_DYNAMIC_CLASS(wxPlotWindow, wxScrolledWindow)
503
504BEGIN_EVENT_TABLE(wxPlotWindow, wxScrolledWindow)
d3a809c7
RR
505 EVT_BUTTON( ID_MOVE_UP, wxPlotWindow::OnMoveUp)
506 EVT_BUTTON( ID_MOVE_DOWN, wxPlotWindow::OnMoveDown)
279ababf
RR
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)
981b2508
RR
515END_EVENT_TABLE()
516
517wxPlotWindow::wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
518 : wxScrolledWindow( parent, id, pos, size, flag, "plotcanvas" )
519{
279ababf
RR
520 m_xUnitsPerValue = 1.0;
521 m_xZoom = 1.0;
06b466c7 522
279ababf 523 m_area = new wxPlotArea( this );
981b2508 524 wxBoxSizer *mainsizer = new wxBoxSizer( wxHORIZONTAL );
279ababf
RR
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 }
06b466c7 580
279ababf
RR
581 mainsizer->Add( plotsizer, 1, wxEXPAND );
582
981b2508
RR
583 SetAutoLayout( TRUE );
584 SetSizer( mainsizer );
585
586 SetTargetWindow( m_area );
587
588 SetBackgroundColour( *wxWHITE );
279ababf 589
981b2508
RR
590 m_current = (wxPlotCurve*) NULL;
591}
592
593wxPlotWindow::~wxPlotWindow()
594{
595}
596
597void wxPlotWindow::Add( wxPlotCurve *curve )
598{
599 m_curves.Append( curve );
600 if (!m_current) m_current = curve;
279ababf
RR
601
602 ResetScrollbar();
981b2508
RR
603}
604
605size_t wxPlotWindow::GetCount()
606{
607 return m_curves.GetCount();
608}
609
610wxPlotCurve *wxPlotWindow::GetAt( size_t n )
611{
612 wxNode *node = m_curves.Nth( n );
613 if (!node)
614 return (wxPlotCurve*) NULL;
279ababf 615
981b2508
RR
616 return (wxPlotCurve*) node->Data();
617}
618
619void wxPlotWindow::SetCurrent( wxPlotCurve* current )
620{
621 m_current = current;
846e1424 622 m_area->Refresh( FALSE );
279ababf 623
d3a809c7 624 RedrawYAxis();
279ababf
RR
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 );
d3a809c7
RR
631}
632
a5a0dd06
RR
633void 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
d3a809c7
RR
644wxPlotCurve *wxPlotWindow::GetCurrent()
645{
646 return m_current;
647}
648
649void wxPlotWindow::Move( wxPlotCurve* curve, int pixels_up )
650{
651 m_area->DeleteCurve( curve );
279ababf 652
d3a809c7 653 curve->SetOffsetY( curve->GetOffsetY() + pixels_up );
279ababf 654
d3a809c7 655 m_area->Refresh( FALSE );
279ababf 656
d3a809c7
RR
657 RedrawYAxis();
658}
659
660void wxPlotWindow::OnMoveUp( wxCommandEvent& WXUNUSED(event) )
661{
662 if (!m_current) return;
279ababf 663
d3a809c7
RR
664 Move( m_current, 25 );
665}
666
667void wxPlotWindow::OnMoveDown( wxCommandEvent& WXUNUSED(event) )
668{
669 if (!m_current) return;
279ababf 670
d3a809c7
RR
671 Move( m_current, -25 );
672}
673
674void wxPlotWindow::Enlarge( wxPlotCurve *curve, double factor )
675{
676 m_area->DeleteCurve( curve );
279ababf 677
d3a809c7 678 double range = curve->GetEndY() - curve->GetStartY();
279ababf 679 double new_range = range / factor;
d3a809c7
RR
680 double middle = curve->GetEndY() - range/2;
681 curve->SetStartY( middle - new_range / 2 );
682 curve->SetEndY( middle + new_range / 2 );
279ababf 683
d3a809c7 684 m_area->Refresh( FALSE );
d3a809c7
RR
685 RedrawYAxis();
686}
687
279ababf 688void wxPlotWindow::SetUnitsPerValue( double upv )
d3a809c7 689{
279ababf
RR
690 m_xUnitsPerValue = upv;
691
692 RedrawXAxis();
d3a809c7
RR
693}
694
279ababf 695void wxPlotWindow::SetZoom( double zoom )
d3a809c7 696{
279ababf
RR
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 );
06b466c7 714
279ababf
RR
715 RedrawXAxis();
716 m_area->Refresh( TRUE );
d3a809c7
RR
717}
718
279ababf 719void wxPlotWindow::ResetScrollbar()
d3a809c7 720{
279ababf
RR
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 );
d3a809c7
RR
732}
733
279ababf 734void wxPlotWindow::RedrawXAxis()
d3a809c7 735{
279ababf
RR
736 if (m_xaxis)
737 m_xaxis->Refresh( FALSE );
d3a809c7
RR
738}
739
740void wxPlotWindow::RedrawYAxis()
741{
279ababf
RR
742 if (m_yaxis)
743 m_yaxis->Refresh( TRUE );
744}
06b466c7 745
279ababf
RR
746void 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}
06b466c7 754
279ababf
RR
755void wxPlotWindow::OnZoomIn( wxCommandEvent& WXUNUSED(event) )
756{
757 SetZoom( m_xZoom * 1.5 );
981b2508
RR
758}
759
279ababf 760void wxPlotWindow::OnZoomOut( wxCommandEvent& WXUNUSED(event) )
981b2508 761{
279ababf
RR
762 SetZoom( m_xZoom * 0.6666 );
763}
06b466c7 764
279ababf
RR
765void wxPlotWindow::OnEnlarge( wxCommandEvent& WXUNUSED(event) )
766{
981b2508 767 if (!m_current) return;
279ababf
RR
768
769 Enlarge( m_current, 1.5 );
770}
06b466c7 771
279ababf
RR
772void wxPlotWindow::OnShrink( wxCommandEvent& WXUNUSED(event) )
773{
774 if (!m_current) return;
775
776 Enlarge( m_current, 0.6666666 );
777}
981b2508 778
279ababf
RR
779void wxPlotWindow::OnScroll2( wxScrollWinEvent& event )
780{
781 wxScrolledWindow::OnScroll( event );
782
783 RedrawXAxis();
784}
06b466c7 785
279ababf
RR
786// ----------------------------------------------------------------------------
787// global functions
788// ----------------------------------------------------------------------------
06b466c7 789
279ababf
RR
790// FIXME MT-UNSAFE
791static wxBitmap *GetEnlargeBitmap()
792{
793 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
794 static bool s_loaded = FALSE;
795
796 if ( !s_loaded )
846e1424 797 {
279ababf
RR
798 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
799
800 #if defined(__WXMSW__) || defined(__WXPM__)
cacc9dae 801 s_bitmap = new wxBitmap("plot_enl_bmp", wxBITMAP_TYPE_RESOURCE);
279ababf
RR
802 #else
803 s_bitmap = new wxBitmap( plot_enl_xpm );
804 #endif
846e1424 805 }
279ababf
RR
806
807 return s_bitmap;
808}
809
810static wxBitmap *GetShrinkBitmap()
811{
812 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
813 static bool s_loaded = FALSE;
814
815 if ( !s_loaded )
846e1424 816 {
279ababf
RR
817 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
818
819 #if defined(__WXMSW__) || defined(__WXPM__)
cacc9dae 820 s_bitmap = new wxBitmap("plot_shr_bmp", wxBITMAP_TYPE_RESOURCE);
279ababf
RR
821 #else
822 s_bitmap = new wxBitmap( plot_shr_xpm );
823 #endif
846e1424 824 }
06b466c7 825
279ababf
RR
826 return s_bitmap;
827}
828
829static wxBitmap *GetZoomInBitmap()
830{
831 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
832 static bool s_loaded = FALSE;
833
834 if ( !s_loaded )
d3a809c7 835 {
279ababf
RR
836 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
837
838 #if defined(__WXMSW__) || defined(__WXPM__)
cacc9dae 839 s_bitmap = new wxBitmap("plot_zin_bmp", wxBITMAP_TYPE_RESOURCE);
279ababf
RR
840 #else
841 s_bitmap = new wxBitmap( plot_zin_xpm );
842 #endif
d3a809c7 843 }
06b466c7 844
279ababf
RR
845 return s_bitmap;
846}
847
848static wxBitmap *GetZoomOutBitmap()
849{
850 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
851 static bool s_loaded = FALSE;
852
853 if ( !s_loaded )
846e1424 854 {
279ababf
RR
855 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
856
857 #if defined(__WXMSW__) || defined(__WXPM__)
cacc9dae 858 s_bitmap = new wxBitmap("plot_zot_bmp", wxBITMAP_TYPE_RESOURCE);
279ababf
RR
859 #else
860 s_bitmap = new wxBitmap( plot_zot_xpm );
861 #endif
846e1424 862 }
06b466c7 863
279ababf
RR
864 return s_bitmap;
865}
866
867static wxBitmap *GetUpBitmap()
868{
869 static wxBitmap* s_bitmap = (wxBitmap *) NULL;
870 static bool s_loaded = FALSE;
871
872 if ( !s_loaded )
846e1424 873 {
279ababf 874 s_loaded = TRUE; // set it to TRUE anyhow, we won't try again
846e1424 875
279ababf 876 #if defined(__WXMSW__) || defined(__WXPM__)
cacc9dae
RR
877 s_bitmap = new wxBitmap("plot_up_bmp", wxBITMAP_TYPE_RESOURCE);
878 #else
279ababf
RR
879 s_bitmap = new wxBitmap( plot_up_xpm );
880 #endif
846e1424 881 }
06b466c7 882
279ababf 883 return s_bitmap;
981b2508
RR
884}
885
279ababf
RR
886static 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__)
cacc9dae 896 s_bitmap = new wxBitmap("plot_dwn_bmp", wxBITMAP_TYPE_RESOURCE);
279ababf
RR
897 #else
898 s_bitmap = new wxBitmap( plot_dwn_xpm );
899 #endif
900 }
901
902 return s_bitmap;
903}