PLplot 5.15.0
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// some special wxWidgets headers
27//We need to include these before wxwidgets_comms.h
28// - it seems like the includion of windows.h in
29// wxwidgets_comms.h before wx/wx.h causes some
30// wierd interation with winsock functions for
31// vs2017.
32#include <wx/wx.h>
33#include <wx/spinctrl.h>
34#include <wx/dcgraph.h>
35
36// plplot headers
37#include "plplotP.h"
38#include "wxwidgets_comms.h"
39
40class wxPLplotFrame;
41
42// A font class which encapsulates the PLplot font metrics and
43// a wxFont object. Importantly however the creation of the
44// wxFont is delayed until it is actually requested. This is
45// useful because on Linux in wxWidgets 3.0 creation of a wxFont
46// in a console mode application caused a crash.
47class Font
48{
49public:
50 Font();
51 Font( PLUNICODE fci, PLFLT size, bool underlined, bool createFontOnConstruction = false );
52 wxFont getWxFont();
53 PLUNICODE getFci() const { return m_fci; }
54 PLFLT getSize() const { return m_size; }
55 bool getUnderlined() const { return m_underlined; }
56private:
57 void createFont();
58 wxFont m_font;
63};
64//check equivalence of two fonts. Note that a font created
65//with the default constructor always compares false to any
66//other font and that whether the wxFont has been created is
67//not included in the test.
68bool operator ==( const Font &lhs, const Font &rhs );
69
71{
72public:
74 Font GetFont( PLUNICODE fci, PLFLT scaledFontSize, bool underlined );
75 bool lastWasCached( ){ return m_lastWasCached; }
76private:
79};
80
82{
83public:
84 PlDevice();
85 virtual ~PlDevice() {}
86 virtual void DrawLine( short x1a, short y1a, short x2a, short y2a ) {}
87 virtual void DrawPolyline( short *xa, short *ya, PLINT npts ){}
88 virtual void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 ){}
89 virtual void FillPolygon( PLStream *pls ){}
90 virtual void SetWidth( PLStream *pls ){}
91 virtual void SetColor( PLStream *pls ){}
92 virtual void SetDC( PLStream *pls, wxDC* dc ){}
93 virtual void EndPage( PLStream* pls ){}
94 virtual void BeginPage( PLStream* pls ){}
95 virtual void SetSize( PLStream* pls, int width, int height ){}
96 virtual void FixAspectRatio( bool fix ){}
97 virtual void Locate( PLStream* pls, PLGraphicsIn *graphicsIn ){}
98 virtual void Flush( PLStream* pls ){}
99 virtual void PreDestructorTidy( PLStream *pls ){}
100 virtual void SetXorMode( bool on ){}
101
102 void drawText( PLStream* pls, EscText* args );
103private:
104 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 );
105 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 ) {}
106
114};
115
116// base device class
117class wxPLDevice : public PlDevice
118{
119public:
120 wxPLDevice( PLStream *pls, char * mfo, PLINT text, PLINT hrshsym );
121 virtual ~wxPLDevice( void );
122
123 void DrawLine( short x1a, short y1a, short x2a, short y2a );
124 void DrawPolyline( short *xa, short *ya, PLINT npts );
125 void ClearBackground( PLStream* pls, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 );
126 void FillPolygon( PLStream *pls );
127 void SetWidth( PLStream *pls );
128 void SetColor( PLStream *pls );
129 void SetXorMode( bool on );
130 void SetDC( PLStream *pls, wxDC* dc );
131 void EndPage( PLStream* pls );
132 void BeginPage( PLStream* pls );
133 void SetSize( PLStream* pls, int width, int height );
134 void FixAspectRatio( bool fix );
135 void Locate( PLStream* pls, PLGraphicsIn *graphicsIn );
136 void Flush( PLStream* pls );
138
139private:
140 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 );
141 void TransmitBuffer( PLStream* pls, unsigned char transmissionType );
142 void SetupMemoryMap();
143 wxRegion GetClipRegion();
144
145 //The DC we will draw on if given by the user
146 wxDC *m_dc;
148 //for the gcdc case we may need to store the graphics context for use
149 // with text transformations
150 wxGraphicsContext *m_gc;
151 wxPen m_pen;
152 wxBrush m_brush;
153
154 //A device context specifically for checking the size of text for use with
155 //the interactive viewer.
158
159 //Size and Scale
160 //As far as plplot is concerned the size of the window is SHRT_MAX by
161 //SHRT_MAX which gives us the best resolution.
163 PLFLT m_width; //native width
164 PLFLT m_height; //native height
165 PLFLT m_xScale; //conversion from native width to plplotEdgeLength
166 PLFLT m_yScale; //conversion from native height to plplotEdgeLength
167 PLFLT m_xAspect; //values which when multiplied by m_plplotEdgeLength give an aspect
168 PLFLT m_yAspect; //ratio equal to the native aspect ratio, the biggest of which is 1.0
169 PLFLT m_scale; //MAX(m_scalex, m_scaley)
171
172 // font variables
173 static const int m_max_string_length = 500;
174 //bool m_underlined;
176 //wxCoord m_textWidth, m_textHeight, m_textDescent, m_textLeading;
177 //PLUNICODE m_fci;
178
179 //Text positioning related variables
180 //wxCoord m_superscriptHeight; //distance between superscript top and baseline
181 //wxCoord m_subscriptDepth; //distance between subscript base and baseline
183 //PLFLT m_yOffset;
184 //PLINT m_posX;
185 //PLINT m_posY;
186 //PLFLT m_rotation;
187
188 //variables for dealing with sending/receiving commands
189 //via a memory map
191#ifdef PL_WXWIDGETS_IPC3
192 // Private variable to hold all components of a MemoryMapHeader struct for a wxPLDevice instance.
193 MemoryMapHeader m_header;
194#else
196#endif
199};
200
201
203{
204 wxString dev_name;
207 wxString dev_file_app;
209};
210
211//--------------------------------------------------------------------------
212// Declarations for the device.
213//--------------------------------------------------------------------------
214
217void plD_line_wxwidgets( PLStream *, short, short, short, short );
218void plD_polyline_wxwidgets( PLStream *, short *, short *, PLINT );
224void plD_esc_wxwidgets( PLStream *, PLINT, void * );
225
226void wx_set_dc( PLStream* pls, wxDC* dc );
227void wx_set_buffer( PLStream* pls, wxImage* buffer );
228
229//--------------------------------------------------------------------------
230// Debug functions
231//--------------------------------------------------------------------------
232
233// define if you want debug output
234// #define _DEBUG //
235// #define _DEBUG_VERBOSE //
236void Log_Verbose( const char *fmt, ... );
237void Log_Debug( const char *fmt, ... );
238
239
240//--------------------------------------------------------------------------
241// Font style and weight lookup tables
242//--------------------------------------------------------------------------
243const wxFontFamily fontFamilyLookup[5] = {
244 wxFONTFAMILY_SWISS, // sans-serif
245 wxFONTFAMILY_ROMAN, // serif
246 wxFONTFAMILY_TELETYPE, // monospace
247 wxFONTFAMILY_SCRIPT, // script
248 wxFONTFAMILY_SWISS // symbol
249};
250
251const int fontStyleLookup[3] = {
252 wxFONTSTYLE_NORMAL, // upright
253 wxFONTSTYLE_ITALIC, // italic
254 wxFONTSTYLE_SLANT // oblique
255};
256
257const int fontWeightLookup[2] = {
258 wxFONTWEIGHT_NORMAL, // medium
259 wxFONTWEIGHT_BOLD // bold
260};
261
262#endif // __WXWIDGETS_H__
bool lastWasCached()
Definition: wxwidgets.h:75
bool m_lastWasCached
Definition: wxwidgets.h:78
Font m_prevFont
Definition: wxwidgets.h:77
Font GetFont(PLUNICODE fci, PLFLT scaledFontSize, bool underlined)
Definition: wxwidgets.h:48
PLUNICODE getFci() const
Definition: wxwidgets.h:53
wxFont m_font
Definition: wxwidgets.h:58
bool m_hasFont
Definition: wxwidgets.h:62
wxFont getWxFont()
void createFont()
bool m_underlined
Definition: wxwidgets.h:61
PLFLT m_size
Definition: wxwidgets.h:60
PLFLT getSize() const
Definition: wxwidgets.h:54
PLUNICODE m_fci
Definition: wxwidgets.h:59
bool getUnderlined() const
Definition: wxwidgets.h:55
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:105
virtual void BeginPage(PLStream *pls)
Definition: wxwidgets.h:94
PLFLT m_prevBaseFontSize
Definition: wxwidgets.h:108
PLUNICODE m_prevSymbol
Definition: wxwidgets.h:107
virtual void FixAspectRatio(bool fix)
Definition: wxwidgets.h:96
virtual void SetColor(PLStream *pls)
Definition: wxwidgets.h:91
virtual void SetSize(PLStream *pls, int width, int height)
Definition: wxwidgets.h:95
virtual void EndPage(PLStream *pls)
Definition: wxwidgets.h:93
void drawText(PLStream *pls, EscText *args)
wxCoord m_prevSymbolDepth
Definition: wxwidgets.h:113
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)
virtual void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
Definition: wxwidgets.h:97
virtual void ClearBackground(PLStream *pls, PLINT x1=-1, PLINT y1=-1, PLINT x2=-1, PLINT y2=-1)
Definition: wxwidgets.h:88
wxCoord m_prevSymbolHeight
Definition: wxwidgets.h:112
virtual void SetDC(PLStream *pls, wxDC *dc)
Definition: wxwidgets.h:92
PLUNICODE m_prevFci
Definition: wxwidgets.h:110
virtual void Flush(PLStream *pls)
Definition: wxwidgets.h:98
virtual ~PlDevice()
Definition: wxwidgets.h:85
virtual void DrawLine(short x1a, short y1a, short x2a, short y2a)
Definition: wxwidgets.h:86
PLINT m_prevLevel
Definition: wxwidgets.h:109
virtual void SetXorMode(bool on)
Definition: wxwidgets.h:100
virtual void SetWidth(PLStream *pls)
Definition: wxwidgets.h:90
wxCoord m_prevSymbolWidth
Definition: wxwidgets.h:111
virtual void DrawPolyline(short *xa, short *ya, PLINT npts)
Definition: wxwidgets.h:87
virtual void PreDestructorTidy(PLStream *pls)
Definition: wxwidgets.h:99
virtual void FillPolygon(PLStream *pls)
Definition: wxwidgets.h:89
wxPen m_pen
Definition: wxwidgets.h:151
void DrawPolyline(short *xa, short *ya, PLINT npts)
void DrawLine(short x1a, short y1a, short x2a, short y2a)
PLFLT m_yScale
Definition: wxwidgets.h:166
bool m_useDcTextTransform
Definition: wxwidgets.h:147
wxImage m_interactiveTextImage
Definition: wxwidgets.h:156
char m_mfo[PLPLOT_MAX_PATH]
Definition: wxwidgets.h:190
static const int m_max_string_length
Definition: wxwidgets.h:173
bool m_fixedAspect
Definition: wxwidgets.h:170
void EndPage(PLStream *pls)
wxRegion GetClipRegion()
virtual ~wxPLDevice(void)
void SetDC(PLStream *pls, wxDC *dc)
FontGrabber m_fontGrabber
Definition: wxwidgets.h:175
PLFLT m_width
Definition: wxwidgets.h:163
void FixAspectRatio(bool fix)
wxBrush m_brush
Definition: wxwidgets.h:152
void PreDestructorTidy(PLStream *pls)
PLFLT m_scale
Definition: wxwidgets.h:169
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)
PLMemoryMap m_outputMemoryMap
Definition: wxwidgets.h:198
void TransmitBuffer(PLStream *pls, unsigned char transmissionType)
PLFLT m_lineSpacing
Definition: wxwidgets.h:182
void Locate(PLStream *pls, PLGraphicsIn *graphicsIn)
void SetXorMode(bool on)
void SetSize(PLStream *pls, int width, int height)
void SetColor(PLStream *pls)
size_t m_localBufferPosition
Definition: wxwidgets.h:197
void BeginPage(PLStream *pls)
PLFLT m_xAspect
Definition: wxwidgets.h:167
wxGraphicsContext * m_gc
Definition: wxwidgets.h:150
void SetWidth(PLStream *pls)
PLFLT m_xScale
Definition: wxwidgets.h:165
const PLFLT m_plplotEdgeLength
Definition: wxwidgets.h:162
PLFLT m_yAspect
Definition: wxwidgets.h:168
void SetupMemoryMap()
void Flush(PLStream *pls)
void ClearBackground(PLStream *pls, PLINT x1=-1, PLINT y1=-1, PLINT x2=-1, PLINT y2=-1)
wxGCDC * m_interactiveTextGcdc
Definition: wxwidgets.h:157
PLNamedMutex m_mutex
Definition: wxwidgets.h:195
PLFLT m_height
Definition: wxwidgets.h:164
wxPLDevice(PLStream *pls, char *mfo, PLINT text, PLINT hrshsym)
wxDC * m_dc
Definition: wxwidgets.h:146
void FillPolygon(PLStream *pls)
static PLStream * pls[PL_NSTREAMS]
Definition: plcore.h:88
static PLINT * buffer
Definition: plfill.c:74
#define PLPLOT_MAX_PATH
Definition: plplotP.h:446
PLUINT PLUNICODE
Definition: plplot.h:201
float PLFLT
Definition: plplot.h:163
int PLINT
Definition: plplot.h:181
static int hrshsym
Definition: ps.c:79
static int text
Definition: ps.c:77
Definition: wxwidgets.h:203
wxString dev_file_app
Definition: wxwidgets.h:207
wxString dev_menu_long
Definition: wxwidgets.h:206
bool pixelDevice
Definition: wxwidgets.h:208
wxString dev_menu_short
Definition: wxwidgets.h:205
wxString dev_name
Definition: wxwidgets.h:204
void wx_set_dc(PLStream *pls, wxDC *dc)
bool operator==(const Font &lhs, const Font &rhs)
void plD_tidy_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:429
void plD_eop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:343
void plD_esc_wxwidgets(PLStream *, PLINT, void *)
Definition: wxwidgets.cpp:504
void plD_init_wxwidgets(PLStream *)
void plD_init_wxpng(PLStream *)
void Log_Verbose(const char *fmt,...)
Definition: wxwidgets.cpp:56
const int fontStyleLookup[3]
Definition: wxwidgets.h:251
const wxFontFamily fontFamilyLookup[5]
Definition: wxwidgets.h:243
const int fontWeightLookup[2]
Definition: wxwidgets.h:257
void plD_state_wxwidgets(PLStream *, PLINT)
Definition: wxwidgets.cpp:463
void Log_Debug(const char *fmt,...)
Definition: wxwidgets.cpp:77
void wx_set_buffer(PLStream *pls, wxImage *buffer)
void plD_line_wxwidgets(PLStream *, short, short, short, short)
Definition: wxwidgets.cpp:285
void plD_wait_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:373
void plD_bop_wxwidgets(PLStream *)
Definition: wxwidgets.cpp:403
void plD_polyline_wxwidgets(PLStream *, short *, short *, PLINT)
Definition: wxwidgets.cpp:313