PLplot  5.13.0
 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 compares 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  PlDevice();
80  virtual ~PlDevice() {}
81  virtual void DrawLine( short x1a, short y1a, short x2a, short y2a ) {}
82  virtual void DrawPolyline( short *xa, short *ya, PLINT npts ){}
83  virtual void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 ){}
84  virtual void FillPolygon( PLStream *pls ){}
85  virtual void SetWidth( PLStream *pls ){}
86  virtual void SetColor( PLStream *pls ){}
87  virtual void SetDC( PLStream *pls, wxDC* dc ){}
88  virtual void EndPage( PLStream* pls ){}
89  virtual void BeginPage( PLStream* pls ){}
90  virtual void SetSize( PLStream* pls, int width, int height ){}
91  virtual void FixAspectRatio( bool fix ){}
92  virtual void Locate( PLStream* pls, PLGraphicsIn *graphicsIn ){}
93  virtual void Flush( PLStream* pls ){}
94  virtual void PreDestructorTidy( PLStream *pls ){}
95 
96  void drawText( PLStream* pls, EscText* args );
97 private:
98  void DrawTextLine( PLUNICODE* ucs4, int ucs4Len, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT baseFontSize, bool drawText, bool &underlined, PLUNICODE &fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &textWidth, wxCoord &textHeight, wxCoord &textDepth );
99  virtual void DrawTextSection( wxString section, wxCoord xOrigin, wxCoord yOrigin, 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, PLFLT &yScale, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth ) {}
100 
108 };
109 
110 // base device class
111 class wxPLDevice : public PlDevice
112 {
113 public:
114  wxPLDevice( PLStream *pls, char * mfo, PLINT text, PLINT hrshsym );
115  virtual ~wxPLDevice( void );
116 
117  void DrawLine( short x1a, short y1a, short x2a, short y2a );
118  void DrawPolyline( short *xa, short *ya, PLINT npts );
119  void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 );
120  void FillPolygon( PLStream *pls );
121  void SetWidth( PLStream *pls );
122  void SetColor( PLStream *pls );
123  void SetDC( PLStream *pls, wxDC* dc );
124  void EndPage( PLStream* pls );
125  void BeginPage( PLStream* pls );
126  void SetSize( PLStream* pls, int width, int height );
127  void FixAspectRatio( bool fix );
128  void Locate( PLStream* pls, PLGraphicsIn *graphicsIn );
129  void Flush( PLStream* pls );
130  void PreDestructorTidy( PLStream *pls );
131 
132 private:
133  void DrawTextSection( wxString section, wxCoord xOrigin, wxCoord yOrigin, 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, PLFLT &yScale, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth );
134  void TransmitBuffer( PLStream* pls, unsigned char transmissionType );
135  void SetupMemoryMap();
136  wxRegion GetClipRegion();
137 
138  //The DC we will draw on if given by the user
139  wxDC *m_dc;
141  //for the gcdc case we may need to store the graphics context for use
142  // with text transformations
143  wxGraphicsContext *m_gc;
144  wxPen m_pen;
145  wxBrush m_brush;
146 
147  //A device context specifically for checking the size of text for use with
148  //the interactive viewer.
151 
152  //Size and Scale
153  //As far as plplot is concerned the size of the window is SHRT_MAX by
154  //SHRT_MAX which gives us the best resolution.
156  PLFLT m_width; //native width
157  PLFLT m_height; //native height
158  PLFLT m_xScale; //conversion from native width to plplotEdgeLength
159  PLFLT m_yScale; //conversion from native height to plplotEdgeLength
160  PLFLT m_xAspect; //values which when multiplied by m_plplotEdgeLength give an aspect
161  PLFLT m_yAspect; //ratio equal to the native aspect ratio, the biggest of which is 1.0
162  PLFLT m_scale; //MAX(m_scalex, m_scaley)
164 
165  // font variables
166  static const int m_max_string_length = 500;
167  //bool m_underlined;
169  //wxCoord m_textWidth, m_textHeight, m_textDescent, m_textLeading;
170  //PLUNICODE m_fci;
171 
172  //Text positioning related variables
173  //wxCoord m_superscriptHeight; //distance between superscript top and baseline
174  //wxCoord m_subscriptDepth; //distance between subscript base and baseline
176  //PLFLT m_yOffset;
177  //PLINT m_posX;
178  //PLINT m_posY;
179  //PLFLT m_rotation;
180 
181  //variables for dealing with sending/receiving commands
182  //via a memory map
184 #ifdef PL_WXWIDGETS_IPC3
185  // Private variable to hold all components of a MemoryMapHeader struct for a wxPLDevice instance.
186  MemoryMapHeader m_header;
187 #else
189 #endif
192 };
193 
194 
195 struct dev_entry
196 {
197  wxString dev_name;
198  wxString dev_menu_short;
199  wxString dev_menu_long;
200  wxString dev_file_app;
202 };
203 
204 //--------------------------------------------------------------------------
205 // Declarations for the device.
206 //--------------------------------------------------------------------------
207 
208 void plD_init_wxwidgets( PLStream * );
209 void plD_init_wxpng( PLStream * );
210 void plD_line_wxwidgets( PLStream *, short, short, short, short );
211 void plD_polyline_wxwidgets( PLStream *, short *, short *, PLINT );
212 void plD_eop_wxwidgets( PLStream * );
213 void plD_wait_wxwidgets( PLStream * );
214 void plD_bop_wxwidgets( PLStream * );
215 void plD_tidy_wxwidgets( PLStream * );
217 void plD_esc_wxwidgets( PLStream *, PLINT, void * );
218 
219 void wx_set_dc( PLStream* pls, wxDC* dc );
220 void wx_set_buffer( PLStream* pls, wxImage* buffer );
221 
222 //--------------------------------------------------------------------------
223 // Debug functions
224 //--------------------------------------------------------------------------
225 
226 // define if you want debug output
227 // #define _DEBUG //
228 // #define _DEBUG_VERBOSE //
229 void Log_Verbose( const char *fmt, ... );
230 void Log_Debug( const char *fmt, ... );
231 
232 
233 //--------------------------------------------------------------------------
234 // Font style and weight lookup tables
235 //--------------------------------------------------------------------------
236 const wxFontFamily fontFamilyLookup[5] = {
237  wxFONTFAMILY_SWISS, // sans-serif
238  wxFONTFAMILY_ROMAN, // serif
239  wxFONTFAMILY_TELETYPE, // monospace
240  wxFONTFAMILY_SCRIPT, // script
241  wxFONTFAMILY_SWISS // symbol
242 };
243 
244 const int fontStyleLookup[3] = {
245  wxFONTSTYLE_NORMAL, // upright
246  wxFONTSTYLE_ITALIC, // italic
247  wxFONTSTYLE_SLANT // oblique
248 };
249 
250 const int fontWeightLookup[2] = {
251  wxFONTWEIGHT_NORMAL, // medium
252  wxFONTWEIGHT_BOLD // bold
253 };
254 
255 #endif // __WXWIDGETS_H__
wxGCDC * m_interactiveTextGcdc
Definition: wxwidgets.h:150
void SetColor(PLStream *pls)
void Flush(PLStream *pls)
bool pixelDevice
Definition: wxwidgets.h:201
const PLFLT m_plplotEdgeLength
Definition: wxwidgets.h:155
bool operator==(const Font &lhs, const Font &rhs)
wxImage m_interactiveTextImage
Definition: wxwidgets.h:149
const int fontWeightLookup[2]
Definition: wxwidgets.h:250
void plD_line_wxwidgets(PLStream *, short, short, short, short)
Definition: wxwidgets.cpp:280
void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
virtual void FillPolygon(PLStream *pls)
Definition: wxwidgets.h:84
Definition: wxwidgets.h:195
Definition: wxwidgets.h:42
void plD_state_wxwidgets(PLStream *, PLINT)
Definition: wxwidgets.cpp:458
void plD_polyline_wxwidgets(PLStream *, short *, short *, PLINT)
Definition: wxwidgets.cpp:308
PLFLT m_yAspect
Definition: wxwidgets.h:161
const int fontStyleLookup[3]
Definition: wxwidgets.h:244
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:104
PLFLT m_prevBaseFontSize
Definition: wxwidgets.h:102
bool m_fixedAspect
Definition: wxwidgets.h:163
wxFont getWxFont()
virtual ~wxPLDevice(void)
virtual void BeginPage(PLStream *pls)
Definition: wxwidgets.h:89
PLINT m_prevLevel
Definition: wxwidgets.h:103
bool m_useDcTextTransform
Definition: wxwidgets.h:140
wxBrush m_brush
Definition: wxwidgets.h:145
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:82
PLFLT m_lineSpacing
Definition: wxwidgets.h:175
void plD_eop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:338
#define PLPLOT_MAX_PATH
Definition: plplotP.h:442
virtual void DrawTextSection(wxString section, wxCoord xOrigin, wxCoord yOrigin, 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, PLFLT &yScale, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth)
Definition: wxwidgets.h:99
static const int m_max_string_length
Definition: wxwidgets.h:166
PLUNICODE getFci() const
Definition: wxwidgets.h:48
bool m_lastWasCached
Definition: wxwidgets.h:73
virtual void SetDC(PLStream *pls, wxDC *dc)
Definition: wxwidgets.h:87
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)
virtual void PreDestructorTidy(PLStream *pls)
Definition: wxwidgets.h:94
bool lastWasCached()
Definition: wxwidgets.h:70
wxPen m_pen
Definition: wxwidgets.h:144
PLFLT m_height
Definition: wxwidgets.h:157
Font m_prevFont
Definition: wxwidgets.h:72
void SetupMemoryMap()
size_t m_localBufferPosition
Definition: wxwidgets.h:190
PLFLT m_width
Definition: wxwidgets.h:156
PLFLT m_xScale
Definition: wxwidgets.h:158
wxString dev_file_app
Definition: wxwidgets.h:200
virtual ~PlDevice()
Definition: wxwidgets.h:80
bool getUnderlined() const
Definition: wxwidgets.h:50
Font GetFont(PLUNICODE fci, PLFLT scaledFontSize, bool underlined)
virtual void EndPage(PLStream *pls)
Definition: wxwidgets.h:88
void DrawTextLine(PLUNICODE *ucs4, int ucs4Len, wxCoord xOrigin, wxCoord yOrigin, wxCoord x, wxCoord y, PLFLT *transform, PLFLT baseFontSize, bool drawText, bool &underlined, PLUNICODE &fci, unsigned char red, unsigned char green, unsigned char blue, PLFLT alpha, wxCoord &textWidth, wxCoord &textHeight, wxCoord &textDepth)
void drawText(PLStream *pls, EscText *args)
wxDC * m_dc
Definition: wxwidgets.h:139
virtual void SetColor(PLStream *pls)
Definition: wxwidgets.h:86
void plD_tidy_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:424
void wx_set_dc(PLStream *pls, wxDC *dc)
const wxFontFamily fontFamilyLookup[5]
Definition: wxwidgets.h:236
static PLINT * buffer
Definition: plfill.c:74
void Log_Verbose(const char *fmt,...)
Definition: wxwidgets.cpp:56
void Log_Debug(const char *fmt,...)
Definition: wxwidgets.cpp:77
char m_mfo[PLPLOT_MAX_PATH]
Definition: wxwidgets.h:183
wxRegion GetClipRegion()
wxString dev_menu_short
Definition: wxwidgets.h:198
void TransmitBuffer(PLStream *pls, unsigned char transmissionType)
PLFLT m_xAspect
Definition: wxwidgets.h:160
static PLStream * pls[PL_NSTREAMS]
Definition: plcore.h:88
bool m_underlined
Definition: wxwidgets.h:56
PLFLT m_yScale
Definition: wxwidgets.h:159
virtual void SetWidth(PLStream *pls)
Definition: wxwidgets.h:85
PLFLT m_scale
Definition: wxwidgets.h:162
wxString dev_name
Definition: wxwidgets.h:197
virtual void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
Definition: wxwidgets.h:92
void FixAspectRatio(bool fix)
PLNamedMutex m_mutex
Definition: wxwidgets.h:188
wxString dev_menu_long
Definition: wxwidgets.h:199
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:90
virtual void Flush(PLStream *pls)
Definition: wxwidgets.h:93
virtual void FixAspectRatio(bool fix)
Definition: wxwidgets.h:91
void plD_init_wxwidgets(PLStream *)
void plD_bop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:398
void SetSize(PLStream *pls, int width, int height)
void SetDC(PLStream *pls, wxDC *dc)
void plD_init_wxpng(PLStream *)
void DrawTextSection(wxString section, wxCoord xOrigin, wxCoord yOrigin, 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, PLFLT &yScale, wxCoord &sectionWidth, wxCoord &sectionHeight, wxCoord &sectionDepth)
wxCoord m_prevSymbolHeight
Definition: wxwidgets.h:106
void BeginPage(PLStream *pls)
virtual void DrawLine(short x1a, short y1a, short x2a, short y2a)
Definition: wxwidgets.h:81
void plD_esc_wxwidgets(PLStream *, PLINT, void *)
Definition: wxwidgets.cpp:499
void plD_wait_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:368
PLMemoryMap m_outputMemoryMap
Definition: wxwidgets.h:191
PLUNICODE m_prevSymbol
Definition: wxwidgets.h:101
wxCoord m_prevSymbolWidth
Definition: wxwidgets.h:105
FontGrabber m_fontGrabber
Definition: wxwidgets.h:168
wxCoord m_prevSymbolDepth
Definition: wxwidgets.h:107
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:83
wxGraphicsContext * m_gc
Definition: wxwidgets.h:143