PLplot
5.10.0
|
00001 // Copyright (C) 2005 Werner Smekal 00002 // 00003 // This file is part of PLplot. 00004 // 00005 // PLplot is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU Library General Public License as published 00007 // by the Free Software Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // PLplot is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU Library General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Library General Public License 00016 // along with PLplot; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 // 00019 00020 // wxwidgets headers 00021 #include "wx/wx.h" 00022 00023 // plplot headers 00024 #include "plplotP.h" 00025 00026 #include "wxPLplotstream.h" 00027 00029 // Here we set the driver (wxwidgets :), and tell plplot in which dc to 00030 // plot to and the size of the canvas. We also check and set several 00031 // device style options. 00032 // 00033 wxPLplotstream::wxPLplotstream( wxDC *dc, int width, int height, int style ) : plstream() 00034 { 00035 Create( dc, width, height, style ); 00036 } 00037 00038 00039 wxPLplotstream::wxPLplotstream() : plstream() 00040 { 00041 } 00042 00043 00044 void wxPLplotstream::Create( wxDC *dc, int width, int height, int style ) 00045 { 00046 const size_t bufferSize = 256; 00047 00048 m_dc = dc; 00049 m_width = width; 00050 m_height = height; 00051 m_style = style; 00052 m_image = NULL; 00053 00054 sdev( "wxwidgets" ); 00055 spage( 0.0, 0.0, m_width, m_height, 0, 0 ); 00056 00057 // use freetype, antialized canvas? 00058 char drvopt[bufferSize], buffer[bufferSize]; 00059 drvopt[0] = '\0'; 00060 #ifdef WX_TEMP_PL_HAVE_FREETYPE_IS_ON 00061 sprintf( buffer, "freetype=%d,smooth=%d,", 00062 m_style & wxPLPLOT_FREETYPE ? 1 : 0, 00063 m_style & wxPLPLOT_SMOOTH_TEXT ? 1 : 0 ); 00064 strcat( drvopt, buffer ); 00065 #endif 00066 00067 int backend; 00068 if ( m_style & wxPLPLOT_BACKEND_GC ) 00069 backend = 2; 00070 else if ( m_style & wxPLPLOT_BACKEND_AGG ) 00071 backend = 1; 00072 else 00073 backend = 0; 00074 00075 sprintf( buffer, "hrshsym=%d,text=%d,backend=%d", 00076 m_style & wxPLPLOT_USE_HERSHEY_SYMBOLS ? 1 : 0, 00077 m_style & wxPLPLOT_DRAW_TEXT ? 1 : 0, 00078 backend ); 00079 strncat( drvopt, buffer, bufferSize - strlen( drvopt ) ); 00080 00081 setopt( "-drvopt", drvopt ); 00082 00083 init(); 00084 00085 cmd( PLESC_GETBACKEND, &m_backend ); 00086 m_backend = 1 << ( m_backend + 2 ); 00087 00088 if ( m_backend == wxPLPLOT_BACKEND_AGG ) 00089 { 00090 m_image = new wxImage( m_width, m_height ); 00091 cmd( PLESC_DEVINIT, (void *) m_image ); 00092 } 00093 else 00094 cmd( PLESC_DEVINIT, (void *) m_dc ); 00095 } 00096 00097 00098 wxPLplotstream::~wxPLplotstream() 00099 { 00100 if ( m_image ) 00101 delete m_image; 00102 } 00103 00104 00106 // code processed before every call of a plplot functions, since set_stream() 00107 // is called before every plplot function. Not used in the moment. 00108 // 00109 void wxPLplotstream::set_stream() 00110 { 00111 plstream::set_stream(); 00112 } 00113 00114 00116 // to set the new size. You need to call RenewPlot afterwards. 00117 // 00118 void wxPLplotstream::SetSize( int width, int height ) 00119 { 00120 // For the AGG backend it is important to set first the new image buffer 00121 // and tell the driver the new size if the buffer size increases and 00122 // the other way round if the buffer size decreases. There is no impact 00123 // for the other backends. This is kind of hacky, but I have no better 00124 // idea in the moment 00125 if ( width * height > m_width * m_height ) 00126 { 00127 if ( m_image ) 00128 { 00129 delete m_image; 00130 m_image = new wxImage( width, height ); 00131 cmd( PLESC_DEVINIT, (void *) m_image ); 00132 } 00133 wxSize size( width, height ); 00134 cmd( PLESC_RESIZE, (void *) &size ); 00135 } 00136 else 00137 { 00138 wxSize size( width, height ); 00139 cmd( PLESC_RESIZE, (void *) &size ); 00140 if ( m_image ) 00141 { 00142 delete m_image; 00143 m_image = new wxImage( width, height ); 00144 cmd( PLESC_DEVINIT, (void *) m_image ); 00145 } 00146 } 00147 00148 m_width = width; 00149 m_height = height; 00150 } 00151 00152 00154 // 00155 void wxPLplotstream::RenewPlot() 00156 { 00157 replot(); 00158 Update(); 00159 } 00160 00161 00162 // After calling plot commands it is not sure, that the dc 00163 // gets updated properly, therefore you need to call this function. 00164 // 00165 void wxPLplotstream::Update() 00166 { 00167 if ( m_image ) 00168 { 00169 wxMemoryDC MemoryDC; 00170 wxBitmap bitmap( *m_image, -1 ); 00171 MemoryDC.SelectObject( bitmap ); 00172 m_dc->Blit( 0, 0, m_width, m_height, &MemoryDC, 0, 0 ); 00173 MemoryDC.SelectObject( wxNullBitmap ); 00174 } 00175 }