1
// $Id: wxPLplotstream.cpp 11760 2011-06-01 19:29:11Z airwin $
3
// Copyright (C) 2005 Werner Smekal
5
// This file is part of PLplot.
7
// PLplot is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU Library General Public License as published
9
// by the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// PLplot is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU Library General Public License for more details.
17
// You should have received a copy of the GNU Library General Public License
18
// along with PLplot; if not, write to the Free Software
19
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28
#include "wxPLplotstream.h"
30
//! Constructor of wxPLplotstream class which is inherited from plstream.
31
// Here we set the driver (wxwidgets :), and tell plplot in which dc to
32
// plot to and the size of the canvas. We also check and set several
33
// device style options.
35
wxPLplotstream::wxPLplotstream( wxDC *dc, int width, int height, int style ) : plstream()
37
Create( dc, width, height, style );
41
wxPLplotstream::wxPLplotstream() : plstream()
46
void wxPLplotstream::Create( wxDC *dc, int width, int height, int style )
48
const size_t bufferSize = 256;
57
spage( 0.0, 0.0, m_width, m_height, 0, 0 );
59
// use freetype, antialized canvas?
60
char drvopt[bufferSize], buffer[bufferSize];
62
#ifdef WX_TEMP_HAVE_FREETYPE_IS_ON
63
sprintf( buffer, "freetype=%d,smooth=%d,",
64
m_style & wxPLPLOT_FREETYPE ? 1 : 0,
65
m_style & wxPLPLOT_SMOOTH_TEXT ? 1 : 0 );
66
strcat( drvopt, buffer );
70
if ( m_style & wxPLPLOT_BACKEND_GC )
72
else if ( m_style & wxPLPLOT_BACKEND_AGG )
77
sprintf( buffer, "hrshsym=%d,text=%d,backend=%d",
78
m_style & wxPLPLOT_USE_HERSHEY_SYMBOLS ? 1 : 0,
79
m_style & wxPLPLOT_DRAW_TEXT ? 1 : 0,
81
strncat( drvopt, buffer, bufferSize - strlen( drvopt ) );
83
setopt( "-drvopt", drvopt );
87
cmd( PLESC_GETBACKEND, &m_backend );
88
m_backend = 1 << ( m_backend + 2 );
90
if ( m_backend == wxPLPLOT_BACKEND_AGG )
92
m_image = new wxImage( m_width, m_height );
93
cmd( PLESC_DEVINIT, (void *) m_image );
96
cmd( PLESC_DEVINIT, (void *) m_dc );
100
wxPLplotstream::~wxPLplotstream()
107
//! This is the overloaded set_stream() function, where we could have some
108
// code processed before every call of a plplot functions, since set_stream()
109
// is called before every plplot function. Not used in the moment.
111
void wxPLplotstream::set_stream()
113
plstream::set_stream();
117
//! Call this method if the size of the dc changed (because of resizing)
118
// to set the new size. You need to call RenewPlot afterwards.
120
void wxPLplotstream::SetSize( int width, int height )
122
// For the AGG backend it is important to set first the new image buffer
123
// and tell the driver the new size if the buffer size increases and
124
// the other way round if the buffer size decreases. There is no impact
125
// for the other backends. This is kind of hacky, but I have no better
126
// idea in the moment
127
if ( width * height > m_width * m_height )
132
m_image = new wxImage( width, height );
133
cmd( PLESC_DEVINIT, (void *) m_image );
135
wxSize size( width, height );
136
cmd( PLESC_RESIZE, (void *) &size );
140
wxSize size( width, height );
141
cmd( PLESC_RESIZE, (void *) &size );
145
m_image = new wxImage( width, height );
146
cmd( PLESC_DEVINIT, (void *) m_image );
155
//! Replot everything.
157
void wxPLplotstream::RenewPlot()
164
// After calling plot commands it is not sure, that the dc
165
// gets updated properly, therefore you need to call this function.
167
void wxPLplotstream::Update()
172
wxBitmap bitmap( *m_image, -1 );
173
MemoryDC.SelectObject( bitmap );
174
m_dc->Blit( 0, 0, m_width, m_height, &MemoryDC, 0, 0 );
175
MemoryDC.SelectObject( wxNullBitmap );