00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "wx/wx.h"
00024
00025
00026 #include "plplotP.h"
00027
00028 #include "wxPLplotstream.h"
00029
00031
00032
00033
00034
00035 wxPLplotstream::wxPLplotstream( wxDC *dc, int width, int height, int style ) : plstream()
00036 {
00037 Create( dc, width, height, style );
00038 }
00039
00040
00041 wxPLplotstream::wxPLplotstream() : plstream()
00042 {
00043 }
00044
00045
00046 void wxPLplotstream::Create( wxDC *dc, int width, int height, int style )
00047 {
00048 const size_t bufferSize = 256;
00049
00050 m_dc = dc;
00051 m_width = width;
00052 m_height = height;
00053 m_style = style;
00054 m_image = NULL;
00055
00056 sdev( "wxwidgets" );
00057 spage( 0.0, 0.0, m_width, m_height, 0, 0 );
00058
00059
00060 char drvopt[bufferSize], buffer[bufferSize];
00061 drvopt[0] = '\0';
00062 #ifdef WX_TEMP_HAVE_FREETYPE_IS_ON
00063 sprintf( buffer, "freetype=%d,smooth=%d,",
00064 m_style & wxPLPLOT_FREETYPE ? 1 : 0,
00065 m_style & wxPLPLOT_SMOOTH_TEXT ? 1 : 0 );
00066 strcat( drvopt, buffer );
00067 #endif
00068
00069 int backend;
00070 if ( m_style & wxPLPLOT_BACKEND_GC )
00071 backend = 2;
00072 else if ( m_style & wxPLPLOT_BACKEND_AGG )
00073 backend = 1;
00074 else
00075 backend = 0;
00076
00077 sprintf( buffer, "hrshsym=%d,text=%d,backend=%d",
00078 m_style & wxPLPLOT_USE_HERSHEY_SYMBOLS ? 1 : 0,
00079 m_style & wxPLPLOT_DRAW_TEXT ? 1 : 0,
00080 backend );
00081 strncat( drvopt, buffer, bufferSize - strlen( drvopt ) );
00082
00083 setopt( "-drvopt", drvopt );
00084
00085 init();
00086
00087 cmd( PLESC_GETBACKEND, &m_backend );
00088 m_backend = 1 << ( m_backend + 2 );
00089
00090 if ( m_backend == wxPLPLOT_BACKEND_AGG )
00091 {
00092 m_image = new wxImage( m_width, m_height );
00093 cmd( PLESC_DEVINIT, (void *) m_image );
00094 }
00095 else
00096 cmd( PLESC_DEVINIT, (void *) m_dc );
00097 }
00098
00099
00100 wxPLplotstream::~wxPLplotstream()
00101 {
00102 if ( m_image )
00103 delete m_image;
00104 }
00105
00106
00108
00109
00110
00111 void wxPLplotstream::set_stream()
00112 {
00113 plstream::set_stream();
00114 }
00115
00116
00118
00119
00120 void wxPLplotstream::SetSize( int width, int height )
00121 {
00122
00123
00124
00125
00126
00127 if ( width * height > m_width * m_height )
00128 {
00129 if ( m_image )
00130 {
00131 delete m_image;
00132 m_image = new wxImage( width, height );
00133 cmd( PLESC_DEVINIT, (void *) m_image );
00134 }
00135 wxSize size( width, height );
00136 cmd( PLESC_RESIZE, (void *) &size );
00137 }
00138 else
00139 {
00140 wxSize size( width, height );
00141 cmd( PLESC_RESIZE, (void *) &size );
00142 if ( m_image )
00143 {
00144 delete m_image;
00145 m_image = new wxImage( width, height );
00146 cmd( PLESC_DEVINIT, (void *) m_image );
00147 }
00148 }
00149
00150 m_width = width;
00151 m_height = height;
00152 }
00153
00154
00156
00157 void wxPLplotstream::RenewPlot()
00158 {
00159 replot();
00160 Update();
00161 }
00162
00163
00164
00165
00166
00167 void wxPLplotstream::Update()
00168 {
00169 if ( m_image )
00170 {
00171 wxMemoryDC MemoryDC;
00172 wxBitmap bitmap( *m_image, -1 );
00173 MemoryDC.SelectObject( bitmap );
00174 m_dc->Blit( 0, 0, m_width, m_height, &MemoryDC, 0, 0 );
00175 MemoryDC.SelectObject( wxNullBitmap );
00176 }
00177 }