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 #ifdef wxUSE_GRAPHICS_CONTEXT
34 #include <wx/dcgraph.h>
35 #endif
36 
37 class wxPLplotFrame;
38 
40 {
41 public:
42  FontGrabber();
43  wxFont GetFont( PLUNICODE fci, PLFLT scaledFontSize, bool underlined );
44  bool lastWasCached( ){ return m_lastWasCached; }
45 private:
46  wxFont m_prevFont;
51 };
52 
53 // base device class
55 {
56 public:
57  wxPLDevice( PLStream *pls, char * mfo, PLINT text, PLINT hrshsym );
58  virtual ~wxPLDevice( void );
59 
60  void DrawLine( short x1a, short y1a, short x2a, short y2a );
61  void DrawPolyline( short *xa, short *ya, PLINT npts );
62  void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 );
63  void FillPolygon( PLStream *pls );
64  void SetWidth( PLStream *pls );
65  void SetColor( PLStream *pls );
66  void SetDC( PLStream *pls, wxDC* dc );
67  void EndPage( PLStream* pls );
68  void BeginPage( PLStream* pls );
69  void SetSize( PLStream* pls, int width, int height );
70  void ProcessString( PLStream* pls, EscText* args );
71  void FixAspectRatio( bool fix );
72  void Locate( PLStream* pls, PLGraphicsIn *graphicsIn );
73  void Flush( PLStream* pls );
74  void PreDestructorTidy( PLStream *pls );
75 
76 private:
77  void DrawTextLine( PLUNICODE* ucs4, int ucs4Len, PLFLT baseFontSize, bool drawText, PLINT &superscriptLevel, bool &underlined );
78  void DrawTextSection( char* utf8_string, PLFLT baseFontSize, PLFLT yOffset, bool underlined, bool drawText );
79  void TransmitBuffer( PLStream* pls, unsigned char transmissionType );
80  void SetupMemoryMap();
81  wxRegion GetClipRegion();
82 
83  //The DC we will draw on if given by the user
84  wxDC *m_dc;
86  //for the gcdc case we may need to store the graphics context for use
87  // with text transformations
88  wxGraphicsContext *m_gc;
89  wxPen m_pen;
90  wxBrush m_brush;
91 
92  //Size and Scale
93  //As far as plplot is concerned the size of the window is SHRT_MAX by
94  //SHRT_MAX which gives us the best resolution.
96  PLFLT m_width; //native width
97  PLFLT m_height; //native height
98  PLFLT m_xScale; //conversion from native width to plplotEdgeLength
99  PLFLT m_yScale; //conversion from native height to plplotEdgeLength
100  PLFLT m_xAspect; //values which when multiplied by m_plplotEdgeLength give an aspect
101  PLFLT m_yAspect; //ratio equal to the native aspect ratio, the biggest of which is 1.0
102  PLFLT m_scale; //MAX(m_scalex, m_scaley)
104 
105  // font variables
106  static const int m_max_string_length = 500;
107  //bool m_underlined;
111 
112  //memory of previous single character string (likely plot point)
116 
117  //Text positioning related variables
118  wxCoord m_superscriptHeight; //distance between superscript top and baseline
119  wxCoord m_subscriptDepth; //distance between subscript base and baseline
121  //PLFLT m_yOffset;
125 
126  //variables for dealing with sending/receiving commands
127  //via a memory map
132 };
133 
134 
135 struct dev_entry
136 {
137  wxString dev_name;
138  wxString dev_menu_short;
139  wxString dev_menu_long;
140  wxString dev_file_app;
142 };
143 
144 //--------------------------------------------------------------------------
145 // Declarations for the device.
146 //--------------------------------------------------------------------------
147 
148 void plD_init_wxwidgets( PLStream * );
149 void plD_init_wxpng( PLStream * );
150 void plD_line_wxwidgets( PLStream *, short, short, short, short );
151 void plD_polyline_wxwidgets( PLStream *, short *, short *, PLINT );
152 void plD_eop_wxwidgets( PLStream * );
153 void plD_bop_wxwidgets( PLStream * );
154 void plD_tidy_wxwidgets( PLStream * );
156 void plD_esc_wxwidgets( PLStream *, PLINT, void * );
157 
158 void wx_set_dc( PLStream* pls, wxDC* dc );
159 void wx_set_buffer( PLStream* pls, wxImage* buffer );
160 
161 //--------------------------------------------------------------------------
162 // Debug functions
163 //--------------------------------------------------------------------------
164 
165 // define if you want debug output
166 // #define _DEBUG //
167 // #define _DEBUG_VERBOSE //
168 void Log_Verbose( const char *fmt, ... );
169 void Log_Debug( const char *fmt, ... );
170 
171 
172 //--------------------------------------------------------------------------
173 // Font style and weight lookup tables
174 //--------------------------------------------------------------------------
175 const wxFontFamily fontFamilyLookup[5] = {
176  wxFONTFAMILY_SWISS, // sans-serif
177  wxFONTFAMILY_ROMAN, // serif
178  wxFONTFAMILY_TELETYPE, // monospace
179  wxFONTFAMILY_SCRIPT, // script
180  wxFONTFAMILY_SWISS // symbol
181 };
182 
183 const int fontStyleLookup[3] = {
184  wxFONTSTYLE_NORMAL, // upright
185  wxFONTSTYLE_ITALIC, // italic
186  wxFONTSTYLE_SLANT // oblique
187 };
188 
189 const int fontWeightLookup[2] = {
190  wxFONTWEIGHT_NORMAL, // medium
191  wxFONTWEIGHT_BOLD // bold
192 };
193 
194 #endif // __WXWIDGETS_H__