1 /***************************************************************************
2  * wx.h.cpp is part of Math Graphic Library
3  * Copyright (C) 2007-2016 Alexey Balakin <mathgl.abalakin@gmail.ru>       *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU Lesser General Public License  as       *
7  *   published by the Free Software Foundation; either version 3 of the    *
8  *   License, or (at your option) any later version.                       *
9  *                                                                         *
10  *   This program 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 General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU Lesser General Public     *
16  *   License along with this program; if not, write to the                 *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef MGL_WX_H
21 #define MGL_WX_H
22 //-----------------------------------------------------------------------------
23 #include <mgl2/wnd.h>
24 #include <wx/window.h>
25 #include <wx/image.h>
26 #include <wx/timer.h>
27 #include <wx/bitmap.h>
28 class mglCanvas;
29 //-----------------------------------------------------------------------------
30 /// Convert MathGL image to wxBitmap
31 wxBitmap MGL_EXPORT ConvertFromGraph(HMGL gr);
32 //-----------------------------------------------------------------------------
33 /// Class is Wx widget which display MathGL graphics
34 class MGL_EXPORT wxMathGL : public wxWindow
35 {
36 public:
37 	wxString appName;	///< Application name for message boxes
38 	bool AutoResize; 	///< Allow auto resizing (default is false)
39 
40 	wxMathGL(wxWindow *parent, wxWindowID id=-1, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=0, const wxString& name=wxPanelNameStr);
41 	virtual ~wxMathGL();
42 	double GetRatio();
SetPopup(wxMenu * p)43 	void SetPopup(wxMenu *p)	{	popup = p;	};	///< Set popup menu pointer
44 	void SetSize(int w, int h);		///< Set window/picture sizes
45 	void SetGraph(HMGL gr);	///< Set grapher object
SetGraph(mglGraph * GR)46 	inline void SetGraph(mglGraph *GR)
47 	{	SetGraph(GR->Self());	}
GetGraph()48 	inline HMGL GetGraph()	{	return (HMGL)gr;	}
49 
50 	/// Set drawing functions and its parameter
51 	inline void SetDraw(int (*func)(mglBase *gr, void *par), void *par=0)
52 	{	draw_func = func;	draw_par = par;	}
SetDraw(mglDraw * dr)53 	inline void SetDraw(mglDraw *dr)
54 	{	draw_cl = dr;	}
SetDraw(int (* draw)(mglGraph * gr))55 	inline void SetDraw(int (*draw)(mglGraph *gr))
56 	{	SetDraw(draw?mgl_draw_graph:0,(void*)draw);	}
ZoomRegion(mreal xx1,mreal xx2,mreal yy1,mreal yy2)57 	inline void ZoomRegion(mreal xx1,mreal xx2,mreal yy1, mreal yy2)
58 	{	x1=xx1;	y1=yy1;	x2=xx2;	y2=yy2;	}
59 
GetPer()60 	int GetPer() 	{return per;};		///< Get perspective value
GetPhi()61 	int GetPhi() 	{return phi;};		///< Get Phi-angle value
GetTet()62 	int GetTet() 	{return tet;};		///< Get Theta-angle value
GetAlpha()63 	bool GetAlpha()	{return alpha;};	///< Get transparency state
GetLight()64 	bool GetLight()	{return light;};	///< Get lightning state
GetZoom()65 	bool GetZoom()	{return zoom;};		///< Get mouse zooming state
GetRotate()66 	bool GetRotate()	{return rotate;};	///< Get mouse rotation state
67 
68 	void Repaint();
69 	void Update();			///< Update picture
70 	void Copy(); 			///< copy graphics to clipboard
71 	void Print();			///< Print plot
72 //	void Stop();			///< Stop execution
73 	void SetPer(int p);		///< Set perspective value
74 	void SetPhi(int p);		///< Set Phi-angle value
75 	void SetTet(int t);		///< Set Theta-angle value
76 	void SetAlpha(bool a);	///< Switch on/off transparency
77 	void SetLight(bool l);	///< Switch on/off lightning
78 	void SetZoom(bool z);	///< Switch on/off mouse zooming
79 	void SetRotate(bool r);	///< Switch on/off mouse rotation
80 	void ZoomIn();			///< Zoom in graphics
81 	void ZoomOut();			///< Zoom out graphics
82 	void Restore();			///< Restore zoom and rotation to default values
83 //	void Reload();			///< Reload data and execute script
84 	void ShiftLeft();		///< Shift graphics to left direction
85 	void ShiftRight();		///< Shift graphics to right direction
86 	void ShiftUp();			///< Shift graphics to up direction
87 	void ShiftDown();		///< Shift graphics to down direction
88 	void ExportPNG(wxString fname=L"");	///< export to PNG file
89 	void ExportPNGs(wxString fname=L"");	///< export to PNG file (no transparency)
90 	void ExportJPG(wxString fname=L"");	///< export to JPEG file
91 	void ExportBPS(wxString fname=L"");	///< export to bitmap EPS file
92 	void ExportEPS(wxString fname=L"");	///< export to vector EPS file
93 	void ExportSVG(wxString fname=L"");	///< export to SVG file
94 
95 	void Adjust();		///< Adjust plot size to fill entire window
96 	void NextSlide();	///< Show next slide
97 	void PrevSlide();	///< Show previous slide
98 	void Animation(bool st=true);	///< Start animation
99 
100 	void About();		///< Show about information
101 
102 protected:
103 	void OnPaint(wxPaintEvent& event);
104 	void OnSize(wxSizeEvent& event);
105 	void OnNextSlide(wxTimerEvent& evt);	///< Show next slide
106 	void OnMouseLeftDown(wxMouseEvent &ev);
107 	void OnMouseDown(wxMouseEvent &ev);
108 	void OnMouseLeftUp(wxMouseEvent &ev);
109 	void OnMouseRightUp(wxMouseEvent &ev);
110 	void OnMouseMove(wxMouseEvent &ev);
111 //	void MousePressEvent(QMouseEvent *);
112 //	void MouseReleaseEvent(QMouseEvent *);
113 //	void MouseMoveEvent(QMouseEvent *);
114 
115 	mglCanvas *gr;		///< pointer to grapher
116 	void *draw_par;		///< Parameters for drawing function mglCanvasWnd::DrawFunc.
117 	/// Drawing function for window procedure. It should return the number of frames.
118 	int (*draw_func)(mglBase *gr, void *par);
119 	mglDraw *draw_cl;
120 
121 	wxString MousePos;	///< Last mouse position
122 	wxBitmap pic;		///< Pixmap for drawing (changed by update)
123 	double tet, phi;	///< Rotation angles
124 	double per;			///< Value of perspective ( must be in [0,1) )
125 	bool alpha;			///< Transparency state
126 	bool light;			///< Lightning state
127 	bool zoom;			///< Mouse zoom state
128 	bool rotate;		///< Mouse rotation state
129 	mreal x1,x2,y1,y2;	///< Zoom in region
130 	wxMenu *popup;		///< Pointer to pop-up menu
131 	wxTimer *timer;		///< Timer for animation
132 	DECLARE_EVENT_TABLE()
133 private:
134 	int x0, y0, xe, ye;		///< Temporary variables for mouse
135 };
136 //-----------------------------------------------------------------------------
137 #endif
138