2006-10-09 17:38:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wxPieCtrl.h
|
|
|
|
// Purpose: wxPieCtrl (v0.1.2)
|
|
|
|
// Author: Volodymir (T-Rex) Tryapichko
|
|
|
|
// Modified by: Frank Weiler, 10.10.2006
|
|
|
|
// Created: June-07-2005
|
|
|
|
// RCS-ID: $Id:
|
|
|
|
// Copyright: (c) Volodymir (T-Rex) Tryapichko
|
|
|
|
// Licence: wxWidgets license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef _WX_PIE_CTRL
|
|
|
|
#define _WX_PIE_CTRL
|
|
|
|
|
2007-01-19 00:59:31 +00:00
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <wx/image.h>
|
|
|
|
#include <wx/dynarray.h>
|
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI 3.14159265358979
|
|
|
|
#endif
|
|
|
|
|
2007-01-19 14:30:18 +00:00
|
|
|
#if ! wxCHECK_VERSION(2,8,0)
|
2006-10-09 17:38:59 +00:00
|
|
|
WX_DECLARE_OBJARRAY(double, wxArrayDouble);
|
2007-01-19 14:30:18 +00:00
|
|
|
#endif
|
2006-10-09 17:38:59 +00:00
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// wxPiePart
|
|
|
|
// ------------------------------------------------------------------------
|
2007-01-10 01:01:24 +00:00
|
|
|
/// This class is used for storing data in wxPieCtrl.
|
2006-10-09 17:38:59 +00:00
|
|
|
class wxPiePart
|
|
|
|
{
|
|
|
|
double m_Value;
|
|
|
|
wxColour m_Colour;
|
|
|
|
wxString m_Label;
|
|
|
|
public:
|
|
|
|
/// Default constructor
|
|
|
|
wxPiePart();
|
|
|
|
/// Parametrized constructor
|
|
|
|
/*!
|
|
|
|
\param value used for drawing the pie. Specifies the size of the sector.
|
|
|
|
\param colour specifies the colour of the sector
|
|
|
|
\param label specifies the text to be shown in diagram legend
|
|
|
|
*/
|
|
|
|
wxPiePart(double value, wxColour colour, wxString label = wxEmptyString);
|
|
|
|
/// Copy constructor
|
2007-01-10 01:01:24 +00:00
|
|
|
wxPiePart(const wxPiePart & part);
|
2006-10-09 17:38:59 +00:00
|
|
|
/// Returns the colour of sector
|
|
|
|
wxColour GetColour() {return m_Colour;}
|
|
|
|
/// Sets the colour of sector
|
|
|
|
void SetColour(wxColour colour) {m_Colour = colour;}
|
|
|
|
/// Returns the size of sector
|
|
|
|
double GetValue() {return m_Value;}
|
|
|
|
/// Sets the size of sector
|
|
|
|
void SetValue(double value) {m_Value = fabs(value);}
|
|
|
|
/// Returns the label of sector
|
|
|
|
wxString GetLabel() {return m_Label;}
|
|
|
|
/// Sets the label of sector
|
|
|
|
void SetLabel(wxString value) {m_Label = value;}
|
2007-01-19 00:59:31 +00:00
|
|
|
//
|
2006-10-09 17:38:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WX_DECLARE_OBJARRAY(wxPiePart, wxPieSeries);
|
|
|
|
|
|
|
|
class wxPieCtrl;
|
|
|
|
|
|
|
|
// ========================================================================
|
|
|
|
// wxPieCtrlLegend
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/// The component draws a rectangle and outputs text information for
|
|
|
|
/// each sector of pie diagram
|
|
|
|
class wxPieCtrlLegend : public wxWindow
|
|
|
|
{
|
|
|
|
wxFont m_TitleFont;
|
|
|
|
wxFont m_LabelFont;
|
|
|
|
bool m_IsTransparent;
|
|
|
|
wxColour m_TitleColour;
|
2007-01-10 01:01:24 +00:00
|
|
|
wxColour m_LabelColour;
|
|
|
|
wxColour m_BackColour;
|
2006-10-09 17:38:59 +00:00
|
|
|
wxBitmap m_Background;
|
|
|
|
wxMemoryDC m_BackgroundDC;
|
|
|
|
unsigned int m_HorBorder;
|
2007-01-10 01:01:24 +00:00
|
|
|
unsigned int m_VerBorder;
|
|
|
|
wxString m_szTitle;
|
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
protected:
|
2007-05-10 09:10:51 +00:00
|
|
|
void MeasureText();
|
2006-10-09 17:38:59 +00:00
|
|
|
void RecreateBackground(wxMemoryDC & parentdc);
|
|
|
|
public:
|
|
|
|
/// Constructor
|
|
|
|
/*!
|
|
|
|
\param parent Pointer to a parent window
|
|
|
|
\param title Legend window title
|
|
|
|
\param pos Legend window position
|
|
|
|
\param sz Legend window size
|
|
|
|
\param style Window style
|
|
|
|
*/
|
2007-01-10 01:01:24 +00:00
|
|
|
wxPieCtrlLegend(wxPieCtrl * parent, wxString title = wxEmptyString,
|
2006-10-09 17:38:59 +00:00
|
|
|
wxPoint pos = wxPoint(10,10), wxSize sz = wxDefaultSize,
|
|
|
|
long style = 0);
|
|
|
|
/// Returns transparency flag of legend window
|
|
|
|
bool IsTransparent() {return m_IsTransparent;}
|
|
|
|
/// Sets transparency flag of legend window
|
2007-01-10 01:01:24 +00:00
|
|
|
void SetTransparent(bool value);
|
2006-10-09 17:38:59 +00:00
|
|
|
/// Returns the font used for displaying the labels of sectors
|
|
|
|
wxFont GetLabelFont() {return m_LabelFont;}
|
|
|
|
/// Sets the font used for displaying the labels of sectors
|
|
|
|
void SetLabelFont(wxFont font);
|
|
|
|
/// Returns the size of horizontal border of legend window
|
|
|
|
unsigned int GetHorBorder() {return m_HorBorder;}
|
|
|
|
/// Returns the size of vertical border of legend window
|
|
|
|
unsigned int GetVerBorder() {return m_VerBorder;}
|
|
|
|
/// Sets the size of horizontal border of legend window
|
|
|
|
void SetHorBorder(unsigned int value);
|
|
|
|
/// Sets the size of vertical border of legend window
|
|
|
|
void SetVerBorder(unsigned int value);
|
|
|
|
/// Returns the colour used for displaying the labels of sectors
|
|
|
|
wxColour GetLabelColour() {return m_LabelColour;}
|
|
|
|
/// Sets the colour used for displaying the labels of sectors
|
|
|
|
void SetLabelColour(wxColour colour);
|
|
|
|
/// Returns the colour used for displaying lagend window background
|
|
|
|
wxColour GetBackColour() {return m_BackColour;}
|
|
|
|
/// Sets the colour used for displaying legend window background
|
|
|
|
void SetBackColour(wxColour colour);
|
|
|
|
|
2007-01-10 01:01:24 +00:00
|
|
|
void SetLabel(const wxString& label);
|
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
void OnPaint(wxPaintEvent & event);
|
|
|
|
void OnEraseBackground(wxEraseEvent & event);
|
|
|
|
friend class wxPieCtrl;
|
|
|
|
};
|
|
|
|
// ========================================================================
|
|
|
|
// wxPieCtrl
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/// The component for drawing pie diagrams
|
|
|
|
class wxPieCtrl : public wxWindow
|
|
|
|
{
|
2007-01-24 16:58:11 +00:00
|
|
|
protected:
|
|
|
|
int m_padding;
|
2006-10-09 17:38:59 +00:00
|
|
|
wxBitmap m_CanvasBitmap;
|
|
|
|
wxMemoryDC m_CanvasDC;
|
|
|
|
wxColour m_BackColour;
|
|
|
|
wxPieCtrlLegend * m_Legend;
|
2007-01-24 16:58:11 +00:00
|
|
|
bool m_CanRepaint;
|
2007-01-10 01:01:24 +00:00
|
|
|
bool m_ShowEdges;
|
2007-01-19 00:59:31 +00:00
|
|
|
int m_lastCoveredPart;
|
2007-01-24 16:58:11 +00:00
|
|
|
//internal methods
|
|
|
|
void GetPartAngles(wxArrayDouble & angles);
|
2006-10-09 17:38:59 +00:00
|
|
|
void RecreateCanvas();
|
2007-01-24 16:58:11 +00:00
|
|
|
int GetCoveredPiePart(int x,int y);
|
|
|
|
void DrawParts(wxRect& pieRect);
|
2006-10-09 17:38:59 +00:00
|
|
|
void Draw(wxPaintDC & pdc);
|
|
|
|
public:
|
|
|
|
/// An array of wxPiePart objects for storing information about sectors
|
|
|
|
wxPieSeries m_Series;
|
2007-01-24 16:58:11 +00:00
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
wxPieCtrl(wxWindow * parent, wxWindowID id = wxID_ANY, wxPoint pos = wxDefaultPosition,
|
|
|
|
wxSize sz = wxDefaultSize, long style = 0, wxString name = wxT("wxPieCtrl"));
|
2007-01-24 16:58:11 +00:00
|
|
|
|
|
|
|
wxColour GetBackColour();
|
2006-10-09 17:38:59 +00:00
|
|
|
void SetBackColour(wxColour colour);
|
2007-01-24 16:58:11 +00:00
|
|
|
|
|
|
|
bool GetShowEdges();
|
2006-10-09 17:38:59 +00:00
|
|
|
void SetShowEdges(bool value);
|
2007-01-24 16:58:11 +00:00
|
|
|
|
|
|
|
void SetPadding(int pad);
|
|
|
|
int GetPadding();
|
2006-10-09 17:38:59 +00:00
|
|
|
/// Returns the pointer of diagram legend
|
|
|
|
wxPieCtrlLegend * GetLegend() {return m_Legend;}
|
|
|
|
virtual void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
|
2007-01-24 16:58:11 +00:00
|
|
|
|
2006-10-09 17:38:59 +00:00
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
void OnPaint(wxPaintEvent & event);
|
2007-01-10 01:01:24 +00:00
|
|
|
void OnSize(wxSizeEvent & event);
|
2007-01-19 00:59:31 +00:00
|
|
|
void OnMouseMove(wxMouseEvent& ev);
|
2007-01-24 16:58:11 +00:00
|
|
|
void OnEraseBackground(wxEraseEvent & /*event*/);
|
2006-10-09 17:38:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|