00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __WXWIDGETS_H__
00023 #define __WXWIDGETS_H__
00024
00025
00026 #include <wx/spinctrl.h>
00027
00028
00029 #ifdef HAVE_FREETYPE
00030 #include "plfreetype.h"
00031
00032 static void plD_pixel_wxwidgets( PLStream *pls, short x, short y );
00033 static PLINT plD_read_pixel_wxwidgets( PLStream *pls, short x, short y );
00034 static void plD_set_pixel_wxwidgets( PLStream *pls, short x, short y, PLINT colour );
00035 static void init_freetype_lv1( PLStream *pls );
00036 static void init_freetype_lv2( PLStream *pls );
00037 #endif
00038
00039 #ifndef max_number_of_grey_levels_used_in_text_smoothing
00040 #define max_number_of_grey_levels_used_in_text_smoothing 64
00041 #endif
00042
00043 #define NDEV 100 // Max number of output device types in menu
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #define VSCALE ( 32. )
00057
00058
00059 #define DEVICE_PIXELS_PER_MM ( 3.14961 )
00060 #define VIRTUAL_PIXELS_PER_MM ( DEVICE_PIXELS_PER_MM * VSCALE )
00061
00062
00063 #define MM_PER_IN ( 25.4 )
00064
00065
00066 #define DEVICE_PIXELS_PER_IN ( DEVICE_PIXELS_PER_MM * MM_PER_IN )
00067 #define VIRTUAL_PIXELS_PER_IN ( VIRTUAL_PIXELS_PER_MM * MM_PER_IN )
00068
00069
00070 #define CANVAS_WIDTH ( 10.0 )
00071 #define CANVAS_HEIGHT ( 7.5 )
00072
00073
00074 #define PLOT_WIDTH ( 800 )
00075 #define PLOT_HEIGHT ( 600 )
00076
00077
00078 #define LOCATE_INVOKED_VIA_API 1
00079 #define LOCATE_INVOKED_VIA_DRIVER 2
00080
00081
00082 #define wxBACKEND_DC 0
00083 #define wxBACKEND_AGG 1
00084 #define wxBACKEND_GC 2
00085
00086 class wxPLplotFrame;
00087
00088
00089 class wxPLDevBase
00090 {
00091 public:
00092 wxPLDevBase( int bcknd );
00093 virtual ~wxPLDevBase( void );
00094
00095
00096 virtual void DrawLine( short x1a, short y1a, short x2a, short y2a ) = 0;
00097 virtual void DrawPolyline( short *xa, short *ya, PLINT npts ) = 0;
00098 virtual void ClearBackground( PLINT bgr, PLINT bgg, PLINT bgb, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 ) = 0;
00099 virtual void FillPolygon( PLStream *pls ) = 0;
00100 virtual void BlitRectangle( wxDC* dc, int vX, int vY, int vW, int vH ) = 0;
00101 void AddtoClipRegion( int x1, int y1, int x2, int y2 );
00102 virtual void CreateCanvas() = 0;
00103 virtual void SetWidth( PLStream *pls ) = 0;
00104 virtual void SetColor0( PLStream *pls ) = 0;
00105 virtual void SetColor1( PLStream *pls ) = 0;
00106 virtual void SetExternalBuffer( void* buffer ) = 0;
00107 #ifdef HAVE_FREETYPE
00108 virtual void PutPixel( short x, short y, PLINT color ) = 0;
00109 virtual void PutPixel( short x, short y ) = 0;
00110 virtual PLINT GetPixel( short x, short y ) = 0;
00111 #endif // HAVE_FREETYPE
00112 virtual void ProcessString( PLStream* pls, EscText* args ) = 0;
00113 virtual void PSDrawText( PLUNICODE* ucs4, int ucs4Len, bool drawText );
00114 virtual void PSDrawTextToDC( char* utf8_string, bool drawText ) = 0;
00115 virtual void PSSetFont( PLUNICODE fci ) = 0;
00116
00117 public:
00118 const int backend;
00119 bool ready;
00120 bool ownGUI;
00121 bool showGUI;
00122 bool waiting;
00123 bool resizing;
00124 bool exit;
00125 int comcount;
00126
00127 wxPLplotFrame* m_frame;
00128 PLINT xpos;
00129 PLINT ypos;
00130 PLINT width;
00131 PLINT height;
00132 PLINT bm_width;
00133 PLINT bm_height;
00134
00135 PLINT xmin;
00136 PLINT xmax;
00137 PLINT ymin;
00138 PLINT ymax;
00139
00140 PLFLT scalex;
00141 PLFLT scaley;
00142
00143 bool plstate_width;
00144 bool plstate_color0;
00145 bool plstate_color1;
00146
00147 PLGraphicsIn gin;
00148 int locate_mode;
00149 bool draw_xhair;
00150
00151
00152 int clipminx, clipmaxx;
00153 int clipminy, clipmaxy;
00154 bool newclipregion;
00155
00156
00157 int freetype;
00158 int smooth_text;
00159
00160 const char ** devDesc;
00161 const char ** devName;
00162 int ndev;
00163 wxBitmapType bitmapType;
00164
00165
00166 static const int max_string_length = 500;
00167 wxFont * m_font;
00168 bool underlined;
00169 double fontSize;
00170 double fontScale;
00171 wxCoord textWidth, textHeight, textDescent, textLeading;
00172 double yOffset;
00173 PLINT posX, posY;
00174 PLFLT rotation, cos_rot, sin_rot;
00175 PLFLT shear, cos_shear, sin_shear;
00176 PLFLT stride;
00177 };
00178
00179
00180 class wxPLDevDC : public wxPLDevBase
00181 {
00182 public:
00183 wxPLDevDC( void );
00184 ~wxPLDevDC( void );
00185
00186 void DrawLine( short x1a, short y1a, short x2a, short y2a );
00187 void DrawPolyline( short *xa, short *ya, PLINT npts );
00188 void ClearBackground( PLINT bgr, PLINT bgg, PLINT bgb, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 );
00189 void FillPolygon( PLStream *pls );
00190 void BlitRectangle( wxDC* dc, int vX, int vY, int vW, int vH );
00191 void CreateCanvas();
00192 void SetWidth( PLStream *pls );
00193 void SetColor0( PLStream *pls );
00194 void SetColor1( PLStream *pls );
00195 void SetExternalBuffer( void* buffer );
00196 #ifdef HAVE_FREETYPE
00197 void PutPixel( short x, short y, PLINT color );
00198 void PutPixel( short x, short y );
00199 PLINT GetPixel( short x, short y );
00200 #endif // HAVE_FREETYPE
00201 void ProcessString( PLStream* pls, EscText* args );
00202 void PSDrawTextToDC( char* utf8_string, bool drawText );
00203 void PSSetFont( PLUNICODE fci );
00204
00205 private:
00206 wxBitmap* m_bitmap;
00207 wxDC * m_dc;
00208 };
00209
00210
00211 #ifdef HAVE_AGG
00212
00213 #include "agg2/agg_basics.h"
00214 #include "agg2/agg_rendering_buffer.h"
00215 #include "agg2/agg_rasterizer_scanline_aa.h"
00216 #include "agg2/agg_scanline_u.h"
00217 #include "agg2/agg_scanline_bin.h"
00218 #include "agg2/agg_conv_stroke.h"
00219 #include "agg2/agg_pixfmt_rgb.h"
00220 #include "agg2/agg_renderer_base.h"
00221 #include "agg2/agg_renderer_scanline.h"
00222 #include "agg2/agg_renderer_primitives.h"
00223 #include "agg2/agg_path_storage.h"
00224 #include "agg2/agg_conv_curve.h"
00225 #include "agg2/agg_conv_contour.h"
00226 #include "agg2/agg_font_freetype.h"
00227
00228 class wxPLDevAGG : public wxPLDevBase
00229 {
00230
00231 typedef agg::pixfmt_rgb24 pixFormat;
00232 typedef agg::renderer_base<pixFormat> rendererBase;
00233 typedef agg::renderer_scanline_aa_solid<rendererBase> rendererSolid;
00234 typedef agg::font_engine_freetype_int32 fontEngineType;
00235 typedef agg::font_cache_manager<fontEngineType> fontManagerType;
00236 typedef agg::font_cache_manager<fontEngineType>::gray8_adaptor_type fontRasterizer;
00237 typedef agg::font_cache_manager<fontEngineType>::gray8_scanline_type fontScanline;
00238 typedef agg::conv_curve<agg::path_storage> convCurve;
00239 typedef agg::conv_stroke<convCurve> convStroke;
00240 typedef agg::conv_transform<convCurve> pathTransform;
00241 typedef agg::conv_transform<convStroke> strokeTransform;
00242
00243 enum drawPathFlag { Fill, Stroke, FillAndStroke };
00244
00245 public:
00246 wxPLDevAGG( void );
00247 ~wxPLDevAGG( void );
00248
00249 void DrawLine( short x1a, short y1a, short x2a, short y2a );
00250 void DrawPolyline( short *xa, short *ya, PLINT npts );
00251 void ClearBackground( PLINT bgr, PLINT bgg, PLINT bgb, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 );
00252 void FillPolygon( PLStream *pls );
00253 void BlitRectangle( wxDC* dc, int vX, int vY, int vW, int vH );
00254 void CreateCanvas();
00255 void SetWidth( PLStream *pls );
00256 void SetColor0( PLStream *pls );
00257 void SetColor1( PLStream *pls );
00258 void SetExternalBuffer( void* buffer );
00259 #ifdef HAVE_FREETYPE
00260 void PutPixel( short x, short y, PLINT color );
00261 void PutPixel( short x, short y );
00262 PLINT GetPixel( short x, short y );
00263 #endif // HAVE_FREETYPE
00264 void ProcessString( PLStream* pls, EscText* args );
00265 void PSDrawTextToDC( char* utf8_string, bool drawText );
00266 void PSSetFont( PLUNICODE fci );
00267 void drawPath( drawPathFlag flag );
00268 void AGGAddtoClipRegion( short x1, short y1, short x2, short y2 );
00269
00270 private:
00271 wxDC * mDC;
00272 wxImage * mBuffer;
00273 agg::rendering_buffer mRenderingBuffer;
00274 fontEngineType mFontEngine;
00275 fontManagerType mFontManager;
00276 agg::conv_curve<fontManagerType::path_adaptor_type> mCurves;
00277 agg::conv_contour<agg::conv_curve<fontManagerType::path_adaptor_type> > mContour;
00278
00279 pixFormat mPixFormat;
00280 rendererBase mRendererBase;
00281 rendererSolid mRendererSolid;
00282
00283 agg::scanline_u8 mScanLine;
00284 agg::rasterizer_scanline_aa<> mRasterizer;
00285 agg::path_storage mPath;
00286 agg::trans_affine mTransform;
00287
00288 convCurve mConvCurve;
00289 convStroke mConvStroke;
00290 pathTransform mPathTransform;
00291 strokeTransform mStrokeTransform;
00292
00293 double mStrokeWidth;
00294 wxUint8 mStrokeOpacity;
00295 unsigned char mColorRedStroke;
00296 unsigned char mColorGreenStroke;
00297 unsigned char mColorBlueStroke;
00298 unsigned char mColorRedFill;
00299 unsigned char mColorGreenFill;
00300 unsigned char mColorBlueFill;
00301
00302 double textWidth, textHeight;
00303 wxString fontdir;
00304 };
00305 #endif
00306
00307
00308 #if wxUSE_GRAPHICS_CONTEXT
00309 #include <wx/graphics.h>
00310
00311 class wxPLDevGC : public wxPLDevBase
00312 {
00313 public:
00314 wxPLDevGC( void );
00315 ~wxPLDevGC( void );
00316
00317 void DrawLine( short x1a, short y1a, short x2a, short y2a );
00318 void DrawPolyline( short *xa, short *ya, PLINT npts );
00319 void ClearBackground( PLINT bgr, PLINT bgg, PLINT bgb, PLINT x1 = -1, PLINT y1 = -1, PLINT x2 = -1, PLINT y2 = -1 );
00320 void FillPolygon( PLStream *pls );
00321 void BlitRectangle( wxDC* dc, int vX, int vY, int vW, int vH );
00322 void CreateCanvas();
00323 void SetWidth( PLStream *pls );
00324 void SetColor0( PLStream *pls );
00325 void SetColor1( PLStream *pls );
00326 void SetExternalBuffer( void* buffer );
00327 #ifdef HAVE_FREETYPE
00328 void PutPixel( short x, short y, PLINT color );
00329 void PutPixel( short x, short y );
00330 PLINT GetPixel( short x, short y );
00331 #endif // HAVE_FREETYPE
00332 void ProcessString( PLStream* pls, EscText* args );
00333 void PSDrawTextToDC( char* utf8_string, bool drawText );
00334 void PSSetFont( PLUNICODE fci );
00335
00336 private:
00337 wxBitmap * m_bitmap;
00338 wxDC * m_dc;
00339 wxGraphicsContext* m_context;
00340
00341
00342 unsigned char textRed, textGreen, textBlue;
00343
00344 unsigned char mStrokeOpacity;
00345 unsigned char mColorRedStroke;
00346 unsigned char mColorGreenStroke;
00347 unsigned char mColorBlueStroke;
00348 unsigned char mColorRedFill;
00349 unsigned char mColorGreenFill;
00350 unsigned char mColorBlueFill;
00351 };
00352 #endif
00353
00354
00355 struct dev_entry
00356 {
00357 wxString dev_name;
00358 wxString dev_menu_short;
00359 wxString dev_menu_long;
00360 wxString dev_file_app;
00361 bool pixelDevice;
00362 };
00363
00364
00365
00366
00367 #define MAX_COMCOUNT 10000
00368
00369
00370 WX_DEFINE_ARRAY( wxPLplotFrame *, wxArrayOfwxPLplotFrame );
00371 class wxPLplotApp : public wxApp
00372 {
00373 public:
00374 virtual bool OnInit();
00375
00376 void SetExitFlag( bool flag = true ) { exit = flag; };
00377 bool GetExitFlag( void ) { return exit; };
00378 void SetAdvanceFlag( bool flag = true ) { advance = flag; };
00379 bool GetAdvanceFlag( void ) { return advance; };
00380 void SetRefreshFlag( bool flag = true );
00381 void AddFrame( wxPLplotFrame* frame ) { FrameArray.Add( frame ); };
00382 void RemoveFrame( wxPLplotFrame* frame ) { FrameArray.Remove( frame ); };
00383 size_t FrameCount( void ) { return FrameArray.GetCount(); }
00384 void OnIdle( wxIdleEvent& event );
00385
00386 private:
00387 bool exit;
00388 bool advance;
00389 wxArrayOfwxPLplotFrame FrameArray;
00390
00391 DECLARE_EVENT_TABLE()
00392 };
00393
00394
00395 class wxPLplotWindow : public wxWindow
00396 {
00397 public:
00398 wxPLplotWindow( wxWindow* parent, PLStream *pls );
00399
00400 void SetRefreshFlag( bool flag = true ) { refresh = flag; };
00401 bool GetRefreshFlag( void ) { return refresh; };
00402 void SetOrientation( int rot );
00403
00404 private:
00405 void OnPaint( wxPaintEvent& event );
00406 void OnChar( wxKeyEvent& event );
00407 void OnIdle( wxIdleEvent& event );
00408 void OnErase( wxEraseEvent & WXUNUSED( event ) );
00409 void OnSize( wxSizeEvent & WXUNUSED( event ) );
00410 void OnMaximize( wxMaximizeEvent & WXUNUSED( event ) );
00411 void OnMouse( wxMouseEvent& event );
00412 void Locate( void );
00413 void DrawCrosshair();
00414
00415 PLStream * m_pls;
00416 wxPLDevBase* m_dev;
00417 bool refresh;
00418 bool xhair_drawn;
00419 int mouse_x, mouse_y, old_mouse_x, old_mouse_y;
00420
00421 DECLARE_EVENT_TABLE()
00422 };
00423
00424
00425
00426 class wxPLplotFrame : public wxFrame
00427 {
00428 public:
00429 wxPLplotFrame( const wxString& title, PLStream* pls );
00430 void OnMenu( wxCommandEvent& event );
00431 void OnClose( wxCloseEvent& event );
00432 bool SavePlot( const char* filename, const char* devname, int width, int height );
00433 void SetRefreshFlag( bool flag = true ) { m_window->SetRefreshFlag( flag ); };
00434 bool GetRefreshFlag( void ) { return m_window->GetRefreshFlag(); };
00435
00436 private:
00437 wxPanel * m_panel;
00438 wxPLplotWindow* m_window;
00439 wxPLDevBase * m_dev;
00440
00441 DECLARE_EVENT_TABLE()
00442 };
00443
00444
00445 enum { wxPL_Save = 10000, wxPL_Next = 10100, wxPL_Locate, wxPL_Orientation_0, wxPL_Orientation_90,
00446 wxPL_Orientation_180, wxPL_Orientation_270 };
00447
00448
00449
00450 class wxGetSizeDialog : public wxDialog
00451 {
00452 public:
00453
00454 wxGetSizeDialog( wxWindow *parent, wxWindowID id, const wxString &title,
00455 const wxPoint& pos = wxDefaultPosition,
00456 const wxSize& size = wxDefaultSize,
00457 long style = wxDEFAULT_DIALOG_STYLE,
00458 int width = 800, int height = 600 );
00459
00460 int getWidth() { return spinControlWidth->GetValue(); }
00461 int getHeight() { return spinControlHeight->GetValue(); }
00462
00463 private:
00464 wxSpinCtrl* spinControlWidth;
00465 wxSpinCtrl* spinControlHeight;
00466
00467 private:
00468 DECLARE_EVENT_TABLE()
00469 };
00470
00471
00472
00473
00474 #define IMPLEMENT_PLAPP_NO_MAIN( appname ) \
00475 wxAppConsole * wxPLCreateApp() \
00476 { \
00477 wxAppConsole::CheckBuildOptions( WX_BUILD_OPTIONS_SIGNATURE, \
00478 "your program" ); \
00479 return new appname; \
00480 } \
00481 wxAppInitializer \
00482 wxAppInitializer( (wxAppInitializerFunction) wxPLCreateApp ); \
00483 DECLARE_PLAPP( appname ) \
00484 appname & wxPLGetApp() { return *wx_static_cast( appname *, wxApp::GetInstance() ); }
00485
00486 #define DECLARE_PLAPP( appname ) extern appname &wxPLGetApp();
00487
00488
00489 static inline void Use( void * )
00490 {
00491 }
00492 #define WX_SUPPRESS_UNUSED_WARN( x ) Use( &x )
00493
00494
00495 static void install_buffer( PLStream *pls );
00496 static void wxRunApp( PLStream *pls, bool runonce = false );
00497 static void GetCursorCmd( PLStream *pls, PLGraphicsIn *ptr );
00498
00499
00500
00501
00502
00503
00504 void plD_init_wxwidgets( PLStream * );
00505 void plD_init_wxpng( PLStream * );
00506 void plD_line_wxwidgets( PLStream *, short, short, short, short );
00507 void plD_polyline_wxwidgets( PLStream *, short *, short *, PLINT );
00508 void plD_eop_wxwidgets( PLStream * );
00509 void plD_bop_wxwidgets( PLStream * );
00510 void plD_tidy_wxwidgets( PLStream * );
00511 void plD_state_wxwidgets( PLStream *, PLINT );
00512 void plD_esc_wxwidgets( PLStream *, PLINT, void * );
00513
00514 static void fill_polygon( PLStream *pls );
00515 void wx_set_dc( PLStream* pls, wxDC* dc );
00516 void wx_set_buffer( PLStream* pls, wxImage* buffer );
00517 void wx_set_size( PLStream* pls, int width, int height );
00518 int plD_errorexithandler_wxwidgets( char *errormessage );
00519 void plD_erroraborthandler_wxwidgets( char *errormessage );
00520
00521
00522
00523
00524
00525
00526
00527
00528 void Log_Verbose( const char *fmt, ... );
00529 void Log_Debug( const char *fmt, ... );
00530
00531
00532
00533
00534
00535 const wxFontFamily fontFamilyLookup[5] = {
00536 wxFONTFAMILY_SWISS,
00537 wxFONTFAMILY_ROMAN,
00538 wxFONTFAMILY_TELETYPE,
00539 wxFONTFAMILY_SCRIPT,
00540 wxFONTFAMILY_SWISS
00541 };
00542
00543 const int fontStyleLookup[3] = {
00544 wxFONTFLAG_DEFAULT,
00545 wxFONTFLAG_ITALIC,
00546 wxFONTFLAG_SLANT
00547 };
00548
00549 const int fontWeightLookup[2] = {
00550 wxFONTFLAG_DEFAULT,
00551 wxFONTFLAG_BOLD
00552 };
00553
00554 #endif // __WXWIDGETS_H__