21#if !defined ( WXPLPLOTWINDOW_H__INCLUDED_ )
22#define WXPLPLOTWINDOW_H__INCLUDED_
27#include <wx/dcmemory.h>
28#include <wx/dcclient.h>
29#include <wx/dcgraph.h>
30#include <wx/dcbuffer.h>
36template <
class WXWINDOW>
40 wxPLplotwindow(
bool useGraphicsContext =
true, wxSize clientSize = wxDefaultSize,
41 int resizeRenderDelay_ms = 0 );
45 bool SavePlot(
const wxString& driver,
const wxString& filename );
52 virtual void OnPaint( wxPaintEvent& event );
53 virtual void OnSize( wxSizeEvent & event );
54 virtual void OnErase( wxEraseEvent &event );
55 virtual void OnCreate( wxWindowCreateEvent &event );
57 void OnMouse( wxMouseEvent &event );
70#ifdef wxUSE_GRAPHICS_CONTEXT
85template<
class WXWINDOW>
93template<
class WXWINDOW>
95 : m_created( false ), m_initialSize( clientSize ), m_resizing( false ), m_completedFirstRender( false ), m_renderTimer( this, ID_RENDERTIMER ), m_resizeRenderDelay( resizeRenderDelay_ms )
100#ifdef wxUSE_GRAPHICS_CONTEXT
126template<
class WXWINDOW>
141template<
class WXWINDOW>
152 int width = WXWINDOW::GetClientSize().GetWidth();
153 int height = WXWINDOW::GetClientSize().GetHeight();
155 wxPaintDC paintDc(
this );
164 paintDc.SetBackground( wxBrush( m_canvasColour ) );
169 paintDc.Blit( 0, 0, width, height, m_memoryDc, 0, 0 );
175 bool needResize = width != m_bitmap.GetWidth() || height != m_bitmap.GetHeight();
178 m_bitmap.Create( width, height, 32 );
181 m_memoryDc =
new wxMemoryDC;
182 m_memoryDc->SelectObject( m_bitmap );
183 wxDC *drawDc = m_memoryDc;
184#ifdef wxUSE_GRAPHICS_CONTEXT
185 if ( m_useGraphicsContext )
189 m_gcDc =
new wxGCDC( *m_memoryDc );
194 m_stream.SetDC( drawDc );
195 drawDc->SetBackground( wxBrush( m_canvasColour ) );
198 m_stream.SetSize( width, height );
201 paintDc.Blit( 0, 0, width, height, m_memoryDc, 0, 0 );
203 if ( width > 0 && height > 0 )
204 m_completedFirstRender =
true;
210template<
class WXWINDOW>
220 int width = WXWINDOW::GetClientSize().GetWidth();
221 int height = WXWINDOW::GetClientSize().GetHeight();
222 int oldWidth = m_bitmap.IsOk() ? m_bitmap.GetWidth() : 0;
223 int oldHeight = m_bitmap.IsOk() ? m_bitmap.GetHeight() : 0;
224 if ( !m_completedFirstRender || ( m_resizeRenderDelay == 0 ) ||
225 ( width == oldWidth && height == oldHeight ) )
240 if ( width > oldWidth )
241 WXWINDOW::RefreshRect( wxRect( width, 0, width - oldWidth, height ) );
242 if ( height > oldHeight )
243 WXWINDOW::RefreshRect( wxRect( 0, oldHeight, oldWidth, height - oldHeight ) );
246 m_renderTimer.Start( m_resizeRenderDelay,
true );
252template<
class WXWINDOW>
264template<
class WXWINDOW>
271 if ( m_initialSize != wxDefaultSize )
272 WXWINDOW::SetClientSize( m_initialSize );
274 int width = WXWINDOW::GetClientSize().GetWidth();
275 int height = WXWINDOW::GetClientSize().GetHeight();
276 m_bitmap.Create( width, height );
279 m_memoryDc =
new wxMemoryDC;
280 m_memoryDc->SelectObject( m_bitmap );
281 wxDC * drawDc = m_memoryDc;
282#ifdef wxUSE_GRAPHICS_CONTEXT
283 if ( m_useGraphicsContext )
287 m_gcDc =
new wxGCDC( *m_memoryDc );
291 if ( !m_stream.IsValid() )
294 m_stream.SetDC( drawDc );
295 drawDc->SetBackground( wxBrush( m_canvasColour ) );
303template<
class WXWINDOW>
314template<
class WXWINDOW>
318 wxPoint cursorPosition =
event.GetPosition();
319 wxSize clientSize = WXWINDOW::GetClientSize();
321 graphicsIn.
pX = cursorPosition.x;
322 graphicsIn.
pY = cursorPosition.y;
323 graphicsIn.
dX =
PLFLT( cursorPosition.x + 0.5 ) /
PLFLT( clientSize.GetWidth() );
324 graphicsIn.
dY = 1.0 -
PLFLT( cursorPosition.y + 0.5 ) /
PLFLT( clientSize.GetHeight() );
326 graphicsIn.
state = 0;
329 graphicsIn.
string[0] =
'\0';
330 if ( event.LeftUp() )
335 else if ( event.MiddleUp() )
340 else if ( event.RightUp() )
345 else if ( event.Aux1Up() )
350 else if ( event.Aux2Up() )
360 graphicsIn.
state = 0;
364 if ( wxGetKeyState( WXK_SHIFT ) )
366 if ( wxGetKeyState( WXK_CAPITAL ) )
368 if ( wxGetKeyState( WXK_ALT ) && wxGetKeyState( WXK_CONTROL ) )
370 else if ( wxGetKeyState( WXK_CONTROL ) )
372 else if ( wxGetKeyState( WXK_ALT ) )
374 if ( wxGetKeyState( WXK_NUMLOCK ) )
376 if ( wxGetKeyState( WXK_SCROLL ) )
381 m_stream.translatecursor( &graphicsIn );
382 this->OnLocate( graphicsIn );
388template<
class WXWINDOW>
401template<
class WXWINDOW>
407 if ( ( sfile = fopen( filename.mb_str(),
"wb+" ) ) == NULL )
419 plsdev( devname.mb_str() );
422 plspage( 0., 0., 800, 600, 0, 0 );
435template<
class WXWINDOW>
439#ifdef wxUSE_GRAPHICS_CONTEXT
440 m_useGraphicsContext = useGraphicsContext;
441 drawDc = m_useGraphicsContext ? (wxDC *) m_gcDc : (wxDC *) m_memoryDc;
443 drawDc = &m_memoryDc;
444 m_useGraphicsContext =
false;
448 m_stream.SetDC( drawDc );
453template<
class WXWINDOW>
456 m_canvasColour = colour;
wxPLplotstream is inherited from plstream, which is the C++ interface
virtual void OnCreate(wxWindowCreateEvent &event)
Window created event.
void RenewPlot(void)
Redo plot.
static const int ID_RENDERTIMER
void setUseGraphicsContext(bool useGraphicsContext)
wxPLplotwindow(bool useGraphicsContext=true, wxSize clientSize=wxDefaultSize, int resizeRenderDelay_ms=0)
Constructor.
wxPLplotstream m_stream
The wxPLplotstream which belongs to this plot widget.
virtual void OnPaint(wxPaintEvent &event)
Paint event.
wxPLplotstream * GetStream()
Get pointer to wxPLplotstream of this widget.
void setCanvasColour(const wxColour &colour)
virtual void OnSize(wxSizeEvent &event)
Size event.
size_t m_resizeRenderDelay
void OnRenderTimer(wxTimerEvent &event)
Timer used in delayed rendering after resize.
virtual void OnErase(wxEraseEvent &event)
Background erase event.
virtual ~wxPLplotwindow(void)
Destructor.
bool m_completedFirstRender
bool m_created
Flag to indicate the window has been Created.
virtual void OnLocate(const PLGraphicsIn &graphicsIn)
bool SavePlot(const wxString &driver, const wxString &filename)
Save plot using a different driver.
void OnMouse(wxMouseEvent &event)
Mouse events.
bool m_useGraphicsContext
Flag to indicate whether we should use a wxGCDC.
static PLStream * pls[PL_NSTREAMS]
#define PLPLOT_wxLogDebug(string)