PLplot: wxPLplotstream.cpp Source File

PLplot 5.10.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
wxPLplotstream.cpp
Go to the documentation of this file.
1 // $Id: wxPLplotstream.cpp 12334 2013-05-04 16:43:33Z airwin $
2 //
3 // Copyright (C) 2005 Werner Smekal
4 //
5 // This file is part of PLplot.
6 //
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.
11 //
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.
16 //
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
20 //
21
22 // wxwidgets headers
23 #include "wx/wx.h"
24
25 // plplot headers
26 #include "plplotP.h"
27
28 #include "wxPLplotstream.h"
29
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.
34 //
35 wxPLplotstream::wxPLplotstream( wxDC *dc, int width, int height, int style ) : plstream()
36 {
37 Create( dc, width, height, style );
38 }
39
40
41 wxPLplotstream::wxPLplotstream() : plstream()
42 {
43 }
44
45
46 void wxPLplotstream::Create( wxDC *dc, int width, int height, int style )
47 {
48 const size_t bufferSize = 256;
49
50 m_dc = dc;
51 m_width = width;
52 m_height = height;
53 m_style = style;
54 m_image = NULL;
55
56 sdev( "wxwidgets" );
57 spage( 0.0, 0.0, m_width, m_height, 0, 0 );
58
59 // use freetype, antialized canvas?
60 char drvopt[bufferSize], buffer[bufferSize];
61 drvopt[0] = '\0';
62 #ifdef WX_TEMP_PL_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 );
67 #endif
68
69 int backend;
70 if ( m_style & wxPLPLOT_BACKEND_GC )
71 backend = 2;
72 else if ( m_style & wxPLPLOT_BACKEND_AGG )
73 backend = 1;
74 else
75 backend = 0;
76
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,
80 backend );
81 strncat( drvopt, buffer, bufferSize - strlen( drvopt ) );
82
83 setopt( "-drvopt", drvopt );
84
85 init();
86
87 cmd( PLESC_GETBACKEND, &m_backend );
88 m_backend = 1 << ( m_backend + 2 );
89
90 if ( m_backend == wxPLPLOT_BACKEND_AGG )
91 {
92 m_image = new wxImage( m_width, m_height );
93 cmd( PLESC_DEVINIT, (void *) m_image );
94 }
95 else
96 cmd( PLESC_DEVINIT, (void *) m_dc );
97 }
98
99
100 wxPLplotstream::~wxPLplotstream()
101 {
102 if ( m_image )
103 delete m_image;
104 }
105
106
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.
110 //
111 void wxPLplotstream::set_stream()
112 {
113 plstream::set_stream();
114 }
115
116
118 // to set the new size. You need to call RenewPlot afterwards.
119 //
120 void wxPLplotstream::SetSize( int width, int height )
121 {
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 )
128 {
129 if ( m_image )
130 {
131 delete m_image;
132 m_image = new wxImage( width, height );
133 cmd( PLESC_DEVINIT, (void *) m_image );
134 }
135 wxSize size( width, height );
136 cmd( PLESC_RESIZE, (void *) &size );
137 }
138 else
139 {
140 wxSize size( width, height );
141 cmd( PLESC_RESIZE, (void *) &size );
142 if ( m_image )
143 {
144 delete m_image;
145 m_image = new wxImage( width, height );
146 cmd( PLESC_DEVINIT, (void *) m_image );
147 }
148 }
149
150 m_width = width;
151 m_height = height;
152 }
153
154
156 //
157 void wxPLplotstream::RenewPlot()
158 {
159 replot();
160 Update();
161 }
162
163
164 // After calling plot commands it is not sure, that the dc
165 // gets updated properly, therefore you need to call this function.
166 //
167 void wxPLplotstream::Update()
168 {
169 if ( m_image )
170 {
171 wxMemoryDC MemoryDC;
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 );
176 }
177 }