1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wxPieCtrl.h
3 // Purpose:     wxPieCtrl (v0.1.2)
4 // Author:      Volodymir (T-Rex) Tryapichko
5 // Modified by: Frank Weiler, 10.10.2006
6 // Created:     June-07-2005
7 // RCS-ID:      $Id:
8 // Copyright:   (c) Volodymir (T-Rex) Tryapichko
9 // Licence:     wxWidgets license
10 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PIE_CTRL
12 #define _WX_PIE_CTRL
13 
14 
15 #include <wx/wx.h>
16 #include <wx/image.h>
17 #include <wx/dynarray.h>
18 
19 #ifndef M_PI
20 #define M_PI 3.14159265358979
21 #endif
22 
23 // ========================================================================
24 //  wxPiePart
25 // ------------------------------------------------------------------------
26 ///	This class is used for storing data in wxPieCtrl.
27 class wxPiePart
28 {
29 	double m_Value;
30 	wxColour m_Colour;
31 	wxString m_Label;
32 public:
33 	/// Default constructor
34 	wxPiePart();
35 	/// Parametrized constructor
36 	/*!
37 		\param value used for drawing the pie. Specifies the size of the sector.
38 		\param colour specifies the colour of the sector
39 		\param label specifies the text to be shown in diagram legend
40 	*/
41 	wxPiePart(double value, wxColour colour, wxString label = wxEmptyString);
42 	/// Copy constructor
43 	wxPiePart(const wxPiePart & part);
44 	/// Returns the colour of sector
GetColour()45 	wxColour GetColour() {return m_Colour;}
46 	/// Sets the colour of sector
SetColour(wxColour colour)47 	void SetColour(wxColour colour) {m_Colour = colour;}
48 	/// Returns the size of sector
GetValue()49 	double GetValue() {return m_Value;}
50 	/// Sets the size of sector
SetValue(double value)51 	void SetValue(double value) {m_Value = fabs(value);}
52 	/// Returns the label of sector
GetLabel()53 	wxString GetLabel() {return m_Label;}
54 	/// Sets the label of sector
SetLabel(wxString value)55 	void SetLabel(wxString value) {m_Label = value;}
56 	//
57 };
58 
59 WX_DECLARE_OBJARRAY(wxPiePart, wxPieSeries);
60 
61 // ========================================================================
62 //  wxPieCtrl
63 // ------------------------------------------------------------------------
64 ///	The component for drawing pie diagrams
65 class wxPieCtrl : public wxWindow
66 {
67 using wxWindow::SetTransparent;
68 
69 protected:
70 	int m_padding;
71 	wxBitmap m_CanvasBitmap;
72 	wxMemoryDC m_CanvasDC;
73 	wxColour m_BackColour;
74 	bool m_CanRepaint;
75 	bool m_ShowEdges;
76 	int m_lastCoveredPart;
77         // parameters affecting legend
78         wxFont m_TitleFont;
79 	wxFont m_LabelFont;
80 	bool m_LegendIsTransparent;
81 	wxColour m_TitleColour;
82 	wxColour m_LabelColour;
83 	wxColour m_LegendBackColour;
84 	unsigned int m_legendHorBorder;
85 	unsigned int m_LegendVerBorder;
86 	wxString m_szTitle;
87     wxScrollBar* m_scrollBar;
88     int m_Scrollbar_width;
89     int m_firstlabelToDraw;
90 
91 	//internal methods
92 	void GetPartAngles(wxArrayDouble & angles);
93 	void RecreateCanvas();
94 	int GetCoveredPiePart(int x,int y);
95 	void DrawParts(wxRect& pieRect);
96         void DrawLegend(int left, int top);
97 	void Draw(wxPaintDC & pdc);
98 public:
99 	/// An array of wxPiePart objects for storing information about sectors
100 	wxPieSeries m_Series;
101 
102 	wxPieCtrl(wxWindow * parent, wxWindowID id = wxID_ANY, wxPoint pos = wxDefaultPosition,
103 		wxSize sz = wxDefaultSize, long style = 0, wxString name = wxT("wxPieCtrl"));
104 
105         ~wxPieCtrl();
106 
107 	wxColour GetBackColour();
108 	void SetBackColour(wxColour colour);
109 
110 	bool GetShowEdges();
111 	void SetShowEdges(bool value);
112 
113 	void SetPadding(int pad);
114 	int GetPadding();
115 	virtual void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
116 
117 	/// Returns transparency flag of legend box
IsTransparent()118 	bool IsTransparent() {return m_LegendIsTransparent;}
119 	/// Sets transparency flag of legend box
120 	void SetTransparent(bool value);
121 	/// Returns the font used for displaying the labels of sectors
GetLabelFont()122 	wxFont GetLabelFont() {return m_LabelFont;}
123 	/// Sets the font used for displaying the labels of sectors
124 	void SetLabelFont(wxFont font);
125 	/// Returns the size of horizontal border of legend box
GeHorLegendBorder()126 	unsigned int GeHorLegendBorder() {return m_legendHorBorder;}
127 	/// Returns the size of vertical border of legend box
GetVerLegendBorder()128 	unsigned int GetVerLegendBorder() {return m_LegendVerBorder;}
129 	/// Sets the size of horizontal border of legend box
130 	void SetHorLegendBorder(unsigned int value);
131 	/// Sets the size of vertical border of legend box
132 	void SetVerLegendBorder(unsigned int value);
133 	/// Returns the colour used for displaying the labels of sectors
GetLabelColour()134 	wxColour GetLabelColour() {return m_LabelColour;}
135 	/// Sets the colour used for displaying the labels of sectors
136 	void SetLabelColour(wxColour colour);
137 	/// Returns the colour used for displaying lagend box background
GetLegendBackColour()138 	wxColour GetLegendBackColour() {return m_LegendBackColour;}
139 	/// Sets the colour used for displaying legend box background
140 	void SetLegendBackColour(wxColour colour);
141 
142 	void SetLabel(const wxString& label);
143 
144 
145 	DECLARE_EVENT_TABLE()
146 	void OnPaint(wxPaintEvent & event);
147 	void OnSize(wxSizeEvent & event);
148 	void OnMouseMove(wxMouseEvent& ev);
149 	void OnEraseBackground(wxEraseEvent & /*event*/);
150 	void OnLegendScroll(wxScrollEvent& event);
151 
152 #ifdef __WXMAC__
153 private:
154     void                    SetupMacAccessibilitySupport();
155     void                    ResizeMacAccessibilitySupport();
156     void                    RemoveMacAccessibilitySupport();
157 
158     void*                   m_fauxResourcesView;
159 #endif
160 
161 };
162 
163 #endif
164