PLplot  5.11.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
wxwidgets.h
Go to the documentation of this file.
1 // Copyright (C) 2008 Werner Smekal
2 //
3 // This file is part of PLplot.
4 //
5 // PLplot is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Library General Public License as published
7 // by the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // PLplot is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU Library General Public License
16 // along with PLplot; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
20 #ifndef __WXWIDGETS_H__
21 #define __WXWIDGETS_H__
22 
23 #include <vector>
24 #include <memory>
25 
26 // plplot headers
27 #include "plplotP.h"
28 #include "wxwidgets_comms.h"
29 
30 // some special wxWidgets headers
31 #include <wx/wx.h>
32 #include <wx/spinctrl.h>
33 #include <wx/dcgraph.h>
34 
35 class wxPLplotFrame;
36 
37 // A font class which encapsulates the PlPlot font metrics and
38 // a wxFont object. Importantly however the creation of the
39 // wxFont is delayed until it is actually requested. This is
40 // useful because on Linux in wxWidgets 3.0 creation of a wxFont
41 // in a console mode application caused a crash.
42 class Font
43 {
44 public:
45  Font();
46  Font( PLUNICODE fci, PLFLT size, bool underlined, bool createFontOnConstruction = false );
47  wxFont getWxFont();
48  PLUNICODE getFci() const { return m_fci; }
49  PLFLT getSize() const { return m_size; }
50  bool getUnderlined() const { return m_underlined; }
51 private:
52  void createFont();
53  wxFont m_font;
57  bool m_hasFont;
58 };
59 //check equivalence of two fonts. Note that a font created
60 //with the default constructor always campares false to any
61 //other font and that whether the wxFont has been created is
62 //not included in the test.
63 bool operator ==( const Font &lhs, const Font &rhs );
64 
66 {
67 public:
68  FontGrabber();
69  Font GetFont( PLUNICODE fci, PLFLT scaledFontSize, bool underlined );
70  bool lastWasCached( ){ return m_lastWasCached; }
71 private:
74 };
75 
76 class PlDevice
77 {
78 public:
79  virtual ~PlDevice() {}
80  virtual void DrawLine( short x1a, short y1a, short x2a, short y2a ) {}
81  virtual void DrawPolyline( short *xa, short *ya, PLINT npts ){}
82  virtual void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 ){}
83  virtual void FillPolygon( PLStream *pls ){}
84  virtual void SetWidth( PLStream *pls ){}
85  virtual void SetColor( PLStream *pls ){}
86  virtual void SetDC( PLStream *pls, wxDC* dc ){}
87  virtual void EndPage( PLStream* pls ){}
88  virtual void BeginPage( PLStream* pls ){}
89  virtual void SetSize( PLStream* pls, int width, int height ){}
90  virtual void FixAspectRatio( bool fix ){}
91  virtual void Locate( PLStream* pls, PLGraphicsIn *graphicsIn ){}
92  virtual void Flush( PLStream* pls ){}
93  virtual void PreDestructorTidy( PLStream *pls ){}
94 
95  void drawText( PLStream* pls, EscText* args );
96 private:
97  void DrawTextLine( PLUNICODE* ucs4, int ucs4Len, wxCoord x, wxCoord y, PLFLT *transform, PLFLT baseFontSize, bool drawText, PLINT &superscriptLevel, PLFLT &superscriptScale, PLFLT &superscriptOffset, bool &underlined, PLUNICODE &fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &textWidth, wxCoord &textHeight, wxCoord &textDepth );
98  virtual void DrawTextSection( wxString section, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth ) {}
99 
106 };
107 
108 // base device class
109 class wxPLDevice : public PlDevice
110 {
111 public:
112  wxPLDevice( PLStream *pls, char * mfo, PLINT text, PLINT hrshsym );
113  virtual ~wxPLDevice( void );
114 
115  void DrawLine( short x1a, short y1a, short x2a, short y2a );
116  void DrawPolyline( short *xa, short *ya, PLINT npts );
117  void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 );
118  void FillPolygon( PLStream *pls );
119  void SetWidth( PLStream *pls );
120  void SetColor( PLStream *pls );
121  void SetDC( PLStream *pls, wxDC* dc );
122  void EndPage( PLStream* pls );
123  void BeginPage( PLStream* pls );
124  void SetSize( PLStream* pls, int width, int height );
125  void FixAspectRatio( bool fix );
126  void Locate( PLStream* pls, PLGraphicsIn *graphicsIn );
127  void Flush( PLStream* pls );
128  void PreDestructorTidy( PLStream *pls );
129 
130 private:
131  void DrawTextSection( wxString section, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth );
132  void TransmitBuffer( PLStream* pls, unsigned char transmissionType );
133  void SetupMemoryMap();
134  wxRegion GetClipRegion();
135 
136  //The DC we will draw on if given by the user
137  wxDC *m_dc;
139  //for the gcdc case we may need to store the graphics context for use
140  // with text transformations
141  wxGraphicsContext *m_gc;
142  wxPen m_pen;
143  wxBrush m_brush;
144 
145  //A device context specifically for checking the size of text for use with
146  //the interactive viewer.
149 
150  //Size and Scale
151  //As far as plplot is concerned the size of the window is SHRT_MAX by
152  //SHRT_MAX which gives us the best resolution.
154  PLFLT m_width; //native width
155  PLFLT m_height; //native height
156  PLFLT m_xScale; //conversion from native width to plplotEdgeLength
157  PLFLT m_yScale; //conversion from native height to plplotEdgeLength
158  PLFLT m_xAspect; //values which when multiplied by m_plplotEdgeLength give an aspect
159  PLFLT m_yAspect; //ratio equal to the native aspect ratio, the biggest of which is 1.0
160  PLFLT m_scale; //MAX(m_scalex, m_scaley)
162 
163  // font variables
164  static const int m_max_string_length = 500;
165  //bool m_underlined;
167  //wxCoord m_textWidth, m_textHeight, m_textDescent, m_textLeading;
168  //PLUNICODE m_fci;
169 
170  //memory of previous single character string (likely plot point)
175 
176  //Text positioning related variables
177  //wxCoord m_superscriptHeight; //distance between superscript top and baseline
178  //wxCoord m_subscriptDepth; //distance between subscript base and baseline
180  //PLFLT m_yOffset;
181  //PLINT m_posX;
182  //PLINT m_posY;
183  //PLFLT m_rotation;
184 
185  //variables for dealing with sending/receiving commands
186  //via a memory map
191 };
192 
193 
194 struct dev_entry
195 {
196  wxString dev_name;
197  wxString dev_menu_short;
198  wxString dev_menu_long;
199  wxString dev_file_app;
201 };
202 
203 //--------------------------------------------------------------------------
204 // Declarations for the device.
205 //--------------------------------------------------------------------------
206 
207 void plD_init_wxwidgets( PLStream * );
208 void plD_init_wxpng( PLStream * );
209 void plD_line_wxwidgets( PLStream *, short, short, short, short );
210 void plD_polyline_wxwidgets( PLStream *, short *, short *, PLINT );
211 void plD_eop_wxwidgets( PLStream * );
212 void plD_bop_wxwidgets( PLStream * );
213 void plD_tidy_wxwidgets( PLStream * );
215 void plD_esc_wxwidgets( PLStream *, PLINT, void * );
216 
217 void wx_set_dc( PLStream* pls, wxDC* dc );
218 void wx_set_buffer( PLStream* pls, wxImage* buffer );
219 
220 //--------------------------------------------------------------------------
221 // Debug functions
222 //--------------------------------------------------------------------------
223 
224 // define if you want debug output
225 // #define _DEBUG //
226 // #define _DEBUG_VERBOSE //
227 void Log_Verbose( const char *fmt, ... );
228 void Log_Debug( const char *fmt, ... );
229 
230 
231 //--------------------------------------------------------------------------
232 // Font style and weight lookup tables
233 //--------------------------------------------------------------------------
234 const wxFontFamily fontFamilyLookup[5] = {
235  wxFONTFAMILY_SWISS, // sans-serif
236  wxFONTFAMILY_ROMAN, // serif
237  wxFONTFAMILY_TELETYPE, // monospace
238  wxFONTFAMILY_SCRIPT, // script
239  wxFONTFAMILY_SWISS // symbol
240 };
241 
242 const int fontStyleLookup[3] = {
243  wxFONTSTYLE_NORMAL, // upright
244  wxFONTSTYLE_ITALIC, // italic
245  wxFONTSTYLE_SLANT // oblique
246 };
247 
248 const int fontWeightLookup[2] = {
249  wxFONTWEIGHT_NORMAL, // medium
250  wxFONTWEIGHT_BOLD // bold
251 };
252 
253 #endif // __WXWIDGETS_H__
wxGCDC * m_interactiveTextGcdc
Definition: wxwidgets.h:148
void SetColor(PLStream *pls)
void Flush(PLStream *pls)
bool pixelDevice
Definition: wxwidgets.h:200
const PLFLT m_plplotEdgeLength
Definition: wxwidgets.h:153
bool operator==(const Font &lhs, const Font &rhs)
wxImage m_interactiveTextImage
Definition: wxwidgets.h:147
const int fontWeightLookup[2]
Definition: wxwidgets.h:248
void plD_line_wxwidgets(PLStream *, short, short, short, short)
Definition: wxwidgets.cpp:277
void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
virtual void FillPolygon(PLStream *pls)
Definition: wxwidgets.h:83
Definition: wxwidgets.h:194
Definition: wxwidgets.h:42
void plD_state_wxwidgets(PLStream *, PLINT)
Definition: wxwidgets.cpp:423
void plD_polyline_wxwidgets(PLStream *, short *, short *, PLINT)
Definition: wxwidgets.cpp:304
PLFLT m_yAspect
Definition: wxwidgets.h:159
const int fontStyleLookup[3]
Definition: wxwidgets.h:242
wxPLDevice(PLStream *pls, char *mfo, PLINT text, PLINT hrshsym)
PLUINT PLUNICODE
Definition: plplot.h:194
PLUNICODE m_fci
Definition: wxwidgets.h:54
void SetWidth(PLStream *pls)
PLUNICODE m_prevFci
Definition: wxwidgets.h:103
PLFLT m_prevBaseFontSize
Definition: wxwidgets.h:101
bool m_fixedAspect
Definition: wxwidgets.h:161
wxFont getWxFont()
virtual ~wxPLDevice(void)
virtual void BeginPage(PLStream *pls)
Definition: wxwidgets.h:88
wxChar m_prevSingleCharString
Definition: wxwidgets.h:171
bool m_useDcTextTransform
Definition: wxwidgets.h:138
wxBrush m_brush
Definition: wxwidgets.h:143
void wx_set_buffer(PLStream *pls, wxImage *buffer)
void FillPolygon(PLStream *pls)
void DrawLine(short x1a, short y1a, short x2a, short y2a)
void ClearBackground(PLStream *pls, PLINT x1=-1, PLINT y1=-1, PLINT x2=-1, PLINT y2=-1)
void createFont()
virtual void DrawPolyline(short *xa, short *ya, PLINT npts)
Definition: wxwidgets.h:81
PLFLT m_lineSpacing
Definition: wxwidgets.h:179
void plD_eop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:333
#define PLPLOT_MAX_PATH
Definition: plplotP.h:442
virtual void DrawTextSection(wxString section, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth)
Definition: wxwidgets.h:98
static const int m_max_string_length
Definition: wxwidgets.h:164
PLUNICODE getFci() const
Definition: wxwidgets.h:48
bool m_lastWasCached
Definition: wxwidgets.h:73
virtual void SetDC(PLStream *pls, wxDC *dc)
Definition: wxwidgets.h:86
PLFLT getSize() const
Definition: wxwidgets.h:49
void DrawPolyline(short *xa, short *ya, PLINT npts)
int PLINT
Definition: plplot.h:174
void PreDestructorTidy(PLStream *pls)
PLINT m_prevSingleCharStringDepth
Definition: wxwidgets.h:174
virtual void PreDestructorTidy(PLStream *pls)
Definition: wxwidgets.h:93
bool lastWasCached()
Definition: wxwidgets.h:70
wxPen m_pen
Definition: wxwidgets.h:142
void DrawTextLine(PLUNICODE *ucs4, int ucs4Len, wxCoord x, wxCoord y, PLFLT *transform, PLFLT baseFontSize, bool drawText, PLINT &superscriptLevel, PLFLT &superscriptScale, PLFLT &superscriptOffset, bool &underlined, PLUNICODE &fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &textWidth, wxCoord &textHeight, wxCoord &textDepth)
PLINT m_prevSingleCharStringHeight
Definition: wxwidgets.h:173
PLFLT m_height
Definition: wxwidgets.h:155
Font m_prevFont
Definition: wxwidgets.h:72
void SetupMemoryMap()
size_t m_localBufferPosition
Definition: wxwidgets.h:189
PLFLT m_width
Definition: wxwidgets.h:154
PLFLT m_xScale
Definition: wxwidgets.h:156
PLINT m_prevSingleCharStringWidth
Definition: wxwidgets.h:172
wxString dev_file_app
Definition: wxwidgets.h:199
virtual ~PlDevice()
Definition: wxwidgets.h:79
bool getUnderlined() const
Definition: wxwidgets.h:50
Font GetFont(PLUNICODE fci, PLFLT scaledFontSize, bool underlined)
virtual void EndPage(PLStream *pls)
Definition: wxwidgets.h:87
void drawText(PLStream *pls, EscText *args)
wxDC * m_dc
Definition: wxwidgets.h:137
virtual void SetColor(PLStream *pls)
Definition: wxwidgets.h:85
void plD_tidy_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:389
void wx_set_dc(PLStream *pls, wxDC *dc)
const wxFontFamily fontFamilyLookup[5]
Definition: wxwidgets.h:234
static PLINT * buffer
Definition: plfill.c:74
void Log_Verbose(const char *fmt,...)
Definition: wxwidgets.cpp:56
void DrawTextSection(wxString section, wxCoord x, wxCoord y, PLFLT *transform, PLFLT scaledFontSize, bool drawText, bool underlined, PLUNICODE fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth)
void Log_Debug(const char *fmt,...)
Definition: wxwidgets.cpp:77
char m_mfo[PLPLOT_MAX_PATH]
Definition: wxwidgets.h:187
wxRegion GetClipRegion()
wxString dev_menu_short
Definition: wxwidgets.h:197
void TransmitBuffer(PLStream *pls, unsigned char transmissionType)
PLFLT m_xAspect
Definition: wxwidgets.h:158
static PLStream * pls[PL_NSTREAMS]
Definition: plcore.h:88
bool m_underlined
Definition: wxwidgets.h:56
PLFLT m_yScale
Definition: wxwidgets.h:157
virtual void SetWidth(PLStream *pls)
Definition: wxwidgets.h:84
PLFLT m_scale
Definition: wxwidgets.h:160
wxString dev_name
Definition: wxwidgets.h:196
virtual void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
Definition: wxwidgets.h:91
void FixAspectRatio(bool fix)
PLNamedMutex m_mutex
Definition: wxwidgets.h:188
wxString dev_menu_long
Definition: wxwidgets.h:198
void EndPage(PLStream *pls)
wxFont m_font
Definition: wxwidgets.h:53
float PLFLT
Definition: plplot.h:157
bool m_hasFont
Definition: wxwidgets.h:57
virtual void SetSize(PLStream *pls, int width, int height)
Definition: wxwidgets.h:89
virtual void Flush(PLStream *pls)
Definition: wxwidgets.h:92
PLINT m_prevSuperscriptLevel
Definition: wxwidgets.h:102
virtual void FixAspectRatio(bool fix)
Definition: wxwidgets.h:90
void plD_init_wxwidgets(PLStream *)
void plD_bop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:363
void SetSize(PLStream *pls, int width, int height)
void SetDC(PLStream *pls, wxDC *dc)
void plD_init_wxpng(PLStream *)
wxCoord m_prevSymbolHeight
Definition: wxwidgets.h:105
void BeginPage(PLStream *pls)
virtual void DrawLine(short x1a, short y1a, short x2a, short y2a)
Definition: wxwidgets.h:80
void plD_esc_wxwidgets(PLStream *, PLINT, void *)
Definition: wxwidgets.cpp:464
PLMemoryMap m_outputMemoryMap
Definition: wxwidgets.h:190
PLUNICODE m_prevSymbol
Definition: wxwidgets.h:100
wxCoord m_prevSymbolWidth
Definition: wxwidgets.h:104
FontGrabber m_fontGrabber
Definition: wxwidgets.h:166
PLFLT m_size
Definition: wxwidgets.h:55
virtual void ClearBackground(PLStream *pls, PLINT x1=-1, PLINT y1=-1, PLINT x2=-1, PLINT y2=-1)
Definition: wxwidgets.h:82
wxGraphicsContext * m_gc
Definition: wxwidgets.h:141